Merge lp:upstart into lp:~daniel-sonck/upstart/cron-replacement
- trunk
- Merge into cron-replacement
Proposed by
Daniël Sonck
Status: | Merged |
---|---|
Approved by: | Daniël Sonck |
Approved revision: | 1329 |
Merged at revision: | 1284 |
Proposed branch: | lp:upstart |
Merge into: | lp:~daniel-sonck/upstart/cron-replacement |
Diff against target: |
18561 lines (+11017/-1183) (has conflicts) 73 files modified
.bzrignore (+4/-0) ChangeLog (+365/-0) Makefile.am (+1/-1) NEWS (+35/-1) TESTING.sessions (+289/-0) conf/rc-sysinit.conf (+2/-0) configure.ac (+7/-3) contrib/bash_completion/upstart (+96/-36) contrib/vim/syntax/upstart.vim (+61/-27) dbus/Upstart.conf (+6/-36) dbus/com.ubuntu.Upstart.xml (+7/-0) dbus/upstart.h (+1/-1) extra/Makefile.am (+125/-0) extra/conf/upstart-socket-bridge.conf (+16/-0) extra/conf/upstart-udev-bridge.conf (+16/-0) extra/man/socket-event.7 (+92/-0) extra/man/upstart-socket-bridge.8 (+47/-0) extra/man/upstart-udev-bridge.8 (+57/-0) extra/upstart-socket-bridge.c (+644/-0) extra/upstart-udev-bridge.c (+310/-0) init/Makefile.am (+12/-0) init/conf.c (+504/-55) init/conf.h (+45/-2) init/control.c (+111/-19) init/control.h (+19/-1) init/environ.c (+0/-1) init/environ.h (+0/-1) init/event.c (+22/-0) init/event.h (+6/-1) init/event_operator.c (+59/-0) init/event_operator.h (+8/-0) init/job.c (+47/-3) init/job.h (+4/-1) init/job_class.c (+115/-67) init/job_class.h (+62/-2) init/job_process.c (+122/-14) init/job_process.h (+5/-3) init/main.c (+297/-134) init/man/init.5 (+236/-48) init/man/init.8 (+32/-4) init/parse_conf.c (+6/-0) init/parse_job.c (+21/-7) init/parse_job.h (+4/-2) init/paths.h (+75/-2) init/session.c (+320/-0) init/session.h (+89/-0) init/tests/test_blocked.c (+4/-1) init/tests/test_conf.c (+1310/-15) init/tests/test_control.c (+15/-11) init/tests/test_environ.c (+3/-1) init/tests/test_event.c (+28/-25) init/tests/test_event_operator.c (+3/-0) init/tests/test_job.c (+71/-76) init/tests/test_job_class.c (+56/-65) init/tests/test_job_process.c (+34/-30) init/tests/test_parse_conf.c (+3/-0) init/tests/test_parse_job.c (+302/-260) init/tests/test_process.c (+3/-0) init/tests/test_system.c (+3/-0) po/POTFILES.in (+2/-0) po/upstart.pot (+352/-155) scripts/Makefile.am (+25/-0) scripts/init-checkconf.sh (+248/-0) scripts/initctl2dot.py (+571/-0) scripts/man/init-checkconf.8 (+73/-0) scripts/man/initctl2dot.8 (+87/-0) util/Makefile.am (+1/-1) util/initctl.c (+1014/-17) util/initctl.h (+458/-0) util/man/initctl.8 (+207/-34) util/reboot.c (+0/-1) util/tests/test_initctl.c (+1189/-19) util/tests/test_user_sessions.sh (+553/-0) Text conflict in init/main.c |
To merge this branch: | bzr merge lp:upstart |
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Daniël Sonck | Approve | ||
Review via email: mp+79391@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Daniël Sonck (daniel-sonck) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file '.bzrignore' | |||
2 | --- .bzrignore 2010-12-10 04:03:25 +0000 | |||
3 | +++ .bzrignore 2011-10-14 11:09:18 +0000 | |||
4 | @@ -59,3 +59,7 @@ | |||
5 | 59 | util/shutdown | 59 | util/shutdown |
6 | 60 | util/telinit | 60 | util/telinit |
7 | 61 | util/test_* | 61 | util/test_* |
8 | 62 | extra/com.ubuntu.Upstart.[ch] | ||
9 | 63 | extra/com.ubuntu.Upstart.Job.[ch] | ||
10 | 64 | extra/upstart-socket-bridge | ||
11 | 65 | extra/upstart-udev-bridge | ||
12 | 62 | 66 | ||
13 | === modified file 'ChangeLog' | |||
14 | --- ChangeLog 2011-05-12 20:42:28 +0000 | |||
15 | +++ ChangeLog 2011-10-14 11:09:18 +0000 | |||
16 | @@ -1,3 +1,368 @@ | |||
17 | 1 | 2011-08-11 Scott James Remnant <keybuk@google.com> | ||
18 | 2 | |||
19 | 3 | * init/job_process.c (job_process_spawn): Can't return on | ||
20 | 4 | dup2() error, we're in the child. Return an error back to | ||
21 | 5 | the child properly. | ||
22 | 6 | |||
23 | 7 | * init/job_process.c (job_process_spawn), init/main.c: error | ||
24 | 8 | should be ENOENT | ||
25 | 9 | |||
26 | 10 | * init/job_class.c, init/job_class.h: Move constants into the | ||
27 | 11 | header file so they can be found from other source files. | ||
28 | 12 | * init/job_process.c (job_process_spawn): Only adjust the OOM | ||
29 | 13 | score if it isn't the default | ||
30 | 14 | * init/main.c: Apply the default OOM score to the init process | ||
31 | 15 | itself. | ||
32 | 16 | |||
33 | 17 | * init/main.c: Deal with failure to setup the system console by | ||
34 | 18 | falling back to /dev/null, so we don't end up without default fds | ||
35 | 19 | and castrate the process. | ||
36 | 20 | |||
37 | 21 | 2011-08-10 Scott James Remnant <keybuk@google.com> | ||
38 | 22 | |||
39 | 23 | * init/job_class.c (job_class_new): nit, use #defines for the default | ||
40 | 24 | nice level and oom score adjustment. | ||
41 | 25 | |||
42 | 26 | 2011-07-25 James Hunt <james.hunt@ubuntu.com> | ||
43 | 27 | |||
44 | 28 | * init/job_process.c: job_process_spawn(): | ||
45 | 29 | - Added dup2() return check. | ||
46 | 30 | * TESTING.sessions: Updated with information on user sessions. | ||
47 | 31 | * init/job_process.c: | ||
48 | 32 | - job_process_spawn(): | ||
49 | 33 | - Change group before user and do it as early as possible. | ||
50 | 34 | - Ensure non-priv user is able to read script fd. Default system | ||
51 | 35 | behaviour is seemingly not consistent/defined, so force it | ||
52 | 36 | to be (LP: #813052) | ||
53 | 37 | - Ensure cwd for user job is home directory by default. | ||
54 | 38 | - job_process_error_read(): | ||
55 | 39 | - Added handling for JOB_PROCESS_ERROR_SETUID and | ||
56 | 40 | JOB_PROCESS_ERROR_SETGID (LP: #807293). | ||
57 | 41 | - Added new entry for JOB_PROCESS_ERROR_CHOWN. | ||
58 | 42 | * init/job_process.h: | ||
59 | 43 | - Added entry for JOB_PROCESS_ERROR_CHOWN in JobProcessErrorType. | ||
60 | 44 | * init/man/init.5: Update for user jobs explaining behaviour of stanzas | ||
61 | 45 | which manipulate system resource limits and when the init | ||
62 | 46 | daemon reads the users job directory. | ||
63 | 47 | * util/tests/test_user_sessions.sh: New script for testing user sessions | ||
64 | 48 | (NOTE: this is *NOT* run automatically). | ||
65 | 49 | * init/session.c: session_from_dbus(): Handle case where a users | ||
66 | 50 | home directory is changed or where a uid is re-used for a | ||
67 | 51 | different username. | ||
68 | 52 | * init/session.h: Updated comments for Session object. | ||
69 | 53 | * init/man/init.5: Explain that symbolic links are not supported. | ||
70 | 54 | |||
71 | 55 | 2011-07-22 James Hunt <james.hunt@ubuntu.com> | ||
72 | 56 | |||
73 | 57 | * util/man/initctl.8: Clarify semantics of restart(8) | ||
74 | 58 | command (LP: #731225). | ||
75 | 59 | |||
76 | 60 | 2011-07-20 James Hunt <james.hunt@ubuntu.com> | ||
77 | 61 | |||
78 | 62 | * util/tests/test_initctl.c: | ||
79 | 63 | - test_show_config(): /* fall through :) */ | ||
80 | 64 | - test_check_config(): Manually start and stop dbus-daemon to work | ||
81 | 65 | around change in dbus autostart behaviour which causes issues when | ||
82 | 66 | running the tests in a chroot and non-X11 environment (see dbus commit | ||
83 | 67 | cea055514a9dfc74e7f0515cf4a256da10a891bc). | ||
84 | 68 | |||
85 | 69 | 2011-06-14 James Hunt <james.hunt@ubuntu.com> | ||
86 | 70 | |||
87 | 71 | * NEWS: Release 1.3 | ||
88 | 72 | |||
89 | 73 | 2011-06-14 James Hunt <james.hunt@ubuntu.com> | ||
90 | 74 | |||
91 | 75 | * contrib/vim/syntax/upstart.vim: Updates for kill, oom, expect | ||
92 | 76 | and limit. | ||
93 | 77 | |||
94 | 78 | 2011-06-07 Scott James Remnant <scott@netsplit.com> | ||
95 | 79 | |||
96 | 80 | * init/job_process.c (job_process_spawn): Make sure we don't close | ||
97 | 81 | our own file descriptor if it already has the right value. | ||
98 | 82 | |||
99 | 83 | 2011-06-06 James Hunt <james.hunt@ubuntu.com> | ||
100 | 84 | |||
101 | 85 | Add override file support. | ||
102 | 86 | |||
103 | 87 | * init/conf.c: | ||
104 | 88 | - conf_reload_path(): Now takes an extra override_path parameter. | ||
105 | 89 | - is_conf_file() / is_conf_file_std() / is_conf_file_override(): New | ||
106 | 90 | functions to determine type of given file path. | ||
107 | 91 | - toggle_conf_name(): New function which convert a conf file | ||
108 | 92 | name to an override name and vice versa. | ||
109 | 93 | - majority of remaining functions updated to handle override | ||
110 | 94 | files. | ||
111 | 95 | * init/conf.h: Prototypes. | ||
112 | 96 | * init/job_class.c: Whitespace. | ||
113 | 97 | * init/man/init.5: Updated to document override file support. | ||
114 | 98 | * init/man/init.8: Added reference to control-alt-delete(7) man page. | ||
115 | 99 | * init/paths.h: New macros CONF_EXT_OVERRIDE, CONF_EXT_STD, | ||
116 | 100 | IS_CONF_FILE_OVERRIDE and IS_CONF_FILE_STD. | ||
117 | 101 | * init/parse_conf.c: Added assertion to remind us forcibly to add | ||
118 | 102 | override-handling code for directories if we ever allow content in | ||
119 | 103 | 'init.conf'. | ||
120 | 104 | * init/parse_job.c (parse_job): Additional parameter 'update' to | ||
121 | 105 | allow override files to replace existing Job details. | ||
122 | 106 | * init/parse_job.h: Updated parse_job() prototype. | ||
123 | 107 | * init/test_conf.c | ||
124 | 108 | - New macros TEST_ENSURE_CLEAN_ENV() and | ||
125 | 109 | TEST_FORCE_WATCH_UPDATE(). | ||
126 | 110 | - test_override(): New function. | ||
127 | 111 | - test_toggle_conf_name(): New function. | ||
128 | 112 | * init/test_parse_job.c: | ||
129 | 113 | - Updated for extra parse_job() parameter. | ||
130 | 114 | - added a test feature to test_parse_job() to exercise new | ||
131 | 115 | parameter to parse_job(). | ||
132 | 116 | * util/man/initctl.8: Clarified what it means to restart a job. | ||
133 | 117 | |||
134 | 118 | Add udev and socket bridges. | ||
135 | 119 | |||
136 | 120 | * Makefile.am: Added extra directory. | ||
137 | 121 | * New files: | ||
138 | 122 | - extra/Makefile.am | ||
139 | 123 | - extra/conf/upstart-socket-bridge.conf | ||
140 | 124 | - extra/conf/upstart-udev-bridge.conf | ||
141 | 125 | - extra/man/socket-event.7 | ||
142 | 126 | - extra/man/upstart-socket-bridge.8 | ||
143 | 127 | - extra/man/upstart-udev-bridge.8 | ||
144 | 128 | - extra/upstart-socket-bridge.c | ||
145 | 129 | - extra/upstart-udev-bridge.c | ||
146 | 130 | * configure.ac: | ||
147 | 131 | - Check for udev (for upstart-udev-bridge). | ||
148 | 132 | - Add extra/Makefile to AC_CONFIG_FILES. | ||
149 | 133 | * dbus/com.ubuntu.Upstart.xml: Add EmitEventWithFile method. | ||
150 | 134 | * init/control.c: | ||
151 | 135 | - control_emit_event(): Now a wrapper for control_emit_event_with_file. | ||
152 | 136 | - control_emit_event_with_file(): New function that operates on an fd. | ||
153 | 137 | * init/control.h: Prototype for control_emit_event_with_file(). | ||
154 | 138 | * init/event.c: | ||
155 | 139 | - event_new(): Initialize event fd. | ||
156 | 140 | - event_pending_handle_jobs(): Now calls event_operator_fds(). | ||
157 | 141 | * init/event.c: Add fd to Event struct. | ||
158 | 142 | * init/event_operator.c: event_operator_fds(): New function. | ||
159 | 143 | * init/event_operator.h: Prototype for event_operator_fds(). | ||
160 | 144 | * init/job.c: job_new(): Initialize fd members. | ||
161 | 145 | * init/job.h: Add fds and num_fds to Job struct. | ||
162 | 146 | |||
163 | 147 | 2011-06-03 James Hunt <james.hunt@ubuntu.com> | ||
164 | 148 | |||
165 | 149 | Add session support. Note that there are no automatically runnable and | ||
166 | 150 | explicit tests yet. However, see TESTING.sessions. | ||
167 | 151 | |||
168 | 152 | * TESTING.sessions: ASCII (reStructuredText) document explaining | ||
169 | 153 | how to run manual tests for session support (for chroots). | ||
170 | 154 | * dbus/Upstart.conf: Simplified to support allowing users to invoke | ||
171 | 155 | all methods (since Upstart now isolates commands by user). | ||
172 | 156 | * init/Makefile.am: Added session.[ch] files. | ||
173 | 157 | * init/session.c: New file. Note that session_from_dbus() will disable sessions | ||
174 | 158 | (by returning the NULL session) if environment variable "UPSTART_NO_SESSIONS" | ||
175 | 159 | is set to any value (used by tests). | ||
176 | 160 | * init/session.h: New file. | ||
177 | 161 | * init/parse_job.h: parse_job(): Add session pointer to prototype. | ||
178 | 162 | * init/parse_job.c: | ||
179 | 163 | - parse_job(): Add session parameter. | ||
180 | 164 | - Update calls to job_class_new() to pass session pointer. | ||
181 | 165 | * init/job.c: job_new(): Crucial change to ensure chroot sessions have | ||
182 | 166 | a unique D-Bus name (LP:#728531). | ||
183 | 167 | * init/job_class.c: | ||
184 | 168 | - job_class_new(): Add session parameter and session support. | ||
185 | 169 | - job_class_remove(): Add session parameter to prototype. | ||
186 | 170 | - job_class_consider(): Only consider jobs from the appropriate session. | ||
187 | 171 | - job_class_reconsider(): Only consider jobs from the appropriate session. | ||
188 | 172 | - job_class_start(): Disallow out-of-session modification. | ||
189 | 173 | - job_class_stop(): Disallow out-of-session modification. | ||
190 | 174 | - job_class_restart(): Disallow out-of-session modification. | ||
191 | 175 | * init/main.c: Add "--no-sessions" command-line option to disable | ||
192 | 176 | sessions and revert to traditional behaviour. | ||
193 | 177 | * init/job_class.h: | ||
194 | 178 | - job_class_new(): Add session pointer to prototype. | ||
195 | 179 | - JobClass: Add session member. | ||
196 | 180 | * init/job_process.c: job_process_spawn(): | ||
197 | 181 | - Call chroot(2) for chroot sessions. | ||
198 | 182 | - Call setuid(2) for user session jobs. | ||
199 | 183 | * init/job.c: | ||
200 | 184 | - job_emit_event(): Set session for event. | ||
201 | 185 | - job_start(): Disallow out-of-session modification. | ||
202 | 186 | - job_stop(): Disallow out-of-session modification. | ||
203 | 187 | - job_restart(): Disallow out-of-session modification. | ||
204 | 188 | * init/event.h: Event: Add session member. | ||
205 | 189 | * init/event.c: | ||
206 | 190 | - event_new(): initialize session to NULL. | ||
207 | 191 | - event_pending_handle_jobs(): Add session handling. | ||
208 | 192 | - event_finished(): Set session for failure event. | ||
209 | 193 | * init/control.c: | ||
210 | 194 | - control_get_job_by_name(): Add session handling. | ||
211 | 195 | - control_get_all_jobs(): Add session handling. | ||
212 | 196 | - control_emit_event(): Add session handling. | ||
213 | 197 | * init/conf.c: | ||
214 | 198 | - conf_source_new(): Initialise session to NULL. | ||
215 | 199 | - conf_reload_path(): Pass session to parse_job(). | ||
216 | 200 | - conf_select_job(): Add session parameter. | ||
217 | 201 | * init/conf.h: | ||
218 | 202 | - ConfSource: Add session member. | ||
219 | 203 | - conf_select_job(): Add session parameter to prototype. | ||
220 | 204 | * All tests updated to set "UPSTART_NO_SESSIONS" (to disable | ||
221 | 205 | sessions). | ||
222 | 206 | |||
223 | 207 | 2011-06-02 James Hunt <james.hunt@ubuntu.com> | ||
224 | 208 | |||
225 | 209 | * contrib/bash_completion/upstart: | ||
226 | 210 | - Made function names more meaningful: | ||
227 | 211 | - _upstart_jobs: Now returns a unique list | ||
228 | 212 | - _upstart_events (nee _upstart_named_events ) now considers all | ||
229 | 213 | "emits" tokens. | ||
230 | 214 | - Updates for "check-config" and "show-config". | ||
231 | 215 | - Added "--session" option. | ||
232 | 216 | - Added "--no-wait" for emit, reload and restart. | ||
233 | 217 | |||
234 | 218 | Man page updates. | ||
235 | 219 | |||
236 | 220 | * init/man/init.5: | ||
237 | 221 | - Quoted dashes. | ||
238 | 222 | - Explain handling of duplicated stanzas. | ||
239 | 223 | - "respawn": Document default count and interval. | ||
240 | 224 | - "emits": Reference "initctl check-config". | ||
241 | 225 | - Added BUGS section. | ||
242 | 226 | - Added copyright. | ||
243 | 227 | * init/man/init.8: | ||
244 | 228 | - Quoted dashes. | ||
245 | 229 | - See Also: Added control-alt-delete(7). | ||
246 | 230 | * util/man/initctl.8: | ||
247 | 231 | - Quoted dashes. | ||
248 | 232 | - "restart": Clarified meaning. | ||
249 | 233 | - "list": Explained "stop/waiting" jobs. | ||
250 | 234 | |||
251 | 235 | 2011-06-01 James Hunt <james.hunt@ubuntu.com> | ||
252 | 236 | |||
253 | 237 | Add D-Bus session support to initctl. | ||
254 | 238 | |||
255 | 239 | * util/initctl.c: | ||
256 | 240 | - Added "--session" command-line option. | ||
257 | 241 | - dbus_bus_type_setter(): New function used by option parser to | ||
258 | 242 | distinguish system/session D-Bus bus type. | ||
259 | 243 | - system_bus variable now replaced by two others: use_dbus (boolean) | ||
260 | 244 | and dbus_bus_type. | ||
261 | 245 | - upstart_open(): Updated to handle multiple D-Bus bus types. | ||
262 | 246 | * util/man/initctl.8: Update for "--session" option. | ||
263 | 247 | * util/tests/test_initctl.c: Updated to make use of use_dbus and | ||
264 | 248 | dbus_bus_type rather than system_bus. | ||
265 | 249 | |||
266 | 250 | Add "show-config" command to initctl. | ||
267 | 251 | |||
268 | 252 | * util/initctl.c: | ||
269 | 253 | - New functions: | ||
270 | 254 | - job_class_condition_handler(): Handler function to retrieve job conditions. | ||
271 | 255 | - job_class_condition_err_handler(): Handler error function for | ||
272 | 256 | job_class_condition_handler(). | ||
273 | 257 | - job_class_parse_events(): Convert RPN "start on" and "stop on" conditions to | ||
274 | 258 | human-readable format. | ||
275 | 259 | - job_class_show_emits(): Display events which job emits. | ||
276 | 260 | - job_class_show_conditions(): Make D-Bus calls to retrieve "start on" and | ||
277 | 261 | "stop on" conditions. | ||
278 | 262 | - show_config_action: Handle "show-config" command.. | ||
279 | 263 | * util/initctl.h: New file providing stack-handling functionality for | ||
280 | 264 | RPN parsing for "show-config" command. | ||
281 | 265 | * util/Makefile.am: Added initctl.h to initctl_SOURCES. | ||
282 | 266 | * util/man/initctl.8: Updated for "show-config" command and associated | ||
283 | 267 | options. | ||
284 | 268 | * util/tests/test_initctl.c: | ||
285 | 269 | - New macros START_UPSTART, STOP_UPSTART, RUN_COMMAND, CREATE_FILE and DELETE_FILE. | ||
286 | 270 | These are required since due to the introduction of the | ||
287 | 271 | "show-config" initctl command, initctl is no longer solely a proxy | ||
288 | 272 | to Upstart: it now has some intelligence (it parses the | ||
289 | 273 | "emits", "start on" and "stop on" conditions) and thus must be | ||
290 | 274 | tested directly. | ||
291 | 275 | - test_show_config(): New function to test "initctl show-config". | ||
292 | 276 | - in_chroot(): New function to detect if tests are being run from | ||
293 | 277 | within a chroot environment. | ||
294 | 278 | - dbus_configured(): New function which performs a basic check to | ||
295 | 279 | establish if D-Bus is configured correctly. | ||
296 | 280 | - main(): Added call to test_show_config(), conditional on | ||
297 | 281 | a non-chroot environment and a working D-Bus system. | ||
298 | 282 | |||
299 | 283 | Add "check-config" command to initctl. | ||
300 | 284 | |||
301 | 285 | * util/initctl.c: | ||
302 | 286 | - New functions: | ||
303 | 287 | - allow_event(): Determine if specified event is erroneous or not. | ||
304 | 288 | Handles globbing. | ||
305 | 289 | - allow_job(): Determine if specified job is erroneous or not. | ||
306 | 290 | Handles variables (such as instance variables). | ||
307 | 291 | - check_condition(): High-level function to handle checking start | ||
308 | 292 | on/stop on conditions. | ||
309 | 293 | - check_config_action: Handler for "check-config" command. | ||
310 | 294 | - display_check_errors(): Display errors from expression tree nodes | ||
311 | 295 | that are in error. | ||
312 | 296 | - eval_expr_tree(): Evaluate expression tree. | ||
313 | 297 | - ignored_events_setter(): handler for '--ignore-events' command-line | ||
314 | 298 | option for "check-config" command. | ||
315 | 299 | - tree_filter(): Used for filtering expression tree nodes. | ||
316 | 300 | - show_config_action(): Update for check-config mode. | ||
317 | 301 | - job_class_parse_events(): Update for check-config mode. | ||
318 | 302 | - job_class_show_emits(): Update for check-config mode. | ||
319 | 303 | * util/initctl.h: | ||
320 | 304 | - Added structs for JobCondition, CheckConfigData and ExprNode. | ||
321 | 305 | - New macros: MAKE_EXPR_NODE() and MAKE_JOB_CONDITION(). | ||
322 | 306 | * util/tests/test_initctl.c: | ||
323 | 307 | - test_check_config(): New function to test "initctl check-config". | ||
324 | 308 | - main(): Added call to test_check_config(), conditional on | ||
325 | 309 | a non-chroot environment and a working D-Bus system. | ||
326 | 310 | * util/man/initctl.8: Updated for "check-config" command and associated | ||
327 | 311 | options. | ||
328 | 312 | * conf/rc-sysinit.conf: Added "emits" stanza, required by | ||
329 | 313 | "check-config". | ||
330 | 314 | |||
331 | 315 | Addition of initctl2dot script for visualisation. | ||
332 | 316 | |||
333 | 317 | * Makefile.am: Added scripts directory. | ||
334 | 318 | * configure.ac: Updated AC_CONFIG_FILES for scripts/Makefile. | ||
335 | 319 | * scripts/Makefile.am: Makefile for scripts. | ||
336 | 320 | * scripts/initctl2dot.py: Python script to produce dot(1) graphs of | ||
337 | 321 | "initctl show-config" output. | ||
338 | 322 | * scripts/man/initctl2dot.8: Man page for initctl2dot.py script. | ||
339 | 323 | |||
340 | 324 | Addition of init-checkconf script. | ||
341 | 325 | |||
342 | 326 | * scripts/init-checkconf.sh: Script to determine if specified job | ||
343 | 327 | config file is valid or not. | ||
344 | 328 | * scripts/man/init-checkconf.8: Man page for init-checkconf.sh. | ||
345 | 329 | * scripts/Makefile.am: Added init-checkconf script and man | ||
346 | 330 | page. | ||
347 | 331 | |||
348 | 332 | 2011-05-31 James Hunt <james.hunt@ubuntu.com> | ||
349 | 333 | |||
350 | 334 | Add command-line option to use D-Bus session bus (for testing). | ||
351 | 335 | |||
352 | 336 | * init/control.c: | ||
353 | 337 | - Added new boolean use_session_bus. | ||
354 | 338 | - Updated comments. | ||
355 | 339 | - control_handle_bus_type(): New function to allow selection of | ||
356 | 340 | session bus via env var "UPSTART_USE_SESSION_BUS". | ||
357 | 341 | Also logs use of session bus if use_session_bus set. | ||
358 | 342 | - control_bus_open(): Now connects to either D-Bus system bus or session bus. | ||
359 | 343 | * init/control.h: New define for USE_SESSION_BUS_ENV. | ||
360 | 344 | * init/main.c: Addition of "--session" command-line option. | ||
361 | 345 | * init/man/init.8: Update for new "--session" command-line option. | ||
362 | 346 | |||
363 | 347 | * Corrected copyright notices. | ||
364 | 348 | |||
365 | 349 | Add option to allow alternate location for job config files. | ||
366 | 350 | |||
367 | 351 | * init/main.c: | ||
368 | 352 | - Added "--confdir <dir>" command-line option. | ||
369 | 353 | - handle_confdir(): New function to select alternate confdir using env | ||
370 | 354 | var "UPSTART_CONFDIR" or command-line option (for testing). | ||
371 | 355 | * init/paths.h: Added define for CONFDIR_ENV. | ||
372 | 356 | * init/man/init.8: Update for new "--confdir" command-line option. | ||
373 | 357 | |||
374 | 358 | Add ability to suppress initial event and/or change its name. | ||
375 | 359 | |||
376 | 360 | * init/main.c: New command-line options: "--no-startup-event" and | ||
377 | 361 | "--startup-event". If "--no-startup-event" specified, log message as a | ||
378 | 362 | debug aid. | ||
379 | 363 | * init/man/init.8: Documentation for new command-line options: | ||
380 | 364 | "--no-startup-event" and "--startup-event". | ||
381 | 365 | |||
382 | 1 | 2011-05-12 Marc - A. Dahlhaus <mad@wol.de> | 366 | 2011-05-12 Marc - A. Dahlhaus <mad@wol.de> |
383 | 2 | 367 | ||
384 | 3 | * init/job_class.h (JobClass): Add kill signal member | 368 | * init/job_class.h (JobClass): Add kill signal member |
385 | 4 | 369 | ||
386 | === modified file 'Makefile.am' | |||
387 | --- Makefile.am 2010-02-04 03:42:29 +0000 | |||
388 | +++ Makefile.am 2011-10-14 11:09:18 +0000 | |||
389 | @@ -1,6 +1,6 @@ | |||
390 | 1 | ## Process this file with automake to produce Makefile.in | 1 | ## Process this file with automake to produce Makefile.in |
391 | 2 | 2 | ||
393 | 3 | SUBDIRS = intl dbus init util conf doc contrib po | 3 | SUBDIRS = intl dbus init util extra conf doc contrib po scripts |
394 | 4 | 4 | ||
395 | 5 | EXTRA_DIST = HACKING | 5 | EXTRA_DIST = HACKING |
396 | 6 | 6 | ||
397 | 7 | 7 | ||
398 | === modified file 'NEWS' | |||
399 | --- NEWS 2011-03-22 17:53:17 +0000 | |||
400 | +++ NEWS 2011-10-14 11:09:18 +0000 | |||
401 | @@ -1,4 +1,38 @@ | |||
403 | 1 | 1.3 xxxx-xx-xx | 1 | 1.4 xxxx-xx-xx |
404 | 2 | |||
405 | 3 | 1.3 2011-06-14 "Concordia" | ||
406 | 4 | |||
407 | 5 | * New upstart-socket-bridge application which allows jobs to be | ||
408 | 6 | started when an incoming client socket connection is initiated | ||
409 | 7 | (requires a suitably modified server daemon since jobs only | ||
410 | 8 | need call accept(2) before reading from the socket). | ||
411 | 9 | * User session support allowing non-privileged users to | ||
412 | 10 | manipulate their own jobs (not available within a chroot | ||
413 | 11 | environment). | ||
414 | 12 | * Chroot support allowing jobs to be controlled within chroot | ||
415 | 13 | environments. | ||
416 | 14 | * Updated bash completion script. | ||
417 | 15 | * Updated vim syntax script. | ||
418 | 16 | * init-checkconf script used to check syntax of Job | ||
419 | 17 | Configuration Files (including script sections). | ||
420 | 18 | * initctl2dot script to convert initctl(8) output to GraphViz | ||
421 | 19 | dot(1) format for analysing relationships between jobs and | ||
422 | 20 | events. | ||
423 | 21 | * New "check-config" initctl command to check for jobs whose | ||
424 | 22 | * "start on" and "stop on" events cannot be satisfied. | ||
425 | 23 | * New "show-config" initctl command to display "start on", "stop | ||
426 | 24 | on" and emits" information in parseable format. | ||
427 | 25 | * New initctl command-line option: "--session" for D-Bus | ||
428 | 26 | session connection. | ||
429 | 27 | * New init command line options (mostly for testing): | ||
430 | 28 | - "--session" for D-Bus session bus. | ||
431 | 29 | - "--confdir <dir>". | ||
432 | 30 | - "--startup-event <event>". | ||
433 | 31 | - "--no-startup-event". | ||
434 | 32 | * New "kill signal" stanza to allow override of SIGTERM when | ||
435 | 33 | stopping jobs. | ||
436 | 34 | * Add support for the oom_score_adj procfs API. | ||
437 | 35 | * Improved POSIX compliance when running shell scripts. | ||
438 | 2 | 36 | ||
439 | 3 | 1.2 2011-03-22 "This sort of thing is my bag, baby" | 37 | 1.2 2011-03-22 "This sort of thing is my bag, baby" |
440 | 4 | 38 | ||
441 | 5 | 39 | ||
442 | === added file 'TESTING.sessions' | |||
443 | --- TESTING.sessions 1970-01-01 00:00:00 +0000 | |||
444 | +++ TESTING.sessions 2011-10-14 11:09:18 +0000 | |||
445 | @@ -0,0 +1,289 @@ | |||
446 | 1 | .. contents:: | ||
447 | 2 | |||
448 | 3 | ============================= | ||
449 | 4 | Testing Sessions with Upstart | ||
450 | 5 | ============================= | ||
451 | 6 | |||
452 | 7 | Upstart now has support for two types of "sessions": | ||
453 | 8 | |||
454 | 9 | * user sessions | ||
455 | 10 | |||
456 | 11 | * chroots sessions | ||
457 | 12 | |||
458 | 13 | Such sessions are implemented by asociating a separate Upstart session | ||
459 | 14 | with every chroot environment and every non-privileged user. | ||
460 | 15 | |||
461 | 16 | The session support does not yet provide full tests (as would be run by | ||
462 | 17 | "``make check``"). This is mostly due to the complexity of automatically | ||
463 | 18 | testing some of the scenarios below. | ||
464 | 19 | |||
465 | 20 | This document attempts to outline the minimum set of tests that should | ||
466 | 21 | be performed to ensure that session support works as expected. | ||
467 | 22 | |||
468 | 23 | Assumptions | ||
469 | 24 | =========== | ||
470 | 25 | |||
471 | 26 | You are running an Ubuntu or Debian system. | ||
472 | 27 | |||
473 | 28 | User Sessions | ||
474 | 29 | ============= | ||
475 | 30 | |||
476 | 31 | User sessions can be minimally tested using the script provided:: | ||
477 | 32 | |||
478 | 33 | util/tests/test_user_sessions.sh | ||
479 | 34 | |||
480 | 35 | Notes: | ||
481 | 36 | |||
482 | 37 | - Run "``test_user_sessions.sh -h``" to understand what this script does. | ||
483 | 38 | |||
484 | 39 | - that this script needs to be run on a system where the version of | ||
485 | 40 | ``/sbin/init`` has session support since the ``/sbin/init`` binary | ||
486 | 41 | itself will be tested. For this reason, the script cannot be run as part | ||
487 | 42 | of the "``make check``" run. | ||
488 | 43 | |||
489 | 44 | - The script will complain loudly if any of the tests fail and tell you | ||
490 | 45 | how to raise a bug. | ||
491 | 46 | |||
492 | 47 | Chroot Sessions | ||
493 | 48 | =============== | ||
494 | 49 | |||
495 | 50 | Setup | ||
496 | 51 | ----- | ||
497 | 52 | |||
498 | 53 | #. Install a chroot environement (such as ``schroot(1)``) and configure it. | ||
499 | 54 | #. run, "``debootstrap(8)``" to install the same release as you are running into your chroot. | ||
500 | 55 | #. Create the following files *outside* your chroot. | ||
501 | 56 | |||
502 | 57 | - ``/etc/init/foo.conf``:: | ||
503 | 58 | |||
504 | 59 | start on wibble | ||
505 | 60 | |||
506 | 61 | script | ||
507 | 62 | exec 2>>/tmp/foo.$$.log | ||
508 | 63 | set -x | ||
509 | 64 | echo "foo: stat=`stat /`" | ||
510 | 65 | echo "foo: env=`env`" | ||
511 | 66 | sleep 999 | ||
512 | 67 | end script | ||
513 | 68 | |||
514 | 69 | - ``/etc/init/outside_chroot.conf``:: | ||
515 | 70 | |||
516 | 71 | start on A | ||
517 | 72 | |||
518 | 73 | script | ||
519 | 74 | exec 2>>/tmp/outside_chroot.$$.log | ||
520 | 75 | set -x | ||
521 | 76 | echo "in_chroot: stat=`stat /`" | ||
522 | 77 | echo "in_chroot: env=`env`" | ||
523 | 78 | sleep 999 | ||
524 | 79 | end script | ||
525 | 80 | |||
526 | 81 | #. Create following files inside chroot environment. | ||
527 | 82 | |||
528 | 83 | - ``/path/to/chroot/etc/init/foo.conf``:: | ||
529 | 84 | |||
530 | 85 | start on wibble | ||
531 | 86 | |||
532 | 87 | script | ||
533 | 88 | exec 2>>/tmp/foo.$$.log | ||
534 | 89 | set -x | ||
535 | 90 | echo "foo: stat=`stat /`" | ||
536 | 91 | echo "foo: env=`env`" | ||
537 | 92 | sleep 999 | ||
538 | 93 | end script | ||
539 | 94 | |||
540 | 95 | - ``/path/to/chroot/etc/init/in_chroot.conf``:: | ||
541 | 96 | |||
542 | 97 | start on A | ||
543 | 98 | |||
544 | 99 | script | ||
545 | 100 | exec 2>>/tmp/in_chroot.$$.log | ||
546 | 101 | set -x | ||
547 | 102 | echo "in_chroot: stat=`stat /`" | ||
548 | 103 | echo "in_chroot: env=`env`" | ||
549 | 104 | sleep 999 | ||
550 | 105 | end script | ||
551 | 106 | |||
552 | 107 | |||
553 | 108 | Run as non-``root`` with no chroot | ||
554 | 109 | ---------------------------------- | ||
555 | 110 | |||
556 | 111 | - ``initctl list`` | ||
557 | 112 | |||
558 | 113 | Ensure list is contents of ``/etc/init/``: the command below should | ||
559 | 114 | return no output:: | ||
560 | 115 | |||
561 | 116 | cmp <(initctl list|awk '{print $1}'|sort -u) <(cd /etc/init && ls *.conf|cut -d: -f2-|sed 's/\.conf//g'|sort -u) | ||
562 | 117 | |||
563 | 118 | - ``initctl status cron`` | ||
564 | 119 | |||
565 | 120 | Should work. | ||
566 | 121 | |||
567 | 122 | - ``initctl show-config`` | ||
568 | 123 | |||
569 | 124 | Should work. | ||
570 | 125 | |||
571 | 126 | - ``initctl check-config`` | ||
572 | 127 | |||
573 | 128 | Should work. | ||
574 | 129 | |||
575 | 130 | - ``start foo`` | ||
576 | 131 | |||
577 | 132 | Should fail ("``initctl: Rejected send message``"). | ||
578 | 133 | |||
579 | 134 | - ``stop cron`` | ||
580 | 135 | |||
581 | 136 | Should fail ("``initctl: Rejected send message``"). | ||
582 | 137 | |||
583 | 138 | - ``restart cron`` | ||
584 | 139 | |||
585 | 140 | Should fail ("``initctl: Rejected send message``"). | ||
586 | 141 | |||
587 | 142 | - ``initctl emit bar`` | ||
588 | 143 | |||
589 | 144 | Should fail ("``initctl: Rejected send message``"). | ||
590 | 145 | |||
591 | 146 | Run as ``root`` with no chroot | ||
592 | 147 | ------------------------------ | ||
593 | 148 | |||
594 | 149 | - ``initctl list`` | ||
595 | 150 | |||
596 | 151 | Ensure list is contents of ``/etc/init/``: command below should return no output:: | ||
597 | 152 | |||
598 | 153 | cmp <(initctl list|awk '{print $1}'|sort -u) <(cd /etc/init && ls *.conf|cut -d: -f2-|sed 's/\.conf//g'|sort -u) | ||
599 | 154 | |||
600 | 155 | - ``initctl status outside_chroot`` | ||
601 | 156 | |||
602 | 157 | Should work. | ||
603 | 158 | |||
604 | 159 | - ``initctl status in_chroot`` | ||
605 | 160 | |||
606 | 161 | Should fail with message:: | ||
607 | 162 | |||
608 | 163 | initct: Unknown job: in_chroot | ||
609 | 164 | |||
610 | 165 | - ``initctl show-config`` | ||
611 | 166 | |||
612 | 167 | Should work. | ||
613 | 168 | |||
614 | 169 | - ``initctl check-config`` | ||
615 | 170 | |||
616 | 171 | Should work. | ||
617 | 172 | |||
618 | 173 | - ``start in_chroot`` | ||
619 | 174 | |||
620 | 175 | Should fail with message:: | ||
621 | 176 | |||
622 | 177 | initct: Unknown job: in_chroot | ||
623 | 178 | |||
624 | 179 | - ``start outside_chroot`` | ||
625 | 180 | |||
626 | 181 | Should work. | ||
627 | 182 | |||
628 | 183 | - ``stop in_chroot`` | ||
629 | 184 | |||
630 | 185 | Should fail with message:: | ||
631 | 186 | |||
632 | 187 | initct: Unknown job: in_chroot | ||
633 | 188 | |||
634 | 189 | - ``restart outside_chroot`` | ||
635 | 190 | |||
636 | 191 | Should work. | ||
637 | 192 | |||
638 | 193 | - ``stop outside_chroot`` | ||
639 | 194 | |||
640 | 195 | Should work. | ||
641 | 196 | |||
642 | 197 | - ``initctl emit wibble`` | ||
643 | 198 | |||
644 | 199 | - Ensure ``/etc/init/foo.conf`` runs by looking at the log and ensuring | ||
645 | 200 | the inode for the stat of '``/``' is the same as running "``stat /``" on | ||
646 | 201 | the command-line. | ||
647 | 202 | |||
648 | 203 | * Ensure ``/path/to/chroot/etc/init/foo.conf`` does *NOT* run. | ||
649 | 204 | |||
650 | 205 | - ``initctl emit A`` | ||
651 | 206 | |||
652 | 207 | - Ensure ``/etc/init/outside_chroot.conf`` runs. | ||
653 | 208 | |||
654 | 209 | - Ensure ``/path/to/chroot/etc/init/in_chroot.conf`` does *NOT* run. | ||
655 | 210 | |||
656 | 211 | Run as ``root`` inside a chroot | ||
657 | 212 | ------------------------------- | ||
658 | 213 | |||
659 | 214 | - ``initctl list`` | ||
660 | 215 | |||
661 | 216 | Ensure list is contents of ``/path/to/chroot/etc/init/``: command below should return no output:: | ||
662 | 217 | |||
663 | 218 | cmp <(initctl list|awk '{print $1}'|sort -u) <(cd /etc/init && ls *.conf|cut -d: -f2-|sed 's/\.conf//g'|sort -u) | ||
664 | 219 | |||
665 | 220 | - ``initctl status in_chroot`` | ||
666 | 221 | |||
667 | 222 | Should work. | ||
668 | 223 | |||
669 | 224 | - ``initctl status outside_chroot`` | ||
670 | 225 | |||
671 | 226 | Should fail with message:: | ||
672 | 227 | |||
673 | 228 | initct: Unknown job: outside_chroot | ||
674 | 229 | |||
675 | 230 | - ``initctl show-config`` | ||
676 | 231 | |||
677 | 232 | Should work. | ||
678 | 233 | |||
679 | 234 | - ``initctl check-config`` | ||
680 | 235 | |||
681 | 236 | Should work. | ||
682 | 237 | |||
683 | 238 | - ``start outside_chroot`` | ||
684 | 239 | |||
685 | 240 | Should fail with message:: | ||
686 | 241 | |||
687 | 242 | initct: Unknown job: outside_chroot | ||
688 | 243 | |||
689 | 244 | - ``stop outside_chroot`` | ||
690 | 245 | |||
691 | 246 | Should fail with message:: | ||
692 | 247 | |||
693 | 248 | initct: Unknown job: outside_chroot | ||
694 | 249 | |||
695 | 250 | - ``start in_chroot`` | ||
696 | 251 | |||
697 | 252 | Should work. | ||
698 | 253 | |||
699 | 254 | - ``restart in_chroot`` | ||
700 | 255 | |||
701 | 256 | Should work. | ||
702 | 257 | |||
703 | 258 | - ``stop in_chroot`` | ||
704 | 259 | |||
705 | 260 | Should work. | ||
706 | 261 | |||
707 | 262 | - ``initctl emit wibble`` | ||
708 | 263 | |||
709 | 264 | - Ensure ``/path/to/chroot/etc/init/foo.conf`` runs by looking at the log and ensuring | ||
710 | 265 | the inode for the stat of '``/``' is the same as running "``stat /``" on the command-line. | ||
711 | 266 | |||
712 | 267 | - Ensure ``/etc/init/foo.conf`` does *NOT* run. | ||
713 | 268 | |||
714 | 269 | - ``initctl emit A`` | ||
715 | 270 | |||
716 | 271 | - Ensure ``/path/to/chroot/etc/init/in_chroot.conf`` runs. | ||
717 | 272 | |||
718 | 273 | - Ensure ``/etc/init/outside_chroot.conf`` does *NOT* run. | ||
719 | 274 | |||
720 | 275 | Run as non-root inside a chroot | ||
721 | 276 | ------------------------------- | ||
722 | 277 | |||
723 | 278 | Not supported. | ||
724 | 279 | |||
725 | 280 | Run with ``--no-sessions`` | ||
726 | 281 | -------------------------- | ||
727 | 282 | |||
728 | 283 | The "``--no-sessions``" option makes Upstart behave as it used to prior to | ||
729 | 284 | the introduction of session support. | ||
730 | 285 | |||
731 | 286 | #. Reboot system and specify "``--no-sessions``" on kernel command-line. | ||
732 | 287 | |||
733 | 288 | #. Ensure "``initctl list``" within a chroot displays the same list as | ||
734 | 289 | "``initctl list``" run outside of any chroot environment. | ||
735 | 0 | 290 | ||
736 | === modified file 'conf/rc-sysinit.conf' | |||
737 | --- conf/rc-sysinit.conf 2010-02-04 03:59:06 +0000 | |||
738 | +++ conf/rc-sysinit.conf 2011-10-14 11:09:18 +0000 | |||
739 | @@ -13,6 +13,8 @@ | |||
740 | 13 | # or by faking an old /etc/inittab entry | 13 | # or by faking an old /etc/inittab entry |
741 | 14 | env DEFAULT_RUNLEVEL=2 | 14 | env DEFAULT_RUNLEVEL=2 |
742 | 15 | 15 | ||
743 | 16 | emits runlevel | ||
744 | 17 | |||
745 | 16 | # There can be no previous runlevel here, but there might be old | 18 | # There can be no previous runlevel here, but there might be old |
746 | 17 | # information in /var/run/utmp that we pick up, and we don't want | 19 | # information in /var/run/utmp that we pick up, and we don't want |
747 | 18 | # that. | 20 | # that. |
748 | 19 | 21 | ||
749 | === modified file 'configure.ac' | |||
750 | --- configure.ac 2011-03-22 17:53:17 +0000 | |||
751 | +++ configure.ac 2011-10-14 11:09:18 +0000 | |||
752 | @@ -1,8 +1,8 @@ | |||
753 | 1 | # Process this file with autoconf to produce a configure script. | 1 | # Process this file with autoconf to produce a configure script. |
754 | 2 | 2 | ||
755 | 3 | AC_PREREQ(2.61) | 3 | AC_PREREQ(2.61) |
758 | 4 | AC_INIT([upstart], [1.3], [upstart-devel@lists.ubuntu.com]) | 4 | AC_INIT([upstart], [1.4], [upstart-devel@lists.ubuntu.com]) |
759 | 5 | NIH_COPYRIGHT([[Copyright © 2011 Scott James Remnant, Google Inc., Canonical Ltd.]]) | 5 | NIH_COPYRIGHT([[Copyright © 2011 Scott James Remnant, Canonical Ltd.]]) |
760 | 6 | AC_CONFIG_SRCDIR([init/main.c]) | 6 | AC_CONFIG_SRCDIR([init/main.c]) |
761 | 7 | AC_CONFIG_MACRO_DIR([m4]) | 7 | AC_CONFIG_MACRO_DIR([m4]) |
762 | 8 | 8 | ||
763 | @@ -30,6 +30,9 @@ | |||
764 | 30 | PKG_CHECK_MODULES([NIH], [libnih >= 1.0.2]) | 30 | PKG_CHECK_MODULES([NIH], [libnih >= 1.0.2]) |
765 | 31 | PKG_CHECK_MODULES([NIH_DBUS], [libnih-dbus >= 1.0.0]) | 31 | PKG_CHECK_MODULES([NIH_DBUS], [libnih-dbus >= 1.0.0]) |
766 | 32 | PKG_CHECK_MODULES([DBUS], [dbus-1 >= 1.2.16]) | 32 | PKG_CHECK_MODULES([DBUS], [dbus-1 >= 1.2.16]) |
767 | 33 | PKG_CHECK_MODULES([UDEV], [libudev >= 146], [have_udev=yes], [have_udev=no]) | ||
768 | 34 | |||
769 | 35 | AM_CONDITIONAL([HAVE_UDEV], [test "$have_udev" = yes]) | ||
770 | 33 | 36 | ||
771 | 34 | # Checks for header files. | 37 | # Checks for header files. |
772 | 35 | AC_CHECK_HEADERS([valgrind/valgrind.h]) | 38 | AC_CHECK_HEADERS([valgrind/valgrind.h]) |
773 | @@ -64,6 +67,7 @@ | |||
774 | 64 | 67 | ||
775 | 65 | AC_CONFIG_FILES([ Makefile intl/Makefile | 68 | AC_CONFIG_FILES([ Makefile intl/Makefile |
776 | 66 | dbus/Makefile init/Makefile util/Makefile conf/Makefile | 69 | dbus/Makefile init/Makefile util/Makefile conf/Makefile |
778 | 67 | doc/Makefile contrib/Makefile po/Makefile.in ]) | 70 | extra/Makefile doc/Makefile contrib/Makefile po/Makefile.in |
779 | 71 | scripts/Makefile ]) | ||
780 | 68 | AC_CONFIG_HEADERS([config.h]) | 72 | AC_CONFIG_HEADERS([config.h]) |
781 | 69 | AC_OUTPUT | 73 | AC_OUTPUT |
782 | 70 | 74 | ||
783 | === modified file 'contrib/bash_completion/upstart' | |||
784 | --- contrib/bash_completion/upstart 2010-12-21 13:54:49 +0000 | |||
785 | +++ contrib/bash_completion/upstart 2011-10-14 11:09:18 +0000 | |||
786 | @@ -3,26 +3,28 @@ | |||
787 | 3 | # | 3 | # |
788 | 4 | # We don't provide completion for 'init' itself for obvious reasons. | 4 | # We don't provide completion for 'init' itself for obvious reasons. |
789 | 5 | have initctl && | 5 | have initctl && |
803 | 6 | _upstart_conf_events() | 6 | _upstart_jobs() |
804 | 7 | { | 7 | { |
805 | 8 | initctl list|awk '{print $1}' | 8 | initctl list|awk '{print $1}'|sort -u |
806 | 9 | } && | 9 | } && |
807 | 10 | _upstart_named_events() | 10 | _upstart_startable_jobs() |
795 | 11 | { | ||
796 | 12 | (cd /etc/init && grep '^emits ' *.conf|sed 's/^emits //g') | ||
797 | 13 | } && | ||
798 | 14 | _upstart_events() | ||
799 | 15 | { | ||
800 | 16 | (_upstart_conf_events;_upstart_named_events)|tr ' ' '\n'|sort -u | ||
801 | 17 | } && | ||
802 | 18 | _upstart_startable_events() | ||
808 | 19 | { | 11 | { |
809 | 20 | initctl list|cut -d\, -f1|awk '$2 == "stop/waiting" {print $1}' | 12 | initctl list|cut -d\, -f1|awk '$2 == "stop/waiting" {print $1}' |
810 | 21 | } && | 13 | } && |
812 | 22 | _upstart_stoppable_events() | 14 | _upstart_stoppable_jobs() |
813 | 23 | { | 15 | { |
814 | 24 | initctl list|cut -d\, -f1|awk '$2 == "start/running" {print $1}' | 16 | initctl list|cut -d\, -f1|awk '$2 == "start/running" {print $1}' |
815 | 25 | } && | 17 | } && |
816 | 18 | _upstart_events() | ||
817 | 19 | { | ||
818 | 20 | # note that we don't provide the internal events such as "starting" | ||
819 | 21 | # (and those from mountall) since the user should be using the | ||
820 | 22 | # associated command to emit such events. | ||
821 | 23 | (cd /etc/init && \ | ||
822 | 24 | egrep '^[[:space:]]*emits ' *.conf |\ | ||
823 | 25 | cut -d: -f2- | sed 's/^[[:space:]]*emits //g' |\ | ||
824 | 26 | tr ' ' '\n' | awk '{print $NF}' | grep -v ^$|sort -u) | ||
825 | 27 | } && | ||
826 | 26 | _upstart_initctl() | 28 | _upstart_initctl() |
827 | 27 | { | 29 | { |
828 | 28 | _get_comp_words_by_ref cur prev | 30 | _get_comp_words_by_ref cur prev |
829 | @@ -32,34 +34,92 @@ | |||
830 | 32 | case "$prev" in | 34 | case "$prev" in |
831 | 33 | 35 | ||
832 | 34 | start) | 36 | start) |
834 | 35 | COMPREPLY=( $(compgen -W "-n --no-wait $(_upstart_startable_events)" -- ${cur}) ) | 37 | COMPREPLY=( $(compgen -W "-n --no-wait $(_upstart_startable_jobs)" -- ${cur}) ) |
835 | 36 | return 0 | 38 | return 0 |
836 | 37 | ;; | 39 | ;; |
837 | 38 | 40 | ||
838 | 39 | stop) | 41 | stop) |
840 | 40 | COMPREPLY=( $(compgen -W "-n --no-wait $(_upstart_stoppable_events)" -- ${cur}) ) | 42 | COMPREPLY=( $(compgen -W "-n --no-wait $(_upstart_stoppable_jobs)" -- ${cur}) ) |
841 | 41 | return 0 | 43 | return 0 |
842 | 42 | ;; | 44 | ;; |
843 | 43 | 45 | ||
844 | 44 | emit) | 46 | emit) |
851 | 45 | COMPREPLY=( $(compgen -W "$(_upstart_events)" -- ${cur}) ) | 47 | COMPREPLY=( $(compgen -W "-n --no-wait $(_upstart_events)" -- ${cur}) ) |
852 | 46 | return 0 | 48 | return 0 |
853 | 47 | ;; | 49 | ;; |
854 | 48 | 50 | ||
855 | 49 | reload|restart|status) | 51 | -i|--ignore-events) |
856 | 50 | COMPREPLY=( $(compgen -W "$(_upstart_conf_events)" -- ${cur}) ) | 52 | # handle visualisation options after check-config command |
857 | 53 | for cmd in check-config | ||
858 | 54 | do | ||
859 | 55 | cwords=${COMP_WORDS[@]##} | ||
860 | 56 | filtered_cwords=${COMP_WORDS[@]##${cmd}} | ||
861 | 57 | if [ "$filtered_cwords" != "$cwords" ] | ||
862 | 58 | then | ||
863 | 59 | COMPREPLY=( $(compgen -W "$(_upstart_jobs)" -- ${cur}) ) | ||
864 | 60 | return 0 | ||
865 | 61 | fi | ||
866 | 62 | done | ||
867 | 63 | ;; | ||
868 | 64 | |||
869 | 65 | -e|--enumerate) | ||
870 | 66 | # handle visualisation options after show-config command | ||
871 | 67 | for cmd in show-config | ||
872 | 68 | do | ||
873 | 69 | cwords=${COMP_WORDS[@]##} | ||
874 | 70 | filtered_cwords=${COMP_WORDS[@]##${cmd}} | ||
875 | 71 | if [ "$filtered_cwords" != "$cwords" ] | ||
876 | 72 | then | ||
877 | 73 | COMPREPLY=( $(compgen -W "$(_upstart_jobs)" -- ${cur}) ) | ||
878 | 74 | return 0 | ||
879 | 75 | fi | ||
880 | 76 | done | ||
881 | 77 | ;; | ||
882 | 78 | |||
883 | 79 | reload|restart) | ||
884 | 80 | COMPREPLY=( $(compgen -W "-n --no-wait $(_upstart_stoppable_jobs)" -- ${cur}) ) | ||
885 | 81 | return 0 | ||
886 | 82 | ;; | ||
887 | 83 | |||
888 | 84 | status) | ||
889 | 85 | COMPREPLY=( $(compgen -W "$(_upstart_jobs)" -- ${cur}) ) | ||
890 | 86 | return 0 | ||
891 | 87 | ;; | ||
892 | 88 | |||
893 | 89 | check-config) | ||
894 | 90 | COMPREPLY=( $(compgen -W "-w --warn -i --ignore-events= $(_upstart_jobs)" -- ${cur}) ) | ||
895 | 91 | return 0 | ||
896 | 92 | ;; | ||
897 | 93 | show-config) | ||
898 | 94 | COMPREPLY=( $(compgen -W "-e --enumerate $(_upstart_jobs)" -- ${cur}) ) | ||
899 | 51 | return 0 | 95 | return 0 |
900 | 52 | ;; | 96 | ;; |
901 | 53 | 97 | ||
902 | 54 | -n|--no-wait) | 98 | -n|--no-wait) |
905 | 55 | # allow no wait after start/stop commands | 99 | # allow 'no wait' for certain commands |
906 | 56 | for cmd in start stop | 100 | for cmd in start stop restart emit |
907 | 57 | do | 101 | do |
908 | 58 | cwords=${COMP_WORDS[@]##} | 102 | cwords=${COMP_WORDS[@]##} |
909 | 59 | filtered_cwords=${COMP_WORDS[@]##${cmd}} | 103 | filtered_cwords=${COMP_WORDS[@]##${cmd}} |
910 | 60 | if [ "$filtered_cwords" != "$cwords" ] | 104 | if [ "$filtered_cwords" != "$cwords" ] |
911 | 61 | then | 105 | then |
913 | 62 | COMPREPLY=( $(compgen -W "$(_upstart_${cmd}able_events)" -- ${cur}) ) | 106 | case "$cmd" in |
914 | 107 | start) | ||
915 | 108 | COMPREPLY=( $(compgen -W "$(_upstart_startable_jobs)" -- ${cur}) ) | ||
916 | 109 | ;; | ||
917 | 110 | |||
918 | 111 | stop) | ||
919 | 112 | COMPREPLY=( $(compgen -W "$(_upstart_stoppable_jobs)" -- ${cur}) ) | ||
920 | 113 | ;; | ||
921 | 114 | |||
922 | 115 | restart) | ||
923 | 116 | COMPREPLY=( $(compgen -W "$(_upstart_stoppable_jobs)" -- ${cur}) ) | ||
924 | 117 | ;; | ||
925 | 118 | |||
926 | 119 | emit) | ||
927 | 120 | COMPREPLY=( $(compgen -W "$(_upstart_events)" -- ${cur}) ) | ||
928 | 121 | ;; | ||
929 | 122 | esac | ||
930 | 63 | return 0 | 123 | return 0 |
931 | 64 | fi | 124 | fi |
932 | 65 | done | 125 | done |
933 | @@ -71,7 +131,7 @@ | |||
934 | 71 | ;; | 131 | ;; |
935 | 72 | esac | 132 | esac |
936 | 73 | 133 | ||
938 | 74 | opts="--help --version -q --quiet -v --verbose --system --dest=" | 134 | opts="--help --version -q --quiet -v --verbose --session --system --dest=" |
939 | 75 | cmds=$(initctl help|grep "^ [^ ]"|awk '{print $1}') | 135 | cmds=$(initctl help|grep "^ [^ ]"|awk '{print $1}') |
940 | 76 | 136 | ||
941 | 77 | COMPREPLY=( $(compgen -W "${opts} ${cmds}" -- ${cur}) ) | 137 | COMPREPLY=( $(compgen -W "${opts} ${cmds}" -- ${cur}) ) |
942 | @@ -84,7 +144,7 @@ | |||
943 | 84 | COMPREPLY=() | 144 | COMPREPLY=() |
944 | 85 | _get_comp_words_by_ref cur prev | 145 | _get_comp_words_by_ref cur prev |
945 | 86 | 146 | ||
947 | 87 | opts="--help --version -q --quiet -v --verbose --system --dest= \ | 147 | opts="--help --version -q --quiet -v --verbose --session --system --dest= \ |
948 | 88 | -n --no-wait" | 148 | -n --no-wait" |
949 | 89 | 149 | ||
950 | 90 | case "$prev" in | 150 | case "$prev" in |
951 | @@ -94,7 +154,7 @@ | |||
952 | 94 | ;; | 154 | ;; |
953 | 95 | esac | 155 | esac |
954 | 96 | 156 | ||
956 | 97 | COMPREPLY=( $(compgen -W "$opts $(_upstart_startable_events)" -- ${cur}) ) | 157 | COMPREPLY=( $(compgen -W "$opts $(_upstart_startable_jobs)" -- ${cur}) ) |
957 | 98 | return 0 | 158 | return 0 |
958 | 99 | } && complete -F _upstart_start start | 159 | } && complete -F _upstart_start start |
959 | 100 | 160 | ||
960 | @@ -104,7 +164,7 @@ | |||
961 | 104 | COMPREPLY=() | 164 | COMPREPLY=() |
962 | 105 | _get_comp_words_by_ref cur prev | 165 | _get_comp_words_by_ref cur prev |
963 | 106 | 166 | ||
965 | 107 | opts="--help --version -q --quiet -v --verbose --system --dest= \ | 167 | opts="--help --version -q --quiet -v --verbose --session --system --dest= \ |
966 | 108 | -n --no-wait" | 168 | -n --no-wait" |
967 | 109 | 169 | ||
968 | 110 | case "$prev" in | 170 | case "$prev" in |
969 | @@ -114,7 +174,7 @@ | |||
970 | 114 | ;; | 174 | ;; |
971 | 115 | esac | 175 | esac |
972 | 116 | 176 | ||
974 | 117 | COMPREPLY=( $(compgen -W "$opts $(_upstart_stoppable_events)" -- ${cur}) ) | 177 | COMPREPLY=( $(compgen -W "$opts $(_upstart_stoppable_jobs)" -- ${cur}) ) |
975 | 118 | return 0 | 178 | return 0 |
976 | 119 | } && complete -F _upstart_stop stop | 179 | } && complete -F _upstart_stop stop |
977 | 120 | 180 | ||
978 | @@ -124,7 +184,7 @@ | |||
979 | 124 | COMPREPLY=() | 184 | COMPREPLY=() |
980 | 125 | _get_comp_words_by_ref cur prev | 185 | _get_comp_words_by_ref cur prev |
981 | 126 | 186 | ||
983 | 127 | opts="--help --version -q --quiet -v --verbose --system --dest= \ | 187 | opts="--help --version -q --quiet -v --verbose --session --system --dest= \ |
984 | 128 | -n --no-wait" | 188 | -n --no-wait" |
985 | 129 | 189 | ||
986 | 130 | case "$prev" in | 190 | case "$prev" in |
987 | @@ -134,7 +194,7 @@ | |||
988 | 134 | ;; | 194 | ;; |
989 | 135 | esac | 195 | esac |
990 | 136 | 196 | ||
992 | 137 | COMPREPLY=( $(compgen -W "$opts $(_upstart_events)" -- ${cur}) ) | 197 | COMPREPLY=( $(compgen -W "$opts $(_upstart_stoppable_jobs)" -- ${cur}) ) |
993 | 138 | return 0 | 198 | return 0 |
994 | 139 | 199 | ||
995 | 140 | } && complete -F _upstart_restart restart | 200 | } && complete -F _upstart_restart restart |
996 | @@ -145,7 +205,7 @@ | |||
997 | 145 | COMPREPLY=() | 205 | COMPREPLY=() |
998 | 146 | _get_comp_words_by_ref cur prev | 206 | _get_comp_words_by_ref cur prev |
999 | 147 | 207 | ||
1001 | 148 | opts="--help --version -q --quiet -v --verbose --system --dest=" | 208 | opts="--help --version -q -d --detail -e --enumerate --quiet -v --verbose --session --system --dest=" |
1002 | 149 | 209 | ||
1003 | 150 | case "$prev" in | 210 | case "$prev" in |
1004 | 151 | --help|--version) | 211 | --help|--version) |
1005 | @@ -154,7 +214,7 @@ | |||
1006 | 154 | ;; | 214 | ;; |
1007 | 155 | esac | 215 | esac |
1008 | 156 | 216 | ||
1010 | 157 | COMPREPLY=( $(compgen -W "$opts $(_upstart_events)" -- ${cur}) ) | 217 | COMPREPLY=( $(compgen -W "$opts $(_upstart_jobs)" -- ${cur}) ) |
1011 | 158 | return 0 | 218 | return 0 |
1012 | 159 | 219 | ||
1013 | 160 | } && complete -F _upstart_status status | 220 | } && complete -F _upstart_status status |
1014 | @@ -165,7 +225,7 @@ | |||
1015 | 165 | COMPREPLY=() | 225 | COMPREPLY=() |
1016 | 166 | _get_comp_words_by_ref cur prev | 226 | _get_comp_words_by_ref cur prev |
1017 | 167 | 227 | ||
1019 | 168 | opts="--help --version -q --quiet -v --verbose --system --dest=" | 228 | opts="--help --version -q --quiet -v --verbose --session --system --dest=" |
1020 | 169 | 229 | ||
1021 | 170 | case "$prev" in | 230 | case "$prev" in |
1022 | 171 | --help|--version) | 231 | --help|--version) |
1023 | @@ -174,7 +234,7 @@ | |||
1024 | 174 | ;; | 234 | ;; |
1025 | 175 | esac | 235 | esac |
1026 | 176 | 236 | ||
1028 | 177 | COMPREPLY=( $(compgen -W "$opts $(_upstart_events)" -- ${cur}) ) | 237 | COMPREPLY=( $(compgen -W "$opts $(_upstart_stoppable_jobs)" -- ${cur}) ) |
1029 | 178 | return 0 | 238 | return 0 |
1030 | 179 | 239 | ||
1031 | 180 | } && complete -F _upstart_reload reload | 240 | } && complete -F _upstart_reload reload |
1032 | 181 | 241 | ||
1033 | === modified file 'contrib/vim/syntax/upstart.vim' | |||
1034 | --- contrib/vim/syntax/upstart.vim 2011-01-27 18:52:25 +0000 | |||
1035 | +++ contrib/vim/syntax/upstart.vim 2011-10-14 11:09:18 +0000 | |||
1036 | @@ -1,10 +1,11 @@ | |||
1037 | 1 | " Vim syntax file | 1 | " Vim syntax file |
1038 | 2 | " Language: Upstart job files | 2 | " Language: Upstart job files |
1039 | 3 | " Maintainer: Michael Biebl <biebl@debian.org> | 3 | " Maintainer: Michael Biebl <biebl@debian.org> |
1041 | 4 | " Last Change: 2007 Feb 13 | 4 | " James Hunt <james.hunt@ubuntu.com> |
1042 | 5 | " Last Change: 2011 Jun 14 | ||
1043 | 5 | " License: GPL v2 | 6 | " License: GPL v2 |
1046 | 6 | " Version: 0.1 | 7 | " Version: 0.3 |
1047 | 7 | " Remark: Syntax highlighting for upstart job files. | 8 | " Remark: Syntax highlighting for Upstart (init(8)) job files. |
1048 | 8 | " | 9 | " |
1049 | 9 | " It is inspired by the initng syntax file and includes sh.vim to do the | 10 | " It is inspired by the initng syntax file and includes sh.vim to do the |
1050 | 10 | " highlighting of script blocks. | 11 | " highlighting of script blocks. |
1051 | @@ -14,11 +15,8 @@ | |||
1052 | 14 | elseif exists("b:current_syntax") | 15 | elseif exists("b:current_syntax") |
1053 | 15 | finish | 16 | finish |
1054 | 16 | endif | 17 | endif |
1055 | 17 | |||
1056 | 18 | setlocal iskeyword=@,48-57,-,. | ||
1057 | 19 | 18 | ||
1058 | 20 | let is_bash = 1 | 19 | let is_bash = 1 |
1059 | 21 | "unlet! b:current_syntax | ||
1060 | 22 | syn include @Shell syntax/sh.vim | 20 | syn include @Shell syntax/sh.vim |
1061 | 23 | 21 | ||
1062 | 24 | syn case match | 22 | syn case match |
1063 | @@ -33,9 +31,12 @@ | |||
1064 | 33 | syn cluster upstartShellCluster contains=@Shell | 31 | syn cluster upstartShellCluster contains=@Shell |
1065 | 34 | 32 | ||
1066 | 35 | " one argument | 33 | " one argument |
1070 | 36 | syn keyword upstartStatement description author version | 34 | syn keyword upstartStatement description author version instance expect |
1071 | 37 | syn keyword upstartStatement pid kill normal console env umask nice limit chroot chdir exec | 35 | syn keyword upstartStatement pid kill normal console env exit export |
1072 | 38 | syn keyword upstartStatement expect export | 36 | syn keyword upstartStatement umask nice oom chroot chdir exec |
1073 | 37 | |||
1074 | 38 | " two arguments | ||
1075 | 39 | syn keyword upstartStatement limit | ||
1076 | 39 | 40 | ||
1077 | 40 | " one or more arguments (events) | 41 | " one or more arguments (events) |
1078 | 41 | syn keyword upstartStatement emits | 42 | syn keyword upstartStatement emits |
1079 | @@ -43,29 +44,62 @@ | |||
1080 | 43 | syn keyword upstartStatement on start stop | 44 | syn keyword upstartStatement on start stop |
1081 | 44 | 45 | ||
1082 | 45 | " flag, no parameter | 46 | " flag, no parameter |
1084 | 46 | syn keyword upstartStatement daemon respawn service instance task | 47 | syn keyword upstartStatement respawn service instance manual debug task |
1085 | 47 | 48 | ||
1087 | 48 | " prefix for exec or script | 49 | " prefix for exec or script |
1088 | 49 | syn keyword upstartOption pre-start post-start pre-stop post-stop | 50 | syn keyword upstartOption pre-start post-start pre-stop post-stop |
1089 | 50 | 51 | ||
1096 | 51 | " options for pid | 52 | " option for kill |
1097 | 52 | syn keyword upstartOption file binary timeout | 53 | syn keyword upstartOption timeout signal |
1098 | 53 | " option for | 54 | " option for oom |
1099 | 54 | syn keyword upstartOption timeout | 55 | syn keyword upstartOption score never |
1094 | 55 | " option for respawn | ||
1095 | 56 | syn keyword upstartOption limit | ||
1100 | 57 | " options for console | 56 | " options for console |
1102 | 58 | syn keyword upstartOption logged output owner none | 57 | syn keyword upstartOption output owner |
1103 | 59 | " options for expect | 58 | " options for expect |
1111 | 60 | syn keyword upstartOption daemon fork stop | 59 | syn keyword upstartOption stop fork daemon none |
1112 | 61 | 60 | " options for limit | |
1113 | 62 | syn keyword upstartEvent startup stalled control-alt-delete kbdrequest starting started stopping stopped runlevel | 61 | syn keyword upstartOption unlimited core cpu data fsize memlock msgqueue nice |
1114 | 63 | 62 | syn keyword upstartOption nofile nproc rss rtprio sigpending stack | |
1115 | 64 | hi def link upstartComment Comment | 63 | |
1116 | 65 | hi def link upstartTodo Todo | 64 | " 'options' for start/stop on |
1117 | 66 | hi def link upstartString String | 65 | syn keyword upstartOption and or |
1118 | 66 | |||
1119 | 67 | " Upstart itself and associated utilities | ||
1120 | 68 | syn keyword upstartEvent runlevel | ||
1121 | 69 | syn keyword upstartEvent started | ||
1122 | 70 | syn keyword upstartEvent starting | ||
1123 | 71 | syn keyword upstartEvent startup | ||
1124 | 72 | syn keyword upstartEvent stopped | ||
1125 | 73 | syn keyword upstartEvent stopping | ||
1126 | 74 | syn match upstartEvent /control-alt-delete/ | ||
1127 | 75 | syn match upstartEvent /keyboard-request/ | ||
1128 | 76 | syn match upstartEvent /power-status-changed/ | ||
1129 | 77 | |||
1130 | 78 | " D-Bus | ||
1131 | 79 | syn match upstartEvent /dbus-activation/ | ||
1132 | 80 | |||
1133 | 81 | " Display Manager (ie gdm) | ||
1134 | 82 | syn match upstartEvent /desktop-session-start/ | ||
1135 | 83 | syn match upstartEvent /login-session-start/ | ||
1136 | 84 | |||
1137 | 85 | " mountall | ||
1138 | 86 | syn keyword upstartEvent filesystem | ||
1139 | 87 | syn keyword upstartEvent mounted | ||
1140 | 88 | syn keyword upstartEvent mounting | ||
1141 | 89 | syn match upstartEvent /\(\<local\>\|\<virtual\>\|\<remote\>\)-filesystems/ | ||
1142 | 90 | syn match upstartEvent /all-swaps/ | ||
1143 | 91 | |||
1144 | 92 | " upstart-udev-bridge and ifup/down | ||
1145 | 93 | syn match upstartEvent /\<\i\{-1,}-device-\(\<added\>\|\<removed\>\|\<up\>\|\<down\>\)/ | ||
1146 | 94 | |||
1147 | 95 | " upstart-socket-bridge | ||
1148 | 96 | syn keyword upstartEvent socket | ||
1149 | 97 | |||
1150 | 98 | hi def link upstartComment Comment | ||
1151 | 99 | hi def link upstartTodo Todo | ||
1152 | 100 | hi def link upstartString String | ||
1153 | 67 | hi def link upstartStatement Statement | 101 | hi def link upstartStatement Statement |
1156 | 68 | hi def link upstartOption Type | 102 | hi def link upstartOption Type |
1157 | 69 | hi def link upstartEvent Define | 103 | hi def link upstartEvent Define |
1158 | 70 | 104 | ||
1159 | 71 | let b:current_syntax = "upstart" | 105 | let b:current_syntax = "upstart" |
1160 | 72 | 106 | ||
1161 | === modified file 'dbus/Upstart.conf' | |||
1162 | --- dbus/Upstart.conf 2009-07-02 17:46:41 +0000 | |||
1163 | +++ dbus/Upstart.conf 2011-10-14 11:09:18 +0000 | |||
1164 | @@ -9,12 +9,14 @@ | |||
1165 | 9 | <allow own="com.ubuntu.Upstart" /> | 9 | <allow own="com.ubuntu.Upstart" /> |
1166 | 10 | </policy> | 10 | </policy> |
1167 | 11 | 11 | ||
1171 | 12 | <!-- Permit the root user to invoke all of the methods on Upstart, its jobs | 12 | <!-- Allow any user to invoke all of the methods on Upstart, its jobs |
1172 | 13 | or their instances, and to get and set properties. --> | 13 | or their instances, and to get and set properties - since Upstart |
1173 | 14 | <policy user="root"> | 14 | isolates commands by user. --> |
1174 | 15 | <policy context="default"> | ||
1175 | 16 | <allow send_destination="com.ubuntu.Upstart" | ||
1176 | 17 | send_interface="org.freedesktop.DBus.Introspectable" /> | ||
1177 | 15 | <allow send_destination="com.ubuntu.Upstart" | 18 | <allow send_destination="com.ubuntu.Upstart" |
1178 | 16 | send_interface="org.freedesktop.DBus.Properties" /> | 19 | send_interface="org.freedesktop.DBus.Properties" /> |
1179 | 17 | |||
1180 | 18 | <allow send_destination="com.ubuntu.Upstart" | 20 | <allow send_destination="com.ubuntu.Upstart" |
1181 | 19 | send_interface="com.ubuntu.Upstart0_6" /> | 21 | send_interface="com.ubuntu.Upstart0_6" /> |
1182 | 20 | <allow send_destination="com.ubuntu.Upstart" | 22 | <allow send_destination="com.ubuntu.Upstart" |
1183 | @@ -22,36 +24,4 @@ | |||
1184 | 22 | <allow send_destination="com.ubuntu.Upstart" | 24 | <allow send_destination="com.ubuntu.Upstart" |
1185 | 23 | send_interface="com.ubuntu.Upstart0_6.Instance" /> | 25 | send_interface="com.ubuntu.Upstart0_6.Instance" /> |
1186 | 24 | </policy> | 26 | </policy> |
1187 | 25 | |||
1188 | 26 | <!-- Allow any user to introspect Upstart's interfaces, to obtain the | ||
1189 | 27 | values of properties (but not set them) and to invoke selected | ||
1190 | 28 | methods on Upstart and its jobs that are used to walk information. --> | ||
1191 | 29 | <policy context="default"> | ||
1192 | 30 | <allow send_destination="com.ubuntu.Upstart" | ||
1193 | 31 | send_interface="org.freedesktop.DBus.Introspectable" /> | ||
1194 | 32 | |||
1195 | 33 | <allow send_destination="com.ubuntu.Upstart" | ||
1196 | 34 | send_interface="org.freedesktop.DBus.Properties" | ||
1197 | 35 | send_type="method_call" send_member="Get" /> | ||
1198 | 36 | <allow send_destination="com.ubuntu.Upstart" | ||
1199 | 37 | send_interface="org.freedesktop.DBus.Properties" | ||
1200 | 38 | send_type="method_call" send_member="GetAll" /> | ||
1201 | 39 | |||
1202 | 40 | <allow send_destination="com.ubuntu.Upstart" | ||
1203 | 41 | send_interface="com.ubuntu.Upstart0_6" | ||
1204 | 42 | send_type="method_call" send_member="GetJobByName" /> | ||
1205 | 43 | <allow send_destination="com.ubuntu.Upstart" | ||
1206 | 44 | send_interface="com.ubuntu.Upstart0_6" | ||
1207 | 45 | send_type="method_call" send_member="GetAllJobs" /> | ||
1208 | 46 | |||
1209 | 47 | <allow send_destination="com.ubuntu.Upstart" | ||
1210 | 48 | send_interface="com.ubuntu.Upstart0_6.Job" | ||
1211 | 49 | send_type="method_call" send_member="GetInstance" /> | ||
1212 | 50 | <allow send_destination="com.ubuntu.Upstart" | ||
1213 | 51 | send_interface="com.ubuntu.Upstart0_6.Job" | ||
1214 | 52 | send_type="method_call" send_member="GetInstanceByName" /> | ||
1215 | 53 | <allow send_destination="com.ubuntu.Upstart" | ||
1216 | 54 | send_interface="com.ubuntu.Upstart0_6.Job" | ||
1217 | 55 | send_type="method_call" send_member="GetAllInstances" /> | ||
1218 | 56 | </policy> | ||
1219 | 57 | </busconfig> | 27 | </busconfig> |
1220 | 58 | 28 | ||
1221 | === modified file 'dbus/com.ubuntu.Upstart.xml' | |||
1222 | --- dbus/com.ubuntu.Upstart.xml 2009-07-03 16:08:10 +0000 | |||
1223 | +++ dbus/com.ubuntu.Upstart.xml 2011-10-14 11:09:18 +0000 | |||
1224 | @@ -49,6 +49,13 @@ | |||
1225 | 49 | <arg name="env" type="as" direction="in" /> | 49 | <arg name="env" type="as" direction="in" /> |
1226 | 50 | <arg name="wait" type="b" direction="in" /> | 50 | <arg name="wait" type="b" direction="in" /> |
1227 | 51 | </method> | 51 | </method> |
1228 | 52 | <method name="EmitEventWithFile"> | ||
1229 | 53 | <annotation name="com.netsplit.Nih.Method.Async" value="true" /> | ||
1230 | 54 | <arg name="name" type="s" direction="in" /> | ||
1231 | 55 | <arg name="env" type="as" direction="in" /> | ||
1232 | 56 | <arg name="wait" type="b" direction="in" /> | ||
1233 | 57 | <arg name="file" type="h" direction="in" /> | ||
1234 | 58 | </method> | ||
1235 | 52 | 59 | ||
1236 | 53 | <!-- Basic information about Upstart --> | 60 | <!-- Basic information about Upstart --> |
1237 | 54 | <property name="version" type="s" access="read" /> | 61 | <property name="version" type="s" access="read" /> |
1238 | 55 | 62 | ||
1239 | === modified file 'dbus/upstart.h' | |||
1240 | --- dbus/upstart.h 2010-12-10 04:04:51 +0000 | |||
1241 | +++ dbus/upstart.h 2011-10-14 11:09:18 +0000 | |||
1242 | @@ -31,7 +31,7 @@ | |||
1243 | 31 | # define DBUS_SERVICE_UPSTART "com.ubuntu.TestUpstart" | 31 | # define DBUS_SERVICE_UPSTART "com.ubuntu.TestUpstart" |
1244 | 32 | # else | 32 | # else |
1245 | 33 | # define DBUS_SERVICE_UPSTART "com.ubuntu.Upstart" | 33 | # define DBUS_SERVICE_UPSTART "com.ubuntu.Upstart" |
1247 | 34 | #endif | 34 | # endif |
1248 | 35 | #endif | 35 | #endif |
1249 | 36 | 36 | ||
1250 | 37 | 37 | ||
1251 | 38 | 38 | ||
1252 | === added directory 'extra' | |||
1253 | === added file 'extra/Makefile.am' | |||
1254 | --- extra/Makefile.am 1970-01-01 00:00:00 +0000 | |||
1255 | +++ extra/Makefile.am 2011-10-14 11:09:18 +0000 | |||
1256 | @@ -0,0 +1,125 @@ | |||
1257 | 1 | ## Process this file with automake to produce Makefile.in | ||
1258 | 2 | |||
1259 | 3 | AM_CFLAGS = \ | ||
1260 | 4 | $(NIH_CFLAGS) \ | ||
1261 | 5 | $(NIH_DBUS_CFLAGS) \ | ||
1262 | 6 | $(DBUS_CFLAGS) \ | ||
1263 | 7 | $(UDEV_CFLAGS) | ||
1264 | 8 | |||
1265 | 9 | AM_CPPFLAGS = \ | ||
1266 | 10 | -DLOCALEDIR="\"$(localedir)\"" \ | ||
1267 | 11 | -DSBINDIR="\"$(sbindir)\"" \ | ||
1268 | 12 | -I$(top_builddir) -I$(top_srcdir) -iquote$(builddir) -iquote$(srcdir) \ | ||
1269 | 13 | -I$(top_srcdir)/intl | ||
1270 | 14 | |||
1271 | 15 | |||
1272 | 16 | initdir = $(sysconfdir)/init | ||
1273 | 17 | |||
1274 | 18 | |||
1275 | 19 | sbin_PROGRAMS = \ | ||
1276 | 20 | upstart-socket-bridge | ||
1277 | 21 | |||
1278 | 22 | dist_init_DATA = \ | ||
1279 | 23 | conf/upstart-socket-bridge.conf | ||
1280 | 24 | |||
1281 | 25 | dist_man_MANS = \ | ||
1282 | 26 | man/upstart-socket-bridge.8 \ | ||
1283 | 27 | man/socket-event.7 | ||
1284 | 28 | |||
1285 | 29 | upstart_socket_bridge_SOURCES = \ | ||
1286 | 30 | upstart-socket-bridge.c | ||
1287 | 31 | nodist_upstart_socket_bridge_SOURCES = \ | ||
1288 | 32 | $(com_ubuntu_Upstart_OUTPUTS) \ | ||
1289 | 33 | $(com_ubuntu_Upstart_Job_OUTPUTS) | ||
1290 | 34 | upstart_socket_bridge_LDADD = \ | ||
1291 | 35 | $(LTLIBINTL) \ | ||
1292 | 36 | $(NIH_LIBS) \ | ||
1293 | 37 | $(NIH_DBUS_LIBS) \ | ||
1294 | 38 | $(DBUS_LIBS) | ||
1295 | 39 | |||
1296 | 40 | |||
1297 | 41 | if HAVE_UDEV | ||
1298 | 42 | dist_init_DATA += \ | ||
1299 | 43 | conf/upstart-udev-bridge.conf | ||
1300 | 44 | |||
1301 | 45 | dist_man_MANS += \ | ||
1302 | 46 | man/upstart-udev-bridge.8 | ||
1303 | 47 | |||
1304 | 48 | sbin_PROGRAMS += \ | ||
1305 | 49 | upstart-udev-bridge | ||
1306 | 50 | |||
1307 | 51 | upstart_udev_bridge_SOURCES = \ | ||
1308 | 52 | upstart-udev-bridge.c | ||
1309 | 53 | nodist_upstart_udev_bridge_SOURCES = \ | ||
1310 | 54 | $(com_ubuntu_Upstart_OUTPUTS) | ||
1311 | 55 | upstart_udev_bridge_LDADD = \ | ||
1312 | 56 | $(LTLIBINTL) \ | ||
1313 | 57 | $(NIH_LIBS) \ | ||
1314 | 58 | $(NIH_DBUS_LIBS) \ | ||
1315 | 59 | $(DBUS_LIBS) \ | ||
1316 | 60 | $(UDEV_LIBS) | ||
1317 | 61 | |||
1318 | 62 | install-data-hook: | ||
1319 | 63 | src=`echo upstart-udev-bridge| sed '$(transform)'`.8; \ | ||
1320 | 64 | for symlink in \ | ||
1321 | 65 | net-device-added \ | ||
1322 | 66 | net-device-removed \ | ||
1323 | 67 | graphics-device-added \ | ||
1324 | 68 | drm-device-added; do \ | ||
1325 | 69 | inst=`echo $$symlink | sed '$(transform)'`.7; \ | ||
1326 | 70 | echo " ln -sf '$(man8dir)/$$src' '$(DESTDIR)$(man7dir)/$$inst'"; \ | ||
1327 | 71 | ln -sf "$(man8dir)/$$src" "$(DESTDIR)$(man7dir)/$$inst"; \ | ||
1328 | 72 | done | ||
1329 | 73 | |||
1330 | 74 | else | ||
1331 | 75 | EXTRA_DIST = \ | ||
1332 | 76 | man/upstart-udev-bridge.8 | ||
1333 | 77 | endif | ||
1334 | 78 | |||
1335 | 79 | |||
1336 | 80 | com_ubuntu_Upstart_OUTPUTS = \ | ||
1337 | 81 | com.ubuntu.Upstart.c \ | ||
1338 | 82 | com.ubuntu.Upstart.h | ||
1339 | 83 | |||
1340 | 84 | com_ubuntu_Upstart_XML = \ | ||
1341 | 85 | ../dbus/com.ubuntu.Upstart.xml | ||
1342 | 86 | |||
1343 | 87 | $(com_ubuntu_Upstart_OUTPUTS): $(com_ubuntu_Upstart_XML) | ||
1344 | 88 | $(AM_V_GEN)$(NIH_DBUS_TOOL) \ | ||
1345 | 89 | --package=$(PACKAGE) \ | ||
1346 | 90 | --mode=proxy --prefix=upstart \ | ||
1347 | 91 | --default-interface=com.ubuntu.Upstart0_6 \ | ||
1348 | 92 | --output=$@ $< | ||
1349 | 93 | |||
1350 | 94 | |||
1351 | 95 | com_ubuntu_Upstart_Job_OUTPUTS = \ | ||
1352 | 96 | com.ubuntu.Upstart.Job.c \ | ||
1353 | 97 | com.ubuntu.Upstart.Job.h | ||
1354 | 98 | |||
1355 | 99 | com_ubuntu_Upstart_Job_XML = \ | ||
1356 | 100 | ../dbus/com.ubuntu.Upstart.Job.xml | ||
1357 | 101 | |||
1358 | 102 | $(com_ubuntu_Upstart_Job_OUTPUTS): $(com_ubuntu_Upstart_Job_XML) | ||
1359 | 103 | $(AM_V_GEN)$(NIH_DBUS_TOOL) \ | ||
1360 | 104 | --package=$(PACKAGE) \ | ||
1361 | 105 | --mode=proxy --prefix=job_class \ | ||
1362 | 106 | --default-interface=com.ubuntu.Upstart0_6.Job \ | ||
1363 | 107 | --output=$@ $< | ||
1364 | 108 | |||
1365 | 109 | |||
1366 | 110 | # These have to be built sources because we can't compile object files | ||
1367 | 111 | # without the header file existing first | ||
1368 | 112 | BUILT_SOURCES = \ | ||
1369 | 113 | $(com_ubuntu_Upstart_OUTPUTS) \ | ||
1370 | 114 | $(com_ubuntu_Upstart_Job_OUTPUTS) | ||
1371 | 115 | |||
1372 | 116 | CLEANFILES = \ | ||
1373 | 117 | $(com_ubuntu_Upstart_OUTPUTS) \ | ||
1374 | 118 | $(com_ubuntu_Upstart_Job_OUTPUTS) | ||
1375 | 119 | |||
1376 | 120 | |||
1377 | 121 | clean-local: | ||
1378 | 122 | rm -f *.gcno *.gcda | ||
1379 | 123 | |||
1380 | 124 | maintainer-clean-local: | ||
1381 | 125 | rm -f *.gcov | ||
1382 | 0 | 126 | ||
1383 | === added directory 'extra/conf' | |||
1384 | === added file 'extra/conf/upstart-socket-bridge.conf' | |||
1385 | --- extra/conf/upstart-socket-bridge.conf 1970-01-01 00:00:00 +0000 | |||
1386 | +++ extra/conf/upstart-socket-bridge.conf 2011-10-14 11:09:18 +0000 | |||
1387 | @@ -0,0 +1,16 @@ | |||
1388 | 1 | # upstart-socket-bridge - Bridge socket events into upstart | ||
1389 | 2 | # | ||
1390 | 3 | # This helper daemon receives socket(7) events and | ||
1391 | 4 | # emits equivalent Upstart events. | ||
1392 | 5 | |||
1393 | 6 | description "Bridge socket events into upstart" | ||
1394 | 7 | |||
1395 | 8 | emits socket | ||
1396 | 9 | |||
1397 | 10 | start on net-device-up IFACE=lo | ||
1398 | 11 | stop on runlevel [!2345] | ||
1399 | 12 | |||
1400 | 13 | expect daemon | ||
1401 | 14 | respawn | ||
1402 | 15 | |||
1403 | 16 | exec upstart-socket-bridge --daemon | ||
1404 | 0 | 17 | ||
1405 | === added file 'extra/conf/upstart-udev-bridge.conf' | |||
1406 | --- extra/conf/upstart-udev-bridge.conf 1970-01-01 00:00:00 +0000 | |||
1407 | +++ extra/conf/upstart-udev-bridge.conf 2011-10-14 11:09:18 +0000 | |||
1408 | @@ -0,0 +1,16 @@ | |||
1409 | 1 | # upstart-udev-bridge - Bridge udev events into upstart | ||
1410 | 2 | # | ||
1411 | 3 | # This helper daemon receives udev events from the netlink socket and | ||
1412 | 4 | # emits equivalent Upstart events. | ||
1413 | 5 | |||
1414 | 6 | description "Bridge udev events into upstart" | ||
1415 | 7 | |||
1416 | 8 | emits *-device-* | ||
1417 | 9 | |||
1418 | 10 | start on starting udev | ||
1419 | 11 | stop on stopped udev | ||
1420 | 12 | |||
1421 | 13 | expect daemon | ||
1422 | 14 | respawn | ||
1423 | 15 | |||
1424 | 16 | exec upstart-udev-bridge --daemon | ||
1425 | 0 | 17 | ||
1426 | === added directory 'extra/man' | |||
1427 | === added file 'extra/man/socket-event.7' | |||
1428 | --- extra/man/socket-event.7 1970-01-01 00:00:00 +0000 | |||
1429 | +++ extra/man/socket-event.7 2011-10-14 11:09:18 +0000 | |||
1430 | @@ -0,0 +1,92 @@ | |||
1431 | 1 | .TH socket\-event 8 2011-03-08 upstart | ||
1432 | 2 | .\" | ||
1433 | 3 | .SH NAME | ||
1434 | 4 | socket \- event signalling that a socket connection has been made | ||
1435 | 5 | .\" | ||
1436 | 6 | .SH SYNOPSIS | ||
1437 | 7 | .B socket | ||
1438 | 8 | .BI PROTO\fR= PROTO | ||
1439 | 9 | .BI PORT\fR= PORT | ||
1440 | 10 | .BI ADDR\fR= ADDR | ||
1441 | 11 | |||
1442 | 12 | .B socket | ||
1443 | 13 | .BI PROTO\fR= PROTO | ||
1444 | 14 | .BI PATH\fR= PATH | ||
1445 | 15 | .\" | ||
1446 | 16 | .SH DESCRIPTION | ||
1447 | 17 | |||
1448 | 18 | The | ||
1449 | 19 | .B socket | ||
1450 | 20 | event is generated by the | ||
1451 | 21 | .BR upstart\-socket\-bridge (8) | ||
1452 | 22 | daemon when a socket connection is made whose details match the | ||
1453 | 23 | socket event condition and environment specified in a jobs | ||
1454 | 24 | .B start on | ||
1455 | 25 | or | ||
1456 | 26 | .B stop on | ||
1457 | 27 | stanza. | ||
1458 | 28 | |||
1459 | 29 | When an incoming connection is detected, the file descriptor | ||
1460 | 30 | representing the socket is passed to the job in question to allow it to | ||
1461 | 31 | .BR accept (2) | ||
1462 | 32 | the connection. Additionally, the environment variable | ||
1463 | 33 | .B UPSTART_JOB | ||
1464 | 34 | will contain the name of the event ("socket") and the environment | ||
1465 | 35 | variable | ||
1466 | 36 | .B UPSTART_FDS | ||
1467 | 37 | will contain the number of the file descriptor corresponding to the | ||
1468 | 38 | listening socket. | ||
1469 | 39 | .\" | ||
1470 | 40 | .SH EXAMPLES | ||
1471 | 41 | .\" | ||
1472 | 42 | .SS Internet socket | ||
1473 | 43 | Start web server when first client connects from localhost: | ||
1474 | 44 | .RS | ||
1475 | 45 | .nf | ||
1476 | 46 | |||
1477 | 47 | start on socket PROTO=inet PORT=80 ADDR=127.0.0.1 | ||
1478 | 48 | .fi | ||
1479 | 49 | .RE | ||
1480 | 50 | .\" | ||
1481 | 51 | .SS Local socket | ||
1482 | 52 | .P | ||
1483 | 53 | .RS | ||
1484 | 54 | .nf | ||
1485 | 55 | |||
1486 | 56 | start on socket PROTO=unix PATH=/var/run/.s.pgsql.1234 | ||
1487 | 57 | .fi | ||
1488 | 58 | .FE | ||
1489 | 59 | .\" | ||
1490 | 60 | .SS Abstract socket | ||
1491 | 61 | .P | ||
1492 | 62 | |||
1493 | 63 | .RS | ||
1494 | 64 | .nf | ||
1495 | 65 | |||
1496 | 66 | start on socket PROTO=unix PATH=@/at/upstart/example | ||
1497 | 67 | .fi | ||
1498 | 68 | .FE | ||
1499 | 69 | .\" | ||
1500 | 70 | .SH AUTHOR | ||
1501 | 71 | Written by Scott James Remnant | ||
1502 | 72 | .RB < scott@netsplit.com > | ||
1503 | 73 | |||
1504 | 74 | Manual page written by James Hunt | ||
1505 | 75 | .RB < james.hunt@ubuntu.com > | ||
1506 | 76 | .\" | ||
1507 | 77 | .SH BUGS | ||
1508 | 78 | Report bugs at | ||
1509 | 79 | .RB < https://launchpad.net/upstart/+bugs > | ||
1510 | 80 | .\" | ||
1511 | 81 | .SH COPYRIGHT | ||
1512 | 82 | Copyright \(co 2011 Canonical Ltd. | ||
1513 | 83 | .PP | ||
1514 | 84 | This is free software; see the source for copying conditions. There is NO | ||
1515 | 85 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
1516 | 86 | .\" | ||
1517 | 87 | .SH SEE ALSO | ||
1518 | 88 | .BR init (5) | ||
1519 | 89 | .BR init (8) | ||
1520 | 90 | .BR socket (2) | ||
1521 | 91 | .BR socket (7) | ||
1522 | 92 | .BR upstart\-socket\-bridge (8) | ||
1523 | 0 | 93 | ||
1524 | === added file 'extra/man/upstart-socket-bridge.8' | |||
1525 | --- extra/man/upstart-socket-bridge.8 1970-01-01 00:00:00 +0000 | |||
1526 | +++ extra/man/upstart-socket-bridge.8 2011-10-14 11:09:18 +0000 | |||
1527 | @@ -0,0 +1,47 @@ | |||
1528 | 1 | .TH upstart-socket-bridge 8 2011-03-08 upstart | ||
1529 | 2 | .\" | ||
1530 | 3 | .SH NAME | ||
1531 | 4 | upstart-socket-bridge \- Bridge between Upstart and sockets | ||
1532 | 5 | .\" | ||
1533 | 6 | .SH SYNOPSIS | ||
1534 | 7 | .B upstart-socket-bridge | ||
1535 | 8 | .RI [ OPTIONS ]... | ||
1536 | 9 | .\" | ||
1537 | 10 | .SH DESCRIPTION | ||
1538 | 11 | The | ||
1539 | 12 | .B upstart-socket-bridge | ||
1540 | 13 | queries the Upstart | ||
1541 | 14 | .BR init (8) | ||
1542 | 15 | daemon for all job configurations which | ||
1543 | 16 | .B start on | ||
1544 | 17 | or | ||
1545 | 18 | .B stop on | ||
1546 | 19 | the socket event. It then waits for an incoming connection on each | ||
1547 | 20 | specified | ||
1548 | 21 | .BR socket (7) | ||
1549 | 22 | and when detected emits the socket event (\fBsocket\-event\fP (7)), | ||
1550 | 23 | setting a number of environment variables for the job to query. | ||
1551 | 24 | .\" | ||
1552 | 25 | .SH AUTHOR | ||
1553 | 26 | Written by Scott James Remnant | ||
1554 | 27 | .RB < scott@netsplit.com > | ||
1555 | 28 | |||
1556 | 29 | Manual page written by James Hunt | ||
1557 | 30 | .RB < james.hunt@ubuntu.com > | ||
1558 | 31 | .\" | ||
1559 | 32 | .SH BUGS | ||
1560 | 33 | Report bugs at | ||
1561 | 34 | .RB < https://launchpad.net/upstart/+bugs > | ||
1562 | 35 | .\" | ||
1563 | 36 | .SH COPYRIGHT | ||
1564 | 37 | Copyright \(co 2011 Canonical Ltd. | ||
1565 | 38 | .PP | ||
1566 | 39 | This is free software; see the source for copying conditions. There is NO | ||
1567 | 40 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
1568 | 41 | .\" | ||
1569 | 42 | .SH SEE ALSO | ||
1570 | 43 | .BR init (5) | ||
1571 | 44 | .BR init (8) | ||
1572 | 45 | .BR socket (2) | ||
1573 | 46 | .BR socket (7) | ||
1574 | 47 | .BR socket\-event (7) | ||
1575 | 0 | 48 | ||
1576 | === added file 'extra/man/upstart-udev-bridge.8' | |||
1577 | --- extra/man/upstart-udev-bridge.8 1970-01-01 00:00:00 +0000 | |||
1578 | +++ extra/man/upstart-udev-bridge.8 2011-10-14 11:09:18 +0000 | |||
1579 | @@ -0,0 +1,57 @@ | |||
1580 | 1 | .TH upstart\-udev\-bridge 8 2011-03-08 upstart | ||
1581 | 2 | .\" | ||
1582 | 3 | .SH NAME | ||
1583 | 4 | upstart\-udev\-bridge \- Bridge between Upstart and udev | ||
1584 | 5 | .\" | ||
1585 | 6 | .SH SYNOPSIS | ||
1586 | 7 | .B upstart\-udev\-bridge | ||
1587 | 8 | .RI [ OPTIONS ]... | ||
1588 | 9 | .\" | ||
1589 | 10 | .SH DESCRIPTION | ||
1590 | 11 | .B upstart\-udev\-bridge | ||
1591 | 12 | receives information about kernel uevents that | ||
1592 | 13 | .BR udev (8) | ||
1593 | 14 | has completed and creates | ||
1594 | 15 | .BR init (8) | ||
1595 | 16 | events for them. | ||
1596 | 17 | |||
1597 | 18 | It emits events which match the pattern "\fIS\fP\-device\-\fIA\fP" where | ||
1598 | 19 | \(aqS\(aq is the udev \fIsubsystem\fP and \(aqA\(aq is the udev \fIaction\fP. | ||
1599 | 20 | See \fBudev\fP(7) and for further details. | ||
1600 | 21 | |||
1601 | 22 | Assuming \fI/sys\fP is mounted, possible values for \fIsubsystem\fP for | ||
1602 | 23 | your system are viewable via \fI/sys/class/\fP. | ||
1603 | 24 | |||
1604 | 25 | .\" | ||
1605 | 26 | .SH EXAMPLES | ||
1606 | 27 | |||
1607 | 28 | .IP net\-device\-added | ||
1608 | 29 | Event emitted when a network device is added. | ||
1609 | 30 | .IP net\-device\-removed | ||
1610 | 31 | Event emitted when a network device is removed. | ||
1611 | 32 | .IP graphics\-card\-added | ||
1612 | 33 | Event emitted when a graphics device is available to the system. | ||
1613 | 34 | .\" | ||
1614 | 35 | .SH NOTES | ||
1615 | 36 | This is a temporary tool until | ||
1616 | 37 | .BR init (8) | ||
1617 | 38 | itself gains the functionality to read them directly; you should not | ||
1618 | 39 | rely on its behaviour. | ||
1619 | 40 | .\" | ||
1620 | 41 | .SH AUTHOR | ||
1621 | 42 | Written by Scott James Remnant | ||
1622 | 43 | .RB < scott@netsplit.com > | ||
1623 | 44 | .\" | ||
1624 | 45 | .SH BUGS | ||
1625 | 46 | Report bugs at | ||
1626 | 47 | .RB < https://launchpad.net/ubuntu/+source/upstart/+bugs > | ||
1627 | 48 | .\" | ||
1628 | 49 | .SH COPYRIGHT | ||
1629 | 50 | Copyright \(co 2009,2010,2011 Canonical Ltd. | ||
1630 | 51 | .PP | ||
1631 | 52 | This is free software; see the source for copying conditions. There is NO | ||
1632 | 53 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
1633 | 54 | .SH SEE ALSO | ||
1634 | 55 | .BR init (5) | ||
1635 | 56 | .BR init (8) | ||
1636 | 57 | .BR udev (7) | ||
1637 | 0 | 58 | ||
1638 | === added file 'extra/upstart-socket-bridge.c' | |||
1639 | --- extra/upstart-socket-bridge.c 1970-01-01 00:00:00 +0000 | |||
1640 | +++ extra/upstart-socket-bridge.c 2011-10-14 11:09:18 +0000 | |||
1641 | @@ -0,0 +1,644 @@ | |||
1642 | 1 | /* upstart | ||
1643 | 2 | * | ||
1644 | 3 | * Copyright © 2010 Canonical Ltd. | ||
1645 | 4 | * Author: Scott James Remnant <scott@netsplit.com>. | ||
1646 | 5 | * | ||
1647 | 6 | * This program is free software; you can redistribute it and/or modify | ||
1648 | 7 | * it under the terms of the GNU General Public License version 2, as | ||
1649 | 8 | * published by the Free Software Foundation. | ||
1650 | 9 | * | ||
1651 | 10 | * This program is distributed in the hope that it will be useful, | ||
1652 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1653 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1654 | 13 | * GNU General Public License for more details. | ||
1655 | 14 | * | ||
1656 | 15 | * You should have received a copy of the GNU General Public License along | ||
1657 | 16 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
1658 | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
1659 | 18 | */ | ||
1660 | 19 | |||
1661 | 20 | #ifdef HAVE_CONFIG_H | ||
1662 | 21 | # include <config.h> | ||
1663 | 22 | #endif /* HAVE_CONFIG_H */ | ||
1664 | 23 | |||
1665 | 24 | |||
1666 | 25 | #include <sys/epoll.h> | ||
1667 | 26 | #include <sys/types.h> | ||
1668 | 27 | #include <sys/socket.h> | ||
1669 | 28 | #include <sys/un.h> | ||
1670 | 29 | |||
1671 | 30 | #include <netinet/in.h> | ||
1672 | 31 | #include <arpa/inet.h> | ||
1673 | 32 | |||
1674 | 33 | #include <errno.h> | ||
1675 | 34 | #include <stdlib.h> | ||
1676 | 35 | #include <string.h> | ||
1677 | 36 | #include <syslog.h> | ||
1678 | 37 | #include <unistd.h> | ||
1679 | 38 | |||
1680 | 39 | #include <nih/macros.h> | ||
1681 | 40 | #include <nih/alloc.h> | ||
1682 | 41 | #include <nih/list.h> | ||
1683 | 42 | #include <nih/hash.h> | ||
1684 | 43 | #include <nih/string.h> | ||
1685 | 44 | #include <nih/io.h> | ||
1686 | 45 | #include <nih/option.h> | ||
1687 | 46 | #include <nih/main.h> | ||
1688 | 47 | #include <nih/logging.h> | ||
1689 | 48 | #include <nih/error.h> | ||
1690 | 49 | |||
1691 | 50 | #include <nih-dbus/dbus_connection.h> | ||
1692 | 51 | #include <nih-dbus/dbus_proxy.h> | ||
1693 | 52 | |||
1694 | 53 | #include "dbus/upstart.h" | ||
1695 | 54 | #include "com.ubuntu.Upstart.h" | ||
1696 | 55 | #include "com.ubuntu.Upstart.Job.h" | ||
1697 | 56 | |||
1698 | 57 | |||
1699 | 58 | /* Structure we use for tracking jobs */ | ||
1700 | 59 | typedef struct job { | ||
1701 | 60 | NihList entry; | ||
1702 | 61 | char *path; | ||
1703 | 62 | NihList sockets; | ||
1704 | 63 | } Job; | ||
1705 | 64 | |||
1706 | 65 | /* Structure we use for tracking listening sockets */ | ||
1707 | 66 | typedef struct socket { | ||
1708 | 67 | NihList entry; | ||
1709 | 68 | |||
1710 | 69 | union { | ||
1711 | 70 | struct sockaddr addr; | ||
1712 | 71 | struct sockaddr_in sin_addr; | ||
1713 | 72 | struct sockaddr_un sun_addr; | ||
1714 | 73 | }; | ||
1715 | 74 | socklen_t addrlen; | ||
1716 | 75 | |||
1717 | 76 | int sock; | ||
1718 | 77 | } Socket; | ||
1719 | 78 | |||
1720 | 79 | |||
1721 | 80 | /* Prototypes for static functions */ | ||
1722 | 81 | static void epoll_watcher (void *data, NihIoWatch *watch, | ||
1723 | 82 | NihIoEvents events); | ||
1724 | 83 | static void upstart_job_added (void *data, NihDBusMessage *message, | ||
1725 | 84 | const char *job); | ||
1726 | 85 | static void upstart_job_removed (void *data, NihDBusMessage *message, | ||
1727 | 86 | const char *job); | ||
1728 | 87 | static void job_add_socket (Job *job, char **socket_info); | ||
1729 | 88 | static void socket_destroy (Socket *socket); | ||
1730 | 89 | static void upstart_disconnected (DBusConnection *connection); | ||
1731 | 90 | static void emit_event_reply (Socket *sock, NihDBusMessage *message); | ||
1732 | 91 | static void emit_event_error (Socket *sock, NihDBusMessage *message); | ||
1733 | 92 | |||
1734 | 93 | |||
1735 | 94 | /** | ||
1736 | 95 | * daemonise: | ||
1737 | 96 | * | ||
1738 | 97 | * Set to TRUE if we should become a daemon, rather than just running | ||
1739 | 98 | * in the foreground. | ||
1740 | 99 | **/ | ||
1741 | 100 | static int daemonise = FALSE; | ||
1742 | 101 | |||
1743 | 102 | /** | ||
1744 | 103 | * epoll_fd: | ||
1745 | 104 | * | ||
1746 | 105 | * Shared epoll file descriptor for listening on. | ||
1747 | 106 | **/ | ||
1748 | 107 | static int epoll_fd = -1; | ||
1749 | 108 | |||
1750 | 109 | /** | ||
1751 | 110 | * jobs: | ||
1752 | 111 | * | ||
1753 | 112 | * Jobs that we're monitoring. | ||
1754 | 113 | **/ | ||
1755 | 114 | static NihHash *jobs = NULL; | ||
1756 | 115 | |||
1757 | 116 | /** | ||
1758 | 117 | * upstart: | ||
1759 | 118 | * | ||
1760 | 119 | * Proxy to Upstart daemon. | ||
1761 | 120 | **/ | ||
1762 | 121 | static NihDBusProxy *upstart = NULL; | ||
1763 | 122 | |||
1764 | 123 | |||
1765 | 124 | /** | ||
1766 | 125 | * options: | ||
1767 | 126 | * | ||
1768 | 127 | * Command-line options accepted by this program. | ||
1769 | 128 | **/ | ||
1770 | 129 | static NihOption options[] = { | ||
1771 | 130 | { 0, "daemon", N_("Detach and run in the background"), | ||
1772 | 131 | NULL, NULL, &daemonise, NULL }, | ||
1773 | 132 | |||
1774 | 133 | NIH_OPTION_LAST | ||
1775 | 134 | }; | ||
1776 | 135 | |||
1777 | 136 | |||
1778 | 137 | int | ||
1779 | 138 | main (int argc, | ||
1780 | 139 | char *argv[]) | ||
1781 | 140 | { | ||
1782 | 141 | char ** args; | ||
1783 | 142 | DBusConnection *connection; | ||
1784 | 143 | char ** job_class_paths; | ||
1785 | 144 | int ret; | ||
1786 | 145 | |||
1787 | 146 | nih_main_init (argv[0]); | ||
1788 | 147 | |||
1789 | 148 | nih_option_set_synopsis (_("Bridge socket events into upstart")); | ||
1790 | 149 | nih_option_set_help ( | ||
1791 | 150 | _("By default, upstart-socket-bridge does not detach from the " | ||
1792 | 151 | "console and remains in the foreground. Use the --daemon " | ||
1793 | 152 | "option to have it detach.")); | ||
1794 | 153 | |||
1795 | 154 | args = nih_option_parser (NULL, argc, argv, options, FALSE); | ||
1796 | 155 | if (! args) | ||
1797 | 156 | exit (1); | ||
1798 | 157 | |||
1799 | 158 | /* Create an epoll file descriptor for listening on; use this so | ||
1800 | 159 | * we can do edge triggering rather than level. | ||
1801 | 160 | */ | ||
1802 | 161 | epoll_fd = epoll_create1 (0); | ||
1803 | 162 | if (epoll_fd < 0) { | ||
1804 | 163 | nih_fatal ("%s: %s", _("Could not create epoll descriptor"), | ||
1805 | 164 | strerror (errno)); | ||
1806 | 165 | exit (1); | ||
1807 | 166 | } | ||
1808 | 167 | |||
1809 | 168 | NIH_MUST (nih_io_add_watch (NULL, epoll_fd, NIH_IO_READ, | ||
1810 | 169 | epoll_watcher, NULL)); | ||
1811 | 170 | |||
1812 | 171 | /* Allocate jobs hash table */ | ||
1813 | 172 | jobs = NIH_MUST (nih_hash_string_new (NULL, 0)); | ||
1814 | 173 | |||
1815 | 174 | /* Initialise the connection to Upstart */ | ||
1816 | 175 | connection = NIH_SHOULD (nih_dbus_connect (DBUS_ADDRESS_UPSTART, upstart_disconnected)); | ||
1817 | 176 | if (! connection) { | ||
1818 | 177 | NihError *err; | ||
1819 | 178 | |||
1820 | 179 | err = nih_error_get (); | ||
1821 | 180 | nih_fatal ("%s: %s", _("Could not connect to Upstart"), | ||
1822 | 181 | err->message); | ||
1823 | 182 | nih_free (err); | ||
1824 | 183 | |||
1825 | 184 | exit (1); | ||
1826 | 185 | } | ||
1827 | 186 | |||
1828 | 187 | upstart = NIH_SHOULD (nih_dbus_proxy_new (NULL, connection, | ||
1829 | 188 | NULL, DBUS_PATH_UPSTART, | ||
1830 | 189 | NULL, NULL)); | ||
1831 | 190 | if (! upstart) { | ||
1832 | 191 | NihError *err; | ||
1833 | 192 | |||
1834 | 193 | err = nih_error_get (); | ||
1835 | 194 | nih_fatal ("%s: %s", _("Could not create Upstart proxy"), | ||
1836 | 195 | err->message); | ||
1837 | 196 | nih_free (err); | ||
1838 | 197 | |||
1839 | 198 | exit (1); | ||
1840 | 199 | } | ||
1841 | 200 | |||
1842 | 201 | /* Connect signals to be notified when jobs come and go */ | ||
1843 | 202 | if (! nih_dbus_proxy_connect (upstart, &upstart_com_ubuntu_Upstart0_6, "JobAdded", | ||
1844 | 203 | (NihDBusSignalHandler)upstart_job_added, NULL)) { | ||
1845 | 204 | NihError *err; | ||
1846 | 205 | |||
1847 | 206 | err = nih_error_get (); | ||
1848 | 207 | nih_fatal ("%s: %s", _("Could not create JobAdded signal connection"), | ||
1849 | 208 | err->message); | ||
1850 | 209 | nih_free (err); | ||
1851 | 210 | |||
1852 | 211 | exit (1); | ||
1853 | 212 | } | ||
1854 | 213 | |||
1855 | 214 | if (! nih_dbus_proxy_connect (upstart, &upstart_com_ubuntu_Upstart0_6, "JobRemoved", | ||
1856 | 215 | (NihDBusSignalHandler)upstart_job_removed, NULL)) { | ||
1857 | 216 | NihError *err; | ||
1858 | 217 | |||
1859 | 218 | err = nih_error_get (); | ||
1860 | 219 | nih_fatal ("%s: %s", _("Could not create JobRemoved signal connection"), | ||
1861 | 220 | err->message); | ||
1862 | 221 | nih_free (err); | ||
1863 | 222 | |||
1864 | 223 | exit (1); | ||
1865 | 224 | } | ||
1866 | 225 | |||
1867 | 226 | /* Request a list of all current jobs */ | ||
1868 | 227 | if (upstart_get_all_jobs_sync (NULL, upstart, &job_class_paths) < 0) { | ||
1869 | 228 | NihError *err; | ||
1870 | 229 | |||
1871 | 230 | err = nih_error_get (); | ||
1872 | 231 | nih_fatal ("%s: %s", _("Could not obtain job list"), | ||
1873 | 232 | err->message); | ||
1874 | 233 | nih_free (err); | ||
1875 | 234 | |||
1876 | 235 | exit (1); | ||
1877 | 236 | } | ||
1878 | 237 | |||
1879 | 238 | for (char **job_class_path = job_class_paths; | ||
1880 | 239 | job_class_path && *job_class_path; job_class_path++) | ||
1881 | 240 | upstart_job_added (NULL, NULL, *job_class_path); | ||
1882 | 241 | |||
1883 | 242 | nih_free (job_class_paths); | ||
1884 | 243 | |||
1885 | 244 | /* Become daemon */ | ||
1886 | 245 | if (daemonise) { | ||
1887 | 246 | if (nih_main_daemonise () < 0) { | ||
1888 | 247 | NihError *err; | ||
1889 | 248 | |||
1890 | 249 | err = nih_error_get (); | ||
1891 | 250 | nih_fatal ("%s: %s", _("Unable to become daemon"), | ||
1892 | 251 | err->message); | ||
1893 | 252 | nih_free (err); | ||
1894 | 253 | |||
1895 | 254 | exit (1); | ||
1896 | 255 | } | ||
1897 | 256 | |||
1898 | 257 | /* Send all logging output to syslog */ | ||
1899 | 258 | openlog (program_name, LOG_PID, LOG_DAEMON); | ||
1900 | 259 | nih_log_set_logger (nih_logger_syslog); | ||
1901 | 260 | } | ||
1902 | 261 | |||
1903 | 262 | /* Handle TERM and INT signals gracefully */ | ||
1904 | 263 | nih_signal_set_handler (SIGTERM, nih_signal_handler); | ||
1905 | 264 | NIH_MUST (nih_signal_add_handler (NULL, SIGTERM, nih_main_term_signal, NULL)); | ||
1906 | 265 | |||
1907 | 266 | if (! daemonise) { | ||
1908 | 267 | nih_signal_set_handler (SIGINT, nih_signal_handler); | ||
1909 | 268 | NIH_MUST (nih_signal_add_handler (NULL, SIGINT, nih_main_term_signal, NULL)); | ||
1910 | 269 | } | ||
1911 | 270 | |||
1912 | 271 | ret = nih_main_loop (); | ||
1913 | 272 | |||
1914 | 273 | return ret; | ||
1915 | 274 | } | ||
1916 | 275 | |||
1917 | 276 | |||
1918 | 277 | static void | ||
1919 | 278 | epoll_watcher (void * data, | ||
1920 | 279 | NihIoWatch *watch, | ||
1921 | 280 | NihIoEvents events) | ||
1922 | 281 | { | ||
1923 | 282 | struct epoll_event event[1024]; | ||
1924 | 283 | int num_events; | ||
1925 | 284 | |||
1926 | 285 | num_events = epoll_wait (epoll_fd, event, 1024, 0); | ||
1927 | 286 | if (num_events < 0) { | ||
1928 | 287 | nih_error ("%s: %s", _("Error from epoll"), strerror (errno)); | ||
1929 | 288 | return; | ||
1930 | 289 | } else if (num_events == 0) | ||
1931 | 290 | return; | ||
1932 | 291 | |||
1933 | 292 | for (int i = 0; i < num_events; i++) { | ||
1934 | 293 | Socket *sock = (Socket *)event[i].data.ptr; | ||
1935 | 294 | nih_local char **env = NULL; | ||
1936 | 295 | size_t env_len = 0; | ||
1937 | 296 | char *var; | ||
1938 | 297 | DBusPendingCall *pending_call; | ||
1939 | 298 | |||
1940 | 299 | if (event[i].events & EPOLLIN) | ||
1941 | 300 | nih_debug ("%p EPOLLIN", sock); | ||
1942 | 301 | if (event[i].events & EPOLLERR) | ||
1943 | 302 | nih_debug ("%p EPOLLERR", sock); | ||
1944 | 303 | if (event[i].events & EPOLLHUP) | ||
1945 | 304 | nih_debug ("%p EPOLLHUP", sock); | ||
1946 | 305 | |||
1947 | 306 | env = NIH_MUST (nih_str_array_new (NULL)); | ||
1948 | 307 | |||
1949 | 308 | switch (sock->addr.sa_family) { | ||
1950 | 309 | case AF_INET: | ||
1951 | 310 | NIH_MUST (nih_str_array_add (&env, NULL, &env_len, | ||
1952 | 311 | "PROTO=inet")); | ||
1953 | 312 | |||
1954 | 313 | var = NIH_MUST (nih_sprintf (NULL, "PORT=%d", | ||
1955 | 314 | ntohs (sock->sin_addr.sin_port))); | ||
1956 | 315 | NIH_MUST (nih_str_array_addp (&env, NULL, &env_len, | ||
1957 | 316 | var)); | ||
1958 | 317 | nih_discard (var); | ||
1959 | 318 | |||
1960 | 319 | var = NIH_MUST (nih_sprintf (NULL, "ADDR=%s", | ||
1961 | 320 | inet_ntoa (sock->sin_addr.sin_addr))); | ||
1962 | 321 | NIH_MUST (nih_str_array_addp (&env, NULL, &env_len, | ||
1963 | 322 | var)); | ||
1964 | 323 | nih_discard (var); | ||
1965 | 324 | break; | ||
1966 | 325 | case AF_UNIX: | ||
1967 | 326 | NIH_MUST (nih_str_array_add (&env, NULL, &env_len, | ||
1968 | 327 | "PROTO=unix")); | ||
1969 | 328 | |||
1970 | 329 | var = NIH_MUST (nih_sprintf (NULL, "PATH=%s", | ||
1971 | 330 | sock->sun_addr.sun_path)); | ||
1972 | 331 | NIH_MUST (nih_str_array_addp (&env, NULL, &env_len, | ||
1973 | 332 | var)); | ||
1974 | 333 | nih_discard (var); | ||
1975 | 334 | break; | ||
1976 | 335 | default: | ||
1977 | 336 | nih_assert_not_reached (); | ||
1978 | 337 | } | ||
1979 | 338 | |||
1980 | 339 | pending_call = NIH_SHOULD (upstart_emit_event_with_file ( | ||
1981 | 340 | upstart, "socket", env, TRUE, | ||
1982 | 341 | sock->sock, | ||
1983 | 342 | (UpstartEmitEventWithFileReply)emit_event_reply, | ||
1984 | 343 | (NihDBusErrorHandler)emit_event_error, | ||
1985 | 344 | sock, | ||
1986 | 345 | NIH_DBUS_TIMEOUT_NEVER)); | ||
1987 | 346 | if (! pending_call) { | ||
1988 | 347 | NihError *err; | ||
1989 | 348 | |||
1990 | 349 | err = nih_error_get (); | ||
1991 | 350 | nih_warn ("%s: %s", _("Could not send socket event"), | ||
1992 | 351 | err->message); | ||
1993 | 352 | nih_free (err); | ||
1994 | 353 | } | ||
1995 | 354 | |||
1996 | 355 | dbus_pending_call_unref (pending_call); | ||
1997 | 356 | |||
1998 | 357 | // might be EPOLLIN | ||
1999 | 358 | // might be EPOLLERR | ||
2000 | 359 | // might be EPOLLHUP | ||
2001 | 360 | } | ||
2002 | 361 | } | ||
2003 | 362 | |||
2004 | 363 | |||
2005 | 364 | static void | ||
2006 | 365 | upstart_job_added (void * data, | ||
2007 | 366 | NihDBusMessage *message, | ||
2008 | 367 | const char * job_class_path) | ||
2009 | 368 | { | ||
2010 | 369 | nih_local NihDBusProxy *job_class = NULL; | ||
2011 | 370 | nih_local char ***start_on = NULL; | ||
2012 | 371 | nih_local char ***stop_on = NULL; | ||
2013 | 372 | Job *job; | ||
2014 | 373 | |||
2015 | 374 | nih_assert (job_class_path != NULL); | ||
2016 | 375 | |||
2017 | 376 | /* Obtain a proxy to the job */ | ||
2018 | 377 | job_class = nih_dbus_proxy_new (NULL, upstart->connection, | ||
2019 | 378 | upstart->name, job_class_path, | ||
2020 | 379 | NULL, NULL); | ||
2021 | 380 | if (! job_class) { | ||
2022 | 381 | NihError *err; | ||
2023 | 382 | |||
2024 | 383 | err = nih_error_get (); | ||
2025 | 384 | nih_error ("Could not create proxy for job %s: %s", | ||
2026 | 385 | job_class_path, err->message); | ||
2027 | 386 | nih_free (err); | ||
2028 | 387 | |||
2029 | 388 | return; | ||
2030 | 389 | } | ||
2031 | 390 | |||
2032 | 391 | job_class->auto_start = FALSE; | ||
2033 | 392 | |||
2034 | 393 | /* Obtain the start_on and stop_on properties of the job */ | ||
2035 | 394 | if (job_class_get_start_on_sync (NULL, job_class, &start_on) < 0) { | ||
2036 | 395 | NihError *err; | ||
2037 | 396 | |||
2038 | 397 | err = nih_error_get (); | ||
2039 | 398 | nih_error ("Could not obtain job start condition %s: %s", | ||
2040 | 399 | job_class_path, err->message); | ||
2041 | 400 | nih_free (err); | ||
2042 | 401 | |||
2043 | 402 | return; | ||
2044 | 403 | } | ||
2045 | 404 | |||
2046 | 405 | if (job_class_get_stop_on_sync (NULL, job_class, &stop_on) < 0) { | ||
2047 | 406 | NihError *err; | ||
2048 | 407 | |||
2049 | 408 | err = nih_error_get (); | ||
2050 | 409 | nih_error ("Could not obtain job stop condition %s: %s", | ||
2051 | 410 | job_class_path, err->message); | ||
2052 | 411 | nih_free (err); | ||
2053 | 412 | |||
2054 | 413 | return; | ||
2055 | 414 | } | ||
2056 | 415 | |||
2057 | 416 | /* Free any existing record for the job (should never happen, | ||
2058 | 417 | * but worth being safe). | ||
2059 | 418 | */ | ||
2060 | 419 | job = (Job *)nih_hash_lookup (jobs, job_class_path); | ||
2061 | 420 | if (job) | ||
2062 | 421 | nih_free (job); | ||
2063 | 422 | |||
2064 | 423 | /* Create new record for the job */ | ||
2065 | 424 | job = NIH_MUST (nih_new (NULL, Job)); | ||
2066 | 425 | job->path = NIH_MUST (nih_strdup (job, job_class_path)); | ||
2067 | 426 | |||
2068 | 427 | nih_list_init (&job->entry); | ||
2069 | 428 | nih_list_init (&job->sockets); | ||
2070 | 429 | |||
2071 | 430 | /* Find out whether this job listens for any socket events */ | ||
2072 | 431 | for (char ***event = start_on; event && *event && **event; event++) | ||
2073 | 432 | if (! strcmp (**event, "socket")) | ||
2074 | 433 | job_add_socket (job, *event); | ||
2075 | 434 | for (char ***event = stop_on; event && *event && **event; event++) | ||
2076 | 435 | if (! strcmp (**event, "socket")) | ||
2077 | 436 | job_add_socket (job, *event); | ||
2078 | 437 | |||
2079 | 438 | /* If we didn't end up with any sockets, free the job and move on */ | ||
2080 | 439 | if (NIH_LIST_EMPTY (&job->sockets)) { | ||
2081 | 440 | nih_free (job); | ||
2082 | 441 | return; | ||
2083 | 442 | } | ||
2084 | 443 | |||
2085 | 444 | nih_debug ("Job got added %s", job_class_path); | ||
2086 | 445 | |||
2087 | 446 | nih_alloc_set_destructor (job, nih_list_destroy); | ||
2088 | 447 | nih_hash_add (jobs, &job->entry); | ||
2089 | 448 | } | ||
2090 | 449 | |||
2091 | 450 | static void | ||
2092 | 451 | upstart_job_removed (void * data, | ||
2093 | 452 | NihDBusMessage *message, | ||
2094 | 453 | const char * job_path) | ||
2095 | 454 | { | ||
2096 | 455 | Job *job; | ||
2097 | 456 | |||
2098 | 457 | nih_assert (job_path != NULL); | ||
2099 | 458 | |||
2100 | 459 | job = (Job *)nih_hash_lookup (jobs, job_path); | ||
2101 | 460 | if (job) { | ||
2102 | 461 | nih_debug ("Job went away %s", job_path); | ||
2103 | 462 | nih_free (job); | ||
2104 | 463 | } | ||
2105 | 464 | } | ||
2106 | 465 | |||
2107 | 466 | |||
2108 | 467 | static void | ||
2109 | 468 | job_add_socket (Job * job, | ||
2110 | 469 | char **socket_info) | ||
2111 | 470 | { | ||
2112 | 471 | Socket *sock; | ||
2113 | 472 | nih_local char *error = NULL; | ||
2114 | 473 | int components = 0; | ||
2115 | 474 | struct epoll_event event; | ||
2116 | 475 | |||
2117 | 476 | nih_assert (job != NULL); | ||
2118 | 477 | nih_assert (socket_info != NULL); | ||
2119 | 478 | nih_assert (! strcmp(socket_info[0], "socket")); | ||
2120 | 479 | |||
2121 | 480 | sock = NIH_MUST (nih_new (job, Socket)); | ||
2122 | 481 | memset (sock, 0, sizeof (Socket)); | ||
2123 | 482 | sock->sock = -1; | ||
2124 | 483 | |||
2125 | 484 | nih_list_init (&sock->entry); | ||
2126 | 485 | |||
2127 | 486 | nih_debug ("Found socket"); | ||
2128 | 487 | for (char **env = socket_info + 1; env && *env; env++) { | ||
2129 | 488 | char *val; | ||
2130 | 489 | size_t name_len; | ||
2131 | 490 | |||
2132 | 491 | val = strchr (*env, '='); | ||
2133 | 492 | if (! val) { | ||
2134 | 493 | nih_warn ("Ignored socket event without variable name in %s", | ||
2135 | 494 | job->path); | ||
2136 | 495 | goto error; | ||
2137 | 496 | } | ||
2138 | 497 | |||
2139 | 498 | name_len = val - *env; | ||
2140 | 499 | val++; | ||
2141 | 500 | |||
2142 | 501 | if (! strncmp (*env, "PROTO", name_len)) { | ||
2143 | 502 | if (! strcmp (val, "inet")) { | ||
2144 | 503 | sock->addrlen = sizeof sock->sin_addr; | ||
2145 | 504 | sock->sin_addr.sin_family = AF_INET; | ||
2146 | 505 | sock->sin_addr.sin_addr.s_addr = INADDR_ANY; | ||
2147 | 506 | components = 1; | ||
2148 | 507 | } else if (! strcmp (val, "unix")) { | ||
2149 | 508 | sock->addrlen = sizeof sock->sun_addr; | ||
2150 | 509 | sock->sun_addr.sun_family = AF_UNIX; | ||
2151 | 510 | components = 1; | ||
2152 | 511 | } else { | ||
2153 | 512 | nih_warn ("Ignored socket event with unknown PROTO=%s in %s", | ||
2154 | 513 | val, job->path); | ||
2155 | 514 | goto error; | ||
2156 | 515 | } | ||
2157 | 516 | |||
2158 | 517 | } else if (! strncmp (*env, "PORT", name_len) | ||
2159 | 518 | && (sock->sin_addr.sin_family == AF_INET)) { | ||
2160 | 519 | sock->sin_addr.sin_port = htons (atoi (val)); | ||
2161 | 520 | components--; | ||
2162 | 521 | |||
2163 | 522 | } else if (! strncmp (*env, "ADDR", name_len) | ||
2164 | 523 | && (sock->sin_addr.sin_family == AF_INET)) { | ||
2165 | 524 | if (inet_aton (val, &(sock->sin_addr.sin_addr)) == 0) { | ||
2166 | 525 | nih_warn ("Ignored socket event with invalid ADDR=%s in %s", | ||
2167 | 526 | val, job->path); | ||
2168 | 527 | goto error; | ||
2169 | 528 | } | ||
2170 | 529 | |||
2171 | 530 | } else if (! strncmp (*env, "PATH", name_len) | ||
2172 | 531 | && (sock->sun_addr.sun_family == AF_UNIX)) { | ||
2173 | 532 | strncpy (sock->sun_addr.sun_path, val, | ||
2174 | 533 | sizeof sock->sun_addr.sun_path); | ||
2175 | 534 | |||
2176 | 535 | if (sock->sun_addr.sun_path[0] == '@') | ||
2177 | 536 | sock->sun_addr.sun_path[0] = '\0'; | ||
2178 | 537 | |||
2179 | 538 | components--; | ||
2180 | 539 | |||
2181 | 540 | } else { | ||
2182 | 541 | nih_warn ("Ignored socket event with unknown variable %.*s in %s", | ||
2183 | 542 | (int)name_len, *env, job->path); | ||
2184 | 543 | goto error; | ||
2185 | 544 | } | ||
2186 | 545 | } | ||
2187 | 546 | |||
2188 | 547 | /* Missing any required components? */ | ||
2189 | 548 | if (components) { | ||
2190 | 549 | nih_warn ("Ignored incomplete socket event in %s", | ||
2191 | 550 | job->path); | ||
2192 | 551 | goto error; | ||
2193 | 552 | } | ||
2194 | 553 | |||
2195 | 554 | /* Let's try and set this baby up */ | ||
2196 | 555 | sock->sock = socket (sock->addr.sa_family, SOCK_STREAM, 0); | ||
2197 | 556 | if (sock->sock < 0) { | ||
2198 | 557 | nih_warn ("Failed to create socket in %s: %s", | ||
2199 | 558 | job->path, strerror (errno)); | ||
2200 | 559 | goto error; | ||
2201 | 560 | } | ||
2202 | 561 | |||
2203 | 562 | int opt = 1; | ||
2204 | 563 | if (setsockopt (sock->sock, SOL_SOCKET, SO_REUSEADDR, | ||
2205 | 564 | &opt, sizeof opt) < 0) { | ||
2206 | 565 | nih_warn ("Failed to set socket reuse in %s: %s", | ||
2207 | 566 | job->path, strerror (errno)); | ||
2208 | 567 | goto error; | ||
2209 | 568 | } | ||
2210 | 569 | |||
2211 | 570 | if (bind (sock->sock, &sock->addr, sock->addrlen) < 0) { | ||
2212 | 571 | nih_warn ("Failed to bind socket in %s: %s", | ||
2213 | 572 | job->path, strerror (errno)); | ||
2214 | 573 | goto error; | ||
2215 | 574 | } | ||
2216 | 575 | |||
2217 | 576 | if (listen (sock->sock, SOMAXCONN) < 0) { | ||
2218 | 577 | nih_warn ("Failed to listen on socket in %s: %s", | ||
2219 | 578 | job->path, strerror (errno)); | ||
2220 | 579 | goto error; | ||
2221 | 580 | } | ||
2222 | 581 | |||
2223 | 582 | /* We have a listening socket, now we want to be notified when someone | ||
2224 | 583 | * connects; but we just want one notification, we don't want to get | ||
2225 | 584 | * a DDoS of wake-ups while waiting for the service to start. | ||
2226 | 585 | * | ||
2227 | 586 | * The solution is to use epoll in edge-triggered mode, this will | ||
2228 | 587 | * fire only on initial connection until a new one comes in. | ||
2229 | 588 | */ | ||
2230 | 589 | event.events = EPOLLIN | EPOLLET; | ||
2231 | 590 | event.data.ptr = sock; | ||
2232 | 591 | |||
2233 | 592 | if (epoll_ctl (epoll_fd, EPOLL_CTL_ADD, sock->sock, &event) < 0) { | ||
2234 | 593 | nih_warn ("Failed to watch socket in %s: %s", | ||
2235 | 594 | job->path, strerror (errno)); | ||
2236 | 595 | goto error; | ||
2237 | 596 | } | ||
2238 | 597 | |||
2239 | 598 | /* Okay then, add to the job */ | ||
2240 | 599 | nih_alloc_set_destructor (sock, socket_destroy); | ||
2241 | 600 | nih_list_add (&job->sockets, &sock->entry); | ||
2242 | 601 | |||
2243 | 602 | return; | ||
2244 | 603 | |||
2245 | 604 | error: | ||
2246 | 605 | if (sock->sock != -1) | ||
2247 | 606 | close (sock->sock); | ||
2248 | 607 | nih_free (sock); | ||
2249 | 608 | } | ||
2250 | 609 | |||
2251 | 610 | static void | ||
2252 | 611 | socket_destroy (Socket *sock) | ||
2253 | 612 | { | ||
2254 | 613 | epoll_ctl (epoll_fd, EPOLL_CTL_DEL, sock->sock, NULL); | ||
2255 | 614 | close (sock->sock); | ||
2256 | 615 | |||
2257 | 616 | nih_list_destroy (&sock->entry); | ||
2258 | 617 | } | ||
2259 | 618 | |||
2260 | 619 | |||
2261 | 620 | static void | ||
2262 | 621 | upstart_disconnected (DBusConnection *connection) | ||
2263 | 622 | { | ||
2264 | 623 | nih_fatal (_("Disconnected from Upstart")); | ||
2265 | 624 | nih_main_loop_exit (1); | ||
2266 | 625 | } | ||
2267 | 626 | |||
2268 | 627 | |||
2269 | 628 | static void | ||
2270 | 629 | emit_event_reply (Socket * sock, | ||
2271 | 630 | NihDBusMessage *message) | ||
2272 | 631 | { | ||
2273 | 632 | nih_debug ("Event completed"); | ||
2274 | 633 | } | ||
2275 | 634 | |||
2276 | 635 | static void | ||
2277 | 636 | emit_event_error (Socket * sock, | ||
2278 | 637 | NihDBusMessage *message) | ||
2279 | 638 | { | ||
2280 | 639 | NihError *err; | ||
2281 | 640 | |||
2282 | 641 | err = nih_error_get (); | ||
2283 | 642 | nih_warn ("%s: %s", _("Error emitting socket event"), err->message); | ||
2284 | 643 | nih_free (err); | ||
2285 | 644 | } | ||
2286 | 0 | 645 | ||
2287 | === added file 'extra/upstart-udev-bridge.c' | |||
2288 | --- extra/upstart-udev-bridge.c 1970-01-01 00:00:00 +0000 | |||
2289 | +++ extra/upstart-udev-bridge.c 2011-10-14 11:09:18 +0000 | |||
2290 | @@ -0,0 +1,310 @@ | |||
2291 | 1 | /* upstart | ||
2292 | 2 | * | ||
2293 | 3 | * Copyright © 2009 Canonical Ltd. | ||
2294 | 4 | * Author: Scott James Remnant <scott@netsplit.com>. | ||
2295 | 5 | * | ||
2296 | 6 | * This program is free software; you can redistribute it and/or modify | ||
2297 | 7 | * it under the terms of the GNU General Public License version 2, as | ||
2298 | 8 | * published by the Free Software Foundation. | ||
2299 | 9 | * | ||
2300 | 10 | * This program is distributed in the hope that it will be useful, | ||
2301 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2302 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2303 | 13 | * GNU General Public License for more details. | ||
2304 | 14 | * | ||
2305 | 15 | * You should have received a copy of the GNU General Public License along | ||
2306 | 16 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
2307 | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
2308 | 18 | */ | ||
2309 | 19 | |||
2310 | 20 | #ifdef HAVE_CONFIG_H | ||
2311 | 21 | # include <config.h> | ||
2312 | 22 | #endif /* HAVE_CONFIG_H */ | ||
2313 | 23 | |||
2314 | 24 | |||
2315 | 25 | #include <libudev.h> | ||
2316 | 26 | |||
2317 | 27 | #include <stdlib.h> | ||
2318 | 28 | #include <string.h> | ||
2319 | 29 | #include <syslog.h> | ||
2320 | 30 | |||
2321 | 31 | #include <nih/macros.h> | ||
2322 | 32 | #include <nih/alloc.h> | ||
2323 | 33 | #include <nih/string.h> | ||
2324 | 34 | #include <nih/io.h> | ||
2325 | 35 | #include <nih/option.h> | ||
2326 | 36 | #include <nih/main.h> | ||
2327 | 37 | #include <nih/logging.h> | ||
2328 | 38 | #include <nih/error.h> | ||
2329 | 39 | |||
2330 | 40 | #include <nih-dbus/dbus_connection.h> | ||
2331 | 41 | #include <nih-dbus/dbus_proxy.h> | ||
2332 | 42 | |||
2333 | 43 | #include "dbus/upstart.h" | ||
2334 | 44 | #include "com.ubuntu.Upstart.h" | ||
2335 | 45 | |||
2336 | 46 | |||
2337 | 47 | /* Prototypes for static functions */ | ||
2338 | 48 | static void udev_monitor_watcher (struct udev_monitor *udev_monitor, | ||
2339 | 49 | NihIoWatch *watch, NihIoEvents events); | ||
2340 | 50 | static void upstart_disconnected (DBusConnection *connection); | ||
2341 | 51 | static void emit_event_error (void *data, NihDBusMessage *message); | ||
2342 | 52 | |||
2343 | 53 | |||
2344 | 54 | /** | ||
2345 | 55 | * daemonise: | ||
2346 | 56 | * | ||
2347 | 57 | * Set to TRUE if we should become a daemon, rather than just running | ||
2348 | 58 | * in the foreground. | ||
2349 | 59 | **/ | ||
2350 | 60 | static int daemonise = FALSE; | ||
2351 | 61 | |||
2352 | 62 | /** | ||
2353 | 63 | * upstart: | ||
2354 | 64 | * | ||
2355 | 65 | * Proxy to Upstart daemon. | ||
2356 | 66 | **/ | ||
2357 | 67 | static NihDBusProxy *upstart = NULL; | ||
2358 | 68 | |||
2359 | 69 | |||
2360 | 70 | /** | ||
2361 | 71 | * options: | ||
2362 | 72 | * | ||
2363 | 73 | * Command-line options accepted by this program. | ||
2364 | 74 | **/ | ||
2365 | 75 | static NihOption options[] = { | ||
2366 | 76 | { 0, "daemon", N_("Detach and run in the background"), | ||
2367 | 77 | NULL, NULL, &daemonise, NULL }, | ||
2368 | 78 | |||
2369 | 79 | NIH_OPTION_LAST | ||
2370 | 80 | }; | ||
2371 | 81 | |||
2372 | 82 | |||
2373 | 83 | int | ||
2374 | 84 | main (int argc, | ||
2375 | 85 | char *argv[]) | ||
2376 | 86 | { | ||
2377 | 87 | char ** args; | ||
2378 | 88 | DBusConnection * connection; | ||
2379 | 89 | struct udev * udev; | ||
2380 | 90 | struct udev_monitor *udev_monitor; | ||
2381 | 91 | int ret; | ||
2382 | 92 | |||
2383 | 93 | nih_main_init (argv[0]); | ||
2384 | 94 | |||
2385 | 95 | nih_option_set_synopsis (_("Bridge udev events into upstart")); | ||
2386 | 96 | nih_option_set_help ( | ||
2387 | 97 | _("By default, upstart-udev-bridge does not detach from the " | ||
2388 | 98 | "console and remains in the foreground. Use the --daemon " | ||
2389 | 99 | "option to have it detach.")); | ||
2390 | 100 | |||
2391 | 101 | args = nih_option_parser (NULL, argc, argv, options, FALSE); | ||
2392 | 102 | if (! args) | ||
2393 | 103 | exit (1); | ||
2394 | 104 | |||
2395 | 105 | /* Initialise the connection to Upstart */ | ||
2396 | 106 | connection = NIH_SHOULD (nih_dbus_connect (DBUS_ADDRESS_UPSTART, upstart_disconnected)); | ||
2397 | 107 | if (! connection) { | ||
2398 | 108 | NihError *err; | ||
2399 | 109 | |||
2400 | 110 | err = nih_error_get (); | ||
2401 | 111 | nih_fatal ("%s: %s", _("Could not connect to Upstart"), | ||
2402 | 112 | err->message); | ||
2403 | 113 | nih_free (err); | ||
2404 | 114 | |||
2405 | 115 | exit (1); | ||
2406 | 116 | } | ||
2407 | 117 | |||
2408 | 118 | upstart = NIH_SHOULD (nih_dbus_proxy_new (NULL, connection, | ||
2409 | 119 | NULL, DBUS_PATH_UPSTART, | ||
2410 | 120 | NULL, NULL)); | ||
2411 | 121 | if (! upstart) { | ||
2412 | 122 | NihError *err; | ||
2413 | 123 | |||
2414 | 124 | err = nih_error_get (); | ||
2415 | 125 | nih_fatal ("%s: %s", _("Could not create Upstart proxy"), | ||
2416 | 126 | err->message); | ||
2417 | 127 | nih_free (err); | ||
2418 | 128 | |||
2419 | 129 | exit (1); | ||
2420 | 130 | } | ||
2421 | 131 | |||
2422 | 132 | /* Initialise the connection to udev */ | ||
2423 | 133 | nih_assert (udev = udev_new ()); | ||
2424 | 134 | nih_assert (udev_monitor = udev_monitor_new_from_netlink (udev, "udev")); | ||
2425 | 135 | nih_assert (udev_monitor_enable_receiving (udev_monitor) == 0); | ||
2426 | 136 | udev_monitor_set_receive_buffer_size(udev_monitor, 128*1024*1024); | ||
2427 | 137 | |||
2428 | 138 | NIH_MUST (nih_io_add_watch (NULL, udev_monitor_get_fd (udev_monitor), | ||
2429 | 139 | NIH_IO_READ, | ||
2430 | 140 | (NihIoWatcher)udev_monitor_watcher, | ||
2431 | 141 | udev_monitor)); | ||
2432 | 142 | |||
2433 | 143 | /* Become daemon */ | ||
2434 | 144 | if (daemonise) { | ||
2435 | 145 | if (nih_main_daemonise () < 0) { | ||
2436 | 146 | NihError *err; | ||
2437 | 147 | |||
2438 | 148 | err = nih_error_get (); | ||
2439 | 149 | nih_fatal ("%s: %s", _("Unable to become daemon"), | ||
2440 | 150 | err->message); | ||
2441 | 151 | nih_free (err); | ||
2442 | 152 | |||
2443 | 153 | exit (1); | ||
2444 | 154 | } | ||
2445 | 155 | |||
2446 | 156 | /* Send all logging output to syslog */ | ||
2447 | 157 | openlog (program_name, LOG_PID, LOG_DAEMON); | ||
2448 | 158 | nih_log_set_logger (nih_logger_syslog); | ||
2449 | 159 | } | ||
2450 | 160 | |||
2451 | 161 | /* Handle TERM and INT signals gracefully */ | ||
2452 | 162 | nih_signal_set_handler (SIGTERM, nih_signal_handler); | ||
2453 | 163 | NIH_MUST (nih_signal_add_handler (NULL, SIGTERM, nih_main_term_signal, NULL)); | ||
2454 | 164 | |||
2455 | 165 | if (! daemonise) { | ||
2456 | 166 | nih_signal_set_handler (SIGINT, nih_signal_handler); | ||
2457 | 167 | NIH_MUST (nih_signal_add_handler (NULL, SIGINT, nih_main_term_signal, NULL)); | ||
2458 | 168 | } | ||
2459 | 169 | |||
2460 | 170 | ret = nih_main_loop (); | ||
2461 | 171 | |||
2462 | 172 | return ret; | ||
2463 | 173 | } | ||
2464 | 174 | |||
2465 | 175 | |||
2466 | 176 | static void | ||
2467 | 177 | udev_monitor_watcher (struct udev_monitor *udev_monitor, | ||
2468 | 178 | NihIoWatch * watch, | ||
2469 | 179 | NihIoEvents events) | ||
2470 | 180 | { | ||
2471 | 181 | struct udev_device * udev_device; | ||
2472 | 182 | const char * subsystem; | ||
2473 | 183 | const char * action; | ||
2474 | 184 | const char * kernel; | ||
2475 | 185 | const char * devpath; | ||
2476 | 186 | const char * devname; | ||
2477 | 187 | nih_local char * name = NULL; | ||
2478 | 188 | nih_local char ** env = NULL; | ||
2479 | 189 | size_t env_len = 0; | ||
2480 | 190 | DBusPendingCall * pending_call; | ||
2481 | 191 | |||
2482 | 192 | udev_device = udev_monitor_receive_device (udev_monitor); | ||
2483 | 193 | if (! udev_device) | ||
2484 | 194 | return; | ||
2485 | 195 | |||
2486 | 196 | subsystem = udev_device_get_subsystem (udev_device); | ||
2487 | 197 | action = udev_device_get_action (udev_device); | ||
2488 | 198 | kernel = udev_device_get_sysname (udev_device); | ||
2489 | 199 | devpath = udev_device_get_devpath (udev_device); | ||
2490 | 200 | devname = udev_device_get_devnode (udev_device); | ||
2491 | 201 | |||
2492 | 202 | if (! strcmp (action, "add")) { | ||
2493 | 203 | name = NIH_MUST (nih_sprintf (NULL, "%s-device-added", | ||
2494 | 204 | subsystem)); | ||
2495 | 205 | } else if (! strcmp (action, "change")) { | ||
2496 | 206 | name = NIH_MUST (nih_sprintf (NULL, "%s-device-changed", | ||
2497 | 207 | subsystem)); | ||
2498 | 208 | } else if (! strcmp (action, "remove")) { | ||
2499 | 209 | name = NIH_MUST (nih_sprintf (NULL, "%s-device-removed", | ||
2500 | 210 | subsystem)); | ||
2501 | 211 | } else { | ||
2502 | 212 | name = NIH_MUST (nih_sprintf (NULL, "%s-device-%s", | ||
2503 | 213 | subsystem, action)); | ||
2504 | 214 | } | ||
2505 | 215 | |||
2506 | 216 | env = NIH_MUST (nih_str_array_new (NULL)); | ||
2507 | 217 | |||
2508 | 218 | if (kernel) { | ||
2509 | 219 | nih_local char *var = NULL; | ||
2510 | 220 | |||
2511 | 221 | var = NIH_MUST (nih_sprintf (NULL, "KERNEL=%s", kernel)); | ||
2512 | 222 | NIH_MUST (nih_str_array_addp (&env, NULL, &env_len, var)); | ||
2513 | 223 | } | ||
2514 | 224 | |||
2515 | 225 | if (devpath) { | ||
2516 | 226 | nih_local char *var = NULL; | ||
2517 | 227 | |||
2518 | 228 | var = NIH_MUST (nih_sprintf (NULL, "DEVPATH=%s", devpath)); | ||
2519 | 229 | NIH_MUST (nih_str_array_addp (&env, NULL, &env_len, var)); | ||
2520 | 230 | } | ||
2521 | 231 | |||
2522 | 232 | if (devname) { | ||
2523 | 233 | nih_local char *var = NULL; | ||
2524 | 234 | |||
2525 | 235 | var = NIH_MUST (nih_sprintf (NULL, "DEVNAME=%s", devname)); | ||
2526 | 236 | NIH_MUST (nih_str_array_addp (&env, NULL, &env_len, var)); | ||
2527 | 237 | } | ||
2528 | 238 | |||
2529 | 239 | if (subsystem) { | ||
2530 | 240 | nih_local char *var = NULL; | ||
2531 | 241 | |||
2532 | 242 | var = NIH_MUST (nih_sprintf (NULL, "SUBSYSTEM=%s", subsystem)); | ||
2533 | 243 | NIH_MUST (nih_str_array_addp (&env, NULL, &env_len, var)); | ||
2534 | 244 | } | ||
2535 | 245 | |||
2536 | 246 | if (action) { | ||
2537 | 247 | nih_local char *var = NULL; | ||
2538 | 248 | |||
2539 | 249 | var = NIH_MUST (nih_sprintf (NULL, "ACTION=%s", action)); | ||
2540 | 250 | NIH_MUST (nih_str_array_addp (&env, NULL, &env_len, var)); | ||
2541 | 251 | } | ||
2542 | 252 | |||
2543 | 253 | for (struct udev_list_entry *list_entry = udev_device_get_properties_list_entry (udev_device); | ||
2544 | 254 | list_entry != NULL; | ||
2545 | 255 | list_entry = udev_list_entry_get_next (list_entry)) { | ||
2546 | 256 | const char * key; | ||
2547 | 257 | nih_local char *var = NULL; | ||
2548 | 258 | |||
2549 | 259 | key = udev_list_entry_get_name (list_entry); | ||
2550 | 260 | if (! strcmp (key, "DEVPATH")) | ||
2551 | 261 | continue; | ||
2552 | 262 | if (! strcmp (key, "DEVNAME")) | ||
2553 | 263 | continue; | ||
2554 | 264 | if (! strcmp (key, "SUBSYSTEM")) | ||
2555 | 265 | continue; | ||
2556 | 266 | if (! strcmp (key, "ACTION")) | ||
2557 | 267 | continue; | ||
2558 | 268 | |||
2559 | 269 | var = NIH_MUST (nih_sprintf (NULL, "%s=%s", key, | ||
2560 | 270 | udev_list_entry_get_value (list_entry))); | ||
2561 | 271 | NIH_MUST (nih_str_array_addp (&env, NULL, &env_len, var)); | ||
2562 | 272 | } | ||
2563 | 273 | |||
2564 | 274 | nih_debug ("%s %s", name, devname); | ||
2565 | 275 | |||
2566 | 276 | pending_call = NIH_SHOULD (upstart_emit_event (upstart, | ||
2567 | 277 | name, env, FALSE, | ||
2568 | 278 | NULL, emit_event_error, NULL, | ||
2569 | 279 | NIH_DBUS_TIMEOUT_NEVER)); | ||
2570 | 280 | if (! pending_call) { | ||
2571 | 281 | NihError *err; | ||
2572 | 282 | |||
2573 | 283 | err = nih_error_get (); | ||
2574 | 284 | nih_warn ("%s", err->message); | ||
2575 | 285 | nih_free (err); | ||
2576 | 286 | } | ||
2577 | 287 | |||
2578 | 288 | dbus_pending_call_unref (pending_call); | ||
2579 | 289 | |||
2580 | 290 | udev_device_unref (udev_device); | ||
2581 | 291 | } | ||
2582 | 292 | |||
2583 | 293 | |||
2584 | 294 | static void | ||
2585 | 295 | upstart_disconnected (DBusConnection *connection) | ||
2586 | 296 | { | ||
2587 | 297 | nih_fatal (_("Disconnected from Upstart")); | ||
2588 | 298 | nih_main_loop_exit (1); | ||
2589 | 299 | } | ||
2590 | 300 | |||
2591 | 301 | static void | ||
2592 | 302 | emit_event_error (void * data, | ||
2593 | 303 | NihDBusMessage *message) | ||
2594 | 304 | { | ||
2595 | 305 | NihError *err; | ||
2596 | 306 | |||
2597 | 307 | err = nih_error_get (); | ||
2598 | 308 | nih_warn ("%s", err->message); | ||
2599 | 309 | nih_free (err); | ||
2600 | 310 | } | ||
2601 | 0 | 311 | ||
2602 | === modified file 'init/Makefile.am' | |||
2603 | --- init/Makefile.am 2010-02-04 03:42:29 +0000 | |||
2604 | +++ init/Makefile.am 2011-10-14 11:09:18 +0000 | |||
2605 | @@ -40,6 +40,7 @@ | |||
2606 | 40 | system.c system.h \ | 40 | system.c system.h \ |
2607 | 41 | environ.c environ.h \ | 41 | environ.c environ.h \ |
2608 | 42 | process.c process.h \ | 42 | process.c process.h \ |
2609 | 43 | session.c session.h \ | ||
2610 | 43 | job_class.c job_class.h \ | 44 | job_class.c job_class.h \ |
2611 | 44 | job_process.c job_process.h \ | 45 | job_process.c job_process.h \ |
2612 | 45 | job.c job.h \ | 46 | job.c job.h \ |
2613 | @@ -158,6 +159,7 @@ | |||
2614 | 158 | system.o environ.o process.o \ | 159 | system.o environ.o process.o \ |
2615 | 159 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ | 160 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ |
2616 | 160 | parse_job.o parse_conf.o conf.o control.o \ | 161 | parse_job.o parse_conf.o conf.o control.o \ |
2617 | 162 | session.o \ | ||
2618 | 161 | com.ubuntu.Upstart.o \ | 163 | com.ubuntu.Upstart.o \ |
2619 | 162 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ | 164 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ |
2620 | 163 | $(NIH_LIBS) \ | 165 | $(NIH_LIBS) \ |
2621 | @@ -169,6 +171,7 @@ | |||
2622 | 169 | system.o environ.o process.o \ | 171 | system.o environ.o process.o \ |
2623 | 170 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ | 172 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ |
2624 | 171 | parse_job.o parse_conf.o conf.o control.o \ | 173 | parse_job.o parse_conf.o conf.o control.o \ |
2625 | 174 | session.o \ | ||
2626 | 172 | com.ubuntu.Upstart.o \ | 175 | com.ubuntu.Upstart.o \ |
2627 | 173 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ | 176 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ |
2628 | 174 | $(NIH_LIBS) \ | 177 | $(NIH_LIBS) \ |
2629 | @@ -180,6 +183,7 @@ | |||
2630 | 180 | system.o environ.o process.o \ | 183 | system.o environ.o process.o \ |
2631 | 181 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ | 184 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ |
2632 | 182 | parse_job.o parse_conf.o conf.o control.o \ | 185 | parse_job.o parse_conf.o conf.o control.o \ |
2633 | 186 | session.o \ | ||
2634 | 183 | com.ubuntu.Upstart.o \ | 187 | com.ubuntu.Upstart.o \ |
2635 | 184 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ | 188 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ |
2636 | 185 | $(NIH_LIBS) \ | 189 | $(NIH_LIBS) \ |
2637 | @@ -191,6 +195,7 @@ | |||
2638 | 191 | system.o environ.o process.o \ | 195 | system.o environ.o process.o \ |
2639 | 192 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ | 196 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ |
2640 | 193 | parse_job.o parse_conf.o conf.o control.o \ | 197 | parse_job.o parse_conf.o conf.o control.o \ |
2641 | 198 | session.o \ | ||
2642 | 194 | com.ubuntu.Upstart.o \ | 199 | com.ubuntu.Upstart.o \ |
2643 | 195 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ | 200 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ |
2644 | 196 | $(NIH_LIBS) \ | 201 | $(NIH_LIBS) \ |
2645 | @@ -202,6 +207,7 @@ | |||
2646 | 202 | system.o environ.o process.o \ | 207 | system.o environ.o process.o \ |
2647 | 203 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ | 208 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ |
2648 | 204 | parse_job.o parse_conf.o conf.o control.o \ | 209 | parse_job.o parse_conf.o conf.o control.o \ |
2649 | 210 | session.o \ | ||
2650 | 205 | com.ubuntu.Upstart.o \ | 211 | com.ubuntu.Upstart.o \ |
2651 | 206 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ | 212 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ |
2652 | 207 | $(NIH_LIBS) \ | 213 | $(NIH_LIBS) \ |
2653 | @@ -213,6 +219,7 @@ | |||
2654 | 213 | system.o environ.o process.o \ | 219 | system.o environ.o process.o \ |
2655 | 214 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ | 220 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ |
2656 | 215 | parse_job.o parse_conf.o conf.o control.o \ | 221 | parse_job.o parse_conf.o conf.o control.o \ |
2657 | 222 | session.o \ | ||
2658 | 216 | com.ubuntu.Upstart.o \ | 223 | com.ubuntu.Upstart.o \ |
2659 | 217 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ | 224 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ |
2660 | 218 | $(NIH_LIBS) \ | 225 | $(NIH_LIBS) \ |
2661 | @@ -224,6 +231,7 @@ | |||
2662 | 224 | system.o environ.o process.o \ | 231 | system.o environ.o process.o \ |
2663 | 225 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ | 232 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ |
2664 | 226 | parse_job.o parse_conf.o conf.o control.o \ | 233 | parse_job.o parse_conf.o conf.o control.o \ |
2665 | 234 | session.o \ | ||
2666 | 227 | com.ubuntu.Upstart.o \ | 235 | com.ubuntu.Upstart.o \ |
2667 | 228 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ | 236 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ |
2668 | 229 | $(NIH_LIBS) \ | 237 | $(NIH_LIBS) \ |
2669 | @@ -235,6 +243,7 @@ | |||
2670 | 235 | system.o environ.o process.o \ | 243 | system.o environ.o process.o \ |
2671 | 236 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ | 244 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ |
2672 | 237 | parse_job.o parse_conf.o conf.o control.o \ | 245 | parse_job.o parse_conf.o conf.o control.o \ |
2673 | 246 | session.o \ | ||
2674 | 238 | com.ubuntu.Upstart.o \ | 247 | com.ubuntu.Upstart.o \ |
2675 | 239 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ | 248 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ |
2676 | 240 | $(NIH_LIBS) \ | 249 | $(NIH_LIBS) \ |
2677 | @@ -246,6 +255,7 @@ | |||
2678 | 246 | system.o environ.o process.o \ | 255 | system.o environ.o process.o \ |
2679 | 247 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ | 256 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ |
2680 | 248 | parse_job.o parse_conf.o conf.o control.o \ | 257 | parse_job.o parse_conf.o conf.o control.o \ |
2681 | 258 | session.o \ | ||
2682 | 249 | com.ubuntu.Upstart.o \ | 259 | com.ubuntu.Upstart.o \ |
2683 | 250 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ | 260 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ |
2684 | 251 | $(NIH_LIBS) \ | 261 | $(NIH_LIBS) \ |
2685 | @@ -257,6 +267,7 @@ | |||
2686 | 257 | system.o environ.o process.o \ | 267 | system.o environ.o process.o \ |
2687 | 258 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ | 268 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ |
2688 | 259 | parse_job.o parse_conf.o conf.o control.o \ | 269 | parse_job.o parse_conf.o conf.o control.o \ |
2689 | 270 | session.o \ | ||
2690 | 260 | com.ubuntu.Upstart.o \ | 271 | com.ubuntu.Upstart.o \ |
2691 | 261 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ | 272 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ |
2692 | 262 | $(NIH_LIBS) \ | 273 | $(NIH_LIBS) \ |
2693 | @@ -268,6 +279,7 @@ | |||
2694 | 268 | system.o environ.o process.o \ | 279 | system.o environ.o process.o \ |
2695 | 269 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ | 280 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ |
2696 | 270 | parse_job.o parse_conf.o conf.o control.o \ | 281 | parse_job.o parse_conf.o conf.o control.o \ |
2697 | 282 | session.o \ | ||
2698 | 271 | com.ubuntu.Upstart.o \ | 283 | com.ubuntu.Upstart.o \ |
2699 | 272 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ | 284 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ |
2700 | 273 | $(NIH_LIBS) \ | 285 | $(NIH_LIBS) \ |
2701 | 274 | 286 | ||
2702 | === modified file 'init/conf.c' | |||
2703 | --- init/conf.c 2011-03-15 18:44:09 +0000 | |||
2704 | +++ init/conf.c 2011-10-14 11:09:18 +0000 | |||
2705 | @@ -2,8 +2,7 @@ | |||
2706 | 2 | * | 2 | * |
2707 | 3 | * conf.c - configuration management | 3 | * conf.c - configuration management |
2708 | 4 | * | 4 | * |
2711 | 5 | * Copyright © 2011 Google Inc. | 5 | * Copyright © 2009,2010,2011 Canonical Ltd. |
2710 | 6 | * Copyright © 2009 Canonical Ltd. | ||
2712 | 7 | * Author: Scott James Remnant <scott@netsplit.com>. | 6 | * Author: Scott James Remnant <scott@netsplit.com>. |
2713 | 8 | * | 7 | * |
2714 | 9 | * This program is free software; you can redistribute it and/or modify | 8 | * This program is free software; you can redistribute it and/or modify |
2715 | @@ -49,7 +48,7 @@ | |||
2716 | 49 | #include "parse_conf.h" | 48 | #include "parse_conf.h" |
2717 | 50 | #include "conf.h" | 49 | #include "conf.h" |
2718 | 51 | #include "errors.h" | 50 | #include "errors.h" |
2720 | 52 | 51 | #include "paths.h" | |
2721 | 53 | 52 | ||
2722 | 54 | /* Prototypes for static functions */ | 53 | /* Prototypes for static functions */ |
2723 | 55 | static int conf_source_reload_file (ConfSource *source) | 54 | static int conf_source_reload_file (ConfSource *source) |
2724 | @@ -71,9 +70,18 @@ | |||
2725 | 71 | struct stat *statbuf) | 70 | struct stat *statbuf) |
2726 | 72 | __attribute__ ((warn_unused_result)); | 71 | __attribute__ ((warn_unused_result)); |
2727 | 73 | 72 | ||
2731 | 74 | static int conf_reload_path (ConfSource *source, const char *path) | 73 | static int conf_reload_path (ConfSource *source, const char *path, |
2732 | 75 | __attribute__ ((warn_unused_result)); | 74 | const char *override_path) |
2733 | 76 | 75 | __attribute__ ((warn_unused_result)); | |
2734 | 76 | |||
2735 | 77 | static inline int is_conf_file (const char *path) | ||
2736 | 78 | __attribute__ ((warn_unused_result)); | ||
2737 | 79 | |||
2738 | 80 | static inline int is_conf_file_std (const char *path) | ||
2739 | 81 | __attribute__ ((warn_unused_result)); | ||
2740 | 82 | |||
2741 | 83 | static inline int is_conf_file_override(const char *path) | ||
2742 | 84 | __attribute__ ((warn_unused_result)); | ||
2743 | 77 | 85 | ||
2744 | 78 | /** | 86 | /** |
2745 | 79 | * conf_sources: | 87 | * conf_sources: |
2746 | @@ -86,6 +94,115 @@ | |||
2747 | 86 | 94 | ||
2748 | 87 | 95 | ||
2749 | 88 | /** | 96 | /** |
2750 | 97 | * is_conf_file_std: | ||
2751 | 98 | * @path: path to check. | ||
2752 | 99 | * | ||
2753 | 100 | * Determine if specified path contains a legitimate | ||
2754 | 101 | * configuration file name. | ||
2755 | 102 | * | ||
2756 | 103 | * Returns: TRUE if @path contains a valid configuration file name, | ||
2757 | 104 | * else FALSE. | ||
2758 | 105 | * | ||
2759 | 106 | **/ | ||
2760 | 107 | static inline int | ||
2761 | 108 | is_conf_file_std (const char *path) | ||
2762 | 109 | { | ||
2763 | 110 | char *ptr = strrchr (path, '.'); | ||
2764 | 111 | |||
2765 | 112 | if (ptr && IS_CONF_EXT_STD (ptr)) | ||
2766 | 113 | return TRUE; | ||
2767 | 114 | |||
2768 | 115 | return FALSE; | ||
2769 | 116 | } | ||
2770 | 117 | |||
2771 | 118 | /** | ||
2772 | 119 | * is_conf_file_override: | ||
2773 | 120 | * @path: path to check. | ||
2774 | 121 | * | ||
2775 | 122 | * Determine if specified path contains a legitimate | ||
2776 | 123 | * override file name. | ||
2777 | 124 | * | ||
2778 | 125 | * Returns: TRUE if @path contains a valid override file name, | ||
2779 | 126 | * else FALSE. | ||
2780 | 127 | * | ||
2781 | 128 | **/ | ||
2782 | 129 | static inline int | ||
2783 | 130 | is_conf_file_override (const char *path) | ||
2784 | 131 | { | ||
2785 | 132 | char *ptr = strrchr (path, '.'); | ||
2786 | 133 | |||
2787 | 134 | if (ptr && IS_CONF_EXT_OVERRIDE (ptr)) | ||
2788 | 135 | return TRUE; | ||
2789 | 136 | |||
2790 | 137 | return FALSE; | ||
2791 | 138 | } | ||
2792 | 139 | |||
2793 | 140 | /** | ||
2794 | 141 | * is_conf_file: | ||
2795 | 142 | * @path: path to check. | ||
2796 | 143 | * | ||
2797 | 144 | * Determine if specified path contains a legitimate | ||
2798 | 145 | * configuration file or override file name. | ||
2799 | 146 | * | ||
2800 | 147 | * Returns: TRUE if @path contains a valid configuration | ||
2801 | 148 | * file or override file name, else FALSE. | ||
2802 | 149 | * | ||
2803 | 150 | **/ | ||
2804 | 151 | static inline int | ||
2805 | 152 | is_conf_file (const char *path) | ||
2806 | 153 | { | ||
2807 | 154 | char *ptr = strrchr (path, '.'); | ||
2808 | 155 | |||
2809 | 156 | if (ptr && (ptr > path) && (ptr[-1] != '/') && IS_CONF_EXT (ptr)) | ||
2810 | 157 | return TRUE; | ||
2811 | 158 | |||
2812 | 159 | return FALSE; | ||
2813 | 160 | } | ||
2814 | 161 | |||
2815 | 162 | /** | ||
2816 | 163 | * Convert a configuration file name to an override file name and vice | ||
2817 | 164 | * versa. | ||
2818 | 165 | * | ||
2819 | 166 | * For example, if @path is "foo.conf", this function will return | ||
2820 | 167 | * "foo.override", whereas if @path is "foo.override", it will return | ||
2821 | 168 | * "foo.conf". | ||
2822 | 169 | * | ||
2823 | 170 | * Note that this function should be static, but isn't to allow the | ||
2824 | 171 | * tests to access it. | ||
2825 | 172 | * | ||
2826 | 173 | * @parent: parent of returned path, | ||
2827 | 174 | * @path: path to a configuration file. | ||
2828 | 175 | * | ||
2829 | 176 | * Returns: newly allocated toggled path, or NULL on error. | ||
2830 | 177 | **/ | ||
2831 | 178 | char * | ||
2832 | 179 | toggle_conf_name (const void *parent, | ||
2833 | 180 | const char *path) | ||
2834 | 181 | { | ||
2835 | 182 | char *new_path; | ||
2836 | 183 | char *ext; | ||
2837 | 184 | char *new_ext; | ||
2838 | 185 | size_t len; | ||
2839 | 186 | |||
2840 | 187 | ext = strrchr (path, '.'); | ||
2841 | 188 | if (!ext) | ||
2842 | 189 | return NULL; | ||
2843 | 190 | |||
2844 | 191 | new_ext = IS_CONF_EXT_STD (ext) | ||
2845 | 192 | ? CONF_EXT_OVERRIDE | ||
2846 | 193 | : CONF_EXT_STD; | ||
2847 | 194 | |||
2848 | 195 | len = strlen (new_ext); | ||
2849 | 196 | |||
2850 | 197 | new_path = NIH_MUST (nih_strndup (parent, path, (ext - path) + len)); | ||
2851 | 198 | |||
2852 | 199 | memcpy (new_path + (ext - path), new_ext, len); | ||
2853 | 200 | |||
2854 | 201 | return new_path; | ||
2855 | 202 | } | ||
2856 | 203 | |||
2857 | 204 | |||
2858 | 205 | /** | ||
2859 | 89 | * conf_init: | 206 | * conf_init: |
2860 | 90 | * | 207 | * |
2861 | 91 | * Initialise the conf_sources list. | 208 | * Initialise the conf_sources list. |
2862 | @@ -147,6 +264,7 @@ | |||
2863 | 147 | 264 | ||
2864 | 148 | source->type = type; | 265 | source->type = type; |
2865 | 149 | source->watch = NULL; | 266 | source->watch = NULL; |
2866 | 267 | source->session = NULL; | ||
2867 | 150 | 268 | ||
2868 | 151 | source->flag = FALSE; | 269 | source->flag = FALSE; |
2869 | 152 | source->files = nih_hash_string_new (source, 0); | 270 | source->files = nih_hash_string_new (source, 0); |
2870 | @@ -235,8 +353,8 @@ | |||
2871 | 235 | err = nih_error_get (); | 353 | err = nih_error_get (); |
2872 | 236 | if (err->number != ENOENT) | 354 | if (err->number != ENOENT) |
2873 | 237 | nih_error ("%s: %s: %s", source->path, | 355 | nih_error ("%s: %s: %s", source->path, |
2876 | 238 | _("Unable to load configuration"), | 356 | _("Unable to load configuration"), |
2877 | 239 | err->message); | 357 | err->message); |
2878 | 240 | nih_free (err); | 358 | nih_free (err); |
2879 | 241 | } | 359 | } |
2880 | 242 | } | 360 | } |
2881 | @@ -329,10 +447,16 @@ | |||
2882 | 329 | conf_source_reload_file (ConfSource *source) | 447 | conf_source_reload_file (ConfSource *source) |
2883 | 330 | { | 448 | { |
2884 | 331 | NihError *err = NULL; | 449 | NihError *err = NULL; |
2885 | 450 | nih_local char *override_path = NULL; | ||
2886 | 451 | |||
2887 | 452 | struct stat statbuf; | ||
2888 | 332 | 453 | ||
2889 | 333 | nih_assert (source != NULL); | 454 | nih_assert (source != NULL); |
2890 | 334 | nih_assert (source->type == CONF_FILE); | 455 | nih_assert (source->type == CONF_FILE); |
2891 | 335 | 456 | ||
2892 | 457 | /* this function should only be called for standard | ||
2893 | 458 | * configuration files. | ||
2894 | 459 | */ | ||
2895 | 336 | if (! source->watch) { | 460 | if (! source->watch) { |
2896 | 337 | nih_local char *dpath = NULL; | 461 | nih_local char *dpath = NULL; |
2897 | 338 | char *dname; | 462 | char *dname; |
2898 | @@ -361,7 +485,7 @@ | |||
2899 | 361 | /* Parse the file itself. If this fails, then we can discard the | 485 | /* Parse the file itself. If this fails, then we can discard the |
2900 | 362 | * inotify error, since this one will be better. | 486 | * inotify error, since this one will be better. |
2901 | 363 | */ | 487 | */ |
2903 | 364 | if (conf_reload_path (source, source->path) < 0) { | 488 | if (conf_reload_path (source, source->path, NULL) < 0) { |
2904 | 365 | if (err) | 489 | if (err) |
2905 | 366 | nih_free (err); | 490 | nih_free (err); |
2906 | 367 | 491 | ||
2907 | @@ -382,6 +506,23 @@ | |||
2908 | 382 | nih_free (err); | 506 | nih_free (err); |
2909 | 383 | } | 507 | } |
2910 | 384 | 508 | ||
2911 | 509 | if (! is_conf_file_std (source->path)) | ||
2912 | 510 | return 0; | ||
2913 | 511 | |||
2914 | 512 | override_path = toggle_conf_name (NULL, source->path); | ||
2915 | 513 | |||
2916 | 514 | if (stat (override_path, &statbuf) != 0) | ||
2917 | 515 | return 0; | ||
2918 | 516 | |||
2919 | 517 | nih_debug ("Updating configuration for %s from %s", | ||
2920 | 518 | source->path, override_path); | ||
2921 | 519 | if (conf_reload_path (source, source->path, override_path) < 0) { | ||
2922 | 520 | if (err) | ||
2923 | 521 | nih_free (err); | ||
2924 | 522 | |||
2925 | 523 | return -1; | ||
2926 | 524 | } | ||
2927 | 525 | |||
2928 | 385 | return 0; | 526 | return 0; |
2929 | 386 | } | 527 | } |
2930 | 387 | 528 | ||
2931 | @@ -501,19 +642,18 @@ | |||
2932 | 501 | * @is_dir: TRUE of @path is a directory. | 642 | * @is_dir: TRUE of @path is a directory. |
2933 | 502 | * | 643 | * |
2934 | 503 | * This is the file filter used for the jobs directory, we only care | 644 | * This is the file filter used for the jobs directory, we only care |
2940 | 504 | * about paths with the ".conf" extension. Directories that | 645 | * about paths with particular extensions (see IS_CONF_EXT). |
2941 | 505 | * match the nih_file_ignore() function are also ignored. | 646 | * |
2942 | 506 | * | 647 | * Directories that match the nih_file_ignore() function are also ignored. |
2943 | 507 | * Returns: FALSE if @path ends in ".conf", or is the original source, | 648 | * |
2944 | 508 | * TRUE otherwise. | 649 | * Returns: FALSE if @path ends in ".conf" or ".override", |
2945 | 650 | * or is the original source, TRUE otherwise. | ||
2946 | 509 | **/ | 651 | **/ |
2947 | 510 | static int | 652 | static int |
2948 | 511 | conf_dir_filter (ConfSource *source, | 653 | conf_dir_filter (ConfSource *source, |
2949 | 512 | const char *path, | 654 | const char *path, |
2950 | 513 | int is_dir) | 655 | int is_dir) |
2951 | 514 | { | 656 | { |
2952 | 515 | char *ptr; | ||
2953 | 516 | |||
2954 | 517 | nih_assert (source != NULL); | 657 | nih_assert (source != NULL); |
2955 | 518 | nih_assert (path != NULL); | 658 | nih_assert (path != NULL); |
2956 | 519 | 659 | ||
2957 | @@ -523,8 +663,7 @@ | |||
2958 | 523 | if (is_dir) | 663 | if (is_dir) |
2959 | 524 | return nih_file_ignore (NULL, path); | 664 | return nih_file_ignore (NULL, path); |
2960 | 525 | 665 | ||
2963 | 526 | ptr = strrchr (path, '.'); | 666 | if (is_conf_file (path)) |
2962 | 527 | if (ptr && (ptr > path) && (ptr[-1] != '/') && (! strcmp (ptr, ".conf"))) | ||
2964 | 528 | return FALSE; | 667 | return FALSE; |
2965 | 529 | 668 | ||
2966 | 530 | return TRUE; | 669 | return TRUE; |
2967 | @@ -546,29 +685,92 @@ | |||
2968 | 546 | * After checking that it was a regular file that was changed, we reload it; | 685 | * After checking that it was a regular file that was changed, we reload it; |
2969 | 547 | * we expect this to fail sometimes since the file may be only partially | 686 | * we expect this to fail sometimes since the file may be only partially |
2970 | 548 | * written. | 687 | * written. |
2972 | 549 | **/ | 688 | **/ |
2973 | 550 | static void | 689 | static void |
2974 | 551 | conf_create_modify_handler (ConfSource *source, | 690 | conf_create_modify_handler (ConfSource *source, |
2975 | 552 | NihWatch *watch, | 691 | NihWatch *watch, |
2976 | 553 | const char *path, | 692 | const char *path, |
2977 | 554 | struct stat *statbuf) | 693 | struct stat *statbuf) |
2978 | 555 | { | 694 | { |
2979 | 695 | ConfFile *file = NULL; | ||
2980 | 696 | const char *error_path = path; | ||
2981 | 697 | nih_local char *new_path = NULL; | ||
2982 | 698 | int ret; | ||
2983 | 699 | |||
2984 | 556 | nih_assert (source != NULL); | 700 | nih_assert (source != NULL); |
2985 | 557 | nih_assert (watch != NULL); | 701 | nih_assert (watch != NULL); |
2986 | 558 | nih_assert (path != NULL); | 702 | nih_assert (path != NULL); |
2987 | 559 | nih_assert (statbuf != NULL); | 703 | nih_assert (statbuf != NULL); |
2988 | 560 | 704 | ||
2989 | 705 | /* note that symbolic links are ignored */ | ||
2990 | 561 | if (! S_ISREG (statbuf->st_mode)) | 706 | if (! S_ISREG (statbuf->st_mode)) |
2991 | 562 | return; | 707 | return; |
2992 | 563 | 708 | ||
2994 | 564 | if (conf_reload_path (source, path) < 0) { | 709 | new_path = toggle_conf_name (NULL, path); |
2995 | 710 | file = (ConfFile *)nih_hash_lookup (source->files, new_path); | ||
2996 | 711 | |||
2997 | 712 | if (is_conf_file_override (path)) { | ||
2998 | 713 | if (! file) { | ||
2999 | 714 | /* override file has no corresponding conf file */ | ||
3000 | 715 | nih_debug ("Ignoring orphan override file %s", path); | ||
3001 | 716 | return; | ||
3002 | 717 | } | ||
3003 | 718 | |||
3004 | 719 | /* reload conf file */ | ||
3005 | 720 | nih_debug ("Loading configuration file %s", new_path); | ||
3006 | 721 | ret = conf_reload_path (source, new_path, NULL); | ||
3007 | 722 | if (ret < 0) { | ||
3008 | 723 | error_path = new_path; | ||
3009 | 724 | goto error; | ||
3010 | 725 | } | ||
3011 | 726 | |||
3012 | 727 | /* overlay override settings */ | ||
3013 | 728 | nih_debug ("Loading override file %s for %s", path, new_path); | ||
3014 | 729 | ret = conf_reload_path (source, new_path, path); | ||
3015 | 730 | if (ret < 0) { | ||
3016 | 731 | error_path = path; | ||
3017 | 732 | goto error; | ||
3018 | 733 | } | ||
3019 | 734 | } else { | ||
3020 | 735 | nih_debug ("Loading configuration and override files for %s", path); | ||
3021 | 736 | |||
3022 | 737 | /* load conf file */ | ||
3023 | 738 | nih_debug ("Loading configuration file %s", path); | ||
3024 | 739 | ret = conf_reload_path (source, path, NULL); | ||
3025 | 740 | if (ret < 0) { | ||
3026 | 741 | error_path = path; | ||
3027 | 742 | goto error; | ||
3028 | 743 | } | ||
3029 | 744 | |||
3030 | 745 | /* ensure we ignore directory changes (which won't have overrides. */ | ||
3031 | 746 | if (is_conf_file_std (path)) { | ||
3032 | 747 | struct stat st; | ||
3033 | 748 | if (stat (new_path, &st) == 0) { | ||
3034 | 749 | /* overlay override settings */ | ||
3035 | 750 | nih_debug ("Loading override file %s for %s", new_path, path); | ||
3036 | 751 | ret = conf_reload_path (source, path, new_path); | ||
3037 | 752 | if (ret < 0) { | ||
3038 | 753 | error_path = new_path; | ||
3039 | 754 | goto error; | ||
3040 | 755 | } | ||
3041 | 756 | } | ||
3042 | 757 | |||
3043 | 758 | } | ||
3044 | 759 | } | ||
3045 | 760 | |||
3046 | 761 | return; | ||
3047 | 762 | |||
3048 | 763 | error: | ||
3049 | 764 | { | ||
3050 | 565 | NihError *err; | 765 | NihError *err; |
3051 | 566 | 766 | ||
3052 | 567 | err = nih_error_get (); | 767 | err = nih_error_get (); |
3056 | 568 | nih_error ("%s: %s: %s", path, | 768 | nih_error ("%s: %s: %s", error_path, |
3057 | 569 | _("Error while loading configuration file"), | 769 | _("Error while loading configuration file"), |
3058 | 570 | err->message); | 770 | err->message); |
3059 | 571 | nih_free (err); | 771 | nih_free (err); |
3060 | 772 | if (file) | ||
3061 | 773 | nih_unref (file, source); | ||
3062 | 572 | } | 774 | } |
3063 | 573 | } | 775 | } |
3064 | 574 | 776 | ||
3065 | @@ -585,13 +787,14 @@ | |||
3066 | 585 | * | 787 | * |
3067 | 586 | * We lookup the file in our hash table, and if we can find it, perform | 788 | * We lookup the file in our hash table, and if we can find it, perform |
3068 | 587 | * the usual deletion of it. | 789 | * the usual deletion of it. |
3070 | 588 | **/ | 790 | **/ |
3071 | 589 | static void | 791 | static void |
3072 | 590 | conf_delete_handler (ConfSource *source, | 792 | conf_delete_handler (ConfSource *source, |
3073 | 591 | NihWatch *watch, | 793 | NihWatch *watch, |
3074 | 592 | const char *path) | 794 | const char *path) |
3075 | 593 | { | 795 | { |
3076 | 594 | ConfFile *file; | 796 | ConfFile *file; |
3077 | 797 | nih_local char *new_path = NULL; | ||
3078 | 595 | 798 | ||
3079 | 596 | nih_assert (source != NULL); | 799 | nih_assert (source != NULL); |
3080 | 597 | nih_assert (watch != NULL); | 800 | nih_assert (watch != NULL); |
3081 | @@ -603,7 +806,11 @@ | |||
3082 | 603 | * it's probably a directory or something, so just ignore it. | 806 | * it's probably a directory or something, so just ignore it. |
3083 | 604 | */ | 807 | */ |
3084 | 605 | file = (ConfFile *)nih_hash_lookup (source->files, path); | 808 | file = (ConfFile *)nih_hash_lookup (source->files, path); |
3086 | 606 | if (! file) { | 809 | /* Note we have to be careful to consider deletion of directories too. |
3087 | 810 | * This is handled implicitly by the override check which will return | ||
3088 | 811 | * false if passed a directory in this case. | ||
3089 | 812 | */ | ||
3090 | 813 | if (! file && ! is_conf_file_override (path)) { | ||
3091 | 607 | if (! strcmp (watch->path, path)) { | 814 | if (! strcmp (watch->path, path)) { |
3092 | 608 | nih_warn ("%s: %s", source->path, | 815 | nih_warn ("%s: %s", source->path, |
3093 | 609 | _("Configuration directory deleted")); | 816 | _("Configuration directory deleted")); |
3094 | @@ -614,7 +821,30 @@ | |||
3095 | 614 | return; | 821 | return; |
3096 | 615 | } | 822 | } |
3097 | 616 | 823 | ||
3099 | 617 | nih_unref (file, source); | 824 | /* non-override files (and directories) are the simple case, so handle |
3100 | 825 | * them and leave. | ||
3101 | 826 | */ | ||
3102 | 827 | if (! is_conf_file_override (path)) { | ||
3103 | 828 | nih_unref (file, source); | ||
3104 | 829 | return; | ||
3105 | 830 | } | ||
3106 | 831 | |||
3107 | 832 | /* if an override file is deleted for which there is a corresponding | ||
3108 | 833 | * conf file, reload the conf file to remove any modifications | ||
3109 | 834 | * introduced by the override file. | ||
3110 | 835 | */ | ||
3111 | 836 | new_path = toggle_conf_name (NULL, path); | ||
3112 | 837 | file = (ConfFile *)nih_hash_lookup (source->files, new_path); | ||
3113 | 838 | |||
3114 | 839 | if (file) { | ||
3115 | 840 | nih_debug ("Reloading configuration for %s on deletion of overide (%s)", | ||
3116 | 841 | new_path, path); | ||
3117 | 842 | |||
3118 | 843 | if ( conf_reload_path (source, new_path, NULL) < 0 ) { | ||
3119 | 844 | nih_warn ("%s: %s", new_path, | ||
3120 | 845 | _("Unable to reload configuration after override deletion")); | ||
3121 | 846 | } | ||
3122 | 847 | } | ||
3123 | 618 | } | 848 | } |
3124 | 619 | 849 | ||
3125 | 620 | /** | 850 | /** |
3126 | @@ -637,22 +867,61 @@ | |||
3127 | 637 | const char *path, | 867 | const char *path, |
3128 | 638 | struct stat *statbuf) | 868 | struct stat *statbuf) |
3129 | 639 | { | 869 | { |
3130 | 870 | ConfFile *file = NULL; | ||
3131 | 871 | nih_local char *new_path = NULL; | ||
3132 | 872 | |||
3133 | 640 | nih_assert (source != NULL); | 873 | nih_assert (source != NULL); |
3134 | 641 | nih_assert (dirname != NULL); | 874 | nih_assert (dirname != NULL); |
3135 | 642 | nih_assert (path != NULL); | 875 | nih_assert (path != NULL); |
3136 | 643 | nih_assert (statbuf != NULL); | 876 | nih_assert (statbuf != NULL); |
3137 | 644 | 877 | ||
3138 | 878 | /* We assume that CONF_EXT_STD files are visited before | ||
3139 | 879 | * CONF_EXT_OVERRIDE files. Happily, this assumption is currently | ||
3140 | 880 | * valid since CONF_EXT_STD comes before CONF_EXT_OVERRIDE if ordered | ||
3141 | 881 | * alphabetically. | ||
3142 | 882 | * | ||
3143 | 883 | * If this were ever to change (for example if we decided to | ||
3144 | 884 | * rename the CONF_EXT_OVERRIDE files to end in ".abc", say), the logic | ||
3145 | 885 | * in this function would be erroneous since it would never be possible when | ||
3146 | 886 | * visiting an override file (before a conf file) to lookup a conf file | ||
3147 | 887 | * in the hash, since the conf file would not yet have been seen and thus would | ||
3148 | 888 | * not exist in the hash (yet). | ||
3149 | 889 | */ | ||
3150 | 890 | nih_assert (CONF_EXT_STD[1] < CONF_EXT_OVERRIDE[1]); | ||
3151 | 891 | |||
3152 | 645 | if (! S_ISREG (statbuf->st_mode)) | 892 | if (! S_ISREG (statbuf->st_mode)) |
3153 | 646 | return 0; | 893 | return 0; |
3154 | 647 | 894 | ||
3163 | 648 | if (conf_reload_path (source, path) < 0) { | 895 | if (is_conf_file_std (path)) { |
3164 | 649 | NihError *err; | 896 | if (conf_reload_path (source, path, NULL) < 0) { |
3165 | 650 | 897 | NihError *err; | |
3166 | 651 | err = nih_error_get (); | 898 | |
3167 | 652 | nih_error ("%s: %s: %s", path, | 899 | err = nih_error_get (); |
3168 | 653 | _("Error while loading configuration file"), | 900 | nih_error ("%s: %s: %s", path, |
3169 | 654 | err->message); | 901 | _("Error while loading configuration file"), |
3170 | 655 | nih_free (err); | 902 | err->message); |
3171 | 903 | nih_free (err); | ||
3172 | 904 | } | ||
3173 | 905 | return 0; | ||
3174 | 906 | } | ||
3175 | 907 | |||
3176 | 908 | new_path = toggle_conf_name (NULL, path); | ||
3177 | 909 | file = (ConfFile *)nih_hash_lookup (source->files, new_path); | ||
3178 | 910 | |||
3179 | 911 | if (file) { | ||
3180 | 912 | /* we're visiting an override file with an associated conf file that | ||
3181 | 913 | * has already been loaded, so just overlay the override file. If | ||
3182 | 914 | * there is no corresponding conf file, we ignore the override file. | ||
3183 | 915 | */ | ||
3184 | 916 | if (conf_reload_path (source, new_path, path) < 0) { | ||
3185 | 917 | NihError *err; | ||
3186 | 918 | |||
3187 | 919 | err = nih_error_get (); | ||
3188 | 920 | nih_error ("%s: %s: %s", new_path, | ||
3189 | 921 | _("Error while reloading configuration file"), | ||
3190 | 922 | err->message); | ||
3191 | 923 | nih_free (err); | ||
3192 | 924 | } | ||
3193 | 656 | } | 925 | } |
3194 | 657 | 926 | ||
3195 | 658 | return 0; | 927 | return 0; |
3196 | @@ -662,16 +931,20 @@ | |||
3197 | 662 | /** | 931 | /** |
3198 | 663 | * conf_reload_path: | 932 | * conf_reload_path: |
3199 | 664 | * @source: configuration source, | 933 | * @source: configuration source, |
3201 | 665 | * @path: path of file to be reloaded. | 934 | * @path: path of conf file to be reloaded. |
3202 | 935 | * @override_path: if not NULL and @path refers to a path associated with @source, | ||
3203 | 936 | * overlay the contents of @path into the existing @source entry for | ||
3204 | 937 | * @path. If FALSE, discard any existing knowledge of @path. | ||
3205 | 666 | * | 938 | * |
3210 | 667 | * This function is used to parse the file at @path in the context of the | 939 | * This function is used to parse the file at @path (or @override_path) in the |
3211 | 668 | * given configuration @source. Necessary ConfFile structures are allocated | 940 | * context of the given configuration @source. Necessary ConfFile structures |
3212 | 669 | * and attached to @source as appropriate. CONF_FILE sources always have | 941 | * are allocated and attached to @source as appropriate. CONF_FILE sources |
3213 | 670 | * a single ConfFile when the file exists. | 942 | * always have a single ConfFile when the file exists. |
3214 | 671 | * | 943 | * |
3215 | 672 | * If the file has been parsed before, then the existing item is deleted and | 944 | * If the file has been parsed before, then the existing item is deleted and |
3216 | 673 | * freed if the file fails to load, or after the new item has been parsed. | 945 | * freed if the file fails to load, or after the new item has been parsed. |
3218 | 674 | * Items are not reused between reloads. | 946 | * Items are only reused between reloads if @override_path is |
3219 | 947 | * non-NULL. | ||
3220 | 675 | * | 948 | * |
3221 | 676 | * Physical errors are returned, parse errors are not. | 949 | * Physical errors are returned, parse errors are not. |
3222 | 677 | * | 950 | * |
3223 | @@ -679,36 +952,47 @@ | |||
3224 | 679 | **/ | 952 | **/ |
3225 | 680 | static int | 953 | static int |
3226 | 681 | conf_reload_path (ConfSource *source, | 954 | conf_reload_path (ConfSource *source, |
3228 | 682 | const char *path) | 955 | const char *path, |
3229 | 956 | const char *override_path) | ||
3230 | 683 | { | 957 | { |
3232 | 684 | ConfFile *file; | 958 | ConfFile *file = NULL; |
3233 | 685 | nih_local char *buf = NULL; | 959 | nih_local char *buf = NULL; |
3234 | 686 | const char *start, *end; | 960 | const char *start, *end; |
3235 | 687 | nih_local char *name = NULL; | 961 | nih_local char *name = NULL; |
3236 | 688 | size_t len, pos, lineno; | 962 | size_t len, pos, lineno; |
3237 | 689 | NihError *err = NULL; | 963 | NihError *err = NULL; |
3238 | 964 | const char *path_to_load; | ||
3239 | 690 | 965 | ||
3240 | 691 | nih_assert (source != NULL); | 966 | nih_assert (source != NULL); |
3241 | 692 | nih_assert (path != NULL); | 967 | nih_assert (path != NULL); |
3242 | 693 | 968 | ||
3245 | 694 | /* Look up the old file in memory, and then free it. In cases | 969 | path_to_load = (override_path ? override_path : path); |
3246 | 695 | * of failure, we discard it anyway, so there's no particular reason | 970 | |
3247 | 971 | /* If there is no corresponding override file, look up the old | ||
3248 | 972 | * conf file in memory, and then free it. In cases of failure, | ||
3249 | 973 | * we discard it anyway, so there's no particular reason | ||
3250 | 696 | * to keep it around anymore. | 974 | * to keep it around anymore. |
3251 | 975 | * | ||
3252 | 976 | * Note: if @override_path has been specified, do not | ||
3253 | 977 | * free the file if found, since we want to _update_ the | ||
3254 | 978 | * existing entry. | ||
3255 | 697 | */ | 979 | */ |
3256 | 698 | file = (ConfFile *)nih_hash_lookup (source->files, path); | 980 | file = (ConfFile *)nih_hash_lookup (source->files, path); |
3258 | 699 | if (file) | 981 | if (! override_path && file) |
3259 | 700 | nih_unref (file, source); | 982 | nih_unref (file, source); |
3260 | 701 | 983 | ||
3261 | 702 | /* Read the file into memory for parsing, if this fails we don't | 984 | /* Read the file into memory for parsing, if this fails we don't |
3262 | 703 | * bother creating a new ConfFile structure for it and bail out | 985 | * bother creating a new ConfFile structure for it and bail out |
3263 | 704 | * now. | 986 | * now. |
3264 | 705 | */ | 987 | */ |
3266 | 706 | buf = nih_file_read (NULL, path, &len); | 988 | buf = nih_file_read (NULL, path_to_load, &len); |
3267 | 707 | if (! buf) | 989 | if (! buf) |
3268 | 708 | return -1; | 990 | return -1; |
3269 | 709 | 991 | ||
3272 | 710 | /* Parse the file, storing the item in a new ConfFile structure. */ | 992 | /* Create a new ConfFile structure (if no @override_path specified) */ |
3273 | 711 | file = NIH_MUST (conf_file_new (source, path)); | 993 | file = (ConfFile *)nih_hash_lookup (source->files, path); |
3274 | 994 | if (! file) | ||
3275 | 995 | file = NIH_MUST (conf_file_new (source, path)); | ||
3276 | 712 | 996 | ||
3277 | 713 | pos = 0; | 997 | pos = 0; |
3278 | 714 | lineno = 1; | 998 | lineno = 1; |
3279 | @@ -717,7 +1001,14 @@ | |||
3280 | 717 | case CONF_FILE: | 1001 | case CONF_FILE: |
3281 | 718 | case CONF_DIR: | 1002 | case CONF_DIR: |
3282 | 719 | /* Simple file of options; usually no item attached to it. */ | 1003 | /* Simple file of options; usually no item attached to it. */ |
3284 | 720 | nih_debug ("Loading configuration from %s", path); | 1004 | if (override_path) { |
3285 | 1005 | nih_debug ("Updating configuration for %s from %s", | ||
3286 | 1006 | path, override_path); | ||
3287 | 1007 | } else { | ||
3288 | 1008 | nih_debug ("Loading configuration from %s %s", | ||
3289 | 1009 | (source->type == CONF_DIR ? "directory" : "file"), path); | ||
3290 | 1010 | } | ||
3291 | 1011 | |||
3292 | 721 | if (parse_conf (file, buf, len, &pos, &lineno) < 0) | 1012 | if (parse_conf (file, buf, len, &pos, &lineno) < 0) |
3293 | 722 | err = nih_error_get (); | 1013 | err = nih_error_get (); |
3294 | 723 | 1014 | ||
3295 | @@ -735,7 +1026,7 @@ | |||
3296 | 735 | start++; | 1026 | start++; |
3297 | 736 | 1027 | ||
3298 | 737 | end = strrchr (start, '.'); | 1028 | end = strrchr (start, '.'); |
3300 | 738 | if (end && (! strcmp (end, ".conf"))) { | 1029 | if (end && IS_CONF_EXT (end)) { |
3301 | 739 | name = NIH_MUST (nih_strndup (NULL, start, end - start)); | 1030 | name = NIH_MUST (nih_strndup (NULL, start, end - start)); |
3302 | 740 | } else { | 1031 | } else { |
3303 | 741 | name = NIH_MUST (nih_strdup (NULL, start)); | 1032 | name = NIH_MUST (nih_strdup (NULL, start)); |
3304 | @@ -744,8 +1035,16 @@ | |||
3305 | 744 | /* Create a new job item and parse the buffer to produce | 1035 | /* Create a new job item and parse the buffer to produce |
3306 | 745 | * the job definition. | 1036 | * the job definition. |
3307 | 746 | */ | 1037 | */ |
3310 | 747 | nih_debug ("Loading %s from %s", name, path); | 1038 | if (override_path) { |
3311 | 748 | file->job = parse_job (NULL, name, buf, len, &pos, &lineno); | 1039 | nih_debug ("Updating %s (%s) with %s", |
3312 | 1040 | name, path, override_path); | ||
3313 | 1041 | } else { | ||
3314 | 1042 | nih_debug ("Loading %s from %s", name, path); | ||
3315 | 1043 | } | ||
3316 | 1044 | |||
3317 | 1045 | file->job = parse_job (NULL, source->session, file->job, | ||
3318 | 1046 | name, buf, len, &pos, &lineno); | ||
3319 | 1047 | |||
3320 | 749 | if (file->job) { | 1048 | if (file->job) { |
3321 | 750 | job_class_consider (file->job); | 1049 | job_class_consider (file->job); |
3322 | 751 | } else { | 1050 | } else { |
3323 | @@ -779,7 +1078,7 @@ | |||
3324 | 779 | case PARSE_EXPECTED_OPERATOR: | 1078 | case PARSE_EXPECTED_OPERATOR: |
3325 | 780 | case PARSE_EXPECTED_VARIABLE: | 1079 | case PARSE_EXPECTED_VARIABLE: |
3326 | 781 | case PARSE_MISMATCHED_PARENS: | 1080 | case PARSE_MISMATCHED_PARENS: |
3328 | 782 | nih_error ("%s:%zi: %s", path, lineno, err->message); | 1081 | nih_error ("%s:%zi: %s", path_to_load, lineno, err->message); |
3329 | 783 | nih_free (err); | 1082 | nih_free (err); |
3330 | 784 | err = NULL; | 1083 | err = NULL; |
3331 | 785 | break; | 1084 | break; |
3332 | @@ -849,7 +1148,8 @@ | |||
3333 | 849 | 1148 | ||
3334 | 850 | /** | 1149 | /** |
3335 | 851 | * conf_select_job: | 1150 | * conf_select_job: |
3337 | 852 | * @name: name of job class to locate. | 1151 | * @name: name of job class to locate, |
3338 | 1152 | * @session: session class name belongs to. | ||
3339 | 853 | * | 1153 | * |
3340 | 854 | * Select the best available class of a job named @name from the registered | 1154 | * Select the best available class of a job named @name from the registered |
3341 | 855 | * configuration sources. | 1155 | * configuration sources. |
3342 | @@ -857,7 +1157,7 @@ | |||
3343 | 857 | * Returns: Best available job class or NULL if none available. | 1157 | * Returns: Best available job class or NULL if none available. |
3344 | 858 | **/ | 1158 | **/ |
3345 | 859 | JobClass * | 1159 | JobClass * |
3347 | 860 | conf_select_job (const char *name) | 1160 | conf_select_job (const char *name, const Session *session) |
3348 | 861 | { | 1161 | { |
3349 | 862 | nih_assert (name != NULL); | 1162 | nih_assert (name != NULL); |
3350 | 863 | 1163 | ||
3351 | @@ -869,6 +1169,9 @@ | |||
3352 | 869 | if (source->type != CONF_JOB_DIR) | 1169 | if (source->type != CONF_JOB_DIR) |
3353 | 870 | continue; | 1170 | continue; |
3354 | 871 | 1171 | ||
3355 | 1172 | if (source->session != session) | ||
3356 | 1173 | continue; | ||
3357 | 1174 | |||
3358 | 872 | NIH_HASH_FOREACH (source->files, file_iter) { | 1175 | NIH_HASH_FOREACH (source->files, file_iter) { |
3359 | 873 | ConfFile *file = (ConfFile *)file_iter; | 1176 | ConfFile *file = (ConfFile *)file_iter; |
3360 | 874 | 1177 | ||
3361 | @@ -882,3 +1185,149 @@ | |||
3362 | 882 | 1185 | ||
3363 | 883 | return NULL; | 1186 | return NULL; |
3364 | 884 | } | 1187 | } |
3365 | 1188 | |||
3366 | 1189 | #ifdef DEBUG | ||
3367 | 1190 | |||
3368 | 1191 | size_t | ||
3369 | 1192 | debug_count_list_entries (const NihList *list) | ||
3370 | 1193 | { | ||
3371 | 1194 | size_t i = 0; | ||
3372 | 1195 | NIH_LIST_FOREACH (list, iter) { | ||
3373 | 1196 | i++; | ||
3374 | 1197 | } | ||
3375 | 1198 | return i; | ||
3376 | 1199 | } | ||
3377 | 1200 | |||
3378 | 1201 | size_t | ||
3379 | 1202 | debug_count_hash_entries (const NihHash *hash) | ||
3380 | 1203 | { | ||
3381 | 1204 | size_t i = 0; | ||
3382 | 1205 | NIH_HASH_FOREACH_SAFE (hash, iter) { | ||
3383 | 1206 | i++; | ||
3384 | 1207 | } | ||
3385 | 1208 | return i; | ||
3386 | 1209 | } | ||
3387 | 1210 | |||
3388 | 1211 | void | ||
3389 | 1212 | debug_show_job_class (const JobClass *job) | ||
3390 | 1213 | { | ||
3391 | 1214 | int i; | ||
3392 | 1215 | char **env = (char **)job->env; | ||
3393 | 1216 | char **export = (char **)job->export; | ||
3394 | 1217 | |||
3395 | 1218 | nih_assert (job); | ||
3396 | 1219 | |||
3397 | 1220 | nih_debug ("JobClass %p: name='%s', path='%s', task=%d, " | ||
3398 | 1221 | "respawn=%d, console=%x, deleted=%d, debug=%d", | ||
3399 | 1222 | job, job->name, job->path, job->task, | ||
3400 | 1223 | job->respawn, job->console, job->deleted, job->debug); | ||
3401 | 1224 | |||
3402 | 1225 | nih_debug ("\tstart_on=%p, stop_on=%p, emits=%p, process=%p", | ||
3403 | 1226 | job->start_on, job->stop_on, job->emits, job->process); | ||
3404 | 1227 | |||
3405 | 1228 | nih_debug ("\tauthor='%s', description='%s'", | ||
3406 | 1229 | job->author, job->description); | ||
3407 | 1230 | |||
3408 | 1231 | if (env && *env) { | ||
3409 | 1232 | nih_debug ("\tenv:"); | ||
3410 | 1233 | i = 0; | ||
3411 | 1234 | while ( *env ) { | ||
3412 | 1235 | nih_debug ("\t\tenv[%d]='%s' (len=%u+1)", | ||
3413 | 1236 | i, *env, strlen (*env)); | ||
3414 | 1237 | env++; | ||
3415 | 1238 | ++i; | ||
3416 | 1239 | } | ||
3417 | 1240 | } else { | ||
3418 | 1241 | nih_debug ("\tenv: none."); | ||
3419 | 1242 | } | ||
3420 | 1243 | |||
3421 | 1244 | |||
3422 | 1245 | if (export && *export) { | ||
3423 | 1246 | nih_debug ("\texport:"); | ||
3424 | 1247 | i = 0; | ||
3425 | 1248 | while ( *export ) { | ||
3426 | 1249 | nih_debug ("\t\tenv[%d]='%s' (len=%u+1)", | ||
3427 | 1250 | i, *export, strlen (*export)); | ||
3428 | 1251 | export++; | ||
3429 | 1252 | ++i; | ||
3430 | 1253 | } | ||
3431 | 1254 | } | ||
3432 | 1255 | else { | ||
3433 | 1256 | nih_debug ("\texport: none"); | ||
3434 | 1257 | } | ||
3435 | 1258 | } | ||
3436 | 1259 | |||
3437 | 1260 | void | ||
3438 | 1261 | debug_show_job_classes (void) | ||
3439 | 1262 | { | ||
3440 | 1263 | nih_debug ("job_classes:"); | ||
3441 | 1264 | |||
3442 | 1265 | NIH_HASH_FOREACH_SAFE (job_classes, iter) { | ||
3443 | 1266 | JobClass *job = (JobClass *)iter; | ||
3444 | 1267 | debug_show_job_class (job); | ||
3445 | 1268 | } | ||
3446 | 1269 | } | ||
3447 | 1270 | |||
3448 | 1271 | void | ||
3449 | 1272 | debug_show_event (const Event *event) | ||
3450 | 1273 | { | ||
3451 | 1274 | nih_assert (event); | ||
3452 | 1275 | |||
3453 | 1276 | nih_debug ("Event %p: name='%s', progress=%x, failed=%d, " | ||
3454 | 1277 | "blockers=%d, blocking=%p", | ||
3455 | 1278 | event, event->name, event->progress, event->failed, | ||
3456 | 1279 | event->blockers, (void *)&event->blocking); | ||
3457 | 1280 | } | ||
3458 | 1281 | |||
3459 | 1282 | void | ||
3460 | 1283 | debug_show_conf_file (const ConfFile *file) | ||
3461 | 1284 | { | ||
3462 | 1285 | nih_assert (file); | ||
3463 | 1286 | |||
3464 | 1287 | nih_debug ("ConfFile %p: path='%s', source=%p, flag=%x, job=%p", | ||
3465 | 1288 | file, file->path, file->source, file->flag, file->job); | ||
3466 | 1289 | |||
3467 | 1290 | /* Some ConfFile objects won't have any JobClass details, for example, | ||
3468 | 1291 | * the ConfFile object associated with "/etc/init.conf". | ||
3469 | 1292 | */ | ||
3470 | 1293 | if (! file->job) { | ||
3471 | 1294 | nih_debug ("ConfFile %p: job: no JobClass object.", file); | ||
3472 | 1295 | return; | ||
3473 | 1296 | } | ||
3474 | 1297 | |||
3475 | 1298 | nih_debug ("ConfFile %p: job:", file); | ||
3476 | 1299 | debug_show_job_class (file->job); | ||
3477 | 1300 | } | ||
3478 | 1301 | |||
3479 | 1302 | void | ||
3480 | 1303 | debug_show_conf_source (const ConfSource *source) | ||
3481 | 1304 | { | ||
3482 | 1305 | nih_assert (source); | ||
3483 | 1306 | |||
3484 | 1307 | nih_debug ("ConfSource %p: path='%s', type=%x, flag=%x", | ||
3485 | 1308 | source, source->path, source->type, source->flag); | ||
3486 | 1309 | |||
3487 | 1310 | nih_debug ("ConfSource %p files (%d):", source, | ||
3488 | 1311 | debug_count_hash_entries (source->files)); | ||
3489 | 1312 | |||
3490 | 1313 | NIH_HASH_FOREACH (source->files, file_iter) { | ||
3491 | 1314 | ConfFile *file = (ConfFile *)file_iter; | ||
3492 | 1315 | debug_show_conf_file (file); | ||
3493 | 1316 | } | ||
3494 | 1317 | } | ||
3495 | 1318 | |||
3496 | 1319 | void | ||
3497 | 1320 | debug_show_conf_sources (void) | ||
3498 | 1321 | { | ||
3499 | 1322 | nih_assert (conf_sources); | ||
3500 | 1323 | |||
3501 | 1324 | nih_debug ("conf_sources:"); | ||
3502 | 1325 | |||
3503 | 1326 | NIH_LIST_FOREACH (conf_sources, iter) { | ||
3504 | 1327 | ConfSource *source = (ConfSource *)iter; | ||
3505 | 1328 | debug_show_conf_source (source); | ||
3506 | 1329 | } | ||
3507 | 1330 | } | ||
3508 | 1331 | |||
3509 | 1332 | #endif /* DEBUG */ | ||
3510 | 1333 | |||
3511 | 885 | 1334 | ||
3512 | === modified file 'init/conf.h' | |||
3513 | --- init/conf.h 2009-07-09 08:36:52 +0000 | |||
3514 | +++ init/conf.h 2011-10-14 11:09:18 +0000 | |||
3515 | @@ -1,6 +1,6 @@ | |||
3516 | 1 | /* upstart | 1 | /* upstart |
3517 | 2 | * | 2 | * |
3519 | 3 | * Copyright © 2009 Canonical Ltd. | 3 | * Copyright © 2010,2011 Canonical Ltd. |
3520 | 4 | * Author: Scott James Remnant <scott@netsplit.com>. | 4 | * Author: Scott James Remnant <scott@netsplit.com>. |
3521 | 5 | * | 5 | * |
3522 | 6 | * This program is free software; you can redistribute it and/or modify | 6 | * This program is free software; you can redistribute it and/or modify |
3523 | @@ -26,6 +26,7 @@ | |||
3524 | 26 | #include <nih/list.h> | 26 | #include <nih/list.h> |
3525 | 27 | #include <nih/watch.h> | 27 | #include <nih/watch.h> |
3526 | 28 | 28 | ||
3527 | 29 | #include "session.h" | ||
3528 | 29 | #include "job_class.h" | 30 | #include "job_class.h" |
3529 | 30 | 31 | ||
3530 | 31 | 32 | ||
3531 | @@ -47,6 +48,7 @@ | |||
3532 | 47 | /** | 48 | /** |
3533 | 48 | * ConfSource: | 49 | * ConfSource: |
3534 | 49 | * @entry: list header, | 50 | * @entry: list header, |
3535 | 51 | * @session: attached session, | ||
3536 | 50 | * @path: path to source, | 52 | * @path: path to source, |
3537 | 51 | * @type: type of source, | 53 | * @type: type of source, |
3538 | 52 | * @watch: NihWatch structure for automatic change notification, | 54 | * @watch: NihWatch structure for automatic change notification, |
3539 | @@ -64,6 +66,7 @@ | |||
3540 | 64 | **/ | 66 | **/ |
3541 | 65 | typedef struct conf_source { | 67 | typedef struct conf_source { |
3542 | 66 | NihList entry; | 68 | NihList entry; |
3543 | 69 | Session * session; | ||
3544 | 67 | char *path; | 70 | char *path; |
3545 | 68 | ConfSourceType type; | 71 | ConfSourceType type; |
3546 | 69 | 72 | ||
3547 | @@ -122,7 +125,47 @@ | |||
3548 | 122 | 125 | ||
3549 | 123 | int conf_file_destroy (ConfFile *file); | 126 | int conf_file_destroy (ConfFile *file); |
3550 | 124 | 127 | ||
3552 | 125 | JobClass * conf_select_job (const char *name); | 128 | JobClass * conf_select_job (const char *name, const Session *session); |
3553 | 129 | |||
3554 | 130 | char *toggle_conf_name (const void *parent, const char *path) | ||
3555 | 131 | __attribute__ ((warn_unused_result, malloc)); | ||
3556 | 132 | |||
3557 | 133 | #ifdef DEBUG | ||
3558 | 134 | |||
3559 | 135 | /* used for debugging only */ | ||
3560 | 136 | |||
3561 | 137 | size_t | ||
3562 | 138 | debug_count_hash_entries (const NihHash *hash); | ||
3563 | 139 | |||
3564 | 140 | size_t | ||
3565 | 141 | debug_count_list_entries (const NihList *list) | ||
3566 | 142 | __attribute__ ((unused)); | ||
3567 | 143 | |||
3568 | 144 | void | ||
3569 | 145 | debug_show_job_class (const JobClass *job) | ||
3570 | 146 | __attribute__ ((unused)); | ||
3571 | 147 | |||
3572 | 148 | void | ||
3573 | 149 | debug_show_job_classes (void) | ||
3574 | 150 | __attribute__ ((unused)); | ||
3575 | 151 | |||
3576 | 152 | void | ||
3577 | 153 | debug_show_event (const Event *event) | ||
3578 | 154 | __attribute__ ((unused)); | ||
3579 | 155 | |||
3580 | 156 | void | ||
3581 | 157 | debug_show_conf_file(const ConfFile *file) | ||
3582 | 158 | __attribute__ ((unused)); | ||
3583 | 159 | |||
3584 | 160 | void | ||
3585 | 161 | debug_show_conf_source(const ConfSource *source) | ||
3586 | 162 | __attribute__ ((unused)); | ||
3587 | 163 | |||
3588 | 164 | void | ||
3589 | 165 | debug_show_conf_sources(void) | ||
3590 | 166 | __attribute__ ((unused)); | ||
3591 | 167 | |||
3592 | 168 | #endif | ||
3593 | 126 | 169 | ||
3594 | 127 | NIH_END_EXTERN | 170 | NIH_END_EXTERN |
3595 | 128 | 171 | ||
3596 | 129 | 172 | ||
3597 | === modified file 'init/control.c' | |||
3598 | --- init/control.c 2009-07-11 11:47:12 +0000 | |||
3599 | +++ init/control.c 2011-10-14 11:09:18 +0000 | |||
3600 | @@ -2,7 +2,7 @@ | |||
3601 | 2 | * | 2 | * |
3602 | 3 | * control.c - D-Bus connections, objects and methods | 3 | * control.c - D-Bus connections, objects and methods |
3603 | 4 | * | 4 | * |
3605 | 5 | * Copyright © 2009 Canonical Ltd. | 5 | * Copyright © 2009-2011 Canonical Ltd. |
3606 | 6 | * Author: Scott James Remnant <scott@netsplit.com>. | 6 | * Author: Scott James Remnant <scott@netsplit.com>. |
3607 | 7 | * | 7 | * |
3608 | 8 | * This program is free software; you can redistribute it and/or modify | 8 | * This program is free software; you can redistribute it and/or modify |
3609 | @@ -25,8 +25,10 @@ | |||
3610 | 25 | 25 | ||
3611 | 26 | #include <dbus/dbus.h> | 26 | #include <dbus/dbus.h> |
3612 | 27 | 27 | ||
3613 | 28 | #include <fcntl.h> | ||
3614 | 28 | #include <stdio.h> | 29 | #include <stdio.h> |
3615 | 29 | #include <string.h> | 30 | #include <string.h> |
3616 | 31 | #include <unistd.h> | ||
3617 | 30 | 32 | ||
3618 | 31 | #include <nih/macros.h> | 33 | #include <nih/macros.h> |
3619 | 32 | #include <nih/alloc.h> | 34 | #include <nih/alloc.h> |
3620 | @@ -46,6 +48,7 @@ | |||
3621 | 46 | #include "dbus/upstart.h" | 48 | #include "dbus/upstart.h" |
3622 | 47 | 49 | ||
3623 | 48 | #include "environ.h" | 50 | #include "environ.h" |
3624 | 51 | #include "session.h" | ||
3625 | 49 | #include "job_class.h" | 52 | #include "job_class.h" |
3626 | 50 | #include "blocked.h" | 53 | #include "blocked.h" |
3627 | 51 | #include "conf.h" | 54 | #include "conf.h" |
3628 | @@ -54,12 +57,19 @@ | |||
3629 | 54 | 57 | ||
3630 | 55 | #include "com.ubuntu.Upstart.h" | 58 | #include "com.ubuntu.Upstart.h" |
3631 | 56 | 59 | ||
3632 | 57 | |||
3633 | 58 | /* Prototypes for static functions */ | 60 | /* Prototypes for static functions */ |
3634 | 59 | static int control_server_connect (DBusServer *server, DBusConnection *conn); | 61 | static int control_server_connect (DBusServer *server, DBusConnection *conn); |
3635 | 60 | static void control_disconnected (DBusConnection *conn); | 62 | static void control_disconnected (DBusConnection *conn); |
3636 | 61 | static void control_register_all (DBusConnection *conn); | 63 | static void control_register_all (DBusConnection *conn); |
3637 | 62 | 64 | ||
3638 | 65 | /** | ||
3639 | 66 | * use_session_bus: | ||
3640 | 67 | * | ||
3641 | 68 | * If TRUE, connect to the D-Bus session bus rather than the system bus. | ||
3642 | 69 | * | ||
3643 | 70 | * Used for testing. | ||
3644 | 71 | **/ | ||
3645 | 72 | int use_session_bus = FALSE; | ||
3646 | 63 | 73 | ||
3647 | 64 | /** | 74 | /** |
3648 | 65 | * control_server_address: | 75 | * control_server_address: |
3649 | @@ -78,7 +88,7 @@ | |||
3650 | 78 | /** | 88 | /** |
3651 | 79 | * control_bus: | 89 | * control_bus: |
3652 | 80 | * | 90 | * |
3654 | 81 | * Open connection to D-Bus system bus. The connection may be opened with | 91 | * Open connection to a D-Bus bus. The connection may be opened with |
3655 | 82 | * control_bus_open() and if lost will become NULL. | 92 | * control_bus_open() and if lost will become NULL. |
3656 | 83 | **/ | 93 | **/ |
3657 | 84 | DBusConnection *control_bus = NULL; | 94 | DBusConnection *control_bus = NULL; |
3658 | @@ -86,7 +96,7 @@ | |||
3659 | 86 | /** | 96 | /** |
3660 | 87 | * control_conns: | 97 | * control_conns: |
3661 | 88 | * | 98 | * |
3663 | 89 | * Open control connections, including the connection to the D-Bus system | 99 | * Open control connections, including the connection to a D-Bus |
3664 | 90 | * bus and any private client connections. | 100 | * bus and any private client connections. |
3665 | 91 | **/ | 101 | **/ |
3666 | 92 | NihList *control_conns = NULL; | 102 | NihList *control_conns = NULL; |
3667 | @@ -190,8 +200,9 @@ | |||
3668 | 190 | /** | 200 | /** |
3669 | 191 | * control_bus_open: | 201 | * control_bus_open: |
3670 | 192 | * | 202 | * |
3673 | 193 | * Open a connection to the D-Bus system bus and store it in the control_bus | 203 | * Open a connection to the appropriate D-Bus bus and store it in the |
3674 | 194 | * global. The connection is handled automatically in the main loop. | 204 | * control_bus global. The connection is handled automatically |
3675 | 205 | * in the main loop. | ||
3676 | 195 | * | 206 | * |
3677 | 196 | * Returns: zero on success, negative value on raised error. | 207 | * Returns: zero on success, negative value on raised error. |
3678 | 197 | **/ | 208 | **/ |
3679 | @@ -207,10 +218,13 @@ | |||
3680 | 207 | 218 | ||
3681 | 208 | control_init (); | 219 | control_init (); |
3682 | 209 | 220 | ||
3683 | 221 | control_handle_bus_type (); | ||
3684 | 222 | |||
3685 | 210 | /* Connect to the D-Bus System Bus and hook everything up into | 223 | /* Connect to the D-Bus System Bus and hook everything up into |
3686 | 211 | * our own main loop automatically. | 224 | * our own main loop automatically. |
3687 | 212 | */ | 225 | */ |
3689 | 213 | conn = nih_dbus_bus (DBUS_BUS_SYSTEM, control_disconnected); | 226 | conn = nih_dbus_bus (use_session_bus ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM, |
3690 | 227 | control_disconnected); | ||
3691 | 214 | if (! conn) | 228 | if (! conn) |
3692 | 215 | return -1; | 229 | return -1; |
3693 | 216 | 230 | ||
3694 | @@ -382,7 +396,9 @@ | |||
3695 | 382 | const char *name, | 396 | const char *name, |
3696 | 383 | char **job) | 397 | char **job) |
3697 | 384 | { | 398 | { |
3699 | 385 | JobClass *class; | 399 | Session *session; |
3700 | 400 | JobClass *class = NULL; | ||
3701 | 401 | JobClass *global_class = NULL; | ||
3702 | 386 | 402 | ||
3703 | 387 | nih_assert (message != NULL); | 403 | nih_assert (message != NULL); |
3704 | 388 | nih_assert (name != NULL); | 404 | nih_assert (name != NULL); |
3705 | @@ -397,8 +413,30 @@ | |||
3706 | 397 | return -1; | 413 | return -1; |
3707 | 398 | } | 414 | } |
3708 | 399 | 415 | ||
3711 | 400 | /* Lookup the job and copy its path into the reply */ | 416 | /* Get the relevant session */ |
3712 | 401 | class = (JobClass *)nih_hash_lookup (job_classes, name); | 417 | session = session_from_dbus (NULL, message); |
3713 | 418 | |||
3714 | 419 | /* Lookup the job */ | ||
3715 | 420 | class = (JobClass *)nih_hash_search (job_classes, name, NULL); | ||
3716 | 421 | |||
3717 | 422 | while (class && (class->session != session)) { | ||
3718 | 423 | |||
3719 | 424 | /* Found a match in the global session which may be used | ||
3720 | 425 | * later if no matching user session job exists. | ||
3721 | 426 | */ | ||
3722 | 427 | if ((! class->session) && (session && ! session->chroot)) | ||
3723 | 428 | global_class = class; | ||
3724 | 429 | |||
3725 | 430 | class = (JobClass *)nih_hash_search (job_classes, name, | ||
3726 | 431 | &class->entry); | ||
3727 | 432 | } | ||
3728 | 433 | |||
3729 | 434 | /* If no job with the given name exists in the appropriate | ||
3730 | 435 | * session, look in the global namespace (aka the NULL session). | ||
3731 | 436 | */ | ||
3732 | 437 | if (! class) | ||
3733 | 438 | class = global_class; | ||
3734 | 439 | |||
3735 | 402 | if (! class) { | 440 | if (! class) { |
3736 | 403 | nih_dbus_error_raise_printf ( | 441 | nih_dbus_error_raise_printf ( |
3737 | 404 | DBUS_INTERFACE_UPSTART ".Error.UnknownJob", | 442 | DBUS_INTERFACE_UPSTART ".Error.UnknownJob", |
3738 | @@ -406,6 +444,7 @@ | |||
3739 | 406 | return -1; | 444 | return -1; |
3740 | 407 | } | 445 | } |
3741 | 408 | 446 | ||
3742 | 447 | /* Copy the path */ | ||
3743 | 409 | *job = nih_strdup (message, class->path); | 448 | *job = nih_strdup (message, class->path); |
3744 | 410 | if (! *job) | 449 | if (! *job) |
3745 | 411 | nih_return_system_error (-1); | 450 | nih_return_system_error (-1); |
3746 | @@ -432,6 +471,7 @@ | |||
3747 | 432 | NihDBusMessage *message, | 471 | NihDBusMessage *message, |
3748 | 433 | char ***jobs) | 472 | char ***jobs) |
3749 | 434 | { | 473 | { |
3750 | 474 | Session *session; | ||
3751 | 435 | char **list; | 475 | char **list; |
3752 | 436 | size_t len; | 476 | size_t len; |
3753 | 437 | 477 | ||
3754 | @@ -445,9 +485,16 @@ | |||
3755 | 445 | if (! list) | 485 | if (! list) |
3756 | 446 | nih_return_system_error (-1); | 486 | nih_return_system_error (-1); |
3757 | 447 | 487 | ||
3758 | 488 | /* Get the relevant session */ | ||
3759 | 489 | session = session_from_dbus (NULL, message); | ||
3760 | 490 | |||
3761 | 448 | NIH_HASH_FOREACH (job_classes, iter) { | 491 | NIH_HASH_FOREACH (job_classes, iter) { |
3762 | 449 | JobClass *class = (JobClass *)iter; | 492 | JobClass *class = (JobClass *)iter; |
3763 | 450 | 493 | ||
3764 | 494 | if ((class->session || (session && session->chroot)) | ||
3765 | 495 | && (class->session != session)) | ||
3766 | 496 | continue; | ||
3767 | 497 | |||
3768 | 451 | if (! nih_str_array_add (&list, message, &len, | 498 | if (! nih_str_array_add (&list, message, &len, |
3769 | 452 | class->path)) { | 499 | class->path)) { |
3770 | 453 | nih_error_raise_system (); | 500 | nih_error_raise_system (); |
3771 | @@ -462,13 +509,24 @@ | |||
3772 | 462 | } | 509 | } |
3773 | 463 | 510 | ||
3774 | 464 | 511 | ||
3775 | 512 | int | ||
3776 | 513 | control_emit_event (void *data, | ||
3777 | 514 | NihDBusMessage *message, | ||
3778 | 515 | const char *name, | ||
3779 | 516 | char * const *env, | ||
3780 | 517 | int wait) | ||
3781 | 518 | { | ||
3782 | 519 | return control_emit_event_with_file (data, message, name, env, wait, -1); | ||
3783 | 520 | } | ||
3784 | 521 | |||
3785 | 465 | /** | 522 | /** |
3787 | 466 | * control_emit_event: | 523 | * control_emit_event_with_file: |
3788 | 467 | * @data: not used, | 524 | * @data: not used, |
3789 | 468 | * @message: D-Bus connection and message received, | 525 | * @message: D-Bus connection and message received, |
3790 | 469 | * @name: name of event to emit, | 526 | * @name: name of event to emit, |
3791 | 470 | * @env: environment of environment, | 527 | * @env: environment of environment, |
3793 | 471 | * @wait: whether to wait for event completion before returning. | 528 | * @wait: whether to wait for event completion before returning, |
3794 | 529 | * @file: file descriptor. | ||
3795 | 472 | * | 530 | * |
3796 | 473 | * Implements the top half of the EmitEvent method of the com.ubuntu.Upstart | 531 | * Implements the top half of the EmitEvent method of the com.ubuntu.Upstart |
3797 | 474 | * interface, the bottom half may be found in event_finished(). | 532 | * interface, the bottom half may be found in event_finished(). |
3798 | @@ -488,11 +546,12 @@ | |||
3799 | 488 | * Returns: zero on success, negative value on raised error. | 546 | * Returns: zero on success, negative value on raised error. |
3800 | 489 | **/ | 547 | **/ |
3801 | 490 | int | 548 | int |
3807 | 491 | control_emit_event (void *data, | 549 | control_emit_event_with_file (void *data, |
3808 | 492 | NihDBusMessage *message, | 550 | NihDBusMessage *message, |
3809 | 493 | const char *name, | 551 | const char *name, |
3810 | 494 | char * const *env, | 552 | char * const *env, |
3811 | 495 | int wait) | 553 | int wait, |
3812 | 554 | int file) | ||
3813 | 496 | { | 555 | { |
3814 | 497 | Event *event; | 556 | Event *event; |
3815 | 498 | Blocked *blocked; | 557 | Blocked *blocked; |
3816 | @@ -505,6 +564,7 @@ | |||
3817 | 505 | if (! strlen (name)) { | 564 | if (! strlen (name)) { |
3818 | 506 | nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, | 565 | nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, |
3819 | 507 | _("Name may not be empty string")); | 566 | _("Name may not be empty string")); |
3820 | 567 | close (file); | ||
3821 | 508 | return -1; | 568 | return -1; |
3822 | 509 | } | 569 | } |
3823 | 510 | 570 | ||
3824 | @@ -512,19 +572,36 @@ | |||
3825 | 512 | if (! environ_all_valid (env)) { | 572 | if (! environ_all_valid (env)) { |
3826 | 513 | nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, | 573 | nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, |
3827 | 514 | _("Env must be KEY=VALUE pairs")); | 574 | _("Env must be KEY=VALUE pairs")); |
3828 | 575 | close (file); | ||
3829 | 515 | return -1; | 576 | return -1; |
3830 | 516 | } | 577 | } |
3831 | 517 | 578 | ||
3832 | 518 | /* Make the event and block the message on it */ | 579 | /* Make the event and block the message on it */ |
3833 | 519 | event = event_new (NULL, name, (char **)env); | 580 | event = event_new (NULL, name, (char **)env); |
3836 | 520 | if (! event) | 581 | if (! event) { |
3837 | 521 | nih_return_system_error (-1); | 582 | nih_error_raise_system (); |
3838 | 583 | close (file); | ||
3839 | 584 | return -1; | ||
3840 | 585 | } | ||
3841 | 586 | |||
3842 | 587 | event->fd = file; | ||
3843 | 588 | if (event->fd >= 0) { | ||
3844 | 589 | long flags; | ||
3845 | 590 | |||
3846 | 591 | flags = fcntl (event->fd, F_GETFD); | ||
3847 | 592 | flags &= ~FD_CLOEXEC; | ||
3848 | 593 | fcntl (event->fd, F_SETFD, flags); | ||
3849 | 594 | } | ||
3850 | 595 | |||
3851 | 596 | /* Obtain the session */ | ||
3852 | 597 | event->session = session_from_dbus (NULL, message); | ||
3853 | 522 | 598 | ||
3854 | 523 | if (wait) { | 599 | if (wait) { |
3855 | 524 | blocked = blocked_new (event, BLOCKED_EMIT_METHOD, message); | 600 | blocked = blocked_new (event, BLOCKED_EMIT_METHOD, message); |
3856 | 525 | if (! blocked) { | 601 | if (! blocked) { |
3857 | 526 | nih_error_raise_system (); | 602 | nih_error_raise_system (); |
3858 | 527 | nih_free (event); | 603 | nih_free (event); |
3859 | 604 | close (file); | ||
3860 | 528 | return -1; | 605 | return -1; |
3861 | 529 | } | 606 | } |
3862 | 530 | 607 | ||
3863 | @@ -669,3 +746,18 @@ | |||
3864 | 669 | 746 | ||
3865 | 670 | return 0; | 747 | return 0; |
3866 | 671 | } | 748 | } |
3867 | 749 | |||
3868 | 750 | /** | ||
3869 | 751 | * control_handle_bus_type: | ||
3870 | 752 | * | ||
3871 | 753 | * Determine D-Bus bus type to connect to. | ||
3872 | 754 | **/ | ||
3873 | 755 | void | ||
3874 | 756 | control_handle_bus_type (void) | ||
3875 | 757 | { | ||
3876 | 758 | if (getenv (USE_SESSION_BUS_ENV)) | ||
3877 | 759 | use_session_bus = TRUE; | ||
3878 | 760 | |||
3879 | 761 | if (use_session_bus) | ||
3880 | 762 | nih_debug ("Using session bus"); | ||
3881 | 763 | } | ||
3882 | 672 | 764 | ||
3883 | === modified file 'init/control.h' | |||
3884 | --- init/control.h 2009-07-09 08:36:52 +0000 | |||
3885 | +++ init/control.h 2011-10-14 11:09:18 +0000 | |||
3886 | @@ -1,6 +1,6 @@ | |||
3887 | 1 | /* upstart | 1 | /* upstart |
3888 | 2 | * | 2 | * |
3890 | 3 | * Copyright © 2009 Canonical Ltd. | 3 | * Copyright © 2009-2011 Canonical Ltd. |
3891 | 4 | * Author: Scott James Remnant <scott@netsplit.com>. | 4 | * Author: Scott James Remnant <scott@netsplit.com>. |
3892 | 5 | * | 5 | * |
3893 | 6 | * This program is free software; you can redistribute it and/or modify | 6 | * This program is free software; you can redistribute it and/or modify |
3894 | @@ -27,6 +27,18 @@ | |||
3895 | 27 | #include <nih-dbus/dbus_connection.h> | 27 | #include <nih-dbus/dbus_connection.h> |
3896 | 28 | #include <nih-dbus/dbus_message.h> | 28 | #include <nih-dbus/dbus_message.h> |
3897 | 29 | 29 | ||
3898 | 30 | /** | ||
3899 | 31 | * USE_SESSION_BUS_ENV: | ||
3900 | 32 | * | ||
3901 | 33 | * If this environment variable is set to any value, connect to | ||
3902 | 34 | * D-Bus session bus rather than the system bus. | ||
3903 | 35 | * | ||
3904 | 36 | * Used for testing. | ||
3905 | 37 | **/ | ||
3906 | 38 | #ifndef USE_SESSION_BUS_ENV | ||
3907 | 39 | #define USE_SESSION_BUS_ENV "UPSTART_USE_SESSION_BUS" | ||
3908 | 40 | #endif | ||
3909 | 41 | |||
3910 | 30 | 42 | ||
3911 | 31 | NIH_BEGIN_EXTERN | 43 | NIH_BEGIN_EXTERN |
3912 | 32 | 44 | ||
3913 | @@ -60,6 +72,10 @@ | |||
3914 | 60 | const char *name, char * const *env, | 72 | const char *name, char * const *env, |
3915 | 61 | int wait) | 73 | int wait) |
3916 | 62 | __attribute__ ((warn_unused_result)); | 74 | __attribute__ ((warn_unused_result)); |
3917 | 75 | int control_emit_event_with_file (void *data, NihDBusMessage *message, | ||
3918 | 76 | const char *name, char * const *env, | ||
3919 | 77 | int wait, int file) | ||
3920 | 78 | __attribute__ ((warn_unused_result)); | ||
3921 | 63 | 79 | ||
3922 | 64 | int control_get_version (void *data, NihDBusMessage *message, | 80 | int control_get_version (void *data, NihDBusMessage *message, |
3923 | 65 | char **version) | 81 | char **version) |
3924 | @@ -72,6 +88,8 @@ | |||
3925 | 72 | const char *log_priority) | 88 | const char *log_priority) |
3926 | 73 | __attribute__ ((warn_unused_result)); | 89 | __attribute__ ((warn_unused_result)); |
3927 | 74 | 90 | ||
3928 | 91 | void control_handle_bus_type (void); | ||
3929 | 92 | |||
3930 | 75 | NIH_END_EXTERN | 93 | NIH_END_EXTERN |
3931 | 76 | 94 | ||
3932 | 77 | #endif /* INIT_CONTROL_H */ | 95 | #endif /* INIT_CONTROL_H */ |
3933 | 78 | 96 | ||
3934 | === modified file 'init/environ.c' | |||
3935 | --- init/environ.c 2011-03-16 22:42:48 +0000 | |||
3936 | +++ init/environ.c 2011-10-14 11:09:18 +0000 | |||
3937 | @@ -2,7 +2,6 @@ | |||
3938 | 2 | * | 2 | * |
3939 | 3 | * environ.c - environment table utilities | 3 | * environ.c - environment table utilities |
3940 | 4 | * | 4 | * |
3941 | 5 | * Copyright © 2011 Google Inc. | ||
3942 | 6 | * Copyright © 2009 Canonical Ltd. | 5 | * Copyright © 2009 Canonical Ltd. |
3943 | 7 | * Author: Scott James Remnant <scott@netsplit.com>. | 6 | * Author: Scott James Remnant <scott@netsplit.com>. |
3944 | 8 | * | 7 | * |
3945 | 9 | 8 | ||
3946 | === modified file 'init/environ.h' | |||
3947 | --- init/environ.h 2011-03-16 22:42:48 +0000 | |||
3948 | +++ init/environ.h 2011-10-14 11:09:18 +0000 | |||
3949 | @@ -1,6 +1,5 @@ | |||
3950 | 1 | /* upstart | 1 | /* upstart |
3951 | 2 | * | 2 | * |
3952 | 3 | * Copyright © 2011 Google Inc. | ||
3953 | 4 | * Copyright © 2009 Canonical Ltd. | 3 | * Copyright © 2009 Canonical Ltd. |
3954 | 5 | * Author: Scott James Remnant <scott@netsplit.com>. | 4 | * Author: Scott James Remnant <scott@netsplit.com>. |
3955 | 6 | * | 5 | * |
3956 | 7 | 6 | ||
3957 | === modified file 'init/event.c' | |||
3958 | --- init/event.c 2010-12-14 15:32:41 +0000 | |||
3959 | +++ init/event.c 2011-10-14 11:09:18 +0000 | |||
3960 | @@ -25,6 +25,7 @@ | |||
3961 | 25 | 25 | ||
3962 | 26 | 26 | ||
3963 | 27 | #include <string.h> | 27 | #include <string.h> |
3964 | 28 | #include <unistd.h> | ||
3965 | 28 | 29 | ||
3966 | 29 | #include <nih/macros.h> | 30 | #include <nih/macros.h> |
3967 | 30 | #include <nih/alloc.h> | 31 | #include <nih/alloc.h> |
3968 | @@ -123,6 +124,9 @@ | |||
3969 | 123 | 124 | ||
3970 | 124 | nih_list_init (&event->entry); | 125 | nih_list_init (&event->entry); |
3971 | 125 | 126 | ||
3972 | 127 | event->session = NULL; | ||
3973 | 128 | event->fd = -1; | ||
3974 | 129 | |||
3975 | 126 | event->progress = EVENT_PENDING; | 130 | event->progress = EVENT_PENDING; |
3976 | 127 | event->failed = FALSE; | 131 | event->failed = FALSE; |
3977 | 128 | 132 | ||
3978 | @@ -293,6 +297,13 @@ | |||
3979 | 293 | NIH_HASH_FOREACH_SAFE (job_classes, iter) { | 297 | NIH_HASH_FOREACH_SAFE (job_classes, iter) { |
3980 | 294 | JobClass *class = (JobClass *)iter; | 298 | JobClass *class = (JobClass *)iter; |
3981 | 295 | 299 | ||
3982 | 300 | /* Only affect jobs within the same session as the event | ||
3983 | 301 | * unless the event has no session, in which case do them | ||
3984 | 302 | * all. | ||
3985 | 303 | */ | ||
3986 | 304 | if (event->session && (class->session != event->session)) | ||
3987 | 305 | continue; | ||
3988 | 306 | |||
3989 | 296 | /* We stop first so that if an event is listed both as a | 307 | /* We stop first so that if an event is listed both as a |
3990 | 297 | * stop and start event, it causes an active running process | 308 | * stop and start event, it causes an active running process |
3991 | 298 | * to be killed, the stop script then the start script to be | 309 | * to be killed, the stop script then the start script to be |
3992 | @@ -393,8 +404,16 @@ | |||
3993 | 393 | job->start_env = env; | 404 | job->start_env = env; |
3994 | 394 | nih_ref (job->start_env, job); | 405 | nih_ref (job->start_env, job); |
3995 | 395 | 406 | ||
3996 | 407 | nih_discard (env); | ||
3997 | 408 | env = NULL; | ||
3998 | 409 | |||
3999 | 396 | job_finished (job, FALSE); | 410 | job_finished (job, FALSE); |
4000 | 397 | 411 | ||
4001 | 412 | NIH_MUST (event_operator_fds (class->start_on, job, | ||
4002 | 413 | &job->fds, &job->num_fds, | ||
4003 | 414 | &job->start_env, &len, | ||
4004 | 415 | "UPSTART_FDS")); | ||
4005 | 416 | |||
4006 | 398 | event_operator_events (job->class->start_on, | 417 | event_operator_events (job->class->start_on, |
4007 | 399 | job, &job->blocking); | 418 | job, &job->blocking); |
4008 | 400 | 419 | ||
4009 | @@ -459,6 +478,8 @@ | |||
4010 | 459 | nih_free (blocked); | 478 | nih_free (blocked); |
4011 | 460 | } | 479 | } |
4012 | 461 | 480 | ||
4013 | 481 | close (event->fd); | ||
4014 | 482 | |||
4015 | 462 | if (event->failed) { | 483 | if (event->failed) { |
4016 | 463 | char *name; | 484 | char *name; |
4017 | 464 | 485 | ||
4018 | @@ -470,6 +491,7 @@ | |||
4019 | 470 | failed = NIH_MUST (nih_sprintf (NULL, "%s/failed", | 491 | failed = NIH_MUST (nih_sprintf (NULL, "%s/failed", |
4020 | 471 | event->name)); | 492 | event->name)); |
4021 | 472 | new_event = NIH_MUST (event_new (NULL, failed, NULL)); | 493 | new_event = NIH_MUST (event_new (NULL, failed, NULL)); |
4022 | 494 | new_event->session = event->session; | ||
4023 | 473 | 495 | ||
4024 | 474 | if (event->env) | 496 | if (event->env) |
4025 | 475 | new_event->env = NIH_MUST (nih_str_array_copy ( | 497 | new_event->env = NIH_MUST (nih_str_array_copy ( |
4026 | 476 | 498 | ||
4027 | === modified file 'init/event.h' | |||
4028 | --- init/event.h 2009-07-09 08:36:52 +0000 | |||
4029 | +++ init/event.h 2011-10-14 11:09:18 +0000 | |||
4030 | @@ -1,6 +1,6 @@ | |||
4031 | 1 | /* upstart | 1 | /* upstart |
4032 | 2 | * | 2 | * |
4034 | 3 | * Copyright © 2009 Canonical Ltd. | 3 | * Copyright © 2010 Canonical Ltd. |
4035 | 4 | * Author: Scott James Remnant <scott@netsplit.com>. | 4 | * Author: Scott James Remnant <scott@netsplit.com>. |
4036 | 5 | * | 5 | * |
4037 | 6 | * This program is free software; you can redistribute it and/or modify | 6 | * This program is free software; you can redistribute it and/or modify |
4038 | @@ -23,6 +23,8 @@ | |||
4039 | 23 | #include <nih/macros.h> | 23 | #include <nih/macros.h> |
4040 | 24 | #include <nih/list.h> | 24 | #include <nih/list.h> |
4041 | 25 | 25 | ||
4042 | 26 | #include "session.h" | ||
4043 | 27 | |||
4044 | 26 | 28 | ||
4045 | 27 | /** | 29 | /** |
4046 | 28 | * EventProgress: | 30 | * EventProgress: |
4047 | @@ -40,6 +42,7 @@ | |||
4048 | 40 | /** | 42 | /** |
4049 | 41 | * Event: | 43 | * Event: |
4050 | 42 | * @entry: list header, | 44 | * @entry: list header, |
4051 | 45 | * @session: session the event is attached to, | ||
4052 | 43 | * @name: string name of the event, | 46 | * @name: string name of the event, |
4053 | 44 | * @env: NULL-terminated array of environment variables, | 47 | * @env: NULL-terminated array of environment variables, |
4054 | 45 | * @progress: progress of event, | 48 | * @progress: progress of event, |
4055 | @@ -61,8 +64,10 @@ | |||
4056 | 61 | typedef struct event { | 64 | typedef struct event { |
4057 | 62 | NihList entry; | 65 | NihList entry; |
4058 | 63 | 66 | ||
4059 | 67 | Session * session; | ||
4060 | 64 | char *name; | 68 | char *name; |
4061 | 65 | char **env; | 69 | char **env; |
4062 | 70 | int fd; | ||
4063 | 66 | 71 | ||
4064 | 67 | EventProgress progress; | 72 | EventProgress progress; |
4065 | 68 | int failed; | 73 | int failed; |
4066 | 69 | 74 | ||
4067 | === modified file 'init/event_operator.c' | |||
4068 | --- init/event_operator.c 2010-11-19 14:34:51 +0000 | |||
4069 | +++ init/event_operator.c 2011-10-14 11:09:18 +0000 | |||
4070 | @@ -552,6 +552,65 @@ | |||
4071 | 552 | return *env; | 552 | return *env; |
4072 | 553 | } | 553 | } |
4073 | 554 | 554 | ||
4074 | 555 | int * | ||
4075 | 556 | event_operator_fds (EventOperator *root, | ||
4076 | 557 | const void *parent, | ||
4077 | 558 | int **fds, | ||
4078 | 559 | size_t *num_fds, | ||
4079 | 560 | char ***env, | ||
4080 | 561 | size_t *len, | ||
4081 | 562 | const char *key) | ||
4082 | 563 | { | ||
4083 | 564 | nih_local char *evlist = NULL; | ||
4084 | 565 | |||
4085 | 566 | nih_assert (root != NULL); | ||
4086 | 567 | nih_assert (fds != NULL); | ||
4087 | 568 | nih_assert (num_fds != NULL); | ||
4088 | 569 | nih_assert (env != NULL); | ||
4089 | 570 | nih_assert (len != NULL); | ||
4090 | 571 | nih_assert (key != NULL); | ||
4091 | 572 | |||
4092 | 573 | /* Initialise the event list variable with the name given. */ | ||
4093 | 574 | evlist = nih_sprintf (NULL, "%s=", key); | ||
4094 | 575 | if (! evlist) | ||
4095 | 576 | return NULL; | ||
4096 | 577 | |||
4097 | 578 | *num_fds = 0; | ||
4098 | 579 | NIH_TREE_FOREACH_FULL (&root->node, iter, | ||
4099 | 580 | (NihTreeFilter)event_operator_filter, NULL) { | ||
4100 | 581 | EventOperator *oper = (EventOperator *)iter; | ||
4101 | 582 | |||
4102 | 583 | if (oper->type != EVENT_MATCH) | ||
4103 | 584 | continue; | ||
4104 | 585 | |||
4105 | 586 | nih_assert (oper->event != NULL); | ||
4106 | 587 | |||
4107 | 588 | if (oper->event->fd >= 0) { | ||
4108 | 589 | *fds = nih_realloc (*fds, parent, sizeof (int) * (*num_fds + 1)); | ||
4109 | 590 | if (! *fds) | ||
4110 | 591 | return NULL; | ||
4111 | 592 | |||
4112 | 593 | (*fds)[(*num_fds)++] = oper->event->fd; | ||
4113 | 594 | |||
4114 | 595 | if (evlist[strlen (evlist) - 1] != '=') { | ||
4115 | 596 | if (! nih_strcat_sprintf (&evlist, NULL, " %d", | ||
4116 | 597 | oper->event->fd)) | ||
4117 | 598 | return NULL; | ||
4118 | 599 | } else { | ||
4119 | 600 | if (! nih_strcat_sprintf (&evlist, NULL, "%d", | ||
4120 | 601 | oper->event->fd)) | ||
4121 | 602 | return NULL; | ||
4122 | 603 | } | ||
4123 | 604 | } | ||
4124 | 605 | } | ||
4125 | 606 | |||
4126 | 607 | if (*num_fds) | ||
4127 | 608 | if (! environ_add (env, parent, len, TRUE, evlist)) | ||
4128 | 609 | return NULL; | ||
4129 | 610 | |||
4130 | 611 | return (void *)1; | ||
4131 | 612 | } | ||
4132 | 613 | |||
4133 | 555 | /** | 614 | /** |
4134 | 556 | * event_operator_events: | 615 | * event_operator_events: |
4135 | 557 | * @root: operator tree to collect from, | 616 | * @root: operator tree to collect from, |
4136 | 558 | 617 | ||
4137 | === modified file 'init/event_operator.h' | |||
4138 | --- init/event_operator.h 2009-06-23 09:29:35 +0000 | |||
4139 | +++ init/event_operator.h 2011-10-14 11:09:18 +0000 | |||
4140 | @@ -95,6 +95,14 @@ | |||
4141 | 95 | char ** event_operator_environment (EventOperator *root, char ***env, | 95 | char ** event_operator_environment (EventOperator *root, char ***env, |
4142 | 96 | const void *parent, size_t *len, | 96 | const void *parent, size_t *len, |
4143 | 97 | const char *key); | 97 | const char *key); |
4144 | 98 | int * | ||
4145 | 99 | event_operator_fds (EventOperator *root, | ||
4146 | 100 | const void *parent, | ||
4147 | 101 | int **fds, | ||
4148 | 102 | size_t *num_fds, | ||
4149 | 103 | char ***env, | ||
4150 | 104 | size_t *len, | ||
4151 | 105 | const char *key); | ||
4152 | 98 | void event_operator_events (EventOperator *root, | 106 | void event_operator_events (EventOperator *root, |
4153 | 99 | const void *parent, NihList *list); | 107 | const void *parent, NihList *list); |
4154 | 100 | 108 | ||
4155 | 101 | 109 | ||
4156 | === modified file 'init/job.c' | |||
4157 | --- init/job.c 2010-12-14 15:32:41 +0000 | |||
4158 | +++ init/job.c 2011-10-14 11:09:18 +0000 | |||
4159 | @@ -2,7 +2,7 @@ | |||
4160 | 2 | * | 2 | * |
4161 | 3 | * job.c - core state machine of tasks and services | 3 | * job.c - core state machine of tasks and services |
4162 | 4 | * | 4 | * |
4164 | 5 | * Copyright © 2010 Canonical Ltd. | 5 | * Copyright © 2010,2011 Canonical Ltd. |
4165 | 6 | * Author: Scott James Remnant <scott@netsplit.com>. | 6 | * Author: Scott James Remnant <scott@netsplit.com>. |
4166 | 7 | * | 7 | * |
4167 | 8 | * This program is free software; you can redistribute it and/or modify | 8 | * This program is free software; you can redistribute it and/or modify |
4168 | @@ -47,6 +47,7 @@ | |||
4169 | 47 | #include "events.h" | 47 | #include "events.h" |
4170 | 48 | #include "environ.h" | 48 | #include "environ.h" |
4171 | 49 | #include "process.h" | 49 | #include "process.h" |
4172 | 50 | #include "session.h" | ||
4173 | 50 | #include "job_class.h" | 51 | #include "job_class.h" |
4174 | 51 | #include "job.h" | 52 | #include "job.h" |
4175 | 52 | #include "job_process.h" | 53 | #include "job_process.h" |
4176 | @@ -99,8 +100,14 @@ | |||
4177 | 99 | 100 | ||
4178 | 100 | job->class = class; | 101 | job->class = class; |
4179 | 101 | 102 | ||
4182 | 102 | job->path = nih_dbus_path (job, DBUS_PATH_UPSTART, "jobs", | 103 | if (job->class->session && job->class->session->chroot) { |
4183 | 103 | class->name, job->name, NULL); | 104 | /* JobClass already contains a valid D-Bus path prefix for the job */ |
4184 | 105 | job->path = nih_dbus_path (job, class->path, job->name, NULL); | ||
4185 | 106 | } else { | ||
4186 | 107 | job->path = nih_dbus_path (job, DBUS_PATH_UPSTART, "jobs", | ||
4187 | 108 | class->name, job->name, NULL); | ||
4188 | 109 | } | ||
4189 | 110 | |||
4190 | 104 | if (! job->path) | 111 | if (! job->path) |
4191 | 105 | goto error; | 112 | goto error; |
4192 | 106 | 113 | ||
4193 | @@ -118,6 +125,9 @@ | |||
4194 | 118 | goto error; | 125 | goto error; |
4195 | 119 | } | 126 | } |
4196 | 120 | 127 | ||
4197 | 128 | job->fds = NULL; | ||
4198 | 129 | job->num_fds = 0; | ||
4199 | 130 | |||
4200 | 121 | job->pid = nih_alloc (job, sizeof (pid_t) * PROCESS_LAST); | 131 | job->pid = nih_alloc (job, sizeof (pid_t) * PROCESS_LAST); |
4201 | 122 | if (! job->pid) | 132 | if (! job->pid) |
4202 | 123 | goto error; | 133 | goto error; |
4203 | @@ -906,6 +916,7 @@ | |||
4204 | 906 | } | 916 | } |
4205 | 907 | 917 | ||
4206 | 908 | event = NIH_MUST (event_new (NULL, name, env)); | 918 | event = NIH_MUST (event_new (NULL, name, env)); |
4207 | 919 | event->session = job->class->session; | ||
4208 | 909 | 920 | ||
4209 | 910 | if (block) { | 921 | if (block) { |
4210 | 911 | Blocked *blocked; | 922 | Blocked *blocked; |
4211 | @@ -1102,11 +1113,22 @@ | |||
4212 | 1102 | NihDBusMessage *message, | 1113 | NihDBusMessage *message, |
4213 | 1103 | int wait) | 1114 | int wait) |
4214 | 1104 | { | 1115 | { |
4215 | 1116 | Session *session; | ||
4216 | 1105 | Blocked *blocked = NULL; | 1117 | Blocked *blocked = NULL; |
4217 | 1106 | 1118 | ||
4218 | 1107 | nih_assert (job != NULL); | 1119 | nih_assert (job != NULL); |
4219 | 1108 | nih_assert (message != NULL); | 1120 | nih_assert (message != NULL); |
4220 | 1109 | 1121 | ||
4221 | 1122 | /* Don't permit out-of-session modification */ | ||
4222 | 1123 | session = session_from_dbus (NULL, message); | ||
4223 | 1124 | if (session != job->class->session) { | ||
4224 | 1125 | nih_dbus_error_raise_printf ( | ||
4225 | 1126 | DBUS_INTERFACE_UPSTART ".Error.PermissionDenied", | ||
4226 | 1127 | _("You do not have permission to modify job: %s"), | ||
4227 | 1128 | job_name (job)); | ||
4228 | 1129 | return -1; | ||
4229 | 1130 | } | ||
4230 | 1131 | |||
4231 | 1110 | if (job->goal == JOB_START) { | 1132 | if (job->goal == JOB_START) { |
4232 | 1111 | nih_dbus_error_raise_printf ( | 1133 | nih_dbus_error_raise_printf ( |
4233 | 1112 | DBUS_INTERFACE_UPSTART ".Error.AlreadyStarted", | 1134 | DBUS_INTERFACE_UPSTART ".Error.AlreadyStarted", |
4234 | @@ -1166,11 +1188,22 @@ | |||
4235 | 1166 | NihDBusMessage *message, | 1188 | NihDBusMessage *message, |
4236 | 1167 | int wait) | 1189 | int wait) |
4237 | 1168 | { | 1190 | { |
4238 | 1191 | Session *session; | ||
4239 | 1169 | Blocked *blocked = NULL; | 1192 | Blocked *blocked = NULL; |
4240 | 1170 | 1193 | ||
4241 | 1171 | nih_assert (job != NULL); | 1194 | nih_assert (job != NULL); |
4242 | 1172 | nih_assert (message != NULL); | 1195 | nih_assert (message != NULL); |
4243 | 1173 | 1196 | ||
4244 | 1197 | /* Don't permit out-of-session modification */ | ||
4245 | 1198 | session = session_from_dbus (NULL, message); | ||
4246 | 1199 | if (session != job->class->session) { | ||
4247 | 1200 | nih_dbus_error_raise_printf ( | ||
4248 | 1201 | DBUS_INTERFACE_UPSTART ".Error.PermissionDenied", | ||
4249 | 1202 | _("You do not have permission to modify job: %s"), | ||
4250 | 1203 | job_name (job)); | ||
4251 | 1204 | return -1; | ||
4252 | 1205 | } | ||
4253 | 1206 | |||
4254 | 1174 | if (job->goal == JOB_STOP) { | 1207 | if (job->goal == JOB_STOP) { |
4255 | 1175 | nih_dbus_error_raise_printf ( | 1208 | nih_dbus_error_raise_printf ( |
4256 | 1176 | DBUS_INTERFACE_UPSTART ".Error.AlreadyStopped", | 1209 | DBUS_INTERFACE_UPSTART ".Error.AlreadyStopped", |
4257 | @@ -1231,11 +1264,22 @@ | |||
4258 | 1231 | NihDBusMessage *message, | 1264 | NihDBusMessage *message, |
4259 | 1232 | int wait) | 1265 | int wait) |
4260 | 1233 | { | 1266 | { |
4261 | 1267 | Session *session; | ||
4262 | 1234 | Blocked *blocked = NULL; | 1268 | Blocked *blocked = NULL; |
4263 | 1235 | 1269 | ||
4264 | 1236 | nih_assert (job != NULL); | 1270 | nih_assert (job != NULL); |
4265 | 1237 | nih_assert (message != NULL); | 1271 | nih_assert (message != NULL); |
4266 | 1238 | 1272 | ||
4267 | 1273 | /* Don't permit out-of-session modification */ | ||
4268 | 1274 | session = session_from_dbus (NULL, message); | ||
4269 | 1275 | if (session != job->class->session) { | ||
4270 | 1276 | nih_dbus_error_raise_printf ( | ||
4271 | 1277 | DBUS_INTERFACE_UPSTART ".Error.PermissionDenied", | ||
4272 | 1278 | _("You do not have permission to modify job: %s"), | ||
4273 | 1279 | job_name (job)); | ||
4274 | 1280 | return -1; | ||
4275 | 1281 | } | ||
4276 | 1282 | |||
4277 | 1239 | if (job->goal == JOB_STOP) { | 1283 | if (job->goal == JOB_STOP) { |
4278 | 1240 | nih_dbus_error_raise_printf ( | 1284 | nih_dbus_error_raise_printf ( |
4279 | 1241 | DBUS_INTERFACE_UPSTART ".Error.AlreadyStopped", | 1285 | DBUS_INTERFACE_UPSTART ".Error.AlreadyStopped", |
4280 | 1242 | 1286 | ||
4281 | === modified file 'init/job.h' | |||
4282 | --- init/job.h 2009-07-03 16:38:02 +0000 | |||
4283 | +++ init/job.h 2011-10-14 11:09:18 +0000 | |||
4284 | @@ -1,6 +1,6 @@ | |||
4285 | 1 | /* upstart | 1 | /* upstart |
4286 | 2 | * | 2 | * |
4288 | 3 | * Copyright © 2009 Canonical Ltd. | 3 | * Copyright © 2010 Canonical Ltd. |
4289 | 4 | * Author: Scott James Remnant <scott@netsplit.com>. | 4 | * Author: Scott James Remnant <scott@netsplit.com>. |
4290 | 5 | * | 5 | * |
4291 | 6 | * This program is free software; you can redistribute it and/or modify | 6 | * This program is free software; you can redistribute it and/or modify |
4292 | @@ -134,6 +134,9 @@ | |||
4293 | 134 | char **stop_env; | 134 | char **stop_env; |
4294 | 135 | EventOperator *stop_on; | 135 | EventOperator *stop_on; |
4295 | 136 | 136 | ||
4296 | 137 | int *fds; | ||
4297 | 138 | size_t num_fds; | ||
4298 | 139 | |||
4299 | 137 | pid_t *pid; | 140 | pid_t *pid; |
4300 | 138 | Event *blocker; | 141 | Event *blocker; |
4301 | 139 | NihList blocking; | 142 | NihList blocking; |
4302 | 140 | 143 | ||
4303 | === modified file 'init/job_class.c' | |||
4304 | --- init/job_class.c 2011-05-12 20:42:28 +0000 | |||
4305 | +++ init/job_class.c 2011-10-14 11:09:18 +0000 | |||
4306 | @@ -2,7 +2,7 @@ | |||
4307 | 2 | * | 2 | * |
4308 | 3 | * job_class.c - job class definition handling | 3 | * job_class.c - job class definition handling |
4309 | 4 | * | 4 | * |
4311 | 5 | * Copyright © 2010 Canonical Ltd. | 5 | * Copyright © 2011 Canonical Ltd. |
4312 | 6 | * Author: Scott James Remnant <scott@netsplit.com>. | 6 | * Author: Scott James Remnant <scott@netsplit.com>. |
4313 | 7 | * | 7 | * |
4314 | 8 | * This program is free software; you can redistribute it and/or modify | 8 | * This program is free software; you can redistribute it and/or modify |
4315 | @@ -45,6 +45,7 @@ | |||
4316 | 45 | 45 | ||
4317 | 46 | #include "environ.h" | 46 | #include "environ.h" |
4318 | 47 | #include "process.h" | 47 | #include "process.h" |
4319 | 48 | #include "session.h" | ||
4320 | 48 | #include "job_class.h" | 49 | #include "job_class.h" |
4321 | 49 | #include "job.h" | 50 | #include "job.h" |
4322 | 50 | #include "event_operator.h" | 51 | #include "event_operator.h" |
4323 | @@ -56,51 +57,9 @@ | |||
4324 | 56 | #include "com.ubuntu.Upstart.Job.h" | 57 | #include "com.ubuntu.Upstart.Job.h" |
4325 | 57 | 58 | ||
4326 | 58 | 59 | ||
4327 | 59 | /** | ||
4328 | 60 | * JOB_DEFAULT_KILL_TIMEOUT: | ||
4329 | 61 | * | ||
4330 | 62 | * The default length of time to wait after sending a process the TERM | ||
4331 | 63 | * signal before sending the KILL signal if it hasn't terminated. | ||
4332 | 64 | **/ | ||
4333 | 65 | #define JOB_DEFAULT_KILL_TIMEOUT 5 | ||
4334 | 66 | |||
4335 | 67 | /** | ||
4336 | 68 | * JOB_DEFAULT_RESPAWN_LIMIT: | ||
4337 | 69 | * | ||
4338 | 70 | * The default number of times in JOB_DEFAULT_RESPAWN_INTERVAL seconds that | ||
4339 | 71 | * we permit a process to respawn before stoping it | ||
4340 | 72 | **/ | ||
4341 | 73 | #define JOB_DEFAULT_RESPAWN_LIMIT 10 | ||
4342 | 74 | |||
4343 | 75 | /** | ||
4344 | 76 | * JOB_DEFAULT_RESPAWN_INTERVAL: | ||
4345 | 77 | * | ||
4346 | 78 | * The default number of seconds before resetting the respawn timer. | ||
4347 | 79 | **/ | ||
4348 | 80 | #define JOB_DEFAULT_RESPAWN_INTERVAL 5 | ||
4349 | 81 | |||
4350 | 82 | /** | ||
4351 | 83 | * JOB_DEFAULT_UMASK: | ||
4352 | 84 | * | ||
4353 | 85 | * The default file creation mark for processes. | ||
4354 | 86 | **/ | ||
4355 | 87 | #define JOB_DEFAULT_UMASK 022 | ||
4356 | 88 | |||
4357 | 89 | /** | ||
4358 | 90 | * JOB_DEFAULT_ENVIRONMENT: | ||
4359 | 91 | * | ||
4360 | 92 | * Environment variables to always copy from our own environment, these | ||
4361 | 93 | * can be overriden in the job definition or by events since they have the | ||
4362 | 94 | * lowest priority. | ||
4363 | 95 | **/ | ||
4364 | 96 | #define JOB_DEFAULT_ENVIRONMENT \ | ||
4365 | 97 | "PATH", \ | ||
4366 | 98 | "TERM" | ||
4367 | 99 | |||
4368 | 100 | |||
4369 | 101 | /* Prototypes for static functions */ | 60 | /* Prototypes for static functions */ |
4370 | 102 | static void job_class_add (JobClass *class); | 61 | static void job_class_add (JobClass *class); |
4372 | 103 | static int job_class_remove (JobClass *class); | 62 | static int job_class_remove (JobClass *class, const Session *session); |
4373 | 104 | 63 | ||
4374 | 105 | 64 | ||
4375 | 106 | /** | 65 | /** |
4376 | @@ -128,13 +87,15 @@ | |||
4377 | 128 | 87 | ||
4378 | 129 | /** | 88 | /** |
4379 | 130 | * job_class_new: | 89 | * job_class_new: |
4380 | 90 | * | ||
4381 | 131 | * @parent: parent for new job class, | 91 | * @parent: parent for new job class, |
4383 | 132 | * @name: name of new job class. | 92 | * @name: name of new job class, |
4384 | 93 | * @session: session. | ||
4385 | 133 | * | 94 | * |
4390 | 134 | * Allocates and returns a new JobClass structure with the @name given. | 95 | * Allocates and returns a new JobClass structure with the given @name |
4391 | 135 | * It will not be automatically added to the job classes table, it is up | 96 | * and @session. It will not be automatically added to the job classes |
4392 | 136 | * to the caller to ensure this is done using job_class_register() once | 97 | * table, it is up to the caller to ensure this is done using |
4393 | 137 | * the class has been set up. | 98 | * job_class_register() once the class has been set up. |
4394 | 138 | * | 99 | * |
4395 | 139 | * If @parent is not NULL, it should be a pointer to another object which | 100 | * If @parent is not NULL, it should be a pointer to another object which |
4396 | 140 | * will be used as a parent for the returned job class. When all parents | 101 | * will be used as a parent for the returned job class. When all parents |
4397 | @@ -145,7 +106,8 @@ | |||
4398 | 145 | **/ | 106 | **/ |
4399 | 146 | JobClass * | 107 | JobClass * |
4400 | 147 | job_class_new (const void *parent, | 108 | job_class_new (const void *parent, |
4402 | 148 | const char *name) | 109 | const char *name, |
4403 | 110 | Session *session) | ||
4404 | 149 | { | 111 | { |
4405 | 150 | JobClass *class; | 112 | JobClass *class; |
4406 | 151 | int i; | 113 | int i; |
4407 | @@ -165,8 +127,41 @@ | |||
4408 | 165 | if (! class->name) | 127 | if (! class->name) |
4409 | 166 | goto error; | 128 | goto error; |
4410 | 167 | 129 | ||
4413 | 168 | class->path = nih_dbus_path (class, DBUS_PATH_UPSTART, "jobs", | 130 | class->session = session; |
4414 | 169 | class->name, NULL); | 131 | if (class->session |
4415 | 132 | && class->session->chroot | ||
4416 | 133 | && class->session->user) { | ||
4417 | 134 | nih_local char *uid = NULL; | ||
4418 | 135 | |||
4419 | 136 | uid = nih_sprintf (NULL, "%d", class->session->user); | ||
4420 | 137 | if (! uid) | ||
4421 | 138 | goto error; | ||
4422 | 139 | |||
4423 | 140 | class->path = nih_dbus_path (class, DBUS_PATH_UPSTART, "jobs", | ||
4424 | 141 | session->chroot, uid, | ||
4425 | 142 | class->name, NULL); | ||
4426 | 143 | |||
4427 | 144 | } else if (class->session | ||
4428 | 145 | && class->session->chroot) { | ||
4429 | 146 | class->path = nih_dbus_path (class, DBUS_PATH_UPSTART, "jobs", | ||
4430 | 147 | session->chroot, | ||
4431 | 148 | class->name, NULL); | ||
4432 | 149 | |||
4433 | 150 | } else if (class->session | ||
4434 | 151 | && class->session->user) { | ||
4435 | 152 | nih_local char *uid = NULL; | ||
4436 | 153 | |||
4437 | 154 | uid = nih_sprintf (NULL, "%d", class->session->user); | ||
4438 | 155 | if (! uid) | ||
4439 | 156 | goto error; | ||
4440 | 157 | |||
4441 | 158 | class->path = nih_dbus_path (class, DBUS_PATH_UPSTART, "jobs", | ||
4442 | 159 | uid, class->name, NULL); | ||
4443 | 160 | |||
4444 | 161 | } else { | ||
4445 | 162 | class->path = nih_dbus_path (class, DBUS_PATH_UPSTART, "jobs", | ||
4446 | 163 | class->name, NULL); | ||
4447 | 164 | } | ||
4448 | 170 | if (! class->path) | 165 | if (! class->path) |
4449 | 171 | goto error; | 166 | goto error; |
4450 | 172 | 167 | ||
4451 | @@ -212,8 +207,8 @@ | |||
4452 | 212 | class->console = CONSOLE_NONE; | 207 | class->console = CONSOLE_NONE; |
4453 | 213 | 208 | ||
4454 | 214 | class->umask = JOB_DEFAULT_UMASK; | 209 | class->umask = JOB_DEFAULT_UMASK; |
4457 | 215 | class->nice = 0; | 210 | class->nice = JOB_DEFAULT_NICE; |
4458 | 216 | class->oom_score_adj = 0; | 211 | class->oom_score_adj = JOB_DEFAULT_OOM_SCORE_ADJ; |
4459 | 217 | 212 | ||
4460 | 218 | for (i = 0; i < RLIMIT_NLIMITS; i++) | 213 | for (i = 0; i < RLIMIT_NLIMITS; i++) |
4461 | 219 | class->limits[i] = NULL; | 214 | class->limits[i] = NULL; |
4462 | @@ -245,19 +240,27 @@ | |||
4463 | 245 | int | 240 | int |
4464 | 246 | job_class_consider (JobClass *class) | 241 | job_class_consider (JobClass *class) |
4465 | 247 | { | 242 | { |
4467 | 248 | JobClass *registered, *best; | 243 | JobClass *registered = NULL, *best = NULL; |
4468 | 249 | 244 | ||
4469 | 250 | nih_assert (class != NULL); | 245 | nih_assert (class != NULL); |
4470 | 251 | 246 | ||
4471 | 252 | job_class_init (); | 247 | job_class_init (); |
4472 | 253 | 248 | ||
4474 | 254 | best = conf_select_job (class->name); | 249 | best = conf_select_job (class->name, class->session); |
4475 | 255 | nih_assert (best != NULL); | 250 | nih_assert (best != NULL); |
4478 | 256 | 251 | nih_assert (best->session == class->session); | |
4479 | 257 | registered = (JobClass *)nih_hash_lookup (job_classes, class->name); | 252 | |
4480 | 253 | registered = (JobClass *)nih_hash_search (job_classes, class->name, NULL); | ||
4481 | 254 | |||
4482 | 255 | /* If we found an entry, ensure we only consider the appropriate session */ | ||
4483 | 256 | while (registered && registered->session != class->session) | ||
4484 | 257 | { | ||
4485 | 258 | registered = (JobClass *)nih_hash_search (job_classes, class->name, ®istered->entry); | ||
4486 | 259 | } | ||
4487 | 260 | |||
4488 | 258 | if (registered != best) { | 261 | if (registered != best) { |
4489 | 259 | if (registered) | 262 | if (registered) |
4491 | 260 | if (! job_class_remove (registered)) | 263 | if (! job_class_remove (registered, class->session)) |
4492 | 261 | return FALSE; | 264 | return FALSE; |
4493 | 262 | 265 | ||
4494 | 263 | job_class_add (best); | 266 | job_class_add (best); |
4495 | @@ -282,18 +285,25 @@ | |||
4496 | 282 | int | 285 | int |
4497 | 283 | job_class_reconsider (JobClass *class) | 286 | job_class_reconsider (JobClass *class) |
4498 | 284 | { | 287 | { |
4500 | 285 | JobClass *registered, *best; | 288 | JobClass *registered = NULL, *best = NULL; |
4501 | 286 | 289 | ||
4502 | 287 | nih_assert (class != NULL); | 290 | nih_assert (class != NULL); |
4503 | 288 | 291 | ||
4504 | 289 | job_class_init (); | 292 | job_class_init (); |
4505 | 290 | 293 | ||
4509 | 291 | best = conf_select_job (class->name); | 294 | best = conf_select_job (class->name, class->session); |
4510 | 292 | 295 | ||
4511 | 293 | registered = (JobClass *)nih_hash_lookup (job_classes, class->name); | 296 | registered = (JobClass *)nih_hash_search (job_classes, class->name, NULL); |
4512 | 297 | |||
4513 | 298 | /* If we found an entry, ensure we only consider the appropriate session */ | ||
4514 | 299 | while (registered && registered->session != class->session) | ||
4515 | 300 | { | ||
4516 | 301 | registered = (JobClass *)nih_hash_search (job_classes, class->name, ®istered->entry); | ||
4517 | 302 | } | ||
4518 | 303 | |||
4519 | 294 | if (registered == class) { | 304 | if (registered == class) { |
4520 | 295 | if (class != best) { | 305 | if (class != best) { |
4522 | 296 | if (! job_class_remove (class)) | 306 | if (! job_class_remove (class, class->session)) |
4523 | 297 | return FALSE; | 307 | return FALSE; |
4524 | 298 | 308 | ||
4525 | 299 | job_class_add (best); | 309 | job_class_add (best); |
4526 | @@ -334,19 +344,24 @@ | |||
4527 | 334 | 344 | ||
4528 | 335 | /** | 345 | /** |
4529 | 336 | * job_class_remove: | 346 | * job_class_remove: |
4531 | 337 | * @class: class to remove. | 347 | * @class: class to remove, |
4532 | 348 | * @session: Session of @class. | ||
4533 | 338 | * | 349 | * |
4534 | 339 | * Removes @class from the hash table and unregisters it from all current | 350 | * Removes @class from the hash table and unregisters it from all current |
4535 | 340 | * D-Bus connections. | 351 | * D-Bus connections. |
4536 | 341 | * | 352 | * |
4537 | 342 | * Returns: TRUE if class could be unregistered, FALSE if there are | 353 | * Returns: TRUE if class could be unregistered, FALSE if there are |
4539 | 343 | * active instances that prevent unregistration. | 354 | * active instances that prevent unregistration, or if @session |
4540 | 355 | * does not match the session associated with @class. | ||
4541 | 344 | **/ | 356 | **/ |
4542 | 345 | static int | 357 | static int |
4544 | 346 | job_class_remove (JobClass *class) | 358 | job_class_remove (JobClass *class, const Session *session) |
4545 | 347 | { | 359 | { |
4546 | 348 | nih_assert (class != NULL); | 360 | nih_assert (class != NULL); |
4547 | 349 | 361 | ||
4548 | 362 | if (class->session != session) | ||
4549 | 363 | return FALSE; | ||
4550 | 364 | |||
4551 | 350 | control_init (); | 365 | control_init (); |
4552 | 351 | 366 | ||
4553 | 352 | /* Return if we have any active instances */ | 367 | /* Return if we have any active instances */ |
4554 | @@ -696,6 +711,7 @@ | |||
4555 | 696 | char * const *env, | 711 | char * const *env, |
4556 | 697 | int wait) | 712 | int wait) |
4557 | 698 | { | 713 | { |
4558 | 714 | Session *session; | ||
4559 | 699 | Blocked *blocked = NULL; | 715 | Blocked *blocked = NULL; |
4560 | 700 | Job *job; | 716 | Job *job; |
4561 | 701 | nih_local char **start_env = NULL; | 717 | nih_local char **start_env = NULL; |
4562 | @@ -706,6 +722,16 @@ | |||
4563 | 706 | nih_assert (message != NULL); | 722 | nih_assert (message != NULL); |
4564 | 707 | nih_assert (env != NULL); | 723 | nih_assert (env != NULL); |
4565 | 708 | 724 | ||
4566 | 725 | /* Don't permit out-of-session modification */ | ||
4567 | 726 | session = session_from_dbus (NULL, message); | ||
4568 | 727 | if (session != class->session) { | ||
4569 | 728 | nih_dbus_error_raise_printf ( | ||
4570 | 729 | DBUS_INTERFACE_UPSTART ".Error.PermissionDenied", | ||
4571 | 730 | _("You do not have permission to modify job: %s"), | ||
4572 | 731 | class->name); | ||
4573 | 732 | return -1; | ||
4574 | 733 | } | ||
4575 | 734 | |||
4576 | 709 | /* Verify that the environment is valid */ | 735 | /* Verify that the environment is valid */ |
4577 | 710 | if (! environ_all_valid (env)) { | 736 | if (! environ_all_valid (env)) { |
4578 | 711 | nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, | 737 | nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, |
4579 | @@ -815,6 +841,7 @@ | |||
4580 | 815 | char * const *env, | 841 | char * const *env, |
4581 | 816 | int wait) | 842 | int wait) |
4582 | 817 | { | 843 | { |
4583 | 844 | Session *session; | ||
4584 | 818 | Blocked *blocked = NULL; | 845 | Blocked *blocked = NULL; |
4585 | 819 | Job *job; | 846 | Job *job; |
4586 | 820 | nih_local char **stop_env = NULL; | 847 | nih_local char **stop_env = NULL; |
4587 | @@ -825,6 +852,16 @@ | |||
4588 | 825 | nih_assert (message != NULL); | 852 | nih_assert (message != NULL); |
4589 | 826 | nih_assert (env != NULL); | 853 | nih_assert (env != NULL); |
4590 | 827 | 854 | ||
4591 | 855 | /* Don't permit out-of-session modification */ | ||
4592 | 856 | session = session_from_dbus (NULL, message); | ||
4593 | 857 | if (session != class->session) { | ||
4594 | 858 | nih_dbus_error_raise_printf ( | ||
4595 | 859 | DBUS_INTERFACE_UPSTART ".Error.PermissionDenied", | ||
4596 | 860 | _("You do not have permission to modify job: %s"), | ||
4597 | 861 | class->name); | ||
4598 | 862 | return -1; | ||
4599 | 863 | } | ||
4600 | 864 | |||
4601 | 828 | /* Verify that the environment is valid */ | 865 | /* Verify that the environment is valid */ |
4602 | 829 | if (! environ_all_valid (env)) { | 866 | if (! environ_all_valid (env)) { |
4603 | 830 | nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, | 867 | nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, |
4604 | @@ -939,6 +976,7 @@ | |||
4605 | 939 | char * const *env, | 976 | char * const *env, |
4606 | 940 | int wait) | 977 | int wait) |
4607 | 941 | { | 978 | { |
4608 | 979 | Session *session; | ||
4609 | 942 | Blocked *blocked = NULL; | 980 | Blocked *blocked = NULL; |
4610 | 943 | Job *job; | 981 | Job *job; |
4611 | 944 | nih_local char **restart_env = NULL; | 982 | nih_local char **restart_env = NULL; |
4612 | @@ -949,6 +987,16 @@ | |||
4613 | 949 | nih_assert (message != NULL); | 987 | nih_assert (message != NULL); |
4614 | 950 | nih_assert (env != NULL); | 988 | nih_assert (env != NULL); |
4615 | 951 | 989 | ||
4616 | 990 | /* Don't permit out-of-session modification */ | ||
4617 | 991 | session = session_from_dbus (NULL, message); | ||
4618 | 992 | if (session != class->session) { | ||
4619 | 993 | nih_dbus_error_raise_printf ( | ||
4620 | 994 | DBUS_INTERFACE_UPSTART ".Error.PermissionDenied", | ||
4621 | 995 | _("You do not have permission to modify job: %s"), | ||
4622 | 996 | class->name); | ||
4623 | 997 | return -1; | ||
4624 | 998 | } | ||
4625 | 999 | |||
4626 | 952 | /* Verify that the environment is valid */ | 1000 | /* Verify that the environment is valid */ |
4627 | 953 | if (! environ_all_valid (env)) { | 1001 | if (! environ_all_valid (env)) { |
4628 | 954 | nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, | 1002 | nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, |
4629 | 955 | 1003 | ||
4630 | === modified file 'init/job_class.h' | |||
4631 | --- init/job_class.h 2011-05-12 20:42:28 +0000 | |||
4632 | +++ init/job_class.h 2011-10-14 11:09:18 +0000 | |||
4633 | @@ -1,6 +1,6 @@ | |||
4634 | 1 | /* upstart | 1 | /* upstart |
4635 | 2 | * | 2 | * |
4637 | 3 | * Copyright © 2010 Canonical Ltd. | 3 | * Copyright © 2011 Canonical Ltd. |
4638 | 4 | * Author: Scott James Remnant <scott@netsplit.com>. | 4 | * Author: Scott James Remnant <scott@netsplit.com>. |
4639 | 5 | * | 5 | * |
4640 | 6 | * This program is free software; you can redistribute it and/or modify | 6 | * This program is free software; you can redistribute it and/or modify |
4641 | @@ -35,6 +35,7 @@ | |||
4642 | 35 | 35 | ||
4643 | 36 | #include "process.h" | 36 | #include "process.h" |
4644 | 37 | #include "event_operator.h" | 37 | #include "event_operator.h" |
4645 | 38 | #include "session.h" | ||
4646 | 38 | 39 | ||
4647 | 39 | 40 | ||
4648 | 40 | /** | 41 | /** |
4649 | @@ -67,10 +68,67 @@ | |||
4650 | 67 | 68 | ||
4651 | 68 | 69 | ||
4652 | 69 | /** | 70 | /** |
4653 | 71 | * JOB_DEFAULT_KILL_TIMEOUT: | ||
4654 | 72 | * | ||
4655 | 73 | * The default length of time to wait after sending a process the TERM | ||
4656 | 74 | * signal before sending the KILL signal if it hasn't terminated. | ||
4657 | 75 | **/ | ||
4658 | 76 | #define JOB_DEFAULT_KILL_TIMEOUT 5 | ||
4659 | 77 | |||
4660 | 78 | /** | ||
4661 | 79 | * JOB_DEFAULT_RESPAWN_LIMIT: | ||
4662 | 80 | * | ||
4663 | 81 | * The default number of times in JOB_DEFAULT_RESPAWN_INTERVAL seconds that | ||
4664 | 82 | * we permit a process to respawn before stoping it | ||
4665 | 83 | **/ | ||
4666 | 84 | #define JOB_DEFAULT_RESPAWN_LIMIT 10 | ||
4667 | 85 | |||
4668 | 86 | /** | ||
4669 | 87 | * JOB_DEFAULT_RESPAWN_INTERVAL: | ||
4670 | 88 | * | ||
4671 | 89 | * The default number of seconds before resetting the respawn timer. | ||
4672 | 90 | **/ | ||
4673 | 91 | #define JOB_DEFAULT_RESPAWN_INTERVAL 5 | ||
4674 | 92 | |||
4675 | 93 | /** | ||
4676 | 94 | * JOB_DEFAULT_UMASK: | ||
4677 | 95 | * | ||
4678 | 96 | * The default file creation mark for processes. | ||
4679 | 97 | **/ | ||
4680 | 98 | #define JOB_DEFAULT_UMASK 022 | ||
4681 | 99 | |||
4682 | 100 | /** | ||
4683 | 101 | * JOB_DEFAULT_NICE: | ||
4684 | 102 | * | ||
4685 | 103 | * The default nice level for processes. | ||
4686 | 104 | **/ | ||
4687 | 105 | #define JOB_DEFAULT_NICE 0 | ||
4688 | 106 | |||
4689 | 107 | /** | ||
4690 | 108 | * JOB_DEFAULT_OOM_SCORE_ADJ: | ||
4691 | 109 | * | ||
4692 | 110 | * The default OOM score adjustment for processes. | ||
4693 | 111 | **/ | ||
4694 | 112 | #define JOB_DEFAULT_OOM_SCORE_ADJ 0 | ||
4695 | 113 | |||
4696 | 114 | /** | ||
4697 | 115 | * JOB_DEFAULT_ENVIRONMENT: | ||
4698 | 116 | * | ||
4699 | 117 | * Environment variables to always copy from our own environment, these | ||
4700 | 118 | * can be overriden in the job definition or by events since they have the | ||
4701 | 119 | * lowest priority. | ||
4702 | 120 | **/ | ||
4703 | 121 | #define JOB_DEFAULT_ENVIRONMENT \ | ||
4704 | 122 | "PATH", \ | ||
4705 | 123 | "TERM" | ||
4706 | 124 | |||
4707 | 125 | |||
4708 | 126 | /** | ||
4709 | 70 | * JobClass: | 127 | * JobClass: |
4710 | 71 | * @entry: list header, | 128 | * @entry: list header, |
4711 | 72 | * @name: unique name, | 129 | * @name: unique name, |
4712 | 73 | * @path: path of D-Bus object, | 130 | * @path: path of D-Bus object, |
4713 | 131 | * @session: attached session, | ||
4714 | 74 | * @instance: pattern to uniquely identify multiple instances, | 132 | * @instance: pattern to uniquely identify multiple instances, |
4715 | 75 | * @instances: hash table of active instances, | 133 | * @instances: hash table of active instances, |
4716 | 76 | * @description: description; intended for humans, | 134 | * @description: description; intended for humans, |
4717 | @@ -110,6 +168,7 @@ | |||
4718 | 110 | 168 | ||
4719 | 111 | char *name; | 169 | char *name; |
4720 | 112 | char *path; | 170 | char *path; |
4721 | 171 | Session * session; | ||
4722 | 113 | 172 | ||
4723 | 114 | char *instance; | 173 | char *instance; |
4724 | 115 | NihHash *instances; | 174 | NihHash *instances; |
4725 | @@ -161,7 +220,8 @@ | |||
4726 | 161 | void job_class_init (void); | 220 | void job_class_init (void); |
4727 | 162 | 221 | ||
4728 | 163 | JobClass * job_class_new (const void *parent, | 222 | JobClass * job_class_new (const void *parent, |
4730 | 164 | const char *name) | 223 | const char *name, |
4731 | 224 | Session *session) | ||
4732 | 165 | __attribute__ ((warn_unused_result, malloc)); | 225 | __attribute__ ((warn_unused_result, malloc)); |
4733 | 166 | 226 | ||
4734 | 167 | int job_class_consider (JobClass *class); | 227 | int job_class_consider (JobClass *class); |
4735 | 168 | 228 | ||
4736 | === modified file 'init/job_process.c' | |||
4737 | --- init/job_process.c 2011-05-12 20:42:28 +0000 | |||
4738 | +++ init/job_process.c 2011-10-14 11:09:18 +0000 | |||
4739 | @@ -2,7 +2,6 @@ | |||
4740 | 2 | * | 2 | * |
4741 | 3 | * job_process.c - job process handling | 3 | * job_process.c - job process handling |
4742 | 4 | * | 4 | * |
4743 | 5 | * Copyright © 2011 Google Inc. | ||
4744 | 6 | * Copyright © 2011 Canonical Ltd. | 5 | * Copyright © 2011 Canonical Ltd. |
4745 | 7 | * Author: Scott James Remnant <scott@netsplit.com>. | 6 | * Author: Scott James Remnant <scott@netsplit.com>. |
4746 | 8 | * | 7 | * |
4747 | @@ -41,6 +40,7 @@ | |||
4748 | 41 | #include <unistd.h> | 40 | #include <unistd.h> |
4749 | 42 | #include <utmp.h> | 41 | #include <utmp.h> |
4750 | 43 | #include <utmpx.h> | 42 | #include <utmpx.h> |
4751 | 43 | #include <pwd.h> | ||
4752 | 44 | 44 | ||
4753 | 45 | #include <nih/macros.h> | 45 | #include <nih/macros.h> |
4754 | 46 | #include <nih/alloc.h> | 46 | #include <nih/alloc.h> |
4755 | @@ -373,14 +373,20 @@ | |||
4756 | 373 | int trace, | 373 | int trace, |
4757 | 374 | int script_fd) | 374 | int script_fd) |
4758 | 375 | { | 375 | { |
4764 | 376 | sigset_t child_set, orig_set; | 376 | sigset_t child_set, orig_set; |
4765 | 377 | pid_t pid; | 377 | pid_t pid; |
4766 | 378 | int i, fds[2]; | 378 | int i, fds[2]; |
4767 | 379 | char filename[PATH_MAX]; | 379 | char filename[PATH_MAX]; |
4768 | 380 | FILE *fd; | 380 | FILE *fd; |
4769 | 381 | int user_job = FALSE; | ||
4770 | 382 | nih_local char *user_dir = NULL; | ||
4771 | 383 | |||
4772 | 381 | 384 | ||
4773 | 382 | nih_assert (class != NULL); | 385 | nih_assert (class != NULL); |
4774 | 383 | 386 | ||
4775 | 387 | if (class && class->session && class->session->user) | ||
4776 | 388 | user_job = TRUE; | ||
4777 | 389 | |||
4778 | 384 | /* Create a pipe to communicate with the child process until it | 390 | /* Create a pipe to communicate with the child process until it |
4779 | 385 | * execs so we know whether that was successful or an error occurred. | 391 | * execs so we know whether that was successful or an error occurred. |
4780 | 386 | */ | 392 | */ |
4781 | @@ -439,6 +445,8 @@ | |||
4782 | 439 | close (fds[0]); | 445 | close (fds[0]); |
4783 | 440 | if (fds[1] == JOB_PROCESS_SCRIPT_FD) { | 446 | if (fds[1] == JOB_PROCESS_SCRIPT_FD) { |
4784 | 441 | int tmp = dup2 (fds[1], fds[0]); | 447 | int tmp = dup2 (fds[1], fds[0]); |
4785 | 448 | if (tmp < 0) | ||
4786 | 449 | job_process_error_abort (fds[1], JOB_PROCESS_ERROR_DUP, 0); | ||
4787 | 442 | close (fds[1]); | 450 | close (fds[1]); |
4788 | 443 | fds[1] = tmp; | 451 | fds[1] = tmp; |
4789 | 444 | } | 452 | } |
4790 | @@ -447,7 +455,7 @@ | |||
4791 | 447 | /* Move the script fd to special fd 9; the only gotcha is if that | 455 | /* Move the script fd to special fd 9; the only gotcha is if that |
4792 | 448 | * would be our error descriptor, but that's handled above. | 456 | * would be our error descriptor, but that's handled above. |
4793 | 449 | */ | 457 | */ |
4795 | 450 | if (script_fd != -1) { | 458 | if ((script_fd != -1) && (script_fd != JOB_PROCESS_SCRIPT_FD)) { |
4796 | 451 | int tmp = dup2 (script_fd, JOB_PROCESS_SCRIPT_FD); | 459 | int tmp = dup2 (script_fd, JOB_PROCESS_SCRIPT_FD); |
4797 | 452 | if (tmp < 0) | 460 | if (tmp < 0) |
4798 | 453 | job_process_error_abort (fds[1], JOB_PROCESS_ERROR_DUP, 0); | 461 | job_process_error_abort (fds[1], JOB_PROCESS_ERROR_DUP, 0); |
4799 | @@ -460,6 +468,84 @@ | |||
4800 | 460 | */ | 468 | */ |
4801 | 461 | setsid (); | 469 | setsid (); |
4802 | 462 | 470 | ||
4803 | 471 | /* Set the process environment from the function paramters. */ | ||
4804 | 472 | environ = (char **)env; | ||
4805 | 473 | |||
4806 | 474 | /* Handle unprivileged user job by dropping privileges to | ||
4807 | 475 | * their level as soon as possible to avoid privilege | ||
4808 | 476 | * escalations when we set resource limits. | ||
4809 | 477 | */ | ||
4810 | 478 | if (user_job) { | ||
4811 | 479 | uid_t uid = class->session->user; | ||
4812 | 480 | struct passwd *pw = NULL; | ||
4813 | 481 | |||
4814 | 482 | /* D-Bus does not expose a public API call to allow | ||
4815 | 483 | * us to query a users primary group. | ||
4816 | 484 | * _dbus_user_info_fill_uid () seems to exist for this | ||
4817 | 485 | * purpose, but is a "secret" API. It is unclear why | ||
4818 | 486 | * D-Bus neglects the gid when it allows the uid | ||
4819 | 487 | * to be queried directly. | ||
4820 | 488 | * | ||
4821 | 489 | * Our only recourse is to disallow user sessions in a | ||
4822 | 490 | * chroot and assume that all other user sessions | ||
4823 | 491 | * originate from the local system. In this way, we can | ||
4824 | 492 | * bypass D-Bus and use getpwuid (). | ||
4825 | 493 | */ | ||
4826 | 494 | |||
4827 | 495 | if (class->session->chroot) { | ||
4828 | 496 | /* We cannot determine the group id of the user | ||
4829 | 497 | * session in the chroot via D-Bus, so disallow | ||
4830 | 498 | * all jobs in such an environment. | ||
4831 | 499 | */ | ||
4832 | 500 | nih_return_error (-1, EPERM, "user jobs not supported in chroots"); | ||
4833 | 501 | } | ||
4834 | 502 | |||
4835 | 503 | pw = getpwuid (uid); | ||
4836 | 504 | |||
4837 | 505 | if (!pw) | ||
4838 | 506 | nih_return_system_error (-1); | ||
4839 | 507 | |||
4840 | 508 | nih_assert (pw->pw_uid == uid); | ||
4841 | 509 | |||
4842 | 510 | if (! pw->pw_dir) { | ||
4843 | 511 | nih_local char *message = NIH_MUST (nih_sprintf (NULL, | ||
4844 | 512 | "no home directory for user with uid %d", | ||
4845 | 513 | uid)); | ||
4846 | 514 | |||
4847 | 515 | nih_return_error (-1, ENOENT, message); | ||
4848 | 516 | |||
4849 | 517 | } | ||
4850 | 518 | |||
4851 | 519 | /* Note we don't use NIH_MUST since this could result in a | ||
4852 | 520 | * DOS for a (low priority) user job in low-memory scenarios. | ||
4853 | 521 | */ | ||
4854 | 522 | user_dir = nih_strdup (NULL, pw->pw_dir); | ||
4855 | 523 | |||
4856 | 524 | if (!user_dir) | ||
4857 | 525 | nih_return_no_memory_error (-1); | ||
4858 | 526 | |||
4859 | 527 | /* Ensure the file associated with fd 9 | ||
4860 | 528 | * (/proc/self/fd/9) is owned by the user we're about to | ||
4861 | 529 | * become to avoid EPERM. | ||
4862 | 530 | */ | ||
4863 | 531 | if (script_fd != -1 && fchown (script_fd, pw->pw_uid, pw->pw_gid) < 0) { | ||
4864 | 532 | nih_error_raise_system (); | ||
4865 | 533 | job_process_error_abort (fds[1], JOB_PROCESS_ERROR_CHOWN, 0); | ||
4866 | 534 | } | ||
4867 | 535 | |||
4868 | 536 | if (pw->pw_gid && setgid (pw->pw_gid) < 0) { | ||
4869 | 537 | nih_error_raise_system (); | ||
4870 | 538 | job_process_error_abort (fds[1], JOB_PROCESS_ERROR_SETGID, 0); | ||
4871 | 539 | } | ||
4872 | 540 | |||
4873 | 541 | if (pw->pw_uid && setuid (pw->pw_uid) < 0) { | ||
4874 | 542 | nih_error_raise_system (); | ||
4875 | 543 | job_process_error_abort (fds[1], JOB_PROCESS_ERROR_SETUID, 0); | ||
4876 | 544 | } | ||
4877 | 545 | |||
4878 | 546 | |||
4879 | 547 | } | ||
4880 | 548 | |||
4881 | 463 | /* Set the standard file descriptors to an output of our chosing; | 549 | /* Set the standard file descriptors to an output of our chosing; |
4882 | 464 | * any other open descriptor must be intended for the child, or have | 550 | * any other open descriptor must be intended for the child, or have |
4883 | 465 | * the FD_CLOEXEC flag so it's automatically closed when we exec() | 551 | * the FD_CLOEXEC flag so it's automatically closed when we exec() |
4884 | @@ -480,6 +566,7 @@ | |||
4885 | 480 | job_process_error_abort (fds[1], JOB_PROCESS_ERROR_CONSOLE, 0); | 566 | job_process_error_abort (fds[1], JOB_PROCESS_ERROR_CONSOLE, 0); |
4886 | 481 | } | 567 | } |
4887 | 482 | 568 | ||
4888 | 569 | |||
4889 | 483 | /* Set resource limits for the process, skipping over any that | 570 | /* Set resource limits for the process, skipping over any that |
4890 | 484 | * aren't set in the job class such that they inherit from | 571 | * aren't set in the job class such that they inherit from |
4891 | 485 | * ourselves (and we inherit from kernel defaults). | 572 | * ourselves (and we inherit from kernel defaults). |
4892 | @@ -495,9 +582,6 @@ | |||
4893 | 495 | } | 582 | } |
4894 | 496 | } | 583 | } |
4895 | 497 | 584 | ||
4896 | 498 | /* Set the process environment from the function paramters. */ | ||
4897 | 499 | environ = (char **)env; | ||
4898 | 500 | |||
4899 | 501 | /* Set the file mode creation mask; this is one of the few operations | 585 | /* Set the file mode creation mask; this is one of the few operations |
4900 | 502 | * that can never fail. | 586 | * that can never fail. |
4901 | 503 | */ | 587 | */ |
4902 | @@ -513,13 +597,13 @@ | |||
4903 | 513 | 597 | ||
4904 | 514 | /* Adjust the process OOM killer priority. | 598 | /* Adjust the process OOM killer priority. |
4905 | 515 | */ | 599 | */ |
4907 | 516 | if (class->oom_score_adj) { | 600 | if (class->oom_score_adj != JOB_DEFAULT_OOM_SCORE_ADJ) { |
4908 | 517 | int oom_value; | 601 | int oom_value; |
4909 | 518 | snprintf (filename, sizeof (filename), | 602 | snprintf (filename, sizeof (filename), |
4910 | 519 | "/proc/%d/oom_score_adj", getpid ()); | 603 | "/proc/%d/oom_score_adj", getpid ()); |
4911 | 520 | oom_value = class->oom_score_adj; | 604 | oom_value = class->oom_score_adj; |
4912 | 521 | fd = fopen (filename, "w"); | 605 | fd = fopen (filename, "w"); |
4914 | 522 | if ((! fd) && (errno == EACCES)) { | 606 | if ((! fd) && (errno == ENOENT)) { |
4915 | 523 | snprintf (filename, sizeof (filename), | 607 | snprintf (filename, sizeof (filename), |
4916 | 524 | "/proc/%d/oom_adj", getpid ()); | 608 | "/proc/%d/oom_adj", getpid ()); |
4917 | 525 | oom_value = (class->oom_score_adj | 609 | oom_value = (class->oom_score_adj |
4918 | @@ -539,6 +623,16 @@ | |||
4919 | 539 | } | 623 | } |
4920 | 540 | } | 624 | } |
4921 | 541 | 625 | ||
4922 | 626 | /* Handle changing a chroot session job prior to dealing with | ||
4923 | 627 | * the 'chroot' stanza. | ||
4924 | 628 | */ | ||
4925 | 629 | if (class->session && class->session->chroot) { | ||
4926 | 630 | if (chroot (class->session->chroot) < 0) { | ||
4927 | 631 | nih_error_raise_system (); | ||
4928 | 632 | job_process_error_abort (fds[1], JOB_PROCESS_ERROR_CHROOT, 0); | ||
4929 | 633 | } | ||
4930 | 634 | } | ||
4931 | 635 | |||
4932 | 542 | /* Change the root directory, confining path resolution within it; | 636 | /* Change the root directory, confining path resolution within it; |
4933 | 543 | * we do this before the working directory call so that is always | 637 | * we do this before the working directory call so that is always |
4934 | 544 | * relative to the new root. | 638 | * relative to the new root. |
4935 | @@ -555,12 +649,11 @@ | |||
4936 | 555 | * configured in the job, or to the root directory of the filesystem | 649 | * configured in the job, or to the root directory of the filesystem |
4937 | 556 | * (or at least relative to the chroot). | 650 | * (or at least relative to the chroot). |
4938 | 557 | */ | 651 | */ |
4940 | 558 | if (chdir (class->chdir ? class->chdir : "/") < 0) { | 652 | if (chdir (class->chdir ? class->chdir : user_job ? user_dir : "/") < 0) { |
4941 | 559 | nih_error_raise_system (); | 653 | nih_error_raise_system (); |
4942 | 560 | job_process_error_abort (fds[1], JOB_PROCESS_ERROR_CHDIR, 0); | 654 | job_process_error_abort (fds[1], JOB_PROCESS_ERROR_CHDIR, 0); |
4943 | 561 | } | 655 | } |
4944 | 562 | 656 | ||
4945 | 563 | |||
4946 | 564 | /* Reset all the signal handlers back to their default handling so | 657 | /* Reset all the signal handlers back to their default handling so |
4947 | 565 | * the child isn't unexpectedly ignoring any, and so we won't | 658 | * the child isn't unexpectedly ignoring any, and so we won't |
4948 | 566 | * surprisingly handle them before we've exec()d the new process. | 659 | * surprisingly handle them before we've exec()d the new process. |
4949 | @@ -787,6 +880,21 @@ | |||
4950 | 787 | err, _("unable to execute: %s"), | 880 | err, _("unable to execute: %s"), |
4951 | 788 | strerror (err->errnum))); | 881 | strerror (err->errnum))); |
4952 | 789 | break; | 882 | break; |
4953 | 883 | case JOB_PROCESS_ERROR_SETUID: | ||
4954 | 884 | err->error.message = NIH_MUST (nih_sprintf ( | ||
4955 | 885 | err, _("unable to setuid: %s"), | ||
4956 | 886 | strerror (err->errnum))); | ||
4957 | 887 | break; | ||
4958 | 888 | case JOB_PROCESS_ERROR_SETGID: | ||
4959 | 889 | err->error.message = NIH_MUST (nih_sprintf ( | ||
4960 | 890 | err, _("unable to setgid: %s"), | ||
4961 | 891 | strerror (err->errnum))); | ||
4962 | 892 | break; | ||
4963 | 893 | case JOB_PROCESS_ERROR_CHOWN: | ||
4964 | 894 | err->error.message = NIH_MUST (nih_sprintf ( | ||
4965 | 895 | err, _("unable to chown: %s"), | ||
4966 | 896 | strerror (err->errnum))); | ||
4967 | 897 | break; | ||
4968 | 790 | default: | 898 | default: |
4969 | 791 | nih_assert_not_reached (); | 899 | nih_assert_not_reached (); |
4970 | 792 | } | 900 | } |
4971 | 793 | 901 | ||
4972 | === modified file 'init/job_process.h' | |||
4973 | --- init/job_process.h 2011-05-12 19:21:16 +0000 | |||
4974 | +++ init/job_process.h 2011-10-14 11:09:18 +0000 | |||
4975 | @@ -1,7 +1,6 @@ | |||
4976 | 1 | /* upstart | 1 | /* upstart |
4977 | 2 | * | 2 | * |
4980 | 3 | * Copyright © 2011 Google Inc. | 3 | * Copyright © 2009,2010,2011 Canonical Ltd. |
4979 | 4 | * Copyright © 2009 Canonical Ltd. | ||
4981 | 5 | * Author: Scott James Remnant <scott@netsplit.com>. | 4 | * Author: Scott James Remnant <scott@netsplit.com>. |
4982 | 6 | * | 5 | * |
4983 | 7 | * This program is free software; you can redistribute it and/or modify | 6 | * This program is free software; you can redistribute it and/or modify |
4984 | @@ -57,7 +56,10 @@ | |||
4985 | 57 | JOB_PROCESS_ERROR_CHROOT, | 56 | JOB_PROCESS_ERROR_CHROOT, |
4986 | 58 | JOB_PROCESS_ERROR_CHDIR, | 57 | JOB_PROCESS_ERROR_CHDIR, |
4987 | 59 | JOB_PROCESS_ERROR_PTRACE, | 58 | JOB_PROCESS_ERROR_PTRACE, |
4989 | 60 | JOB_PROCESS_ERROR_EXEC | 59 | JOB_PROCESS_ERROR_EXEC, |
4990 | 60 | JOB_PROCESS_ERROR_SETUID, | ||
4991 | 61 | JOB_PROCESS_ERROR_SETGID, | ||
4992 | 62 | JOB_PROCESS_ERROR_CHOWN | ||
4993 | 61 | } JobProcessErrorType; | 63 | } JobProcessErrorType; |
4994 | 62 | 64 | ||
4995 | 63 | /** | 65 | /** |
4996 | 64 | 66 | ||
4997 | === modified file 'init/main.c' | |||
4998 | --- init/main.c 2011-05-30 00:06:07 +0000 | |||
4999 | +++ init/main.c 2011-10-14 11:09:18 +0000 | |||
5000 | @@ -1,7 +1,6 @@ |
The diff has been truncated for viewing.