diff options
Diffstat (limited to 'os')
-rw-r--r-- | os/access.c | 2 | ||||
-rw-r--r-- | os/config.c | 2 | ||||
-rw-r--r-- | os/configstr.h | 2 | ||||
-rw-r--r-- | os/connection.c | 2 | ||||
-rw-r--r-- | os/daemon.c | 151 | ||||
-rw-r--r-- | os/error.c | 4 | ||||
-rw-r--r-- | os/io.c | 2 | ||||
-rw-r--r-- | os/osdep.h | 2 | ||||
-rw-r--r-- | os/osglue.c | 2 | ||||
-rw-r--r-- | os/osinit.c | 2 | ||||
-rw-r--r-- | os/utils.c | 1 | ||||
-rw-r--r-- | os/waitfor.c | 2 |
12 files changed, 72 insertions, 102 deletions
diff --git a/os/access.c b/os/access.c index 83103da..c500728 100644 --- a/os/access.c +++ b/os/access.c @@ -43,7 +43,7 @@ in this Software without prior written authorization from The Open Group. * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF * THIS SOFTWARE. */ -/* $XFree86: xc/programs/xfs/os/access.c,v 3.8 2003/07/09 15:27:40 tsi Exp $ */ +/* $XFree86: xc/programs/xfs/os/access.c,v 3.7tsi Exp $ */ #include <X11/Xos.h> #ifndef Lynx diff --git a/os/config.c b/os/config.c index 64f8992..795455b 100644 --- a/os/config.c +++ b/os/config.c @@ -47,7 +47,7 @@ in this Software without prior written authorization from The Open Group. * $NCDXorg: @(#)config.c,v 4.6 1991/07/09 14:08:09 lemke Exp $ * */ -/* $XFree86: xc/programs/xfs/os/config.c,v 3.16 2002/10/15 01:45:03 dawes Exp $ */ +/* $XFree86: xc/programs/xfs/os/config.c,v 3.15 2002/05/31 18:46:12 dawes Exp $ */ #include <stdio.h> #include <stdlib.h> diff --git a/os/configstr.h b/os/configstr.h index 9000acc..9c1a8af 100644 --- a/os/configstr.h +++ b/os/configstr.h @@ -47,7 +47,7 @@ in this Software without prior written authorization from The Open Group. * @(#)configstr.h 4.1 91/05/02 * */ -/* $XFree86: xc/programs/xfs/os/configstr.h,v 1.5 2001/12/14 20:01:41 dawes Exp $ */ +/* $XFree86: xc/programs/xfs/os/configstr.h,v 1.4 2001/01/17 23:45:32 dawes Exp $ */ #ifndef _CONFIGSTR_H_ #define _CONFIGSTR_H_ #include "config.h" diff --git a/os/connection.c b/os/connection.c index d17de6d..5d17773 100644 --- a/os/connection.c +++ b/os/connection.c @@ -67,7 +67,7 @@ in this Software without prior written authorization from The Open Group. * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF * THIS SOFTWARE. */ -/* $XFree86: xc/programs/xfs/os/connection.c,v 3.26 2003/07/09 15:27:40 tsi Exp $ */ +/* $XFree86: xc/programs/xfs/os/connection.c,v 3.25tsi Exp $ */ #include <stdlib.h> #include <X11/Xtrans.h> diff --git a/os/daemon.c b/os/daemon.c index 0e5ce3e..2b23de3 100644 --- a/os/daemon.c +++ b/os/daemon.c @@ -34,16 +34,7 @@ from the X Consortium. #include <errno.h> #include <stdlib.h> -#ifndef __GLIBC__ -# if defined(__osf__) || \ - defined(__GNU__) || \ - defined(__CYGWIN__) || \ - defined(linux) -# define setpgrp setpgid -# endif -#endif - -#if defined(SVR4) || defined(USG) || defined(__GLIBC__) +#if defined(USG) # include <termios.h> #else # include <sys/ioctl.h> @@ -60,108 +51,88 @@ from the X Consortium. #include "os.h" -void -BecomeOrphan () -{ - Pid_t child_id; +#if defined(__GLIBC__) || defined(CSRG_BASED) +#define HAS_DAEMON +#endif - chdir("/"); - /* - * fork so that the process goes into the background automatically. Also - * has a nice side effect of having the child process get inherited by - * init (pid 1). - * Separate the child into its own process group before the parent - * exits. This eliminates the possibility that the child might get - * killed when the init script that's running xfs exits. - */ +#ifndef X_NOT_POSIX +#define HAS_SETSID +#endif - child_id = fork(); - switch (child_id) { - case 0: - /* child */ - break; - case -1: - /* error */ - FatalError("daemon fork failed, %s\n", strerror(errno)); - break; +#ifndef HAS_SETSID - default: - /* parent */ +#define setsid() MySetsid() + +static Pid_t +MySetsid(void) +{ +#if defined(TIOCNOTTY) || defined(TCCLRCTTY) || defined(TIOCTTY) + int fd; +#endif + int stat; -#if defined(CSRG_BASED) || \ - defined(SYSV) || \ - defined(SVR4) || \ - defined(__QNXNTO__) || \ - defined(__GLIBC__) || \ - defined(linux) - { - int stat; -# if defined(SVR4) || defined(__QNXNTO__) - /* This gets error EPERM. Why? */ - stat = setpgid (child_id, child_id); -# elif defined(SYSV) - stat = 0; /* don't know how to set child's process group */ -# elif defined(__GLIBC__) - stat = setpgrp (); -# else - stat = setpgrp (child_id, child_id); -# endif - if (stat != 0) - FatalError("setting process group for daemon failed: %s\n", - strerror(errno)); - } -#endif /* ! (CSRG_BASED || SYSV || SVR4 || __QNXNTO__ || __GLIBC__) */ - exit (0); + fd = open("/dev/tty", O_RDWR); + if (fd >= 0) { +#if defined(USG) && defined(TCCLRCTTY) + int zero = 0; + (void) ioctl (fd, TCCLRCTTY, &zero); +#elif (defined(SYSV) || defined(SVR4)) && defined(TIOCTTY) + int zero = 0; + (void) ioctl (i, TIOCTTY, &zero); +#elif defined(TIOCNOTTY) + (void) ioctl (i, TIOCNOTTY, (char *) 0); /* detach, BSD style */ +#endif + close(fd); } + +#if defined(SYSV) || defined(__QNXNTO__) + return setpgrp(); +#else + return setpgid(0, getpid()); +#endif } +#endif /* !HAS_SETSID */ + + +/* detach */ void BecomeDaemon () { - /* - * Close standard file descriptors and get rid of controlling tty. - */ - /* If our C library has the daemon() function, just use it. */ -#if defined(__GLIBC__) || defined(CSRG_BASED) +#ifdef HAS_DAEMON daemon (0, 0); #else - register int i; -# if defined(SYSV) || defined(SVR4) || defined(__QNXNTO__) - setpgrp (); -# else - setpgrp (0, getpid()); -# endif + switch (fork()) { + case -1: + /* error */ + FatalError("daemon fork failed, %s\n", strerror(errno)); + break; + case 0: + /* child */ + break; + default: + /* parent */ + exit(0); + } + + if (setsid() == -1) + FatalError("setting session id for daemon failed: %s\n", + strerror(errno)); + + chdir("/"); close (0); close (1); close (2); -# if !defined(__UNIXOS2__) && !defined(__CYGWIN__) -# if !((defined(SYSV) || defined(SVR4)) && defined(i386)) - if ((i = open ("/dev/tty", O_RDWR)) >= 0) { /* did open succeed? */ -# if defined(USG) && defined(TCCLRCTTY) - int zero = 0; - (void) ioctl (i, TCCLRCTTY, &zero); -# else -# if (defined(SYSV) || defined(SVR4)) && defined(TIOCTTY) - int zero = 0; - (void) ioctl (i, TIOCTTY, &zero); -# else - (void) ioctl (i, TIOCNOTTY, (char *) 0); /* detach, BSD style */ -# endif -# endif - (void) close (i); - } -# endif /* !((SYSV || SVR4) && i386) */ -# endif /* !__UNIXOS2__ && !__CYGWIN__ */ - /* * Set up the standard file descriptors. */ - (void) open ("/", O_RDONLY); /* root inode already in core */ + (void) open ("/dev/null", O_RDWR); (void) dup2 (0, 1); (void) dup2 (0, 2); -#endif + +#endif /* HAS_DAEMON */ } @@ -44,7 +44,7 @@ in this Software without prior written authorization from The Open Group. * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF * THIS SOFTWARE. */ -/* $XFree86: xc/programs/xfs/os/error.c,v 1.11 2002/10/15 01:45:03 dawes Exp $ */ +/* $XFree86: error.c,v 1.11 2002/10/15 01:45:03 dawes Exp $ */ #include <stdio.h> #include <stdlib.h> @@ -95,7 +95,7 @@ abort_server(void) #ifdef SABER saber_stop(); #else - abort(); + _exit(1); #endif } @@ -46,7 +46,7 @@ in this Software without prior written authorization from The Open Group. * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF * THIS SOFTWARE. */ -/* $XFree86: xc/programs/xfs/os/io.c,v 3.19 2002/05/31 18:46:12 dawes Exp $ */ +/* $XFree86: xc/programs/xfs/os/io.c,v 3.18 2001/12/14 20:01:41 dawes Exp $ */ #include <X11/Xtrans.h> #include <stdio.h> @@ -47,7 +47,7 @@ in this Software without prior written authorization from The Open Group. * @(#)osdep.h 4.1 5/2/91 * */ -/* $XFree86: xc/programs/xfs/os/osdep.h,v 3.12 2002/05/31 18:46:12 dawes Exp $ */ +/* $XFree86: xc/programs/xfs/os/osdep.h,v 3.11 2001/12/14 20:01:41 dawes Exp $ */ #ifndef _OSDEP_H_ #define _OSDEP_H_ diff --git a/os/osglue.c b/os/osglue.c index 67f784c..6c1b1ac 100644 --- a/os/osglue.c +++ b/os/osglue.c @@ -47,7 +47,7 @@ in this Software without prior written authorization from The Open Group. * $NCDXorg: @(#)osglue.c,v 4.6 1991/07/09 14:07:30 lemke Exp $ * */ -/* $XFree86: xc/programs/xfs/os/osglue.c,v 3.19 2002/10/19 20:04:20 herrb Exp $ */ +/* $XFree86: xc/programs/xfs/os/osglue.c,v 3.18 2002/10/15 01:45:03 dawes Exp $ */ /* * this is miscellaneous OS specific stuff. diff --git a/os/osinit.c b/os/osinit.c index 7d0a068..a12bb00 100644 --- a/os/osinit.c +++ b/os/osinit.c @@ -50,7 +50,7 @@ in this Software without prior written authorization from The Open Group. * @(#)osinit.c 4.3 5/7/91 * */ -/* $XFree86: xc/programs/xfs/os/osinit.c,v 1.5 2001/12/14 20:01:41 dawes Exp $ */ +/* $XFree86: xc/programs/xfs/os/osinit.c,v 1.4 2001/01/17 23:45:33 dawes Exp $ */ #include "os.h" @@ -526,7 +526,6 @@ SetDaemonState(void) int oldpid; if (becomeDaemon) { - BecomeOrphan(); BecomeDaemon(); if ((oldpid = StorePid ())) { if (oldpid == -1) diff --git a/os/waitfor.c b/os/waitfor.c index c5f1f23..1c3ebef 100644 --- a/os/waitfor.c +++ b/os/waitfor.c @@ -50,7 +50,7 @@ in this Software without prior written authorization from The Open Group. * $NCDXorg: @(#)waitfor.c,v 4.5 1991/06/24 11:59:20 lemke Exp $ * */ -/* $XFree86: xc/programs/xfs/os/waitfor.c,v 3.16 2002/05/31 18:46:12 dawes Exp $ */ +/* $XFree86: xc/programs/xfs/os/waitfor.c,v 3.15 2001/12/14 20:01:41 dawes Exp $ */ #include <X11/Xos.h> /* strings, time, etc */ |