Dmitrijs Ledkovs has proposed merging lp:~xnox/upstart/kfreebsd into lp:upstart.

Requested reviews:
  Upstart Reviewers (upstart-reviewers)

For more details, see:
https://code.launchpad.net/~xnox/upstart/kfreebsd/+merge/196028
-- 
https://code.launchpad.net/~xnox/upstart/kfreebsd/+merge/196028
Your team Upstart Reviewers is requested to review the proposed merge of 
lp:~xnox/upstart/kfreebsd into lp:upstart.
=== added file 'config-freebsd.h'
--- config-freebsd.h	1970-01-01 00:00:00 +0000
+++ config-freebsd.h	2013-11-20 22:14:54 +0000
@@ -0,0 +1,17 @@
+#if defined(__FreeBSD__)
+/* Stolen from sysvinit */
+#ifndef SIGPWR
+#  define SIGPWR SIGUSR2
+#endif
+
+#ifndef CBAUD
+#  define CBAUD         0
+#endif
+#ifndef CBAUDEX
+#  define CBAUDEX       0
+#endif
+
+#define PTRACE_TRACEME PT_TRACE_ME
+#define PTRACE_CONT PT_CONTINUE
+#define PTRACE_DETACH PT_DETACH
+#endif

=== modified file 'configure.ac'
--- configure.ac	2013-11-14 14:33:24 +0000
+++ configure.ac	2013-11-20 22:14:54 +0000
@@ -152,6 +152,7 @@
 
 NIH_LINKER_OPTIMISATIONS
 
