Skip to content

Commit 9515486

Browse files
committed
0.1 (19991020)
- Initial version
0 parents  commit 9515486

39 files changed

+6577
-0
lines changed

Makefile

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#
2+
# daemon: http://www.zip.com.au/~raf2/lib/software/daemon
3+
#
4+
# Copyright (c) 1999 raf
5+
#
6+
7+
# Uncomment these to override the defines in main.h
8+
# PATH_SEP = /
9+
# ROOT_DIR = /
10+
# PID_DIR = /var/run
11+
# ETC_DIR = /etc
12+
# APP = $(TARGETAPP)
13+
# DEFINES += -DPATH_SEP=\"$(PATH_SEP)\" -DROOT_DIR=\"$(ROOT_DIR)\" -DPID_DIR=\"$(PID_DIR)\" -DETC_DIR=\"$(ETC_DIR)\" -DAPP=\"$(APP)\"
14+
15+
# Uncomment these if your system doesn't have snprintf()
16+
# SNPRINTF = snprintf
17+
# DEFINES += -DNEEDS_SNPRINTF=1
18+
19+
# Uncomment this under SVR4 if not predefined
20+
# DEFINES += -DSVR4
21+
22+
PROJECT = daemon
23+
VERSION = 0.1
24+
TARGETAPP = daemon
25+
TARGETLIBNAME = prog
26+
INSTALLIBNAME = $(TARGETLIBNAME)-$(VERSION)
27+
TARGETLIB = lib$(TARGETLIBNAME).a
28+
INSTALLIB = lib$(INSTALLIBNAME).a
29+
TARGETDIST = $(PROJECT)-$(VERSION).tar.gz
30+
31+
PREFIX = /usr/local
32+
APPINSDIR = $(PREFIX)/bin
33+
LIBINSDIR = $(PREFIX)/lib
34+
MANINSDIR = $(PREFIX)/man
35+
HDRINSDIR = $(PREFIX)/include/$(TARGETLIBNAME)
36+
APPMANSECT = 1
37+
LIBMANSECT = 3
38+
39+
APPFILES = main
40+
APPCFILES = $(patsubst %,%.c,$(APPFILES))
41+
APPOFILES = $(patsubst %,%.o,$(APPFILES))
42+
APPHFILES = # $(patsubst %,%.h,$(APPFILES))
43+
APPMFILES = $(TARGETAPP).$(APPMANSECT)
44+
APPMANDIR = $(MANINSDIR)/man$(APPMANSECT)
45+
APPCATDIR = $(MANINSDIR)/cat$(APPMANSECT)
46+
47+
LIBFILES = daemon prog opt mem msg err sig lim slog fifo $(SNPRINTF)
48+
LIBCFILES = $(patsubst %,%.c,$(LIBFILES))
49+
LIBOFILES = $(patsubst %,%.o,$(LIBFILES))
50+
LIBHFILES = $(patsubst %,%.h,$(LIBFILES))
51+
LIBMFILES = $(patsubst %,%.$(LIBMANSECT),$(LIBFILES)) lib$(TARGETLIBNAME).$(LIBMANSECT)
52+
LIBMANDIR = $(MANINSDIR)/man$(LIBMANSECT)
53+
LIBTESTS = $(patsubst %,%.test,$(LIBFILES))
54+
55+
DEFINES += -DBUILD_PROG
56+
57+
CFLAGS = -g -O2 $(DEFINES) -Wall -pedantic
58+
LDFLAGS = -L. -l$(TARGETLIBNAME)
59+
ARFLAGS = cr
60+
61+
$(TARGETAPP): $(APPOFILES) $(TARGETLIB)
62+
$(CC) $(CFLAGS) -o $(TARGETAPP) $(APPOFILES) $(LDFLAGS)
63+
64+
$(TARGETLIB): $(LIBOFILES)
65+
$(AR) $(ARFLAGS) $(TARGETLIB) $(LIBOFILES)
66+
67+
$(LIBTESTS): $(TARGETLIB)
68+
%.test: %.c
69+
$(CC) $(CFLAGS) -DTEST -o $@ $< $(LDFLAGS)
70+
71+
test: $(LIBTESTS)
72+
@for i in $(LIBTESTS); do ./$$i; echo; done
73+
74+
tags:
75+
@ctags $(APPCFILES) $(APPHFILES) $(LIBCFILES) $(LIBHFILES)
76+
77+
depend dep: $(APPCFILES) $(APPHFILES) $(LIBCFILES) $(LIBHFILES)
78+
@makedepend $(DEFINES) $(APPCFILES) $(LIBCFILES)
79+
80+
clean:
81+
@rm -f $(APPOFILES) $(LIBOFILES) tags core Makefile.bak .makefile.bak
82+
83+
clobber: clean
84+
@rm -f $(TARGETAPP) $(TARGETLIB) $(LIBTESTS)
85+
86+
dist-clobber: clobber
87+
@perl -pi -e 'last if /[D]O NOT DELETE/;' Makefile
88+
89+
dist: dist-clobber
90+
@srcdir=`basename \`pwd\``; cd ..; tar czf $(TARGETDIST) $$srcdir
91+
92+
install: install-app install-lib
93+
install-app: install-app-bin # install-app-man
94+
install-lib: install-lib-bin install-lib-h # install-lib-man
95+
96+
install-app-bin:
97+
install -m 555 $(TARGETAPP) $(APPINSDIR)
98+
#install-app-man:
99+
# install -m 444 $(APPMFILES) $(APPMANDIR)
100+
install-lib-bin:
101+
install -m 555 $(TARGETLIB) $(LIBINSDIR)/$(INSTALLIB)
102+
rm -f $(LIBINSDIR)/$(TARGETLIB)
103+
ln -s $(INSTALLIB) $(LIBINSDIR)/$(TARGETLIB)
104+
install-lib-h:
105+
-[ ! -d $(HDRINSDIR) ] && mkdir -p $(HDRINSDIR)
106+
install -m 444 $(LIBHFILES) $(HDRINSDIR)
107+
#install-lib-man:
108+
# install -m 444 $(LIBMFILES) $(LIBMANDIR)
109+
110+
uninstall: uninstall-app uninstall-lib
111+
uninstall-app: uninstall-app-bin # uninstall-app-man
112+
uninstall-lib: uninstall-lib-bin uninstall-lib-h # uninstall-lib-man
113+
114+
uninstall-app-bin:
115+
-cd $(APPINSDIR) && rm -f $(TARGETAPP)
116+
#uninstall-app-man:
117+
# -cd $(APPMANDIR) && rm -f $(APPMFILES) && cd $(APPCATDIR) && rm -f $(APPMFILES)
118+
uninstall-lib-bin:
119+
-cd $(LIBINSDIR) && rm -f $(TARGETLIB) $(INSTALLIB)
120+
uninstall-lib-h:
121+
-cd $(HDRINSDIR) && rm -f $(LIBHFILES) && cd .. && rmdir $(HDRINSDIR)
122+
#uninstall-lib-man:
123+
# cd $(LIBMANDIR) && rm -f $(LIBMFILES)
124+
125+
help:
126+
@echo "This makefile provides the following targets."
127+
@echo
128+
@echo "make $(TARGETAPP) -- makes $(TARGETAPP) and $(TARGETLIB) (default)"
129+
@echo "make $(TARGETLIB) -- just makes $(TARGETLIB)"
130+
@echo "make tags -- generates a tags file using ctags"
131+
@echo "make depend -- generates source dependencies using makedepend"
132+
@echo "make dep -- same as depend"
133+
@echo "make clean -- removes object files, tags, core and Makefile.bak"
134+
@echo "make clobber -- same as clean but also removes $(TARGETAPP) and $(TARGETLIB)"
135+
@echo "make dist-clobber -- same as clobber but also removes source dependencies"
136+
@echo "make dist -- creates the distribution: ../$(TARGETDIST)"
137+
@echo "make install -- installs everything under $(PREFIX)"
138+
@echo "make install-app -- installs $(TARGETAPP) and its man page"
139+
@echo "make install-app-bin -- installs $(TARGETAPP) in $(APPINSDIR)"
140+
@echo "make install-app-man -- installs the $(TARGETAPP) man page in $(APPMANDIR)"
141+
@echo "make install-lib -- installs $(TARGETLIB), its headers and man pages"
142+
@echo "make install-lib-bin -- installs $(TARGETLIB) in $(LIBINSDIR)"
143+
@echo "make install-lib-h -- installs $(TARGETLIB) headers in $(HDRINSDIR)"
144+
@echo "make install-lib-man -- installs $(TARGETLIB) man pages in $(LIBMANDIR)"
145+
@echo "make uninstall -- uninstalls everything"
146+
@echo "make uninstall-app -- uninstalls $(TARGETAPP) and its man page"
147+
@echo "make uninstall-app-bin -- uninstalls $(TARGETAPP) from $(APPINSDIR)"
148+
@echo "make uninstall-app-man -- uninstalls the $(TARGETAPP) man page from $(APPMANDIR)"
149+
@echo "make uninstall-lib -- uninstalls $(TARGETLIB), its headers and man pages"
150+
@echo "make uninstall-lib-bin -- uninstalls $(TARGETLIB) from $(LIBINSDIR)"
151+
@echo "make uninstall-lib-h -- uninstalls $(TARGETLIB) headers from $(HDRINSDIR)"
152+
@echo "make uninstall-lib-man -- uninstalls $(TARGETLIB) man pages from $(LIBMANDIR)"
153+
@echo "make help -- shows this list of targets"
154+
@echo
155+

