}
}
-static int get_loglevel_by_name(const char *txt, size_t n)
-{
- if (!strncasecmp(txt, "debug", n))
- return LL_DEBUG;
- if (!strncasecmp(txt, "info", n))
- return LL_INFO;
- if (!strncasecmp(txt, "notice", n))
- return LL_NOTICE;
- if (!strncasecmp(txt, "warning", n))
- return LL_WARNING;
- if (!strncasecmp(txt, "error", n))
- return LL_ERROR;
- if (!strncasecmp(txt, "crit", n))
- return LL_CRIT;
- if (!strncasecmp(txt, "emerg", n))
- return LL_EMERG;
- return -1;
-}
-
/**
* Set the color for one loglevel.
*
if (!p)
goto err;
- ret = get_loglevel_by_name(arg, p - arg);
+ ret = get_loglevel_by_name(arg);
if (ret < 0)
goto err;
ll = ret;
}
/**
- * 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.
*/
-void daemon_set_loglevel(int loglevel)
+void daemon_set_loglevel(char *loglevel)
{
- me->loglevel = loglevel;
+ int ret = get_loglevel_by_name(loglevel);
+
+ assert(ret >= 0);
+ me->loglevel = ret;
}
/**
goto err;
if (chdir("/") < 0)
goto err;
- umask(0);
null = open("/dev/null", O_RDONLY);
if (null < 0)
goto err;
/**
* Log the startup message containing the paraslash version.
*/
-void log_welcome(const char *whoami, int loglevel)
+void log_welcome(const char *whoami)
{
PARA_INFO_LOG("welcome to %s " PACKAGE_VERSION " ("BUILD_DATE")\n",
whoami);
- PARA_DEBUG_LOG("using loglevel %d\n", loglevel);
}
/**
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());
}
* 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).
*/
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)) {