Skip to content

Commit 1420354

Browse files
authored
Merge pull request #130 from garlick/no_syslog
diod: do not daemonize, do not syslog
2 parents 655a9fe + 7aea316 commit 1420354

12 files changed

+36
-225
lines changed

etc/diod.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
-- listen = { "0.0.0.0:564" }
88
-- nwthreads = 16
99
-- auth_required = 1
10-
-- logdest = "syslog:daemon:err"
10+
-- logdest = "/var/log/diod.log"
1111

1212
-- exports = { "ctl", "/g/g0", "/g/g10" }
1313

etc/diod.service.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Description=9P File Server
33

44
[Service]
5-
Type=forking
5+
Type=exec
66
ExecStart=@X_SBINDIR@/diod
77

88
[Install]

man/diod.8.in

-6
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ Configuration is read from the diod.conf (5) config file.
1313
Some configuration can be overridden on the command line, as described below.
1414
.SH OPTIONS
1515
.TP
16-
.I "-f, --foreground"
17-
Do not change working directory to @X_LOCALSTATEDIR@/run,
18-
drop the controlling terminal, or run in the background.
19-
Send logs to stderr not syslog, unless sent somewhere else by \fI\-L\fR.
20-
.TP
2116
.I "-r, --rfdno INT"
2217
.TP
2318
.I "-w, --wfdno INT"
@@ -82,7 +77,6 @@ supplementary groups to those belonging to UID.
8277
.TP
8378
.I "-L, --logdest DEST"
8479
Set the destination for logging. Possible destinations are
85-
\fIsyslog:facility:level\fR,
8680
\fIstderr\fR,
8781
\fIstdout\fR, or
8882
a file name.

man/diod.conf.5.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ The squash user must be present in the password file.
6565
.TP
6666
\fIlogdest = "DEST"\fR
6767
Set the destination for logging.
68-
\fIDEST\fR is in the form of \fIsyslog:facility:level\fR or \fIfilename\fR.
69-
The default is \fIsyslog:daemon:err\fR.
68+
\fIDEST\fR is \fIstdout\fR, \fIstderr\fR, or \fIfilename\fR.
69+
The default is \fIstderr\fR.
7070
.TP
7171
.I "statfs_passthru = 1"
7272
This option configures statfs to return the host file system's type

src/cmd/diod.c

+2-36
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
#include "config.h"
1515
#endif
1616
#include <poll.h>
17-
#ifndef _BSD_SOURCE
18-
#define _BSD_SOURCE /* daemon () */
19-
#endif
2017
#include <stdlib.h>
2118
#include <stdint.h>
2219
#include <sys/types.h>
@@ -57,7 +54,6 @@
5754

5855
typedef enum { SRV_FILEDES, SRV_SOCKTEST, SRV_NORMAL } srvmode_t;
5956

60-
static void _daemonize (void);
6157
static void _setrlimit (void);
6258
static void _become_user (char *name, uid_t uid, int realtoo);
6359
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);
6662
#define NR_OPEN 1048576 /* works on RHEL 5 x86_64 arch */
6763
#endif
6864

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";
7066

