Merge lp:~xnox/upstart/kfreebsd into lp:upstart

Proposed by Dimitri John Ledkov
Status: Work in progress
Proposed branch: lp:~xnox/upstart/kfreebsd
Merge into: lp:upstart
Diff against target: 541 lines (+134/-27)
12 files modified
config-freebsd.h (+19/-0)
configure.ac (+1/-0)
init/job_process.c (+24/-0)
init/main.c (+16/-10)
init/parse_job.c (+8/-0)
init/state.c (+4/-1)
init/system.c (+18/-1)
init/system.h (+20/-0)
init/tests/test_job.c (+4/-2)
init/tests/test_job_process.c (+2/-3)
init/tests/test_parse_job.c (+10/-8)
util/reboot.c (+8/-2)
To merge this branch: bzr merge lp:~xnox/upstart/kfreebsd
Reviewer Review Type Date Requested Status
Upstart Reviewers Pending
Review via email: mp+196028@code.launchpad.net
To post a comment you must log in.
lp:~xnox/upstart/kfreebsd updated
1578. By xnox <xnox@localhost>

Unbreak build

1579. By Dimitri John Ledkov

Merge trunk

Unmerged revisions

1579. By Dimitri John Ledkov

Merge trunk

1578. By xnox <xnox@localhost>

Unbreak build

1577. By Dimitri John Ledkov

