Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diod: do not daemonize, do not syslog #130

Merged
merged 6 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion etc/diod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-- listen = { "0.0.0.0:564" }
-- nwthreads = 16
-- auth_required = 1
-- logdest = "syslog:daemon:err"
-- logdest = "/var/log/diod.log"

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

Expand Down
2 changes: 1 addition & 1 deletion etc/diod.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Description=9P File Server

[Service]
Type=forking
Type=exec
ExecStart=@X_SBINDIR@/diod

[Install]
Expand Down
6 changes: 0 additions & 6 deletions man/diod.8.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ Configuration is read from the diod.conf (5) config file.
Some configuration can be overridden on the command line, as described below.
.SH OPTIONS
.TP
.I "-f, --foreground"
Do not change working directory to @X_LOCALSTATEDIR@/run,
drop the controlling terminal, or run in the background.
Send logs to stderr not syslog, unless sent somewhere else by \fI\-L\fR.
.TP
.I "-r, --rfdno INT"
.TP
.I "-w, --wfdno INT"
Expand Down Expand Up @@ -82,7 +77,6 @@ supplementary groups to those belonging to UID.
.TP
.I "-L, --logdest DEST"
Set the destination for logging. Possible destinations are
\fIsyslog:facility:level\fR,
\fIstderr\fR,
\fIstdout\fR, or
a file name.
Expand Down
4 changes: 2 additions & 2 deletions man/diod.conf.5.in
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ The squash user must be present in the password file.
.TP
\fIlogdest = "DEST"\fR
Set the destination for logging.
\fIDEST\fR is in the form of \fIsyslog:facility:level\fR or \fIfilename\fR.
The default is \fIsyslog:daemon:err\fR.
\fIDEST\fR is \fIstdout\fR, \fIstderr\fR, or \fIfilename\fR.
The default is \fIstderr\fR.
.TP
.I "statfs_passthru = 1"
This option configures statfs to return the host file system's type
Expand Down
38 changes: 2 additions & 36 deletions src/cmd/diod.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
#include "config.h"
#endif
#include <poll.h>
#ifndef _BSD_SOURCE
#define _BSD_SOURCE /* daemon () */
#endif
#include <stdlib.h>
#include <stdint.h>
#include <sys/types.h>
Expand Down Expand Up @@ -57,7 +54,6 @@

typedef enum { SRV_FILEDES, SRV_SOCKTEST, SRV_NORMAL } srvmode_t;

static void _daemonize (void);
static void _setrlimit (void);
static void _become_user (char *name, uid_t uid, int realtoo);
static void _service_run (srvmode_t mode, int rfdno, int wfdno);
Expand All @@ -66,10 +62,9 @@ static void _service_run (srvmode_t mode, int rfdno, int wfdno);
#define NR_OPEN 1048576 /* works on RHEL 5 x86_64 arch */
#endif

static const char *options = "fr:w:d:l:t:e:Eo:u:SL:nHpc:NU:s";
static const char *options = "r:w:d:l:t:e:Eo:u:SL:nHpc:NU:s";

