*/
/** \file daemon.c Some helpers for programs that detach from the console. */
-#include "para.h"
-#include "daemon.h"
+
+#include <regex.h>
#include <pwd.h>
#include <sys/types.h> /* getgrnam() */
#include <grp.h>
+#include "para.h"
+#include "daemon.h"
#include "string.h"
#include "color.h"
goto err;
if (chdir("/") < 0)
goto err;
- umask(0);
null = open("/dev/null", O_RDONLY);
if (null < 0)
goto err;
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());
}
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);
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)) {