Start on freebsd

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'config-freebsd.h'
2--- config-freebsd.h 1970-01-01 00:00:00 +0000
3+++ config-freebsd.h 2013-12-31 00:12:51 +0000
4@@ -0,0 +1,19 @@
5+#if defined(__FreeBSD_kernel__)
6+/* Stolen from sysvinit */
7+#ifndef SIGPWR
8+# define SIGPWR SIGUSR2
9+#endif
10+
11+#ifndef CBAUD
12+# define CBAUD 0
13+#endif
14+#ifndef CBAUDEX
15+# define CBAUDEX 0
16+#endif
17+
18+#define PTRACE_TRACEME PT_TRACE_ME
19+#define PTRACE_CONT PT_CONTINUE
20+#define PTRACE_DETACH PT_DETACH
21+
22+#define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC_FAST
23+#endif
24
25=== modified file 'configure.ac'
26--- configure.ac 2013-11-14 14:33:24 +0000
27+++ configure.ac 2013-12-31 00:12:51 +0000
28@@ -152,6 +152,7 @@
29
30 NIH_LINKER_OPTIMISATIONS
31
32+AH_BOTTOM([#include "config-freebsd.h"])
33
34 AC_CONFIG_FILES([ Makefile
35 dbus/Makefile init/Makefile util/Makefile conf/Makefile
36
37=== modified file 'init/job_process.c'
38--- init/job_process.c 2013-11-03 02:54:03 +0000
39+++ init/job_process.c 2013-12-31 00:12:51 +0000
40@@ -1071,21 +1071,31 @@
41 case RLIMIT_AS:
42 res = "as";
43 break;
44+#if defined(RLIMIT_LOCKS)
45 case RLIMIT_LOCKS:
46 res = "locks";
47 break;
48+#endif
49+#if defined(RLIMIT_SIGPENDING)
50 case RLIMIT_SIGPENDING:
51 res = "sigpending";
52 break;
53+#endif
54+#if defined(RLIMIT_MSGQUEUE)
55 case RLIMIT_MSGQUEUE:
56 res = "msgqueue";
57 break;
58+#endif
59+#if defined(RLIMIT_NICE)
60 case RLIMIT_NICE:
61 res = "nice";
62 break;
63+#endif
64+#if defined(RLIMIT_RTPRIO)
65 case RLIMIT_RTPRIO:
66 res = "rtprio";
67 break;
68+#endif
69 default:
70 nih_assert_not_reached ();
71 }
72@@ -1533,12 +1543,14 @@
73 * state of the process trace we hold.
74 */
75 switch (status) {
76+#if defined(__linux)
77 case PTRACE_EVENT_FORK:
78 job_process_trace_fork (job, process);
79 break;
80 case PTRACE_EVENT_EXEC:
81 job_process_trace_exec (job, process);
82 break;
83+#endif
84 default:
85 nih_assert_not_reached ();
86 }
87@@ -1923,14 +1935,18 @@
88 * get a different kind of notification when it execs to a plain
89 * SIGTRAP.
90 */
91+#if defined(__linux__)
92 if (ptrace (PTRACE_SETOPTIONS, job->pid[process], NULL,
93 PTRACE_O_TRACEFORK | PTRACE_O_TRACEEXEC) < 0) {
94+#endif
95 nih_warn (_("Failed to set ptrace options for "
96 "%s %s process (%d): %s"),
97 job_name (job), process_name (process),
98 job->pid[process], strerror (errno));
99 return;
100+#if defined(__linux__)
101 }
102+#endif
103
104 job->trace_state = TRACE_NORMAL;
105
106@@ -2051,14 +2067,18 @@
107 || (job->trace_state != TRACE_NORMAL))
108 return;
109
110+#if defined(__linux__)
111 /* Obtain the child process id from the ptrace event. */
112 if (ptrace (PTRACE_GETEVENTMSG, job->pid[process], NULL, &data) < 0) {
113+#endif
114 nih_warn (_("Failed to obtain child process id "
115 "for %s %s process (%d): %s"),
116 job_name (job), process_name (process),
117 job->pid[process], strerror (errno));
118 return;
119+#if defined(__linux__)
120 }
121+#endif
122
123 nih_info (_("%s %s process (%d) became new process (%d)"),
124 job_name (job), process_name (process),
125@@ -2083,13 +2103,17 @@
126 * waiting at SIGSTOP, in which case a ptrace() call will succeed
127 * for it.
128 */
129+#if defined(__linux__)
130 if (ptrace (PTRACE_SETOPTIONS, job->pid[process], NULL, 0) < 0) {
131+#endif
132 nih_debug ("Failed to set options for new %s %s process (%d), "
133 "probably not yet forked: %s",
134 job_name (job), process_name (process),
135 job->pid[process], strerror (errno));
136 return;
137+#if defined(__linux__)
138 }
139+#endif
140
141 job_process_trace_new_child (job, process);
142 }
143
144=== modified file 'init/main.c'
145--- init/main.c 2013-11-05 16:15:19 +0000
146+++ init/main.c 2013-12-31 00:12:51 +0000
147@@ -46,7 +46,9 @@
148 #include <syslog.h>
149 #include <unistd.h>
150
151+#if defined(__linux__)
152 #include <linux/kd.h>
153+#endif
154
155 #include <nih/macros.h>
156 #include <nih/alloc.h>
157@@ -293,8 +295,7 @@
158 needs_devtmpfs = 1;
159
160 if (needs_devtmpfs) {
161- if (system_mount ("devtmpfs", "/dev",
162- MS_NOEXEC | MS_NOSUID, NULL) < 0) {
163+ if (system_mount_DEVFS () < 0) {
164 NihError *err;
165
166 err = nih_error_get ();
167@@ -310,8 +311,7 @@
168 nih_error ("%s: %s", _("Cannot create directory"), "/dev/pts");
169 }
170
171- if (system_mount ("devpts", "/dev/pts", MS_NOEXEC | MS_NOSUID,
172- "gid=5,mode=0620") < 0) {
173+ if (system_mount_DEVPTS () < 0) {
174 NihError *err;
175
176 err = nih_error_get ();
177@@ -327,10 +327,13 @@
178 * hence these checks are performed as early as is
179 * feasible.
180 */
181+#if defined(__linux__)
182+ system_mknod ("/dev/kmsg", (S_IFCHR | 0600), makedev (1, 11));
183+#endif
184 system_mknod ("/dev/null", (S_IFCHR | 0666), makedev (1, 3));
185 system_mknod ("/dev/tty", (S_IFCHR | 0666), makedev (5, 0));
186 system_mknod ("/dev/console", (S_IFCHR | 0600), makedev (5, 1));
187- system_mknod ("/dev/kmsg", (S_IFCHR | 0600), makedev (1, 11));
188+
189
190 /* Set the standard file descriptors to the ordinary console device,
191 * resetting it to sane defaults unless we're inheriting from another
192@@ -371,8 +374,7 @@
193 * ourselves. Also mount /dev/pts to allow CONSOLE_LOG
194 * to function if booted in an initramfs-less environment.
195 */
196- if (system_mount ("proc", "/proc",
197- MS_NODEV | MS_NOEXEC | MS_NOSUID, NULL) < 0) {
198+ if (system_mount_PROC () < 0) {
199 NihError *err;
200
201 err = nih_error_get ();
202@@ -381,8 +383,8 @@
203 nih_free (err);
204 }
205
206- if (system_mount ("sysfs", "/sys",
207- MS_NODEV | MS_NOEXEC | MS_NOSUID, NULL) < 0) {
208+#ifdef system_mount_SYSFS
209+ if (system_mount_SYSFS () < 0) {
210 NihError *err;
211
212 err = nih_error_get ();
213@@ -390,6 +392,7 @@
214 err->message);
215 nih_free (err);
216 }
217+#endif
218
219 } else {
220 nih_debug ("Running with UID %d as PID %d (PPID %d)",
221@@ -437,10 +440,13 @@
222 /* Ask the kernel to send us SIGINT when control-alt-delete is
223 * pressed; generate an event with the same name.
224 */
225+#if defined(__linux__)
226 reboot (RB_DISABLE_CAD);
227+#endif
228 nih_signal_set_handler (SIGINT, nih_signal_handler);
229 NIH_MUST (nih_signal_add_handler (NULL, SIGINT, cad_handler, NULL));
230
231+#if defined(__linux__)
232 /* Ask the kernel to send us SIGWINCH when alt-uparrow is pressed;
233 * generate a keyboard-request event.
234 */
235@@ -449,7 +455,7 @@
236 NIH_MUST (nih_signal_add_handler (NULL, SIGWINCH,
237 kbd_handler, NULL));
238 }
239-
240+#endif
241 /* powstatd sends us SIGPWR when it changes /etc/powerstatus */
242 nih_signal_set_handler (SIGPWR, nih_signal_handler);
243 NIH_MUST (nih_signal_add_handler (NULL, SIGPWR, pwr_handler, NULL));
244
245=== modified file 'init/parse_job.c'
246--- init/parse_job.c 2013-07-21 23:54:16 +0000
247+++ init/parse_job.c 2013-12-31 00:12:51 +0000
248@@ -2641,20 +2641,28 @@
249 resource = RLIMIT_FSIZE;
250 } else if (! strcmp (arg, "memlock")) {
251 resource = RLIMIT_MEMLOCK;
252+#if defined(RLIMIT_MSGQUEUE)
253 } else if (! strcmp (arg, "msgqueue")) {
254 resource = RLIMIT_MSGQUEUE;
255+#endif
256+#if defined(RLIMIT_NICE)
257 } else if (! strcmp (arg, "nice")) {
258 resource = RLIMIT_NICE;
259+#endif
260 } else if (! strcmp (arg, "nofile")) {
261 resource = RLIMIT_NOFILE;
262 } else if (! strcmp (arg, "nproc")) {
263 resource = RLIMIT_NPROC;
264 } else if (! strcmp (arg, "rss")) {
265 resource = RLIMIT_RSS;
266+#if defined(RLIMIT_RTPRIO)
267 } else if (! strcmp (arg, "rtprio")) {
268 resource = RLIMIT_RTPRIO;
269+#endif
270+#if defined(RLIMIT_SIGPENDING)
271 } else if (! strcmp (arg, "sigpending")) {
272 resource = RLIMIT_SIGPENDING;
273+#endif
274 } else if (! strcmp (arg, "stack")) {
275 resource = RLIMIT_STACK;
276 } else {
277
278=== modified file 'init/state.c'
279--- init/state.c 2013-10-11 13:35:51 +0000
280+++ init/state.c 2013-12-31 00:12:51 +0000
281@@ -1046,8 +1046,11 @@
282 for (i = 0; i < json_object_array_length (json_limits); i++) {
283 json_object *json_rlimit;
284
285+#if defined(__FreeBSD_kernel__)
286+ if (i > RLIMIT_NLIMITS) continue;
287+#else
288 nih_assert (i <= RLIMIT_NLIMITS);
289-
290+#endif
291 json_rlimit = json_object_array_get_idx (json_limits, i);
292 if (! json_rlimit)
293 goto error;
294
295=== modified file 'init/system.c'
296--- init/system.c 2013-10-25 19:11:25 +0000
297+++ init/system.c 2013-12-31 00:12:51 +0000
298@@ -207,12 +207,29 @@
299 return 0;
300
301 /* Mount the filesystem */
302- if (mount ("none", dir, type, flags, options) < 0)
303+ if (MOUNT (dir, type, flags, options) < 0)
304 nih_return_system_error (-1);
305
306 return 0;
307 }
308
309+
310+/**
311+ * system_mount_NAME:
312+ *
313+ * Implement wrapper system_mount functions for well known
314+ * filesystems, e.g. proc.
315+ **/
316+#define MOUNT_POINT(name, type, dir, flags, options) \
317+ int \
318+ system_mount_##name(void) \
319+ { \
320+ return system_mount(type, dir, flags, options); \
321+ }
322+ MOUNT_POINTS
323+#undef MOUNT_POINT
324+
325+
326 /**
327 * system_mknod:
328 *
329
330=== modified file 'init/system.h'
331--- init/system.h 2013-10-25 19:11:25 +0000
332+++ init/system.h 2013-12-31 00:12:51 +0000
333@@ -26,6 +26,22 @@
334
335 #include "job_class.h"
336
337+#if defined(__linux__)
338+#define MOUNT_POINTS \
339+ MOUNT_POINT(PROC, "proc", "/proc", (MS_NODEV | MS_NOEXEC | MS_NOSUID), NULL) \
340+ MOUNT_POINT(DEVFS, "devtmpfs", "/dev", (MS_NOEXEC | MS_NOSUID), NULL) \
341+ MOUNT_POINT(DEVPTS, "devpts", "/dev/pts", (MS_NOEXEC | MS_NOSUID), "gid=5,mode=0620") \
342+ MOUNT_POINT(SYSFS, "sysfs", "/sys", (MS_NODEV | MS_NOEXEC | MS_NOSUID), NULL)
343+#define MOUNT(type, dir, flags, options) mount("none", dir, type, flags, options)
344+#elif defined (__FreeBSD_kernel__)
345+#define MOUNT_POINTS \
346+ MOUNT_POINT(PROC, "linprocfs", "/proc", MNT_LOCAL, NULL) \
347+ MOUNT_POINT(DEVFS, "devfs", "/dev", (MNT_LOCAL | MNT_MULTILABEL), NULL) \
348+ MOUNT_POINT(DEVPTS, "fdescfs", "/dev/fd", 0, NULL)
349+#define MOUNT(type, dir, flags, options) mount(type, dir, flags, NULL)
350+#else
351+#define MOUNT_POINTS "Mount points unknown for target"
352+#endif
353
354 NIH_BEGIN_EXTERN
355
356@@ -44,6 +60,10 @@
357 int system_check_file (const char *path, mode_t type, dev_t dev)
358 __attribute__ ((warn_unused_result));
359
360+#define MOUNT_POINT(name, type, dir, flags, options) int system_mount_##name(void);
361+ MOUNT_POINTS
362+#undef MOUNT_POINT
363+
364 NIH_END_EXTERN
365
366 #endif /* INIT_SYSTEM_H */
367
368=== modified file 'init/tests/test_job.c'
369--- init/tests/test_job.c 2013-08-23 12:46:42 +0000
370+++ init/tests/test_job.c 2013-12-31 00:12:51 +0000
371@@ -7410,6 +7410,7 @@
372 }
373 }
374
375+#if defined(__linux__)
376 void
377 test_deserialise_ptrace (void)
378 {
379@@ -7492,7 +7493,7 @@
380 /* Continue in deserialise_ptrace_next */
381 }
382 }
383-
384+#endif
385
386 void
387 deserialise_ptrace_next (void)
388@@ -7605,8 +7606,9 @@
389 test_get_state ();
390
391 test_get_processes ();
392-
393+#if defined(__linux__)
394 test_deserialise_ptrace ();
395+#endif
396
397 return 0;
398 }
399
400=== modified file 'init/tests/test_job_process.c'
401--- init/tests/test_job_process.c 2013-11-11 10:13:08 +0000
402+++ init/tests/test_job_process.c 2013-12-31 00:12:51 +0000
403@@ -8535,7 +8535,7 @@
404
405 class->expect = EXPECT_NONE;
406
407-
408+#if defined(__linux__)
409 /* Check that when a process forks and we receive the event for
410 * the parent before the child (faked by killing the child), the
411 * trace state is to expect a new child - with the state updated
412@@ -8682,7 +8682,6 @@
413
414 class->expect = EXPECT_NONE;
415
416-
417 /* Check that should the process call exec() before the first fork()
418 * it's allowed since it's likely a shell script calling the real
419 * thing that we want to follow.
420@@ -8789,7 +8788,7 @@
421
422 nih_free (job);
423 }
424-
425+#endif
426 class->expect = EXPECT_NONE;
427 #if HAVE_VALGRIND_VALGRIND_H
428 }
429
430=== modified file 'init/tests/test_parse_job.c'
431--- init/tests/test_parse_job.c 2013-07-21 23:54:16 +0000
432+++ init/tests/test_parse_job.c 2013-12-31 00:12:51 +0000
433@@ -7608,7 +7608,7 @@
434 nih_free (job);
435 }
436
437-
438+#if defined(RLIMIT_MSGQUEUE)
439 /* Check that the limit msgqueue stanza sets the RLIMIT_MSGQUEUE
440 * resource.
441 */
442@@ -7642,8 +7642,9 @@
443
444 nih_free (job);
445 }
446-
447-
448+#endif
449+
450+#if defined(RLIMIT_NICE)
451 /* Check that the limit nice stanza sets the RLIMIT_NICE resource.
452 */
453 TEST_FEATURE ("with nice limit");
454@@ -7676,7 +7677,7 @@
455
456 nih_free (job);
457 }
458-
459+#endif
460
461 /* Check that the limit nofile stanza sets the RLIMIT_NOFILE
462 * resource.
463@@ -7780,7 +7781,7 @@
464 nih_free (job);
465 }
466
467-
468+#if defined(RLIMIT_RTPRIO)
469 /* Check that the limit rtprio stanza sets the RLIMIT_RTPRIO resource.
470 */
471 TEST_FEATURE ("with rtprio limit");
472@@ -7813,8 +7814,9 @@
473
474 nih_free (job);
475 }
476-
477-
478+#endif
479+
480+#if defined(RLIMIT_SIGPENDING)
481 /* Check that the limit sigpending stanza sets the RLIMIT_SIGPENDING
482 * resource.
483 */
484@@ -7848,7 +7850,7 @@
485
486 nih_free (job);
487 }
488-
489+#endif
490
491 /* Check that the limit stack stanza sets the RLIMIT_STACK resource.
492 */
493
494=== modified file 'util/reboot.c'
495--- util/reboot.c 2013-08-22 11:13:41 +0000
496+++ util/reboot.c 2013-12-31 00:12:51 +0000
497@@ -21,8 +21,9 @@
498 # include <config.h>
499 #endif /* HAVE_CONFIG_H */
500
501-
502+#if defined(__linux__)
503 #include <linux/reboot.h>
504+#endif
505 #include <sys/reboot.h>
506 #include <sys/syscall.h>
507
508@@ -237,9 +238,10 @@
509 if (! no_sync)
510 sync ();
511
512+#if defined(RB_ENABLE_CAD)
513 /* Re-enable Control-Alt-Delete in case it breaks */
514 reboot (RB_ENABLE_CAD);
515-
516+#endif
517 /* Do the syscall */
518 switch (mode) {
519 case REBOOT:
520@@ -254,6 +256,7 @@
521 nih_info (_("Powering off"));
522 reboot (RB_POWER_OFF);
523 break;
524+#if defined(__linux__)
525 case REBOOTCOMMAND:
526 nih_info (_("Rebooting with %s"), rebootcommand);
527 syscall (SYS_reboot,
528@@ -261,10 +264,13 @@
529 LINUX_REBOOT_MAGIC2,
530 LINUX_REBOOT_CMD_RESTART2,
531 rebootcommand);
532+#endif
533 }
534
535+#if defined(__linux_)
536 /* Shouldn't get here, but if we do, carry on */
537 reboot (RB_DISABLE_CAD);
538+#endif
539
540 return 0;
541 }

Subscribers

People subscribed via source and target branches