From: Andre Noll Date: Sun, 13 Dec 2015 11:21:44 +0000 (+0100) Subject: Merge branch 'refs/heads/t/priority' X-Git-Tag: v0.5.6~84 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=74322f0fab30777d8e34486fce1d81d4bc1106a0;hp=d3ef0055a567db260e32f0eb6975d50490d6edb1 Merge branch 'refs/heads/t/priority' A single commit which was cooking in next for two months. * refs/heads/t/priority: daemon: New option --priority for server and audiod. --- diff --git a/NEWS b/NEWS index 7faa0ddd..a5bef9f6 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,7 @@ current master branch "cascading gradient" - The check command now also checks the attribute table for inconsistencies. - New -v flag for the version command (print verbose version string) + - New option --priority for para_server and para_audiod. -------------------------------------- diff --git a/audiod.c b/audiod.c index accf0244..e5f9c6be 100644 --- a/audiod.c +++ b/audiod.c @@ -1474,6 +1474,7 @@ int main(int argc, char *argv[]) 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, diff --git a/daemon.c b/daemon.c index 94c4a8cb..478b0f47 100644 --- a/daemon.c +++ b/daemon.c @@ -11,6 +11,7 @@ #include /* getgrnam() */ #include #include +#include #include "para.h" #include "daemon.h" @@ -260,6 +261,21 @@ 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_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. * diff --git a/daemon.h b/daemon.h index ca3da140..621420a4 100644 --- a/daemon.h +++ b/daemon.h @@ -5,6 +5,7 @@ void daemonize(bool parent_waits); 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); diff --git a/m4/gengetopt/audiod.m4 b/m4/gengetopt/audiod.m4 index 732f8087..75c04581 100644 --- a/m4/gengetopt/audiod.m4 +++ b/m4/gengetopt/audiod.m4 @@ -20,6 +20,7 @@ include(log_timing.m4) include(daemon.m4) include(user.m4) include(group.m4) +include(priority.m4) ######################## diff --git a/m4/gengetopt/priority.m4 b/m4/gengetopt/priority.m4 new file mode 100644 index 00000000..0b37dc06 --- /dev/null +++ b/m4/gengetopt/priority.m4 @@ -0,0 +1,16 @@ +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. +" diff --git a/m4/gengetopt/server.m4 b/m4/gengetopt/server.m4 index 916e8856..6aca7bac 100644 --- a/m4/gengetopt/server.m4 +++ b/m4/gengetopt/server.m4 @@ -18,6 +18,7 @@ include(color.m4) include(daemon.m4) include(user.m4) include(group.m4) +include(priority.m4) option "port" p diff --git a/server.c b/server.c index 7cb6e520..71a9ec50 100644 --- a/server.c +++ b/server.c @@ -463,6 +463,7 @@ static void server_init(int argc, char **argv) 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);