Remove support for compile-time loglevel.
[paraslash.git] / daemon.c
index 316432e68a5f116c9f2035d9bfb661b99b7061a1..478b0f47acc94d3098cc17576599032f007b43ca 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -11,6 +11,7 @@
 #include <sys/types.h> /* getgrnam() */
 #include <grp.h>
 #include <signal.h>
+#include <sys/resource.h>
 
 #include "para.h"
 #include "daemon.h"
@@ -199,7 +200,7 @@ void daemonize(bool parent_waits)
                goto err;
        if (chdir("/") < 0)
                goto err;
-       null = open("/dev/null", O_RDONLY);
+       null = open("/dev/null", O_RDWR);
        if (null < 0)
                goto err;
        if (dup2(null, STDIN_FILENO) < 0)
@@ -249,11 +250,30 @@ void daemon_open_log_or_die(void)
 
 /**
  * Log the startup message containing the paraslash version.
+ *
+ * \param name The name of the executable.
+ *
+ * First the given \a name is prefixed with the string "para_". Next the git
+ * version is appended. The resulting string is logged with priority "INFO".
+ */
+void daemon_log_welcome(const char *name)
+{
+       PARA_INFO_LOG("welcome to para_%s-" PACKAGE_VERSION " \n", name);
+}
+
+/**
+ * Renice the calling process.
+ *
+ * \param prio The priority value to set.
+ *
+ * Errors are not considered fatal, but a warning message is logged if the
+ * underlying call to setpriority(2) fails.
  */
-void daemon_log_welcome(const char *whoami)
+void daemon_set_priority(int prio)
 {
-       PARA_INFO_LOG("welcome to %s " PACKAGE_VERSION " ("BUILD_DATE")\n",
-               whoami);
+       if (setpriority(PRIO_PROCESS, 0, prio) < 0)
+               PARA_WARNING_LOG("could not set priority to %d: %s\n", prio,
+                       strerror(errno));
 }
 
 /**