diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2008-10-02 16:44:44 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2008-10-02 16:44:44 +0000 |
commit | 062f4c18445ce835506656182a95f522dbf7b5b8 (patch) | |
tree | 38704dcbdc0546ae6d1ec97007936da1b3fe2b34 /games/hunt | |
parent | 00458a4a503572c5ba7b4f5986e086274d5a0518 (diff) |
Remove useless setsid() and setpgrp() calls and add -b option to
run huntd in the background like a true daemon. OK deraadt@
Diffstat (limited to 'games/hunt')
-rw-r--r-- | games/hunt/huntd/driver.c | 26 | ||||
-rw-r--r-- | games/hunt/huntd/huntd.6 | 16 |
2 files changed, 29 insertions, 13 deletions
diff --git a/games/hunt/huntd/driver.c b/games/hunt/huntd/driver.c index f18d2bd54c8..0ab3bbf3e06 100644 --- a/games/hunt/huntd/driver.c +++ b/games/hunt/huntd/driver.c @@ -1,4 +1,4 @@ -/* $OpenBSD: driver.c,v 1.17 2007/04/02 14:55:16 jmc Exp $ */ +/* $OpenBSD: driver.c,v 1.18 2008/10/02 16:44:43 millert Exp $ */ /* $NetBSD: driver.c,v 1.5 1997/10/20 00:37:16 lukem Exp $ */ /* * Copyright (c) 1983-2003, Regents of the University of California. @@ -63,7 +63,7 @@ in_addr_t Server_addr = INADDR_ANY; /* address to bind to */ static void clear_scores(void); static int havechar(PLAYER *); -static void init(void); +static void init(int); int main(int, char *[]); static void makeboots(void); static void send_stats(void); @@ -96,13 +96,19 @@ main(ac, av) int ret; int nready; int fd; + int background = 0; First_arg = av[0]; config(); - while ((c = getopt(ac, av, "sp:a:D:")) != -1) { + while ((c = getopt(ac, av, "bsp:a:D:")) != -1) { switch (c) { + case 'b': + background = 1; + conf_syslog = 1; + conf_logerr = 0; + break; case 's': server = TRUE; break; @@ -120,7 +126,7 @@ main(ac, av) default: erred: fprintf(stderr, - "usage: %s [-s] [-a addr] [-Dvar=value ...] " + "usage: %s [-bs] [-a addr] [-Dvar=value ...] " "[-p port]\n", av[0]); exit(2); @@ -134,7 +140,7 @@ erred: LOG_DAEMON); /* Initialise game parameters: */ - init(); + init(background); again: do { @@ -320,7 +326,7 @@ again: * Initialize the global parameters. */ static void -init() +init(int background) { int i; struct sockaddr_in test_port; @@ -330,10 +336,6 @@ init() struct sigaction sact; struct servent *se; - (void) setsid(); - if (setpgid(getpid(), getpid()) == -1) - err(1, "setpgid"); - sact.sa_flags = SA_RESTART; sigemptyset(&sact.sa_mask); @@ -452,6 +454,10 @@ init() cleanup(1); } + /* Become a daemon if asked to do so. */ + if (background) + daemon(0, 0); + /* Datagram sockets do not need a listen() call. */ } diff --git a/games/hunt/huntd/huntd.6 b/games/hunt/huntd/huntd.6 index 96f1de660d9..9d12839a531 100644 --- a/games/hunt/huntd/huntd.6 +++ b/games/hunt/huntd/huntd.6 @@ -1,5 +1,5 @@ .\" $NetBSD: huntd.6,v 1.3 1998/01/09 08:03:42 perry Exp $ -.\" $OpenBSD: huntd.6,v 1.18 2007/05/31 19:19:18 jmc Exp $ +.\" $OpenBSD: huntd.6,v 1.19 2008/10/02 16:44:43 millert Exp $ .\" .\" Hunt .\" Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold @@ -9,7 +9,7 @@ .\" All rights reserved. The Berkeley software License Agreement .\" specifies the terms and conditions for redistribution. .\" -.Dd $Mdocdate: May 31 2007 $ +.Dd $Mdocdate: October 2 2008 $ .Dt HUNTD 6 .Os .Sh NAME @@ -17,7 +17,7 @@ .Nd hunt daemon, back-end for hunt game .Sh SYNOPSIS .Nm huntd -.Op Fl s +.Op Fl bs .Op Fl a Ar addr .Sm off .Oo @@ -39,6 +39,16 @@ The .Ar addr argument must be given as an IP address. .Pp +If the +.Fl b +option is specified, +.Nm +will fork and go into the background. +In this mode, errors will be logged via +.Va syslog +intead of to +.Va stderr . +.Pp Options given with .Fl D override those read from configuration files |