1 | /* |
---|
2 | * xdm - display manager daemon |
---|
3 | * |
---|
4 | * $XConsortium: daemon.c,v 1.8 91/05/11 15:37:38 gildea Exp $ |
---|
5 | * |
---|
6 | * Copyright 1988 Massachusetts Institute of Technology |
---|
7 | * |
---|
8 | * Permission to use, copy, modify, and distribute this software and its |
---|
9 | * documentation for any purpose and without fee is hereby granted, provided |
---|
10 | * that the above copyright notice appear in all copies and that both that |
---|
11 | * copyright notice and this permission notice appear in supporting |
---|
12 | * documentation, and that the name of M.I.T. not be used in advertising or |
---|
13 | * publicity pertaining to distribution of the software without specific, |
---|
14 | * written prior permission. M.I.T. makes no representations about the |
---|
15 | * suitability of this software for any purpose. It is provided "as is" |
---|
16 | * without express or implied warranty. |
---|
17 | * |
---|
18 | * Author: Keith Packard, MIT X Consortium |
---|
19 | */ |
---|
20 | |
---|
21 | #include <X11/Xos.h> |
---|
22 | |
---|
23 | #ifdef SVR4 |
---|
24 | #include <termios.h> |
---|
25 | #else |
---|
26 | #include <sys/ioctl.h> |
---|
27 | #endif |
---|
28 | |
---|
29 | #ifdef hpux |
---|
30 | #include <sys/ptyio.h> |
---|
31 | #endif |
---|
32 | |
---|
33 | extern void exit (); |
---|
34 | |
---|
35 | BecomeOrphan () |
---|
36 | { |
---|
37 | /* |
---|
38 | * fork so that the process goes into the background automatically. Also |
---|
39 | * has a nice side effect of having the child process get inherited by |
---|
40 | * init (pid 1). |
---|
41 | */ |
---|
42 | |
---|
43 | if (fork ()) |
---|
44 | exit (0); |
---|
45 | } |
---|
46 | |
---|
47 | BecomeDaemon () |
---|
48 | { |
---|
49 | register int i; |
---|
50 | |
---|
51 | /* |
---|
52 | * Close standard file descriptors and get rid of controlling tty |
---|
53 | */ |
---|
54 | |
---|
55 | #if defined(SYSV) || defined(SVR4) |
---|
56 | setpgrp (); |
---|
57 | #else |
---|
58 | setpgrp (0, getpid()); |
---|
59 | #endif |
---|
60 | |
---|
61 | close (0); |
---|
62 | close (1); |
---|
63 | close (2); |
---|
64 | |
---|
65 | #ifndef SYSV386 |
---|
66 | if ((i = open ("/dev/tty", O_RDWR)) >= 0) { /* did open succeed? */ |
---|
67 | #if (defined(SYSV) || defined(SVR4)) && defined(TIOCTTY) |
---|
68 | int zero = 0; |
---|
69 | (void) ioctl (i, TIOCTTY, &zero); |
---|
70 | #else |
---|
71 | (void) ioctl (i, TIOCNOTTY, (char *) 0); /* detach, BSD style */ |
---|
72 | #endif |
---|
73 | (void) close (i); |
---|
74 | } |
---|
75 | #endif /* !SYSV386 */ |
---|
76 | |
---|
77 | /* |
---|
78 | * Set up the standard file descriptors. |
---|
79 | */ |
---|
80 | (void) open ("/", O_RDONLY); /* root inode already in core */ |
---|
81 | (void) dup2 (0, 1); |
---|
82 | (void) dup2 (0, 2); |
---|
83 | } |
---|