README

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
ABOUT
2+
~~~~~
3+
This contains the unfinished source for the daemon program and the prog library.
4+
5+
daemon is a command that invokes other commands (specified on the command line)
6+
after placing itself in a process context suitable for a daemon.
7+
this is useful for writing daemons in languages other than C, C++ or perl.
8+
9+
the prog library contains functions for placing a C or C++ program in a
10+
process context suitable for daemon.
11+
12+
description of initialising a daemon context:
13+
14+
Disables core files to prevent security holes.
15+
If the process wasn't started by init(8) or inetd(8):
16+
Backgrounds the process to lose process group leadership.
17+
Becomes a process session leader.
18+
When SVR4 is defined:
19+
Backgrounds the process again to lose process group leadership.
20+
This prevents the process from gaining a controlling terminal.
21+
Under BSD, you must still include O_NOCTTY when opening terminals
22+
to prevent the process from gaining a controlling terminal.
23+
Changes directory to the root directory so as not to hamper umounts.
24+
Clears the umask to enable explicit file modes.
25+
If the process wasn't started by inetd(8):
26+
Closes all files (as determined by sysconf(2)).
27+
Opens stdin, stdout and stderr to /dev/null in case something needs them.
28+
If the hup parameter is non-null:
29+
Registers a SIGHUP handler (prog library only).
30+
If the term parameter is non-null:
31+
Registers a SIGTERM handler (prog library only).
32+
If the name parameter is non-null:
33+
Places the process id in the file system and locks it.
34+
35+
not all of the unit tests are complete.
36+
37+
not all of the man pages are written (but the code is copiously documented).
38+
39+
both the unit tests and the man pages are currently being written.
40+
41+
this is only currently known to work on Linux Redhat 6.0.
42+
it will be tested again on Solaris 2.6 soon.
43+
44+
INSTALL
45+
~~~~~~~
46+
there is no autoconf script so you will no doubt encounter problems.
47+
an ansi C and posix.1 environment will help greatly.
48+
49+
to start:
50+
51+
make
52+
make test
53+
54+
to install just the daemon program:
55+
56+
make install-app
57+
58+
to install just the prog library:
59+
60+
make install-lib
61+
62+
to install both:
63+
64+
make install
65+
66+
for more details:
67+
68+
make help
69+
70+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
71+
url: http://www.zip.com.au/~raf2/lib/software/daemon
72+
date: 19991020
73+
author: raf <raf2@zip.com.au>
74+

