14
14
#include "config.h"
15
15
#endif
16
16
#include <poll.h>
17
- #ifndef _BSD_SOURCE
18
- #define _BSD_SOURCE /* daemon () */
19
- #endif
20
17
#include <stdlib.h>
21
18
#include <stdint.h>
22
19
#include <sys/types.h>
57
54
58
55
typedef enum { SRV_FILEDES , SRV_SOCKTEST , SRV_NORMAL } srvmode_t ;
59
56
60
- static void _daemonize (void );
61
57
static void _setrlimit (void );
62
58
static void _become_user (char * name , uid_t uid , int realtoo );
63
59
static void _service_run (srvmode_t mode , int rfdno , int wfdno );
@@ -66,10 +62,9 @@ static void _service_run (srvmode_t mode, int rfdno, int wfdno);
66
62
#define NR_OPEN 1048576 /* works on RHEL 5 x86_64 arch */
67
63
#endif
68
64
69
- static const char * options = "fr :w:d:l:t:e:Eo:u:SL:nHpc:NU:s" ;
65
+ static const char * options = "r :w:d:l:t:e:Eo:u:SL:nHpc:NU:s" ;
70
66
71
67
static const struct option longopts [] = {
72
- {"foreground" , no_argument , 0 , 'f' },
73
68
{"rfdno" , required_argument , 0 , 'r' },
74
69
{"wfdno" , required_argument , 0 , 'w' },
75
70
{"debug" , required_argument , 0 , 'd' },
@@ -96,7 +91,6 @@ usage()
96
91
{
97
92
fprintf (stderr ,
98
93
"Usage: diod [OPTIONS]\n"
99
- " -f,--foreground do not fork and disassociate with tty\n"
100
94
" -r,--rfdno service connected client on read file descriptor\n"
101
95
" -w,--wfdno service connected client on write file descriptor\n"
102
96
" -l,--listen IP:PORT set interface to listen on (multiple -l allowed)\n"
@@ -111,7 +105,7 @@ usage()
111
105
" -u,--runas-uid UID only allow UID to attach\n"
112
106
" -S,--allsquash map all users to the squash user\n"
113
107
" -U,--squashuser USER set the squash user (default nobody)\n"
114
- " -L,--logdest DEST log to DEST, can be syslog , stderr, or file\n"
108
+ " -L,--logdest DEST log to DEST, can be stdout , stderr, or file\n"
115
109
" -d,--debug MASK set debugging mask\n"
116
110
" -c,--config-file FILE set config file path\n"
117
111
" -s,--socktest run in test mode where server exits early\n"
@@ -149,9 +143,6 @@ main(int argc, char **argv)
149
143
opterr = 0 ;
150
144
while ((c = getopt_long (argc , argv , options , longopts , NULL )) != -1 ) {
151
145
switch (c ) {
152
- case 'f' : /* --foreground */
153
- diod_conf_set_foreground (1 );
154
- break ;
155
146
case 'r' : /* --rfdno */
156
147
mode = SRV_FILEDES ;
157
148
rfdno = strtoul (optarg , NULL , 10 );
@@ -339,26 +330,6 @@ _setrlimit (void)
339
330
340
331
}
341
332
342
- /* Create run directory if it doesn't exist and chdir there.
343
- * Disassociate from parent's controlling tty. Switch logging to syslog.
344
- * Exit on error.
345
- */
346
- static void
347
- _daemonize (void )
348
- {
349
- char rdir [PATH_MAX ];
350
-
351
- snprintf (rdir , sizeof (rdir ), "%s/run/diod" , X_LOCALSTATEDIR );
352
- if (mkdir (rdir , 0755 ) < 0 && errno != EEXIST ) {
353
- msg ("failed to find/create %s, running out of /tmp" , rdir );
354
- snprintf (rdir , sizeof (rdir ), "/tmp" );
355
- }
356
- if (chdir (rdir ) < 0 )
357
- err_exit ("chdir %s" , rdir );
358
- if (daemon (1 , 0 ) < 0 )
359
- err_exit ("daemon" );
360
- }
361
-
362
333
/**
363
334
** Service startup
364
335
**/
@@ -599,11 +570,6 @@ _service_run (srvmode_t mode, int rfdno, int wfdno)
599
570
}
600
571
}
601
572
602
- if (!diod_conf_get_foreground () && mode != SRV_FILEDES )
603
- _daemonize (); /* implicit fork - no pthreads before this */
604
- if (!diod_conf_get_foreground () && mode != SRV_FILEDES )
605
- diod_log_set_dest (diod_conf_get_logdest ());
606
-
607
573
/* drop root */
608
574
if (euid == 0 ) {
609
575
if (diod_conf_get_allsquash ())
0 commit comments