Move runas down into daemonize()

This commit is contained in:
Julien BLACHE 2009-06-05 16:36:07 +02:00
parent f39c48b989
commit f3c0145346

View File

@ -80,17 +80,20 @@ usage(char *program)
} }
static int static int
daemonize(int background, char *runas, char *pidfile) daemonize(int background, char *pidfile)
{ {
FILE *fp; FILE *fp;
int fd;
pid_t childpid; pid_t childpid;
pid_t ret; pid_t ret;
int fd;
int iret; int iret;
char *runas;
struct passwd *pw; struct passwd *pw;
if (geteuid() == (uid_t) 0) if (geteuid() == (uid_t) 0)
{ {
runas = cfg_getstr(cfg_getsec(cfg, "general"), "uid");
pw = getpwnam(runas); pw = getpwnam(runas);
if (!pw) if (!pw)
@ -258,7 +261,7 @@ main(int argc, char **argv)
char *logdomains; char *logdomains;
char *logfile; char *logfile;
cfg_t *lib; cfg_t *lib;
char *runas, *tmp; char *tmp;
int port; int port;
char *servername; char *servername;
char *ffid; char *ffid;
@ -409,9 +412,7 @@ main(int argc, char **argv)
} }
/* Daemonize and drop privileges */ /* Daemonize and drop privileges */
runas = cfg_getstr(cfg_getsec(cfg, "general"), "uid"); ret = daemonize(background, pidfile);
ret = daemonize(background, runas, pidfile);
if (ret < 0) if (ret < 0)
{ {
DPRINTF(E_LOG, L_MAIN, "Could not initialize server\n"); DPRINTF(E_LOG, L_MAIN, "Could not initialize server\n");