Merge lp:~daniel-sonck/upstart/cron-replacement into lp:upstart

Proposed by Marcus
Status: Needs review
Proposed branch: lp:~daniel-sonck/upstart/cron-replacement
Merge into: lp:upstart
Diff against target: 133 lines (+62/-2)
2 files modified
init/events.h (+7/-0)
init/main.c (+55/-2)
To merge this branch: bzr merge lp:~daniel-sonck/upstart/cron-replacement
Reviewer Review Type Date Requested Status
Scott James Remnant Pending
Review via email: mp+118942@code.launchpad.net

Description of the change

Add cron support soon!

To post a comment you must log in.

Unmerged revisions

1284. By dsonck <dsonck@daniel-desktop>

Merged with the latest startup branch

1283. By dsonck <dsonck@daniel-desktop>

* Added the `time` event with environment TIME=hh:mm DAY_OF_WEEK=d DATE=mm/dd/yyyy

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'init/events.h'
2--- init/events.h 2009-06-23 09:29:35 +0000
3+++ init/events.h 2012-08-09 12:39:33 +0000
4@@ -93,5 +93,12 @@
5 **/
6 #define JOB_STOPPED_EVENT "stopped"
7
8+/**
9+ * TIME_EVENT:
10+ *
11+ * Name of the event we generate every minute, which includes arguments and
12+ * environment indictating when the event was generated.
13+ **/
14+#define TIME_EVENT "time"
15
16 #endif /* INIT_EVENTS_H */
17
18=== modified file 'init/main.c'
19--- init/main.c 2012-08-07 16:39:00 +0000
20+++ init/main.c 2012-08-09 12:39:33 +0000
21@@ -46,6 +46,7 @@
22 #include <nih/list.h>
23 #include <nih/timer.h>
24 #include <nih/signal.h>
25+#include <nih/string.h>
26 #include <nih/child.h>
27 #include <nih/option.h>
28 #include <nih/main.h>
29@@ -54,6 +55,7 @@
30
31 #include "paths.h"
32 #include "events.h"
33+#include "environ.h"
34 #include "system.h"
35 #include "job_class.h"
36 #include "job_process.h"
37@@ -71,6 +73,7 @@
38 static void pwr_handler (void *data, NihSignal *signal);
39 static void hup_handler (void *data, NihSignal *signal);
40 static void usr1_handler (void *data, NihSignal *signal);
41+static void timer_handler (void *data, NihTimer *timer);
42 #endif /* DEBUG */
43
44 static void handle_confdir (void);
45@@ -172,7 +175,7 @@
46 argv0 = argv[0];
47 nih_main_init (argv0);
48
49- nih_option_set_synopsis (_("Process management daemon."));
50+ nih_option_set_synopsis (_("Process management daemon. (cron-replacement version)"));
51 nih_option_set_help (
52 _("This daemon is normally executed by the kernel and given "
53 "process id 1 to denote its special status. When executed "
54@@ -423,6 +426,8 @@
55 NIH_MUST (nih_main_loop_add_func (NULL, (NihMainLoopCb)event_poll,
56 NULL));
57
58+ /* Initialize the timers */
59+ nih_timer_init();
60
61 /* Adjust our OOM priority to the default, which will be inherited
62 * by all jobs.
63@@ -514,7 +519,7 @@
64 #endif /* DEBUG */
65
66
67- /* Generate and run the startup event or read the state from the
68+ /* Generate and run the startup and time event or read the state from the
69 * init daemon that exec'd us
70 */
71 if (! restart) {
72@@ -526,6 +531,7 @@
73 ? initial_event
74 : STARTUP_EVENT,
75 NULL));
76+ timer_handler(NULL,NULL);
77 }
78
79 } else {
80@@ -775,6 +781,53 @@
81 }
82 }
83 }
84+
85+/**
86+ * timer_handler:
87+ * @data: an integer which specifies the timer phase: initial, next minute, every minute,
88+ * @timer: timer that called this handler.
89+ *
90+ * Handle having recieved the minute-wise timer event, which we use to
91+ * generate a TIME event.
92+ **/
93+static void
94+timer_handler (void *data,
95+ NihTimer *timer)
96+{
97+ nih_local char **env = NULL;
98+ size_t len;
99+ time_t rawtime;
100+ struct tm *timeinfo;
101+
102+ time ( &rawtime );
103+ timeinfo = localtime ( &rawtime );
104+
105+ len = 0;
106+ env = NIH_MUST (nih_str_array_new (NULL));
107+
108+ /* Add the job and instance name */
109+ NIH_MUST (environ_set (&env, NULL, &len, TRUE,
110+ "TIME=%.2d:%.2d", timeinfo->tm_hour,timeinfo->tm_min));
111+ NIH_MUST (environ_set (&env, NULL, &len, TRUE,
112+ "DAY_OF_WEEK=%.1d", timeinfo->tm_wday+1));
113+ NIH_MUST (environ_set (&env, NULL, &len, TRUE,
114+ "DATE=%.2d/%.2d/%.4d", timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_year+1900));
115+
116+ NIH_MUST (event_new (NULL, TIME_EVENT, env));
117+
118+ if(data == (void*)0)
119+ {
120+ /* Start at next minute a new time event */
121+ NihTimer *timer = nih_timer_add_timeout(NULL, 61 - (rawtime % 60), timer_handler,
122+ (void*)1);
123+ }
124+ if(data == (void*)1)
125+ {
126+ /* Every minute a new time event */
127+ NihTimer *timer = nih_timer_add_periodic(NULL, 60, timer_handler,
128+ (void*)2);
129+ }
130+}
131 #endif /* DEBUG */
132
133 /**

Subscribers

People subscribed via source and target branches