writer_init();
if (conf.help_given || conf.detailed_help_given)
print_help_and_die();
+ daemon_set_priority(conf.priority_arg);
daemon_drop_privileges_or_die(conf.user_arg, conf.group_arg);
parse_config_or_die();
daemon_init_colors_or_die(conf.color_arg, color_arg_auto, color_arg_no,
#include <sys/types.h> /* getgrnam() */
#include <grp.h>
#include <signal.h>
+#include <sys/resource.h>
#include "para.h"
#include "daemon.h"
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_set_priority(int prio)
+{
+ if (setpriority(PRIO_PROCESS, 0, prio) < 0)
+ PARA_WARNING_LOG("could not set priority to %d: %s\n", prio,
+ strerror(errno));
+}
+
/**
* Give up superuser privileges.
*
void daemon_open_log_or_die(void);
void daemon_close_log(void);
void daemon_log_welcome(const char *whoami);
+void daemon_set_priority(int prio);
void daemon_drop_privileges_or_die(const char *username, const char *groupname);
void daemon_set_start_time(void);
time_t daemon_get_uptime(const struct timeval *current_time);
include(daemon.m4)
include(user.m4)
include(group.m4)
+include(priority.m4)
<qu>
########################
--- /dev/null
+option "priority" -
+#~~~~~~~~~~~~~~~~~~
+"adjust scheduling priority"
+int typestr = "prio"
+default = "0"
+optional
+details = "
+ The priority (also known as nice value) is a value in the range -20
+ to 19. Lower priorities cause more favorable scheduling. Since only
+ privileged processes may request a negative priority, specifying
+ a negative value works only if the daemon is started with root
+ privileges.
+
+ Failure to set the given priority value is not considered an error
+ but a log message is printed in this case.
+"
include(daemon.m4)
include(user.m4)
include(group.m4)
+include(priority.m4)
<qu>
option "port" p
version_handle_flag("server", conf.version_given);
if (conf.help_given || conf.detailed_help_given)
print_help_and_die();
+ daemon_set_priority(conf.priority_arg);
daemon_drop_privileges_or_die(conf.user_arg, conf.group_arg);
/* parse config file, open log and set defaults */
parse_config_or_die(0);