sched: Mark global now pointer as const.
authorAndre Noll <maan@systemlinux.org>
Thu, 9 Jan 2014 17:04:28 +0000 (17:04 +0000)
committerAndre Noll <maan@systemlinux.org>
Sun, 25 May 2014 13:40:20 +0000 (15:40 +0200)
The timeval structure pointed to by the public now pointer should not
be modified outside sched.c. Fortunately play.c is the only place
which violates this rule. This patch fixes up play.c and marks the
pointer as const.

play.c
sched.c
sched.h

diff --git a/play.c b/play.c
index cf7c5a302d2cac9e96fd3793778733f874d3e267..c2a383c1555eb53bf84fef487ec6ba622f9659b0 100644 (file)
--- a/play.c
+++ b/play.c
@@ -301,7 +301,7 @@ static int shuffle_compare(__a_unused const void *a, __a_unused const void *b)
 
 static void shuffle(char **base, size_t num)
 {
-       srandom(now->tv_sec);
+       srandom(time(NULL));
        qsort(base, num, sizeof(char *), shuffle_compare);
 }
 
@@ -1240,7 +1240,6 @@ int main(int argc, char *argv[])
        filter_init();
        writer_init();
 
-       clock_get_realtime(now);
        sched.default_timeout.tv_sec = 5;
 
        parse_config_or_die(argc, argv);
diff --git a/sched.c b/sched.c
index f355c9750bc3ee2c426b2b5505073813973ce3cb..44062a66196c814a19b827f31a40cdec89fb4f37 100644 (file)
--- a/sched.c
+++ b/sched.c
@@ -49,7 +49,7 @@ struct task {
 };
 
 static struct timeval now_struct;
-struct timeval *now = &now_struct;
+const struct timeval *now = &now_struct;
 
 static inline bool timeout_is_zero(struct sched *s)
 {
@@ -147,7 +147,7 @@ again:
        FD_ZERO(&s->wfds);
        s->select_timeout = s->default_timeout;
        s->max_fileno = -1;
-       clock_get_realtime(now);
+       clock_get_realtime(&now_struct);
        sched_preselect(s);
        ret = s->select_function(s->max_fileno + 1, &s->rfds, &s->wfds,
                &s->select_timeout);
@@ -163,7 +163,7 @@ again:
                FD_ZERO(&s->rfds);
                FD_ZERO(&s->wfds);
        }
-       clock_get_realtime(now);
+       clock_get_realtime(&now_struct);
        num_running_tasks = sched_post_select(s);
        if (num_running_tasks == 0)
                return 0;
diff --git a/sched.h b/sched.h
index 9c0e10a33b38d7df6f64d893473f54d58ed65938..07877c461b81b76e1c207478b88d57db1f1fafd9 100644 (file)
--- a/sched.h
+++ b/sched.h
@@ -68,7 +68,7 @@ struct task_info {
  * scheduler are allowed to block, this value should be accurate enough so that
  * there is no need to call clock_gettime() directly.
  */
-extern struct timeval *now;
+extern const struct timeval *now;
 
 struct task *task_register(struct task_info *info, struct sched *s);
 int schedule(struct sched *s);