+AH_BOTTOM([#include "config-freebsd.h"])
 
 AC_CONFIG_FILES([ Makefile
 		  dbus/Makefile init/Makefile util/Makefile conf/Makefile

=== modified file 'init/job_process.c'
--- init/job_process.c	2013-11-03 02:54:03 +0000
+++ init/job_process.c	2013-11-20 22:14:54 +0000
@@ -1071,21 +1071,31 @@
 		case RLIMIT_AS:
 			res = "as";
 			break;
+#if defined(RLIMIT_LOCKS)
 		case RLIMIT_LOCKS:
 			res = "locks";
 			break;
+#endif
+#if defined(RLIMIT_SIGPENDING)
 		case RLIMIT_SIGPENDING:
 			res = "sigpending";
 			break;
+#endif
+#if defined(RLIMIT_MSGQUEUE)
 		case RLIMIT_MSGQUEUE:
 			res = "msgqueue";
 			break;
+#endif
+#if defined(RLIMIT_NICE)
 		case RLIMIT_NICE:
 			res = "nice";
 			break;
+#endif
+#if defined(RLIMIT_RTPRIO)
 		case RLIMIT_RTPRIO:
 			res = "rtprio";
 			break;
+#endif
 		default:
 			nih_assert_not_reached ();
 		}
@@ -1533,12 +1543,14 @@
 		 * state of the process trace we hold.
 		 */
 		switch (status) {
+#if defined(__linux)
 		case PTRACE_EVENT_FORK:
 			job_process_trace_fork (job, process);
 			break;
 		case PTRACE_EVENT_EXEC:
 			job_process_trace_exec (job, process);
 			break;
+#endif
 		default:
 			nih_assert_not_reached ();
 		}
@@ -1923,14 +1935,18 @@
 	 * get a different kind of notification when it execs to a plain
 	 * SIGTRAP.
 	 */
+#if defined(__linux__)
 	if (ptrace (PTRACE_SETOPTIONS, job->pid[process], NULL,
 		    PTRACE_O_TRACEFORK | PTRACE_O_TRACEEXEC) < 0) {
+#endif
 		nih_warn (_("Failed to set ptrace options for "
 			    "%s %s process (%d): %s"),
 			  job_name (job), process_name (process),
 			  job->pid[process], strerror (errno));
 		return;
+#if defined(__linux__)
 	}
+#endif
 
 	job->trace_state = TRACE_NORMAL;
 
@@ -2051,14 +2067,18 @@
 	    || (job->trace_state != TRACE_NORMAL))
 		return;
 
+#if defined(__linux__)
 	/* Obtain the child process id from the ptrace event. */
 	if (ptrace (PTRACE_GETEVENTMSG, job->pid[process], NULL, &data) < 0) {
+#endif
 		nih_warn (_("Failed to obtain child process id "
 			    "for %s %s process (%d): %s"),
 			  job_name (job), process_name (process),
 			  job->pid[process], strerror (errno));
 		return;
+#if defined(__linux__)
 	}
+#endif
 
 	nih_info (_("%s %s process (%d) became new process (%d)"),
 		  job_name (job), process_name (process),
@@ -2083,13 +2103,17 @@
 	 * waiting at SIGSTOP, in which case a ptrace() call will succeed
 	 * for it.
 	 */
+#if defined(__linux__)
 	if (ptrace (PTRACE_SETOPTIONS, job->pid[process], NULL, 0) < 0) {
+#endif
 		nih_debug ("Failed to set options for new %s %s process (%d), "
 			   "probably not yet forked: %s",
 			   job_name (job), process_name (process),
 			   job->pid[process], strerror (errno));
 		return;
+#if defined(__linux__)
 	}
+#endif
 
 	job_process_trace_new_child (job, process);
 }

=== modified file 'init/main.c'
--- init/main.c	2013-11-05 16:15:19 +0000
+++ init/main.c	2013-11-20 22:14:54 +0000
@@ -46,7 +46,9 @@
 #include <syslog.h>
 #include <unistd.h>
 
+#if defined(__linux__)
 #include <linux/kd.h>
+#endif
 
 #include <nih/macros.h>
 #include <nih/alloc.h>
@@ -293,8 +295,7 @@
 			needs_devtmpfs = 1;
 
 		if (needs_devtmpfs) {
-			if (system_mount ("devtmpfs", "/dev",
-					  MS_NOEXEC | MS_NOSUID, NULL) < 0) {
+			if (system_mount_DEVFS () < 0) {
 				NihError *err;
 
 				err = nih_error_get ();
@@ -310,8 +311,7 @@
 				nih_error ("%s: %s", _("Cannot create directory"), "/dev/pts");
 		}
 
-		if (system_mount ("devpts", "/dev/pts", MS_NOEXEC | MS_NOSUID,
-				  "gid=5,mode=0620") < 0) {
+		if (system_mount_DEVPTS () < 0) {
 			NihError *err;
 
 			err = nih_error_get ();
@@ -327,10 +327,13 @@
 		 * hence these checks are performed as early as is
 		 * feasible.
 		 */
+#if defined(__linux__)
+		system_mknod ("/dev/kmsg", (S_IFCHR | 0600), makedev (1, 11));
+#endif
 		system_mknod ("/dev/null", (S_IFCHR | 0666), makedev (1, 3));
 		system_mknod ("/dev/tty", (S_IFCHR | 0666), makedev (5, 0));
 		system_mknod ("/dev/console", (S_IFCHR | 0600), makedev (5, 1));
-		system_mknod ("/dev/kmsg", (S_IFCHR | 0600), makedev (1, 11));
+
 
 		/* Set the standard file descriptors to the ordinary console device,
 		 * resetting it to sane defaults unless we're inheriting from another
@@ -371,8 +374,7 @@
 		 * ourselves. Also mount /dev/pts to allow CONSOLE_LOG
 		 * to function if booted in an initramfs-less environment.
 		 */
-		if (system_mount ("proc", "/proc",
-				  MS_NODEV | MS_NOEXEC | MS_NOSUID, NULL) < 0) {
+		if (system_mount_PROC () < 0) {
 			NihError *err;
 
 			err = nih_error_get ();
@@ -381,8 +383,8 @@
 			nih_free (err);
 		}
 
-		if (system_mount ("sysfs", "/sys",
-				  MS_NODEV | MS_NOEXEC | MS_NOSUID, NULL) < 0) {
+#ifdef system_mount_SYSFS
+		if (system_mount_SYSFS () < 0) {
 			NihError *err;
 
 			err = nih_error_get ();
@@ -390,6 +392,7 @@
 				err->message);
 			nih_free (err);
 		}
+#endif
 
 	} else {
 		nih_debug ("Running with UID %d as PID %d (PPID %d)",
@@ -437,10 +440,13 @@
 		/* Ask the kernel to send us SIGINT when control-alt-delete is
 		 * pressed; generate an event with the same name.
 		 */
+#if defined(__linux__)
 		reboot (RB_DISABLE_CAD);
+#endif
 		nih_signal_set_handler (SIGINT, nih_signal_handler);
 		NIH_MUST (nih_signal_add_handler (NULL, SIGINT, cad_handler, NULL));
 
+#if defined(__linux__)
 		/* Ask the kernel to send us SIGWINCH when alt-uparrow is pressed;
 		 * generate a keyboard-request event.
 		 */
@@ -449,7 +455,7 @@
 			NIH_MUST (nih_signal_add_handler (NULL, SIGWINCH,
 						kbd_handler, NULL));
 		}
-
+#endif
 		/* powstatd sends us SIGPWR when it changes /etc/powerstatus */
 		nih_signal_set_handler (SIGPWR, nih_signal_handler);
 		NIH_MUST (nih_signal_add_handler (NULL, SIGPWR, pwr_handler, NULL));

=== modified file 'init/parse_job.c'
--- init/parse_job.c	2013-07-21 23:54:16 +0000
+++ init/parse_job.c	2013-11-20 22:14:54 +0000
@@ -2641,20 +2641,28 @@
 		resource = RLIMIT_FSIZE;
 	} else if (! strcmp (arg, "memlock")) {
 		resource = RLIMIT_MEMLOCK;
+#if defined(RLIMIT_MSGQUEUE)
 	} else if (! strcmp (arg, "msgqueue")) {
 		resource = RLIMIT_MSGQUEUE;
+#endif
+#if defined(RLIMIT_NICE)
 	} else if (! strcmp (arg, "nice")) {
 		resource = RLIMIT_NICE;
+#endif
 	} else if (! strcmp (arg, "nofile")) {
 		resource = RLIMIT_NOFILE;
 	} else if (! strcmp (arg, "nproc")) {
 		resource = RLIMIT_NPROC;
 	} else if (! strcmp (arg, "rss")) {
 		resource = RLIMIT_RSS;
+#if defined(RLIMIT_RTPRIO)
 	} else if (! strcmp (arg, "rtprio")) {
 		resource = RLIMIT_RTPRIO;
+#endif
+#if defined(RLIMIT_SIGPENDING)
 	} else if (! strcmp (arg, "sigpending")) {
 		resource = RLIMIT_SIGPENDING;
+#endif
 	} else if (! strcmp (arg, "stack")) {
 		resource = RLIMIT_STACK;
 	} else {

=== modified file 'init/system.c'
--- init/system.c	2013-10-25 19:11:25 +0000
+++ init/system.c	2013-11-20 22:14:54 +0000
@@ -207,12 +207,29 @@
 		return 0;
 
 	/* Mount the filesystem */
-	if (mount ("none", dir, type, flags, options) < 0)
+	if (MOUNT (dir, type, flags, options) < 0)
 		nih_return_system_error (-1);
 
 	return 0;
 }
 
+
+/**
+ * system_mount_NAME:
+ *
+ * Implement wrapper system_mount functions for well known
+ * filesystems, e.g. proc.
+ **/
+#define MOUNT_POINT(name, type, dir, flags, options)		\
+	int							\
+	system_mount_##name(void)				\
+	{							\
+		return system_mount(type, dir, flags, options);	\
+	}
+	MOUNT_POINTS
+#undef MOUNT_POINT
+
+
 /**
  * system_mknod:
  *

=== modified file 'init/system.h'
--- init/system.h	2013-10-25 19:11:25 +0000
+++ init/system.h	2013-11-20 22:14:54 +0000
@@ -26,6 +26,22 @@
 
 #include "job_class.h"
 
+#if defined(__linux__)
+#define MOUNT_POINTS \
+	MOUNT_POINT(PROC, "proc", "/proc", (MS_NODEV | MS_NOEXEC | MS_NOSUID), NULL) \
+	MOUNT_POINT(DEVFS, "devtmpfs", "/dev", (MS_NOEXEC | MS_NOSUID), NULL) \
+	MOUNT_POINT(DEVPTS, "devpts", "/dev/pts", (MS_NOEXEC | MS_NOSUID), "gid=5,mode=0620") \
+	MOUNT_POINT(SYSFS, "sysfs", "/sys", (MS_NODEV | MS_NOEXEC | MS_NOSUID), NULL)
+#define MOUNT(type, dir, flags, options) mount("none", dir, type, flags, options)
+#elif defined (__FreeBSD__)
+#define MOUNT_POINTS \
+	MOUNT_POINT(PROC, "linprocfs", "/proc", MNT_LOCAL, NULL)		\
+	MOUNT_POINT(DEVFS, "devfs", "/dev", (MNT_LOCAL | MNT_MULTILABEL), NULL) \
+	MOUNT_POINT(DEVPTS, "fdescfs", "/dev/fd", 0, NULL)
+#define MOUNT(type, dir, flags, options) mount(type, dir, flags, options)
+#else
+#define MOUNT_POINTS "Mount points unknown for target"
+#endif
 
 NIH_BEGIN_EXTERN
 
@@ -44,6 +60,10 @@
 int  system_check_file   (const char *path, mode_t type, dev_t dev)
 	__attribute__ ((warn_unused_result));
 
+#define MOUNT_POINT(name, type, dir, flags, options) int system_mount_##name(void);
+        MOUNT_POINTS
+#undef MOUNT_POINT
+
 NIH_END_EXTERN
 
 #endif /* INIT_SYSTEM_H */

=== modified file 'init/tests/test_job.c'
--- init/tests/test_job.c	2013-08-23 12:46:42 +0000
+++ init/tests/test_job.c	2013-11-20 22:14:54 +0000
@@ -7410,6 +7410,7 @@
 	}
 }
 
+#if defined(__linux__)
 void
 test_deserialise_ptrace (void)
 {
@@ -7492,7 +7493,7 @@
 		/* Continue in deserialise_ptrace_next */
 	}
 }
-
+#endif
 
 void
 deserialise_ptrace_next (void)
@@ -7605,8 +7606,9 @@
 	test_get_state ();
 
 	test_get_processes ();
-
+#if defined(__linux__)
 	test_deserialise_ptrace ();
+#endif
 
 	return 0;
 }

=== modified file 'init/tests/test_job_process.c'
--- init/tests/test_job_process.c	2013-11-11 10:13:08 +0000
+++ init/tests/test_job_process.c	2013-11-20 22:14:54 +0000
@@ -8535,7 +8535,7 @@
 
 	class->expect = EXPECT_NONE;
 
-
+#if defined(__linux__)
 	/* Check that when a process forks and we receive the event for
 	 * the parent before the child (faked by killing the child), the
 	 * trace state is to expect a new child - with the state updated
@@ -8682,7 +8682,6 @@
 
 	class->expect = EXPECT_NONE;
 
-
 	/* Check that should the process call exec() before the first fork()
 	 * it's allowed since it's likely a shell script calling the real
 	 * thing that we want to follow.
@@ -8789,7 +8788,7 @@
 
 		nih_free (job);
 	}
-
+#endif
 	class->expect = EXPECT_NONE;
 #if HAVE_VALGRIND_VALGRIND_H
 	}

=== modified file 'init/tests/test_parse_job.c'
--- init/tests/test_parse_job.c	2013-07-21 23:54:16 +0000
+++ init/tests/test_parse_job.c	2013-11-20 22:14:54 +0000
@@ -7608,7 +7608,7 @@
 		nih_free (job);
 	}
 
-
+#if defined(RLIMIT_MSGQUEUE)
 	/* Check that the limit msgqueue stanza sets the RLIMIT_MSGQUEUE
 	 * resource.
 	 */
@@ -7642,8 +7642,9 @@
 
 		nih_free (job);
 	}
-
-
+#endif
+
+#if defined(RLIMIT_NICE)
 	/* Check that the limit nice stanza sets the RLIMIT_NICE resource.
 	 */
 	TEST_FEATURE ("with nice limit");
@@ -7676,7 +7677,7 @@
 
 		nih_free (job);
 	}