daemon.1

Whitespace-only changes.

daemon.3

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
.\" Copyright 1999 raf (raf2@zip.com.au)
2+
.TH daemon 3 "25 June 1999" "raf" "Twisted Systems Freeware"
3+
.SH NAME
4+
daemon_init, daemon_close - initialise and close a daemon
5+
.SH SYNOPSIS
6+
.nf
7+
.B #include <daemon/daemon.h>
8+
.B #include <daemon/sig.h>
9+
.sp
10+
.BI "int daemon_init(const char *" name ", sighandler_t *" hup ", sighandler_t *" term );
11+
.sp
12+
.BI "int daemon_close()"
13+
.fi
14+
.SH DESCRIPTION
15+
.I daemon_init()
16+
initialises a daemon by performing the following tasks. Disables core files to
17+
prevent security holes. Backgrounds the process to lose process group
18+
leadership. Becomes a process session leader. When SVR4 is defined, backgrounds
19+
the process again to lose process group leadership. This prevents the process
20+
from gaining a controlling terminal. Under BSD, you must include O_NOCTTY when
21+
opening terminals to prevent the process from gaining a controlling terminal.
22+
Changes the current directory to the root directory so as not to hamper
23+
umounts. Clears the umask to enable explicit file modes. Closes all files (as
24+
determined by sysconf(2)). Opens stdin, stdout and stderr to /dev/null in case
25+
something expects them to be open. If
26+
.I hup
27+
is non-null, registers a SIGHUP handler. If
28+
.I term
29+
is non-null, registers a SIGTERM handler. If
30+
.I name
31+
is non-null, places the process id in the file system and locks it.
32+
.PP
33+
.I daemon_close()
34+
unlinks the daemon's (locked) process id file.
35+
.SH RETURNS
36+
Returns 0 on success, -1 on error (with errno set appropriately).
37+
Reasons for failure are: setrlimit(2), fork(2), chdir(2), sysconf(2),
38+
open(2), dup2(2), open(2), fcntl(2), write(2), sigemptyset(2), sigaddset(2),
39+
sigaction(2), ENAMETOOLONG if the path for the process id file is too long,
40+
and ENOMEM if memory for the path cannot be allocated.
41+
.SH "SEE ALSO"
42+
.BR daemon(1),
43+
.BR err(3),
44+
.BR fifo(3),
45+
.BR lim(3),
46+
.BR mem(3),
47+
.BR msg(3),
48+
.BR prog(3),
49+
.BR sig(3),
50+
.BR slog(3)

0 commit comments

Comments
 (0)