3 * $Id: pixie.c,v 1.2 1999/12/22 22:13:42 mdw Exp $
5 * Passphrase pixie for Catacomb
7 * (c) 1999 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
14 * Catacomb is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * Catacomb is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
24 * You should have received a copy of the GNU Library General Public
25 * License along with Catacomb; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 /*----- Revision history --------------------------------------------------*
33 * Revision 1.2 1999/12/22 22:13:42 mdw
34 * Fix bug in passphrase flushing loop.
36 * Revision 1.1 1999/12/22 15:58:41 mdw
37 * Passphrase pixie support.
41 /*----- Header files ------------------------------------------------------*/
56 #include <sys/types.h>
63 #include <sys/ioctl.h>
67 #include <sys/socket.h>
70 #include <mLib/alloc.h>
71 #include <mLib/dstr.h>
72 #include <mLib/fdflags.h>
73 #include <mLib/mdwopt.h>
74 #include <mLib/quis.h>
75 #include <mLib/report.h>
77 #include <mLib/selbuf.h>
84 #include "passphrase.h"
87 /*----- Static variables --------------------------------------------------*/
89 static unsigned long timeout
= 300;
91 static unsigned verbose
= 1;
92 static const char *command
= 0;
94 static unsigned flags
= 0;
100 /*----- Event logging -----------------------------------------------------*/
104 * Arguments: @const char *p@ = @printf@-style format string
105 * @...@ = extra arguments to fill in
109 * Use: Writes out a timestamped log message.
112 static void log(const char *p
, ...)
117 if (!(flags
& F_SYSLOG
)) {
119 struct tm
*tm
= localtime(&t
);
121 d
.len
+= strftime(d
.buf
, d
.sz
, "%Y-%m-%d %H:%M:%S ", tm
);
124 dstr_vputf(&d
, p
, ap
);
127 if (flags
& F_SYSLOG
)
128 syslog(LOG_NOTICE
, "%s", d
.buf
);
131 dstr_write(&d
, stderr
);
136 /*----- Passphrase management ---------------------------------------------*/
138 /* --- Data structures --- */
140 typedef struct phrase
{
150 /* --- Variables --- */
152 #define P_ROOT ((phrase *)&p_root)
153 static struct { phrase
*next
; phrase
*prev
; } p_root
= { P_ROOT
, P_ROOT
};
155 /* --- @p_free@ --- *
157 * Arguments: @phrase *p@ = pointer to phrase block
161 * Use: Frees a phrase block.
164 static void p_free(phrase
*p
)
167 sel_rmtimer(&p
->timer
);
170 p
->next
->prev
= p
->prev
;
171 p
->prev
->next
= p
->next
;
175 /* --- @p_timer@ --- *
177 * Arguments: @struct timeval *tv@ = current time
178 * @void *p@ = pointer to phrase
182 * Use: Expires a passphrase.
185 static void p_timer(struct timeval
*tv
, void *p
)
189 log("expiring passphrase `%s'", pp
->tag
);
193 /* --- @p_alloc@ --- *
195 * Arguments: @size_t sz@ = amount of memory required
197 * Returns: Pointer to allocated memory, or null.
199 * Use: Allocates some locked memory, flushing old passphrases if
200 * there's not enough space.
203 static void *p_alloc(size_t sz
)
207 if ((p
= l_alloc(&lm
, sz
)) != 0)
209 if (P_ROOT
->next
== P_ROOT
)
212 log("flushing passphrase `%s' to free up needed space",
215 p_free(P_ROOT
->next
);
219 /* --- @p_find@ --- *
221 * Arguments: @const char *tag@ = pointer to tag to find
223 * Returns: Pointer to passphrase block, or null.
225 * Use: Finds a passphrase with a given tag.
228 static phrase
*p_find(const char *tag
)
232 for (p
= P_ROOT
->next
; p
!= P_ROOT
; p
= p
->next
) {
233 if (strcmp(p
->tag
, tag
) == 0) {
236 sel_rmtimer(&p
->timer
);
237 gettimeofday(&tv
, 0);
239 sel_addtimer(&sel
, &p
->timer
, &tv
, p_timer
, p
);
241 p
->next
->prev
= p
->prev
;
242 p
->prev
->next
= p
->next
;
244 p
->prev
= P_ROOT
->prev
;
245 P_ROOT
->prev
->next
= p
;
255 * Arguments: @const char *tag@ = pointer to tag string
256 * @const char *p@ = pointer to passphrase
257 * @unsigned long t@ = expiry timeout
259 * Returns: Pointer to newly-added passphrase.
261 * Use: Adds a new passphrase. The tag must not already exist.
264 static phrase
*p_add(const char *tag
, const char *p
, unsigned long t
)
266 size_t sz
= strlen(p
) + 1;
267 char *l
= p_alloc(sz
);
270 /* --- Make sure the locked memory was allocated --- */
275 /* --- Fill in some other bits of the block --- */
280 pp
->tag
= xstrdup(tag
);
283 /* --- Set the timer --- */
288 gettimeofday(&tv
, 0);
290 sel_addtimer(&sel
, &pp
->timer
, &tv
, p_timer
, pp
);
293 /* --- Link the block into the chain --- */
296 pp
->prev
= P_ROOT
->prev
;
297 P_ROOT
->prev
->next
= pp
;
302 /* --- @p_flush@ --- *
304 * Arguments: @const char *tag@ = pointer to tag string, or zero for all
308 * Use: Immediately flushes either a single phrase or all of them.
311 static void p_flush(const char *tag
)
315 if (!tag
&& verbose
> 1)
316 log("flushing all passphrases");
318 while (p
!= P_ROOT
) {
319 phrase
*pp
= p
->next
;
322 else if (strcmp(p
->tag
, tag
) == 0) {
324 log("flushing passphrase `%s'", tag
);
332 /*----- Reading passphrases -----------------------------------------------*/
334 /* --- @p_request@ --- *
336 * Arguments: @const char *msg@ = message string
337 * @const char *tag@ = pointer to tag string
338 * @char *buf@ = pointer to (locked) buffer
339 * @size_t sz@ = size of buffer
341 * Returns: Zero if all went well, nonzero otherwise.
343 * Use: Requests a passphrase from the user.
346 static int p_request(const char *msg
, const char *tag
, char *buf
, size_t sz
)
348 /* --- If there's a passphrase-fetching command, run it --- */
357 /* --- Substitute the prompt string into the command --- */
361 const char *q
= strchr(p
, '%');
384 /* --- Create a pipe and start a child process --- */
388 if ((kid
= fork()) < 0)
391 /* --- Child process --- */
395 if (dup2(fd
[1], STDOUT_FILENO
) < 0)
398 execl("/bin/sh", "sh", "-c", d
.buf
, (void *)0);
402 /* --- Read the data back into my buffer --- */
405 if ((r
= read(fd
[0], buf
, sz
- 1)) >= 0) {
406 char *q
= memchr(buf
, '\n', r
);
418 /* --- Tidy up when things go wrong --- */
429 /* --- Read a passphrase from the terminal --- *
431 * Use the standard Catacomb passphrase-reading function, so it'll read the
432 * passphrase from a file descriptor or something if the appropriate
433 * environment variable is set.
439 dstr_putf(&d
, "%s %s: ", msg
, tag
);
440 rc
= pixie_getpass(d
.buf
, buf
, sz
);
448 * Arguments: @const char *tag@ = pointer to tag string
449 * @unsigned mode@ = reading mode (verify?)
450 * @time_t exp@ = expiry time suggestion
452 * Returns: Pointer to passphrase, or zero.
454 * Use: Reads a passphrase from somewhere.
457 static const char *p_get(const char *tag
, unsigned mode
, time_t exp
)
464 /* --- Write a log message --- */
467 log("passphrase `%s' requested", tag
);
469 /* --- Try to find the phrase --- */
471 if ((p
= p_find(tag
)) == 0) {
472 if ((pp
= p_alloc(LBUFSZ
)) == 0)
474 if (p_request("Passphrase", tag
, pp
, LBUFSZ
) < 0)
476 p
= p_add(tag
, pp
, exp
);
481 /* --- If verification is requested, verify the passphrase --- */
483 if (mode
== PMODE_VERIFY
) {
484 if (!pp
&& (pp
= p_alloc(LBUFSZ
)) == 0)
486 if (p_request("Verify passphrase", tag
, pp
, LBUFSZ
) < 0)
488 if (strcmp(pp
, p
->p
) != 0) {
490 log("passphrases for `%s' don't match", tag
);
496 /* --- Tidy up and return the passphrase --- */
499 memset(pp
, 0, LBUFSZ
);
504 /* --- Tidy up if things went wrong --- */
508 memset(pp
, 0, LBUFSZ
);
516 /*----- Server command parsing --------------------------------------------*/
518 /* --- Data structures --- */
520 typedef struct pixserv
{
526 #define PIXSERV_TIMEOUT 300
528 /* --- @pixserv_expire@ --- *
530 * Arguments: @struct timeval *tv@ = pointer to current time
531 * @void *p@ = pointer to server block
535 * Use: Expires a pixie connection if the remote end decides he's not
536 * interested any more.
539 static void pixserv_expire(struct timeval
*tv
, void *p
)
542 if (px
->fd
!= px
->b
.reader
.fd
)
544 selbuf_disable(&px
->b
);
545 close(px
->b
.reader
.fd
);
549 /* --- @pixserv_write@ --- *
551 * Arguments: @pixserv *px@ = pointer to server block
552 * @const char *p@ = pointer to skeleton string
553 * @...@ = other arguments to fill in
557 * Use: Formats a string and emits it to the output file.
560 static void pixserv_write(pixserv
*px
, const char *p
, ...)
566 dstr_vputf(&d
, p
, ap
);
567 write(px
->fd
, d
.buf
, d
.len
);
572 /* --- @pixserv_timeout@ --- *
574 * Arguments: @const char *p@ = pointer to timeout string
576 * Returns: Timeout in seconds.
578 * Use: Translates a string to a timeout value in seconds.
581 static unsigned long pixserv_timeout(const char *p
)
589 t
= strtoul(p
, &q
, 0);
594 case 's': if (q
[1] != 0)
601 /* --- @pixserv_line@ --- *
603 * Arguments: @char *s@ = pointer to the line read
604 * @void *p@ = pointer to server block
608 * Use: Handles a line read from the client.
611 static void pixserv_line(char *s
, void *p
)
617 /* --- Handle an end-of-file --- */
619 sel_rmtimer(&px
->timer
);
621 if (px
->fd
!= px
->b
.reader
.fd
)
623 selbuf_disable(&px
->b
);
624 close(px
->b
.reader
.fd
);
628 /* --- Fiddle the timeout --- */
632 gettimeofday(&tv
, 0);
633 tv
.tv_sec
+= PIXSERV_TIMEOUT
;
634 sel_addtimer(&sel
, &px
->timer
, &tv
, pixserv_expire
, px
);
637 /* --- Scan out the first word --- */
639 if ((q
= str_getword(&s
)) == 0)
641 for (qq
= q
; *qq
; qq
++)
642 *qq
= tolower((unsigned char)*qq
);
644 /* --- Handle a help request --- */
646 if (strcmp(q
, "help") == 0) {
648 INFO Commands supported:\n\
651 INFO PASS tag [expire]\n\
652 INFO VERIFY tag [expire]\n\
659 /* --- List the passphrases --- */
661 else if (strcmp(q
, "list") == 0) {
664 for (p
= P_ROOT
->next
; p
!= P_ROOT
; p
= p
->next
) {
666 pixserv_write(px
, "ITEM %s no-expire\n", p
->tag
);
669 gettimeofday(&tv
, 0);
670 TV_SUB(&tv
, &p
->timer
.tv
, &tv
);
671 pixserv_write(px
, "ITEM %s %i\n", p
->tag
, tv
.tv_sec
);
674 pixserv_write(px
, "OK\n");
677 /* --- Request a passphrase --- */
679 else if ((mode
= PMODE_READ
, strcmp(q
, "pass") == 0) ||
680 (mode
= PMODE_VERIFY
, strcmp(q
, "verify") == 0)) {
684 if ((q
= str_getword(&s
)) == 0)
685 pixserv_write(px
, "FAIL missing tag\n");
686 else if ((t
= pixserv_timeout(s
)) == 0)
687 pixserv_write(px
, "FAIL bad timeout\n");
688 else if ((p
= p_get(q
, mode
, t
> timeout ? timeout
: t
)) == 0)
689 pixserv_write(px
, "FAIL error reading passphrase\n");
691 pixserv_write(px
, "OK %s\n", p
);
694 /* --- Flush existing passphrases --- */
696 else if (strcmp(q
, "flush") == 0) {
699 pixserv_write(px
, "OK\n");
702 /* --- Shut the server down --- */
704 else if (strcmp(q
, "quit") == 0) {
706 log("client requested shutdown");
707 pixserv_write(px
, "OK\n");
711 /* --- Report an error for other commands --- */
714 pixserv_write(px
, "FAIL unknown command `%s'\n", q
);
717 /* --- @pixserv_create@ --- *
719 * Arguments: @int fd@ = file descriptor to read from
720 * @int ofd@ = file descriptor to write to
724 * Use: Creates a new Pixie server instance for a new connection.
727 static void pixserv_create(int fd
, int ofd
)
729 pixserv
*px
= CREATE(pixserv
);
731 fdflags(fd
, O_NONBLOCK
, O_NONBLOCK
, FD_CLOEXEC
, FD_CLOEXEC
);
733 fdflags(ofd
, O_NONBLOCK
, O_NONBLOCK
, FD_CLOEXEC
, FD_CLOEXEC
);
735 selbuf_init(&px
->b
, &sel
, fd
, pixserv_line
, px
);
736 gettimeofday(&tv
, 0);
737 tv
.tv_sec
+= PIXSERV_TIMEOUT
;
738 sel_addtimer(&sel
, &px
->timer
, &tv
, pixserv_expire
, px
);
741 /* --- @pixserv_accept@ --- *
743 * Arguments: @int fd@ = file descriptor
744 * @unsigned mode@ = what's happened
745 * @void *p@ = an uninteresting argument
749 * Use: Accepts a new connection.
752 static void pixserv_accept(int fd
, unsigned mode
, void *p
)
755 struct sockaddr_un sun
;
756 int sunsz
= sizeof(sun
);
758 if (mode
!= SEL_READ
)
760 if ((nfd
= accept(fd
, (struct sockaddr
*)&sun
, &sunsz
)) < 0) {
762 log("new connection failed: %s", strerror(errno
));
765 pixserv_create(nfd
, nfd
);
768 /*----- Setting up the server ---------------------------------------------*/
770 /* --- @unlinksocket@ --- *
776 * Use: Tidies up the socket when it's finished with.
779 static char *sockpath
;
781 static void unlinksocket(void)
787 /* --- @pix_sigdie@ --- *
789 * Arguments: @int sig@ = signal number
790 * @void *p@ = uninteresting argument
794 * Use: Shuts down the program after a fatal signal.
797 static void pix_sigdie(int sig
, void *p
)
804 case SIGTERM
: p
= "SIGTERM"; break;
805 case SIGINT
: p
= "SIGINT"; break;
807 sprintf(buf
, "signal %i", sig
);
811 log("shutting down on %s", p
);
816 /* --- @pix_sigflush@ --- *
818 * Arguments: @int sig@ = signal number
819 * @void *p@ = uninteresting argument
823 * Use: Flushes the passphrase cache on receipt of a signal.
826 static void pix_sigflush(int sig
, void *p
)
833 case SIGHUP
: p
= "SIGHUP"; break;
834 case SIGQUIT
: p
= "SIGQUIT"; break;
836 sprintf(buf
, "signal %i", sig
);
840 log("received %s; flushing passphrases", p
);
845 /* --- @pix_setup@ --- *
847 * Arguments: @struct sockaddr_un *sun@ = pointer to address to use
848 * @size_t sz@ = size of socket address
852 * Use: Sets up the pixie's Unix-domain socket.
855 static void pix_setup(struct sockaddr_un
*sun
, size_t sz
)
859 /* --- Set up the parent directory --- */
863 char *p
= sun
->sun_path
;
864 char *q
= strrchr(p
, '/');
873 if (stat(d
.buf
, &st
))
874 die(1, "couldn't stat `%s': %s", d
.buf
, strerror(errno
));
875 if (st
.st_mode
& 0077)
876 die(1, "parent directory `%s' has group or world access", d
.buf
);
880 /* --- Initialize the socket --- */
888 if ((fd
= socket(PF_UNIX
, SOCK_STREAM
, 0)) < 0)
889 die(1, "couldn't create socket: %s", strerror(errno
));
890 if (bind(fd
, (struct sockaddr
*)sun
, sz
) < 0) {
892 if (errno
!= EADDRINUSE
)
893 die(1, "couldn't bind to address: %s", strerror(e
));
895 die(1, "too many retries; giving up");
897 if (connect(fd
, (struct sockaddr
*)sun
, sz
)) {
898 if (errno
!= ECONNREFUSED
)
899 die(1, "couldn't bind to address: %s", strerror(e
));
901 log("stale socket found; removing it");
902 unlink(sun
->sun_path
);
906 log("server already running; shutting it down");
907 write(fd
, "QUIT\n", 5);
913 chmod(sun
->sun_path
, 0600);
914 fdflags(fd
, O_NONBLOCK
, O_NONBLOCK
, FD_CLOEXEC
, FD_CLOEXEC
);
916 die(1, "couldn't listen on socket: %s", strerror(errno
));
919 /* --- Set up the rest of the server --- */
922 static sel_file serv
;
923 sockpath
= sun
->sun_path
;
924 atexit(unlinksocket
);
925 sel_initfile(&sel
, &serv
, fd
, SEL_READ
, pixserv_accept
, 0);
930 /*----- Client support code -----------------------------------------------*/
932 /* --- Variables --- */
934 static selbuf c_server
, c_client
;;
936 /* --- Line handler functions --- */
938 static void c_uline(char *s
, void *p
)
945 write(c_server
.reader
.fd
, s
, sz
);
948 static void c_sline(char *s
, void *p
)
952 moan("server closed the connection");
958 /* --- @pix_client@ --- *
960 * Arguments: @struct sockaddr_un *sun@ = pointer to socket address
961 * @size_t sz@ = size of socket address
962 * @char *argv[]@ = pointer to arguments to send
966 * Use: Performs client-side actions for the passphrase pixie.
969 static void pix_client(struct sockaddr_un
*sun
, size_t sz
, char *argv
[])
973 /* --- Open the socket --- */
975 if ((fd
= socket(PF_UNIX
, SOCK_STREAM
, 0)) < 0)
976 die(1, "couldn't create socket: %s", strerror(errno
));
977 if (connect(fd
, (struct sockaddr
*)sun
, sz
))
978 die(1, "couldn't connect to server: %s", strerror(errno
));
979 selbuf_init(&c_server
, &sel
, fd
, c_sline
, 0);
981 /* --- If there are any arguments, turn them into a string --- */
984 selbuf_init(&c_client
, &sel
, STDIN_FILENO
, c_uline
, 0);
993 write(fd
, d
.buf
, d
.len
);
998 /* --- And repeat --- */
1004 /*----- Main code ---------------------------------------------------------*/
1006 /* --- @help@, @version@, @usage@ --- *
1008 * Arguments: @FILE *fp@ = stream to write on
1012 * Use: Emit helpful messages.
1015 static void usage(FILE *fp
)
1019 $ [-qvidl] [-c command] [-t timeout] [-s socket]\n\
1020 $ [-s socket] -C [command args...]\n\
1024 static void version(FILE *fp
)
1026 pquis(fp
, "$, Catacomb version " VERSION
"\n");
1029 static void help(FILE *fp
)
1035 The Catacomb passphrase pixie collects and caches passphrases used to\n\
1036 protect important keys. Options provided:\n\
1038 -h, --help Show this help text.\n\
1039 -V, --version Show the program's version number.\n\
1040 -u, --usage Show a (very) terse usage summary.\n\
1042 -C, --client Connect to a running pixie as a client.\n\
1044 -q, --quiet Emit fewer log messages.\n\
1045 -v, --version Emit more log messages.\n\
1046 -s, --socket=FILE Name the pixie's socket.\n\
1047 -c, --command=COMMAND Shell command to read a passphrase.\n\
1048 -t, --timeout=TIMEOUT Length of time to retain a passphrase in memory.\n\
1049 -i, --interactive Allow commands to be typed interactively.\n\
1050 -l, --syslog Emit log messages to the system log.\n\
1052 The COMMAND may contain `%m' and `%t' markers which are replaced by a\n\
1053 prompt message and the passphrase tag respectively. The TIMEOUT is an\n\
1054 integer, optionally followed by `d', `h', `m' or `s' to specify units of\n\
1055 days, hours, minutes or seconds respectively.\n\
1057 In client mode, if a command is specified on the command line, it is sent\n\
1058 to the running server; otherwise the program reads requests from stdin.\n\
1059 Responses from the pixie are written to stdout. Send a HELP request for\n\
1060 a quick summary of the pixie communication protocol.\n\
1066 * Arguments: @int argc@ = number of arguments
1067 * @char *argv[]@ = vector of argument values
1069 * Returns: Zero if OK.
1071 * Use: Main program. Listens on a socket and responds with a PGP
1072 * passphrase when asked.
1075 int main(int argc
, char *argv
[])
1078 struct sockaddr_un
*sun
;
1090 /* --- Initialize libraries --- */
1095 /* --- Set up the locked memory area --- */
1100 /* --- Parse command line arguments --- */
1103 static struct option opts
[] = {
1105 /* --- Standard GNUy help options --- */
1107 { "help", 0, 0, 'h' },
1108 { "version", 0, 0, 'V' },
1109 { "usage", 0, 0, 'u' },
1111 /* --- Other options --- */
1113 { "quiet", 0, 0, 'q' },
1114 { "verbose", 0, 0, 'v' },
1115 { "client", 0, 0, 'C' },
1116 { "socket", OPTF_ARGREQ
, 0, 's' },
1117 { "command", OPTF_ARGREQ
, 0, 'c' },
1118 { "timeout", OPTF_ARGREQ
, 0, 't' },
1119 { "interactive", 0, 0, 'i' },
1120 { "stdin", 0, 0, 'i' },
1121 { "daemon", 0, 0, 'd' },
1122 { "log", 0, 0, 'l' },
1123 { "syslog", 0, 0, 'l' },
1125 /* --- Magic terminator --- */
1130 int i
= mdwopt(argc
, argv
, "hVuqvCs:c:t:idl", opts
, 0, 0, 0);
1136 /* --- GNUy help options --- */
1148 /* --- Other interesting things --- */
1164 if ((timeout
= pixserv_timeout(optarg
)) == 0)
1165 die(1, "bad timeout `%s'", optarg
);
1180 /* --- Something else --- */
1188 if (f
& f_bogus
|| (optind
< argc
&& !(f
& f_client
))) {
1193 /* --- Set up the socket address --- */
1195 sun
= pixie_address(path
, &sz
);
1197 /* --- Initialize selectory --- */
1200 signal(SIGPIPE
, SIG_IGN
);
1202 /* --- Be a client if a client's wanted --- */
1205 pix_client(sun
, sz
, argv
+ optind
);
1207 /* --- Open the syslog if requested --- */
1211 openlog(QUIS
, 0, LOG_DAEMON
);
1214 /* --- Check on the locked memory area --- */
1218 int rc
= l_report(&lm
, &d
);
1220 die(EXIT_FAILURE
, d
.buf
);
1221 else if (rc
&& verbose
) {
1223 log("couldn't lock passphrase buffer");
1228 /* --- Set signal behaviours --- */
1231 static sig sigint
, sigterm
, sigquit
, sighup
;
1233 sig_add(&sigint
, SIGINT
, pix_sigdie
, 0);
1234 sig_add(&sigterm
, SIGTERM
, pix_sigdie
, 0);
1235 sig_add(&sigquit
, SIGQUIT
, pix_sigflush
, 0);
1236 sig_add(&sighup
, SIGHUP
, pix_sigflush
, 0);
1239 /* --- Set up the server --- */
1243 pixserv_create(STDIN_FILENO
, STDOUT_FILENO
);
1245 /* --- Fork into the background if requested --- */
1250 if (((f
& f_stdin
) &&
1251 (isatty(STDIN_FILENO
) || isatty(STDOUT_FILENO
))) ||
1253 die(1, "can't become a daemon if terminal required");
1255 if ((kid
= fork()) < 0)
1256 die(1, "fork failed: %s", strerror(errno
));
1262 if ((fd
= open("/dev/tty", O_RDONLY
)) >= 0) {
1263 ioctl(fd
, TIOCNOTTY
);
1274 log("initialized ok");
1280 /*----- That's all, folks -------------------------------------------------*/