From: Andre Noll Date: Sun, 17 Aug 2014 11:17:23 +0000 (+0200) Subject: Merge branch 't/daemon_cleanups' X-Git-Tag: v0.5.4~60 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=c1b282afb8e8422d12ae01a77937f27281748f1b;hp=197a489a36e7b11264c87aeae67f3553172e598c Merge branch 't/daemon_cleanups' Cooking for two months. * daemon: Rename public functions. * Simplify set_server_start_time(). Conflicts: server.c --- diff --git a/NEWS b/NEWS index 40ab08a1..e179240b 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,14 @@ NEWS ==== +----------------------------------------------- +0.5.4 (to be announced) "exponential alignment" +----------------------------------------------- + + * Minor cleanups to daemon.c. + +Download: ./releases/paraslash-git.tar.bz2 + --------------------------------------------- 0.5.3 (2014-08-01) "symbolic synchronization" --------------------------------------------- diff --git a/audiod.c b/audiod.c index 6fd101a0..b536ea4a 100644 --- a/audiod.c +++ b/audiod.c @@ -1394,7 +1394,7 @@ int main(int argc, char *argv[]) writer_init(); if (conf.help_given || conf.detailed_help_given) print_help_and_die(); - drop_privileges_or_die(conf.user_arg, conf.group_arg); + daemon_drop_privileges_or_die(conf.user_arg, conf.group_arg); parse_config_or_die(); init_colors_or_die(); init_random_seed_or_die(); @@ -1412,8 +1412,8 @@ int main(int argc, char *argv[]) PARA_EMERG_LOG("%s\n", para_strerror(-ret)); exit(EXIT_FAILURE); } - log_welcome("para_audiod"); - set_server_start_time(NULL); + daemon_log_welcome("para_audiod"); + daemon_set_start_time(); set_initial_status(); FOR_EACH_SLOT(i) clear_slot(i); diff --git a/audiod_command.c b/audiod_command.c index 56d922e6..7d284dc7 100644 --- a/audiod_command.c +++ b/audiod_command.c @@ -527,7 +527,7 @@ void audiod_status_dump(bool force) free(new); } - new = get_server_uptime_str(now); + new = daemon_get_uptime_str(now); old = stat_item_values[SI_AUDIOD_UPTIME]; if (force || !old || strcmp(old, new)) { free(old); diff --git a/command.c b/command.c index eb15875c..41276933 100644 --- a/command.c +++ b/command.c @@ -385,7 +385,7 @@ static int com_si(struct command_context *cc) sender_info = para_strcat(sender_info, info); free(info); } - ut = get_server_uptime_str(now); + ut = daemon_get_uptime_str(now); ret = xasprintf(&msg, "version: %s\n" "up: %s\nplayed: %u\n" diff --git a/daemon.c b/daemon.c index 05002f4e..3879c0d8 100644 --- a/daemon.c +++ b/daemon.c @@ -229,7 +229,7 @@ void daemon_open_log_or_die(void) /** * Log the startup message containing the paraslash version. */ -void log_welcome(const char *whoami) +void daemon_log_welcome(const char *whoami) { PARA_INFO_LOG("welcome to %s " PACKAGE_VERSION " ("BUILD_DATE")\n", whoami); @@ -249,7 +249,7 @@ void log_welcome(const char *whoami) * * \sa getpwnam(3), getuid(2), setuid(2), getgrnam(2), setgid(2) */ -void drop_privileges_or_die(const char *username, const char *groupname) +void daemon_drop_privileges_or_die(const char *username, const char *groupname) { struct passwd *p; char *tmp; @@ -290,27 +290,20 @@ void drop_privileges_or_die(const char *username, const char *groupname) } /** - * Set the server startup time. + * Set the startup time. * - * \param startuptime The value to store as the server start time. + * This should be called once on startup. It sets the start time to the + * current time. The stored time is used for retrieving the server uptime. * - * This should be called once on startup with \a startuptime either NULL or a - * pointer to a struct timeval which contains the current time. If \a - * startuptime is NULL, the server start time is set to the current time. - * - * \sa time(2), difftime(3) \ref get_server_uptime(), \ref - * get_server_uptime_str(). + * \sa time(2), \ref daemon_get_uptime(), \ref daemon_get_uptime_str(). */ -void set_server_start_time(const struct timeval *startuptime) +void daemon_set_start_time(void) { - if (startuptime) - me->startuptime = startuptime->tv_sec; - else - time(&me->startuptime); + time(&me->startuptime); } /** - * Get the server uptime. + * Get the uptime. * * \param current_time The current time. * @@ -319,9 +312,9 @@ void set_server_start_time(const struct timeval *startuptime) * * \return This returns the server uptime in seconds, i.e. the difference * between the current time and the value stored previously via \ref - * set_server_start_time(). + * daemon_set_start_time(). */ -time_t get_server_uptime(const struct timeval *current_time) +time_t daemon_get_uptime(const struct timeval *current_time) { time_t t; @@ -334,15 +327,15 @@ time_t get_server_uptime(const struct timeval *current_time) /** * Construct a string containing the current uptime. * - * \param current_time See a \ref get_server_uptime(). + * \param current_time See a \ref daemon_get_uptime(). * * \return A dynamically allocated string of the form "days:hours:minutes". * * \sa server_uptime. */ -__malloc char *get_server_uptime_str(const struct timeval *current_time) +__malloc char *daemon_get_uptime_str(const struct timeval *current_time) { - long t = get_server_uptime(current_time); + long t = daemon_get_uptime(current_time); return make_message("%li:%02li:%02li", t / 86400, (t / 3600) % 24, (t / 60) % 60); } diff --git a/daemon.h b/daemon.h index fd435577..df9de6a3 100644 --- a/daemon.h +++ b/daemon.h @@ -4,12 +4,11 @@ void daemonize(bool parent_waits); void daemon_open_log_or_die(void); void daemon_close_log(void); -void log_welcome(const char *whoami); -void drop_privileges_or_die(const char *username, const char *groupname); -/** used for server_uptime() */ -void set_server_start_time(const struct timeval *startuptime); -time_t get_server_uptime(const struct timeval *current_time); -__malloc char *get_server_uptime_str(const struct timeval *current_time); +void daemon_log_welcome(const char *whoami); +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); +__malloc char *daemon_get_uptime_str(const struct timeval *current_time); void daemon_set_logfile(char *logfile_name); void daemon_set_flag(unsigned flag); void daemon_clear_flag(unsigned flag); diff --git a/server.c b/server.c index 908e039b..2c74e613 100644 --- a/server.c +++ b/server.c @@ -483,12 +483,12 @@ 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(); - drop_privileges_or_die(conf.user_arg, conf.group_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); - log_welcome("para_server"); + daemon_log_welcome("para_server"); init_ipc_or_die(); /* init mmd struct and mmd->lock */ - set_server_start_time(NULL); + daemon_set_start_time(); init_user_list(user_list_file); /* become daemon */ if (conf.daemon_given) @@ -526,7 +526,7 @@ static void server_init(int argc, char **argv) static void status_refresh(void) { static int prev_uptime = -1, prev_events = -1; - int uptime = get_server_uptime(now); + int uptime = daemon_get_uptime(now); if (prev_events != mmd->events) goto out;