-
+#endif
 
 	/* Check that the limit nofile stanza sets the RLIMIT_NOFILE
 	 * resource.
@@ -7780,7 +7781,7 @@
 		nih_free (job);
 	}
 
-
+#if defined(RLIMIT_RTPRIO)
 	/* Check that the limit rtprio stanza sets the RLIMIT_RTPRIO resource.
 	 */
 	TEST_FEATURE ("with rtprio limit");
@@ -7813,8 +7814,9 @@
 
 		nih_free (job);
 	}
-
-
+#endif
+
+#if defined(RLIMIT_SIGPENDING)
 	/* Check that the limit sigpending stanza sets the RLIMIT_SIGPENDING
 	 * resource.
 	 */
@@ -7848,7 +7850,7 @@
 
 		nih_free (job);
 	}
-
+#endif
 
 	/* Check that the limit stack stanza sets the RLIMIT_STACK resource.
 	 */

=== modified file 'util/reboot.c'
--- util/reboot.c	2013-08-22 11:13:41 +0000
+++ util/reboot.c	2013-11-20 22:14:54 +0000
@@ -21,8 +21,9 @@
 # include <config.h>
 #endif /* HAVE_CONFIG_H */
 
-
+#if defined(__linux__)
 #include <linux/reboot.h>
+#endif
 #include <sys/reboot.h>
 #include <sys/syscall.h>
 
@@ -237,9 +238,10 @@
 	if (! no_sync)
 		sync ();
 
+#if defined(RB_ENABLE_CAD)
 	/* Re-enable Control-Alt-Delete in case it breaks */
 	reboot (RB_ENABLE_CAD);
-
+#endif
 	/* Do the syscall */
 	switch (mode) {
 	case REBOOT:
@@ -254,6 +256,7 @@
 		nih_info (_("Powering off"));
 		reboot (RB_POWER_OFF);
 		break;
+#if defined(__linux__)
 	case REBOOTCOMMAND:
 		nih_info (_("Rebooting with %s"), rebootcommand);
 		syscall (SYS_reboot,
@@ -261,10 +264,13 @@
 			 LINUX_REBOOT_MAGIC2,
 			 LINUX_REBOOT_CMD_RESTART2,
 			 rebootcommand);
+#endif
 	}
 
+#if defined(__linux_)
 	/* Shouldn't get here, but if we do, carry on */
 	reboot (RB_DISABLE_CAD);
+#endif
 
 	return 0;
 }

-- 
upstart-devel mailing list
[email protected]
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/upstart-devel

Reply via email to