static const struct option longopts[] = {
{"foreground", no_argument, 0, 'f'},
{"rfdno", required_argument, 0, 'r'},
{"wfdno", required_argument, 0, 'w'},
{"debug", required_argument, 0, 'd'},
Expand All @@ -96,7 +91,6 @@ usage()
{
fprintf (stderr,
"Usage: diod [OPTIONS]\n"
" -f,--foreground do not fork and disassociate with tty\n"
" -r,--rfdno service connected client on read file descriptor\n"
" -w,--wfdno service connected client on write file descriptor\n"
" -l,--listen IP:PORT set interface to listen on (multiple -l allowed)\n"
Expand All @@ -111,7 +105,7 @@ usage()
" -u,--runas-uid UID only allow UID to attach\n"
" -S,--allsquash map all users to the squash user\n"
" -U,--squashuser USER set the squash user (default nobody)\n"
" -L,--logdest DEST log to DEST, can be syslog, stderr, or file\n"
" -L,--logdest DEST log to DEST, can be stdout, stderr, or file\n"
" -d,--debug MASK set debugging mask\n"
" -c,--config-file FILE set config file path\n"
" -s,--socktest run in test mode where server exits early\n"
Expand Down Expand Up @@ -149,9 +143,6 @@ main(int argc, char **argv)
opterr = 0;
while ((c = getopt_long (argc, argv, options, longopts, NULL)) != -1) {
switch (c) {
case 'f': /* --foreground */
diod_conf_set_foreground (1);
break;
case 'r': /* --rfdno */
mode = SRV_FILEDES;
rfdno = strtoul (optarg, NULL, 10);
Expand Down Expand Up @@ -339,26 +330,6 @@ _setrlimit (void)

}

/* Create run directory if it doesn't exist and chdir there.
* Disassociate from parent's controlling tty. Switch logging to syslog.
* Exit on error.
*/
static void
_daemonize (void)
{
char rdir[PATH_MAX];

snprintf (rdir, sizeof(rdir), "%s/run/diod", X_LOCALSTATEDIR);
if (mkdir (rdir, 0755) < 0 && errno != EEXIST) {
msg ("failed to find/create %s, running out of /tmp", rdir);
snprintf (rdir, sizeof(rdir), "/tmp");
}
if (chdir (rdir) < 0)
err_exit ("chdir %s", rdir);
if (daemon (1, 0) < 0)
err_exit ("daemon");
}

/**
** Service startup
**/
Expand Down Expand Up @@ -599,11 +570,6 @@ _service_run (srvmode_t mode, int rfdno, int wfdno)
}
}

if (!diod_conf_get_foreground () && mode != SRV_FILEDES)
_daemonize (); /* implicit fork - no pthreads before this */
if (!diod_conf_get_foreground () && mode != SRV_FILEDES)
diod_log_set_dest (diod_conf_get_logdest ());

/* drop root */
if (euid == 0) {
if (diod_conf_get_allsquash ())
Expand Down
13 changes: 0 additions & 13 deletions src/libdiod/diod_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
/* ro_mask values to protect attribute from overwrite by config file */
#define RO_DEBUGLEVEL 0x00000001
#define RO_NWTHREADS 0x00000002
#define RO_FOREGROUND 0x00000004
#define RO_AUTH_REQUIRED 0x00000008
#define RO_RUNASUID 0x00000010
#define RO_USERDB 0x00000020
Expand All @@ -77,7 +76,6 @@
typedef struct {
int debuglevel;
int nwthreads;
int foreground;
int auth_required;
int hostname_lookup;
int statfs_passthru;
Expand Down Expand Up @@ -165,7 +163,6 @@ diod_conf_init (void)
{
config.debuglevel = DFLT_DEBUGLEVEL;
config.nwthreads = DFLT_NWTHREADS;
config.foreground = DFLT_FOREGROUND;
config.auth_required = DFLT_AUTH_REQUIRED;
config.hostname_lookup = DFLT_HOSTNAME_LOOKUP;
config.statfs_passthru = DFLT_STATFS_PASSTHRU;
Expand Down Expand Up @@ -242,16 +239,6 @@ void diod_conf_set_nwthreads (int i)
config.ro_mask |= RO_NWTHREADS;
}

/* foreground - run daemon in foreground
*/
int diod_conf_get_foreground (void) { return config.foreground; }
int diod_conf_opt_foreground (void) { return config.ro_mask & RO_FOREGROUND; }
void diod_conf_set_foreground (int i)
{
config.foreground = i;
config.ro_mask |= RO_FOREGROUND;
}

/* auth_required - whether to accept unauthenticated attaches
*/
int diod_conf_get_auth_required (void) { return config.auth_required; }
Expand Down
7 changes: 1 addition & 6 deletions src/libdiod/diod_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#define DFLT_DEBUGLEVEL 0
#define DFLT_NWTHREADS 16
#define DFLT_MAXMMAP 0
#define DFLT_FOREGROUND 0
#define DFLT_AUTH_REQUIRED 1
#define DFLT_HOSTNAME_LOOKUP 1
#define DFLT_STATFS_PASSTHRU 0
Expand All @@ -29,7 +28,7 @@
#ifdef HAVE_CONFIG_FILE
#define DFLT_CONFIGPATH X_SYSCONFDIR "/diod.conf"
#endif
#define DFLT_LOGDEST "syslog:daemon:err"
#define DFLT_LOGDEST "stderr"

void diod_conf_init (void);
void diod_conf_fini (void);
Expand All @@ -50,10 +49,6 @@ int diod_conf_get_nwthreads (void);
int diod_conf_opt_nwthreads (void);
void diod_conf_set_nwthreads (int i);

int diod_conf_get_foreground (void);
int diod_conf_opt_foreground (void);
void diod_conf_set_foreground (int i);

int diod_conf_get_auth_required (void);
int diod_conf_opt_auth_required (void);
void diod_conf_set_auth_required (int i);
Expand Down
Loading
Loading