diff options
Diffstat (limited to 'libexec/rbootd/rbootd.c')
-rw-r--r-- | libexec/rbootd/rbootd.c | 93 |
1 files changed, 17 insertions, 76 deletions
diff --git a/libexec/rbootd/rbootd.c b/libexec/rbootd/rbootd.c index aa01583..11d5445 100644 --- a/libexec/rbootd/rbootd.c +++ b/libexec/rbootd/rbootd.c @@ -1,3 +1,5 @@ +/* $NetBSD: rbootd.c,v 1.5 1995/10/06 05:12:17 thorpej Exp $ */ + /* * Copyright (c) 1988, 1992 The University of Utah and the Center * for Software Science (CSS). @@ -38,9 +40,9 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)rbootd.c 8.2 (Berkeley) 2/22/94 + * from: @(#)rbootd.c 8.1 (Berkeley) 6/4/93 * - * Utah $Hdr: rbootd.c 3.1 92/07/06$ + * From: Utah Hdr: rbootd.c 3.1 92/07/06 * Author: Jeff Forys, University of Utah CSS */ @@ -51,14 +53,14 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)rbootd.c 8.2 (Berkeley) 2/22/94"; +/*static char sccsid[] = "@(#)rbootd.c 8.1 (Berkeley) 6/4/93";*/ +static char rcsid[] = "$NetBSD: rbootd.c,v 1.5 1995/10/06 05:12:17 thorpej Exp $"; #endif /* not lint */ #include <sys/param.h> -#include <sys/ioctl.h> #include <sys/time.h> - #include <ctype.h> +#include <err.h> #include <errno.h> #include <fcntl.h> #include <signal.h> @@ -69,19 +71,7 @@ static char sccsid[] = "@(#)rbootd.c 8.2 (Berkeley) 2/22/94"; #include <unistd.h> #include "defs.h" - -/* fd mask macros (backward compatibility with 4.2BSD) */ -#ifndef FD_SET -#ifdef notdef -typedef struct fd_set { /* this should already be in 4.2 */ - int fds_bits[1]; -} fd_set; -#endif -#define FD_ZERO(p) ((p)->fds_bits[0] = 0) -#define FD_SET(n, p) ((p)->fds_bits[0] |= (1 << (n))) -#define FD_CLR(n, p) ((p)->fds_bits[0] &= ~(1 << (n))) -#define FD_ISSET(n, p) ((p)->fds_bits[0] & (1 << (n))) -#endif +extern char *__progname; /* from crt0.o */ int main(argc, argv) @@ -92,11 +82,6 @@ main(argc, argv) fd_set rset; /* - * Find what name we are running under. - */ - ProgName = (ProgName = rindex(argv[0],'/')) ? ++ProgName : *argv; - - /* * Close any open file descriptors. * Temporarily leave stdin & stdout open for `-d', * and stderr open for any pre-syslog error messages. @@ -129,9 +114,8 @@ main(argc, argv) if (ConfigFile == NULL) ConfigFile = argv[optind]; else { - fprintf(stderr, - "%s: too many config files (`%s' ignored)\n", - ProgName, argv[optind]); + warnx("too many config files (`%s' ignored)\n", + argv[optind]); } } @@ -143,57 +127,16 @@ main(argc, argv) (void) signal(SIGUSR1, SIG_IGN); /* dont muck w/DbgFp */ (void) signal(SIGUSR2, SIG_IGN); + (void) fclose(stderr); /* finished with it */ } else { - (void) fclose(stdin); /* dont need these */ - (void) fclose(stdout); - - /* - * Fork off a child to do the work & exit. - */ - switch(fork()) { - case -1: /* fork failed */ - fprintf(stderr, "%s: ", ProgName); - perror("fork"); - Exit(0); - case 0: /* this is the CHILD */ - break; - default: /* this is the PARENT */ - _exit(0); - } - - /* - * Try to disassociate from the current tty. - */ - { - char *devtty = "/dev/tty"; - int i; - - if ((i = open(devtty, O_RDWR)) < 0) { - /* probably already disassociated */ - if (setpgrp(0, 0) < 0) { - fprintf(stderr, "%s: ", ProgName); - perror("setpgrp"); - } - } else { - if (ioctl(i, (u_long)TIOCNOTTY, (char *)0) < 0){ - fprintf(stderr, "%s: ", ProgName); - perror("ioctl"); - } - (void) close(i); - } - } + if (daemon(0, 0)) + err(1, "can't detach from terminal"); (void) signal(SIGUSR1, DebugOn); (void) signal(SIGUSR2, DebugOff); } - (void) fclose(stderr); /* finished with it */ - -#ifdef SYSLOG4_2 - openlog(ProgName, LOG_PID); -#else - openlog(ProgName, LOG_PID, LOG_DAEMON); -#endif + openlog(__progname, LOG_PID, LOG_DAEMON); /* * If no interface was specified, get one now. @@ -237,7 +180,7 @@ main(argc, argv) FILE *fp; if ((fp = fopen(PidFile, "w")) != NULL) { - (void) fprintf(fp, "%d\n", MyPid); + (void) fprintf(fp, "%d\n", (int) MyPid); (void) fclose(fp); } else { syslog(LOG_WARNING, "fopen: failed (%s)", PidFile); @@ -286,13 +229,11 @@ main(argc, argv) r = rset; if (RmpConns == NULL) { /* timeout isnt necessary */ - nsel = select(maxfds, &r, (fd_set *)0, (fd_set *)0, - (struct timeval *)0); + nsel = select(maxfds, &r, NULL, NULL, NULL); } else { timeout.tv_sec = RMP_TIMEOUT; timeout.tv_usec = 0; - nsel = select(maxfds, &r, (fd_set *)0, (fd_set *)0, - &timeout); + nsel = select(maxfds, &r, NULL, NULL, &timeout); } if (nsel < 0) { |