7167
static const struct option longopts[] = {
72-
{"foreground", no_argument, 0, 'f'},
7368
{"rfdno", required_argument, 0, 'r'},
7469
{"wfdno", required_argument, 0, 'w'},
7570
{"debug", required_argument, 0, 'd'},
@@ -96,7 +91,6 @@ usage()
9691
{
9792
fprintf (stderr,
9893
"Usage: diod [OPTIONS]\n"
99-
" -f,--foreground do not fork and disassociate with tty\n"
10094
" -r,--rfdno service connected client on read file descriptor\n"
10195
" -w,--wfdno service connected client on write file descriptor\n"
10296
" -l,--listen IP:PORT set interface to listen on (multiple -l allowed)\n"
@@ -111,7 +105,7 @@ usage()
111105
" -u,--runas-uid UID only allow UID to attach\n"
112106
" -S,--allsquash map all users to the squash user\n"
113107
" -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"
115109
" -d,--debug MASK set debugging mask\n"
116110
" -c,--config-file FILE set config file path\n"
117111
" -s,--socktest run in test mode where server exits early\n"
@@ -149,9 +143,6 @@ main(int argc, char **argv)
149143
opterr = 0;
150144
while ((c = getopt_long (argc, argv, options, longopts, NULL)) != -1) {
151145
switch (c) {
152-
case 'f': /* --foreground */
153-
diod_conf_set_foreground (1);
154-
break;
155146
case 'r': /* --rfdno */
156147
mode = SRV_FILEDES;
157148
rfdno = strtoul (optarg, NULL, 10);
@@ -339,26 +330,6 @@ _setrlimit (void)
339330

340331
}
341332

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-
362333
/**
363334
** Service startup
364335
**/
@@ -599,11 +570,6 @@ _service_run (srvmode_t mode, int rfdno, int wfdno)
599570
}
600571
}
601572

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-
607573
/* drop root */
608574
if (euid == 0) {
609575
if (diod_conf_get_allsquash ())

src/libdiod/diod_conf.c

-13
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
/* ro_mask values to protect attribute from overwrite by config file */
5757
#define RO_DEBUGLEVEL 0x00000001
5858
#define RO_NWTHREADS 0x00000002
59-
#define RO_FOREGROUND 0x00000004
6059
#define RO_AUTH_REQUIRED 0x00000008
6160
#define RO_RUNASUID 0x00000010
6261
#define RO_USERDB 0x00000020
@@ -77,7 +76,6 @@
7776
typedef struct {
7877
int debuglevel;
7978
int nwthreads;
80-
int foreground;
8179
int auth_required;
8280
int hostname_lookup;
8381
int statfs_passthru;
@@ -165,7 +163,6 @@ diod_conf_init (void)
165163
{
166164
config.debuglevel = DFLT_DEBUGLEVEL;
167165
config.nwthreads = DFLT_NWTHREADS;
168-
config.foreground = DFLT_FOREGROUND;
169166
config.auth_required = DFLT_AUTH_REQUIRED;
170167
config.hostname_lookup = DFLT_HOSTNAME_LOOKUP;
171168
config.statfs_passthru = DFLT_STATFS_PASSTHRU;
@@ -242,16 +239,6 @@ void diod_conf_set_nwthreads (int i)
242239
config.ro_mask |= RO_NWTHREADS;
243240
}
244241

245-
/* foreground - run daemon in foreground
246-
*/
247-
int diod_conf_get_foreground (void) { return config.foreground; }
248-
int diod_conf_opt_foreground (void) { return config.ro_mask & RO_FOREGROUND; }
249-
void diod_conf_set_foreground (int i)
250-
{
251-
config.foreground = i;
252-
config.ro_mask |= RO_FOREGROUND;
253-
}
254-
255242
/* auth_required - whether to accept unauthenticated attaches
256243
*/
257244
int diod_conf_get_auth_required (void) { return config.auth_required; }

src/libdiod/diod_conf.h

+1-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#define DFLT_DEBUGLEVEL 0
1717
#define DFLT_NWTHREADS 16
1818
#define DFLT_MAXMMAP 0
19-
#define DFLT_FOREGROUND 0
2019
#define DFLT_AUTH_REQUIRED 1
2120
#define DFLT_HOSTNAME_LOOKUP 1
2221
#define DFLT_STATFS_PASSTHRU 0
@@ -29,7 +28,7 @@
2928
#ifdef HAVE_CONFIG_FILE
3029
#define DFLT_CONFIGPATH X_SYSCONFDIR "/diod.conf"
3130
#endif
32-
#define DFLT_LOGDEST "syslog:daemon:err"
31+
#define DFLT_LOGDEST "stderr"
3332

3433
void diod_conf_init (void);
3534
void diod_conf_fini (void);
@@ -50,10 +49,6 @@ int diod_conf_get_nwthreads (void);
5049
int diod_conf_opt_nwthreads (void);
5150
void diod_conf_set_nwthreads (int i);
5251

53-
int diod_conf_get_foreground (void);
54-
int diod_conf_opt_foreground (void);
55-
void diod_conf_set_foreground (int i);
56-
5752
int diod_conf_get_auth_required (void);
5853
int diod_conf_opt_auth_required (void);
5954
void diod_conf_set_auth_required (int i);

0 commit comments

Comments
 (0)