Dimitri John Ledkov has proposed merging lp:~xnox/upstart/aux1 into lp:upstart.
Requested reviews:
Upstart Reviewers (upstart-reviewers)
For more details, see:
https://code.launchpad.net/~xnox/upstart/aux1/+merge/218787
I've started to review lp:~jamesodhunt/upstart/async-spawn.WIP, but it turned
out to be a very large branch, with multiple changes & debugging intermixed.
So I've picked it apart into individual commits that are self-contained:
* bitesize pieces
* which compile cleanly
* which compile all tests
* and pass all tests
So far these are trivial auxiliary changes, which can be merged independently
of the rest of the async branch changes.
--
https://code.launchpad.net/~xnox/upstart/aux1/+merge/218787
Your team Upstart Reviewers is requested to review the proposed merge of
lp:~xnox/upstart/aux1 into lp:upstart.
=== modified file 'doc/states.dot'
--- doc/states.dot 2014-03-05 11:17:37 +0000
+++ doc/states.dot 2014-05-08 11:48:46 +0000
@@ -26,38 +26,73 @@
waiting [shape=diamond];
starting [label="starting\n(emit starting)"];
security [label="security"];
+ security_spawning [label="security-spawning"];
+ pre_starting [label="pre-starting"];
pre_start [label="pre-start"];
+ spawning [label="spawning"];
spawned [label="spawned\n(wait for pid)"];
+ post_starting [label="post-starting"];
post_start [label="post-start"];
emit_started [shape=rectangle,label="emit started"];
running [shape=diamond];
+ pre_stopping [label="pre-stopping"];
pre_stop [label="pre-stop"];
stopping [label="stopping\n(emit stopping)"];
killed [label="killed\n(wait for SIGCHLD)"];
+ post_stopping [label="post-stopping"];
post_stop [label="post-stop"];
emit_stopped [shape=rectangle,label="emit stopped"];
waiting -> starting [color=green];
- starting -> security [color=green];
- security -> pre_start [color=green];
+
+ starting -> security_spawning [color=green];
+ starting -> stopping [color=red];
+
+ security_spawning -> security [color=green];
+ security_spawning -> stopping [color=red];
+
+ security -> pre_starting [color=green];
security -> stopping [color=red];
- starting -> stopping [color=red];
- pre_start -> spawned [color=green];
+
+ pre_starting -> pre_start [color=green];
+ pre_starting -> stopping [color=red];
+
+ pre_start -> spawning [color=green];
pre_start -> stopping [color=red];
- spawned -> post_start [color=green];
+
+ spawning -> spawned [color=green];
+ spawning -> stopping [color=red];
+
+ spawned -> post_starting [color=green];
spawned -> stopping [color=red];
+
+ post_starting -> post_start [color=green];
+ post_starting -> stopping [color=red];
+
post_start -> emit_started -> running [color=green];
post_start -> stopping [color=red];
- running -> pre_stop [color=red,label="pid > 0"];
+
+ running -> pre_stopping [color=red,label="pid > 0"];
running -> stopping [color=red,label="pid == 0"];
running -> stopping [color=green,label="respawn"];
+
+ pre_stopping -> pre_stop [color=green];
+ pre_stopping -> pre_stop [color=red];
+
pre_stop -> running [color=green];
pre_stop -> stopping [color=red];
+
stopping -> killed [color=green];
stopping -> killed [color=red];
- killed -> post_stop [color=green];
- killed -> post_stop [color=red];
+
+ killed -> post_stopping [color=green];
+ killed -> post_stopping [color=red];
+
+ post_stopping -> post_stop [color=green];
+ post_stopping -> waiting [color=red];
+
post_stop -> starting [color=green];
post_stop -> emit_stopped [color=red];
+
emit_stopped -> waiting [color=red];
}
=== removed file 'doc/states.png'
Binary files doc/states.png 2014-03-05 11:17:37 +0000 and doc/states.png 1970-01-01 00:00:00 +0000 differ
=== modified file 'init/Makefile.am'
--- init/Makefile.am 2013-11-12 14:00:36 +0000
+++ init/Makefile.am 2014-05-08 11:48:46 +0000
@@ -265,6 +265,7 @@
session.o log.o state.o xdg.o apparmor.o \
com.ubuntu.Upstart.o \
com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \
+ $(top_builddir)/test/libtest_util_common.a \
$(NIH_LIBS) \
$(NIH_DBUS_LIBS) \
$(DBUS_LIBS) \
=== modified file 'init/job_class.c'
--- init/job_class.c 2014-05-07 16:34:44 +0000
+++ init/job_class.c 2014-05-08 11:48:46 +0000
@@ -2584,14 +2584,14 @@
if (fd < 0)
continue;
- if (state_toggle_cloexec (fd, FALSE) < 0)
+ if (state_modify_cloexec (fd, FALSE) < 0)
goto error;
fd = log->fd;
if (fd < 0)
continue;
- if (state_toggle_cloexec (fd, FALSE) < 0)
+ if (state_modify_cloexec (fd, FALSE) < 0)
goto error;
}
}
=== modified file 'init/log.c'
--- init/log.c 2014-05-07 16:34:44 +0000
+++ init/log.c 2014-05-08 11:48:46 +0000
@@ -974,7 +974,7 @@
nih_assert (io_watch_fd != -1);
/* re-apply CLOEXEC flag to stop job fd being leaked to children */
- if (state_toggle_cloexec (io_watch_fd, TRUE) < 0)
+ if (state_modify_cloexec (io_watch_fd, TRUE) < 0)
return NULL;
if (! state_get_json_int_var (json, "uid", uid))
@@ -993,7 +993,7 @@
* we would never close the fd.
*/
if (log->fd != -1)
- (void)state_toggle_cloexec (log->fd, TRUE);
+ (void)state_modify_cloexec (log->fd, TRUE);
log->unflushed = nih_io_buffer_new (log);
if (! log->unflushed)
=== modified file 'init/state.c'
--- init/state.c 2014-05-07 16:34:44 +0000
+++ init/state.c 2014-05-08 11:48:46 +0000
@@ -532,7 +532,7 @@
/**
- * state_toggle_cloexec:
+ * state_modify_cloexec:
*
* @fd: file descriptor,
* @set: set close-on-exec flag if TRUE, clear if FALSE.
@@ -542,7 +542,7 @@
* Returns: 0 on success, -1 on error.
**/
int
-state_toggle_cloexec (int fd, int set)
+state_modify_cloexec (int fd, int set)
{
long flags;
int ret;
=== modified file 'init/state.h'
--- init/state.h 2013-06-04 16:51:55 +0000
+++ init/state.h 2014-05-08 11:48:46 +0000
@@ -1144,7 +1144,7 @@
int state_from_string (const char *state)
__attribute__ ((warn_unused_result));
-int state_toggle_cloexec (int fd, int set);
+int state_modify_cloexec (int fd, int set);
json_object *
state_serialise_str_array (char ** const array)
=== 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 2014-05-08 11:48:46 +0000
@@ -147,33 +147,6 @@
static int get_available_pty_count (void) __attribute__((unused));
static void close_all_files (void);
-/**
- * fd_valid:
- * @fd: file descriptor.
- *
- * Return 1 if @fd is valid, else 0.
- **/
-static int
-fd_valid (int fd)
-{
- int flags = 0;
-
- if (fd < 0)
- return 0;
-
- errno = 0;
- flags = fcntl (fd, F_GETFL);
-
- if (flags < 0)
- return 0;
-
- /* redundant really */
- if (errno == EBADF)
- return 0;
-
- return 1;
-}
-
static void
child (enum child_tests test,
const char *filename)
=== modified file 'init/tests/test_util.c'
--- init/tests/test_util.c 2013-07-17 14:18:42 +0000
+++ init/tests/test_util.c 2014-05-08 11:48:46 +0000
@@ -1,5 +1,6 @@
+#include "test_util_common.h"
+#undef PACKAGE_COPYRIGHT
#include "test_util.h"
-#include "test_util_common.h"
#include <nih/logging.h>
#include <nih/test.h>
=== modified file 'test/test_util_common.c'
--- test/test_util_common.c 2014-04-11 21:15:39 +0000
+++ test/test_util_common.c 2014-05-08 11:48:46 +0000
@@ -28,6 +28,10 @@
#include <nih/string.h>
#include <nih/signal.h>
#include <nih/logging.h>
+#include <nih/timer.h>
+#include <nih/io.h>
+#include <nih/child.h>
+#include <nih/main.h>
#include <nih-dbus/test_dbus.h>
#include <dbus/dbus.h>
@@ -1003,3 +1007,89 @@
}
}
+
+/**
+ * timer_cb:
+ *
+ * @data: unused,
+ * @timer: timer.
+ *
+ * Exit main loop with an error value indicating that the expected main
+ * loop events/actions were not performed within the expected time.
+ **/
+void
+timer_cb (void *data, NihTimer *timer)
+{
+ nih_assert (timer);
+
+ /* Return non-zero to denote failure */
+ nih_main_loop_exit (42);
+}
+
+/**
+ * fd_valid:
+ * @fd: file descriptor.
+ *
+ * Return 1 if @fd is valid, else 0.
+ **/
+int
+fd_valid (int fd)
+{
+ int flags = 0;
+
+ if (fd < 0)
+ return 0;
+
+ errno = 0;
+ flags = fcntl (fd, F_GETFL);
+
+ if (flags < 0)
+ return 0;
+
+ /* redundant really */
+ if (errno == EBADF)
+ return 0;
+
+ return 1;
+}
+
+/**
+ * read_from_fd:
+ *
+ * @parent: parent,
+ * @fd: open file descriptor.
+ *
+ * Read from the specified fd, close the fd and return the data.
+ *
+ * Returns: Newly-allocated NihIoBuffer representing data read from @fd.
+ *
+ **/
+NihIoBuffer *
+read_from_fd (void *parent, int fd)
+{
+ NihIoBuffer *buffer = NULL;
+ ssize_t len;
+
+ assert (fd >= 0);
+
+ buffer = nih_io_buffer_new (parent);
+ nih_assert (buffer);
+
+ while (TRUE) {
+
+ nih_assert (! nih_io_buffer_resize (buffer, 1024));
+
+ len = read (fd,
+ buffer->buf + buffer->len,
+ buffer->size - buffer->len);
+
+ if (len <= 0)
+ break;
+ else if (len > 0)
+ buffer->len += len;
+ }
+
+ close (fd);
+
+ return buffer;
+}
=== modified file 'test/test_util_common.h'
--- test/test_util_common.h 2013-11-15 23:47:31 +0000
+++ test/test_util_common.h 2014-05-08 11:48:46 +0000
@@ -6,6 +6,10 @@
#include <sys/wait.h>
#include <nih-dbus/test_dbus.h>
+#include <nih/timer.h>
+#include <nih/main.h>
+#include <nih/child.h>
+#include <nih/io.h>
/**
* TEST_DIR_MODE:
@@ -34,6 +38,16 @@
#define TEST_QUIESCE_TOTAL_WAIT_TIME (TEST_EXIT_TIME + TEST_QUIESCE_KILL_PHASE)
+/**
+ * TEST_MAIN_LOOP_TIMEOUT_SECS:
+ *
+ * Number of seconds to wait until the main loop is exited in error.
+ *
+ * To avoid a test failure, all main loops must exit within this
+ * number of seconds.
+ **/
+#define TEST_MAIN_LOOP_TIMEOUT_SECS 5
+
/* A 'reasonable' path, but which also contains a marker at the end so
* we know when we're looking at a PATH these tests have set.
*/
@@ -169,6 +183,30 @@
}
/**
+ * TEST_RESET_MAIN_LOOP:
+ *
+ * Reset main loop and associated test variables.
+ **/
+#define TEST_RESET_MAIN_LOOP() \
+ if (nih_main_loop_functions) { \
+ nih_free (nih_main_loop_functions); \
+ nih_main_loop_functions = NULL; \
+ } \
+ if (nih_child_watches) { \
+ nih_free (nih_child_watches); \
+ nih_child_watches = NULL; \
+ } \
+ if (nih_timers) { \
+ nih_free (nih_timers); \
+ nih_timers = NULL; \
+ } \
+ nih_child_init (); \
+ nih_main_loop_init (); \
+ nih_timer_init (); \
+ nih_io_init ()
+
+
+/**
* obj_string_check:
*
* @a: first object,
@@ -702,10 +740,10 @@
int string_check (const char *a, const char *b)
__attribute__ ((warn_unused_result));
-const char * get_upstart_binary (void)
+const char *get_upstart_binary (void)
__attribute__ ((warn_unused_result));
-const char * get_initctl_binary (void)
+const char *get_initctl_binary (void)
__attribute__ ((warn_unused_result));
int strcmp_compar (const void *a, const void *b)
@@ -731,4 +769,17 @@
void test_common_cleanup (void);
+void timer_cb (void *data, NihTimer *timer);
+
+void test_job_process_handler (void *data, pid_t pid,
+ NihChildEvents event, int status);
+
+void test_main_loop_func (void *data, NihMainLoopFunc *self);
+
+int fd_valid (int fd)
+ __attribute__ ((warn_unused_result));
+
+NihIoBuffer *read_from_fd (void *parent, int fd)
+ __attribute__ ((warn_unused_result));
+
#endif /* TEST_UTIL_COMMON_H */
--
upstart-devel mailing list
[email protected]
Modify settings or unsubscribe at:
https://lists.ubuntu.com/mailman/listinfo/upstart-devel