X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=daemon.c;h=011ece6d3d7689b34e793fb4b00f813afc324fc2;hp=cae63ea7f48488124085d79360458ee44b5620a8;hb=3f9051d22fcf6e968259946eaf521ac3daac470e;hpb=002731cd3938f3be6b71651e56c062af1adcdec0 diff --git a/daemon.c b/daemon.c index cae63ea7..011ece6d 100644 --- a/daemon.c +++ b/daemon.c @@ -103,7 +103,7 @@ void daemon_set_logfile(char *logfile_name) } /** - * Supress log messages with severity lower than the given loglevel. + * Suppress log messages with severity lower than the given loglevel. * * \param loglevel The smallest level that should be logged. */ @@ -167,7 +167,6 @@ void daemonize(void) goto err; if (chdir("/") < 0) goto err; - umask(0); null = open("/dev/null", O_RDONLY); if (null < 0) goto err; @@ -270,7 +269,11 @@ void drop_privileges_or_die(const char *username, const char *groupname) exit(EXIT_FAILURE); } PARA_INFO_LOG("dropping root privileges\n"); - setuid(p->pw_uid); + if (setuid(p->pw_uid) < 0) { + PARA_EMERG_LOG("failed to set effective user ID (%s)", + strerror(errno)); + exit(EXIT_FAILURE); + } PARA_DEBUG_LOG("uid: %d, euid: %d\n", (int)getuid(), (int)geteuid()); } @@ -284,7 +287,7 @@ void drop_privileges_or_die(const char *username, const char *groupname) * set_or_get equal to \p UPTIME_GET return the uptime. * \return Zero if called with \a set_or_get equal to \p UPTIME_SET, the number - * of seconds ellapsed since the last reset otherwise. + * of seconds elapsed since the last reset otherwise. * * \sa time(2), difftime(3). */ @@ -328,7 +331,7 @@ __printf_2_3 void para_log(int ll, const char* fmt,...) FILE *fp; struct tm *tm; time_t t1; - char *color, str[MAXLINE] = ""; + char *color; ll = PARA_MIN(ll, NUM_LOGLEVELS - 1); ll = PARA_MAX(ll, LL_DEBUG); @@ -339,11 +342,11 @@ __printf_2_3 void para_log(int ll, const char* fmt,...) color = daemon_test_flag(DF_COLOR_LOG)? me->log_colors[ll] : NULL; if (color) fprintf(fp, "%s", color); - if (daemon_test_flag(DF_LOG_TIME)) { - /* date and time */ + if (daemon_test_flag(DF_LOG_TIME)) { /* print date and time */ + char str[100]; time(&t1); tm = localtime(&t1); - strftime(str, MAXLINE, "%b %d %H:%M:%S", tm); + strftime(str, sizeof(str), "%b %d %H:%M:%S", tm); fprintf(fp, "%s ", str); } if (daemon_test_flag(DF_LOG_HOSTNAME)) {