]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Merge branch 't/daemon_cleanups'
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 17 Aug 2014 11:17:23 +0000 (13:17 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 17 Aug 2014 11:18:53 +0000 (13:18 +0200)
Cooking for two months.

* daemon: Rename public functions.
* Simplify set_server_start_time().

Conflicts:
server.c

NEWS
audiod.c
audiod_command.c
command.c
daemon.c
daemon.h
server.c

diff --git a/NEWS b/NEWS
index 40ab08a10cc59a8dd8849436feee4a669b5d972c..e179240b9d480f5c7159c40bf7a9c92d779eb2cb 100644 (file)
--- 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"
 ---------------------------------------------
index 6fd101a093b2f7f94abe43cab0331781c8a57a3a..b536ea4a8fad6b1aa8b0465efd7c33ba069c4277 100644 (file)
--- 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);
index 56d922e6681e66d0d9c4f65df86569806a38ca80..7d284dc770eab6aef83a9e7d4fe5c74d241b7d47 100644 (file)
@@ -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);
index eb15875c36b8affba5a3defdce8f787ad73026ba..412769336a2896555142eac66cf6c9469f9c394b 100644 (file)
--- 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"
index 05002f4eff228e0200d5d6cdce9be0c697ed3bc3..3879c0d8c81e1235298aa74b923a7ef968160b24 100644 (file)
--- 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);
 }
index fd435577e6258aa24fe2fe1edc9bde2ce50c7d5f..df9de6a316f5d56dedaece3d37a8847c5902e6ff 100644 (file)
--- 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);
index 908e039b1cf66be5909b102edfb20aa83ceb2b2a..2c74e6138b04e402492b3fda566616e289dff968 100644 (file)
--- 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;