From 2225ff7444175650a0613c8d2f19aebbd2007061 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Thu, 9 Jan 2014 16:57:58 +0000 Subject: [PATCH] Simplify set_server_start_time(). This function receives a pointer to a timeval structure which is supposed to contain the daemon startup time. Passing NULL means to set the daemon startup time to the current time. There are only two callers of this function, in audiod.c and in server.c. The first one passes NULL, the other one initialises the timeval structure pointed to by the global now pointer to the current time, and passes this pointer. It's easier to let set_server_start_time() always act as if NULL had been passed. --- audiod.c | 2 +- daemon.c | 17 +++++------------ daemon.h | 3 +-- server.c | 4 +--- 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/audiod.c b/audiod.c index a8f40183..d5c603e9 100644 --- a/audiod.c +++ b/audiod.c @@ -1411,7 +1411,7 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } log_welcome("para_audiod"); - set_server_start_time(NULL); + set_server_start_time(); set_initial_status(); FOR_EACH_SLOT(i) clear_slot(i); diff --git a/daemon.c b/daemon.c index 05002f4e..cace3b78 100644 --- a/daemon.c +++ b/daemon.c @@ -292,21 +292,14 @@ void drop_privileges_or_die(const char *username, const char *groupname) /** * Set the server startup time. * - * \param startuptime The value to store as the server start time. + * This should be called once on startup. It sets the server 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 get_server_uptime(), \ref get_server_uptime_str(). */ -void set_server_start_time(const struct timeval *startuptime) +void set_server_start_time(void) { - if (startuptime) - me->startuptime = startuptime->tv_sec; - else - time(&me->startuptime); + time(&me->startuptime); } /** diff --git a/daemon.h b/daemon.h index fd435577..025b6a5e 100644 --- a/daemon.h +++ b/daemon.h @@ -6,8 +6,7 @@ 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); +void set_server_start_time(void); time_t get_server_uptime(const struct timeval *current_time); __malloc char *get_server_uptime_str(const struct timeval *current_time); void daemon_set_logfile(char *logfile_name); diff --git a/server.c b/server.c index fa19ce42..bdb5df98 100644 --- a/server.c +++ b/server.c @@ -484,9 +484,7 @@ static void server_init(int argc, char **argv) parse_config_or_die(0); log_welcome("para_server"); init_ipc_or_die(); /* init mmd struct and mmd->lock */ - /* make sure, the global now pointer is uptodate */ - clock_get_realtime(now); - set_server_start_time(now); + set_server_start_time(); init_user_list(user_list_file); /* become daemon */ if (conf.daemon_given) -- 2.39.2