--
James Hunt
____________________________________
http://upstart.ubuntu.com/cookbook
http://upstart.ubuntu.com/cookbook/upstart_cookbook.pdf
=== modified file 'ChangeLog'
--- ChangeLog 2012-03-16 08:56:38 +0000
+++ ChangeLog 2012-03-16 09:03:02 +0000
@@ -3,6 +3,15 @@
* init/tests/test_job_process:
- Fixed multiple TEST_FAILED() typos
("unexpected" => unexpectedly").
+ * job_process_spawn(): Only display single message
+ if pty setup fails.
+ * init/man/init.5: Typo.
+ * init/tests/test_job_process:
+ - child(): New TEST_OUTPUT_WITH_STOP test.
+ - test_run(): New test "with multiple processes and log".
+ - test_spawn():
+ - umask reset.
+ - New test "ensure multi processes output logged".
[ Steve Langasek <[email protected]> ]
* init/tests/test_job_process:
=== modified file 'init/job_process.c'
--- init/job_process.c 2012-03-07 12:13:28 +0000
+++ init/job_process.c 2012-03-16 09:03:02 +0000
@@ -466,19 +466,7 @@
pty_master = posix_openpt (O_RDWR | O_NOCTTY);
if (pty_master < 0) {
- /* Give the user an indication that they need to
- * increase the available ptys.
- *
- * This error will also been seen when:
- *
- * - the kernel does not support ptys.
- * - /dev/pts mounted, possibly due to an
- * initramfs-less system.
- */
- if (errno == ENOENT)
- nih_error (_("No available ptys"));
-
- nih_error (_("Failed to create pty - disabling logging"));
+ nih_error (_("Failed to create pty - disabling logging for job"));
/* Ensure that the job can still be started by
* disabling logging.
=== modified file 'init/man/init.5'
--- init/man/init.5 2012-03-05 17:29:48 +0000
+++ init/man/init.5 2012-03-16 09:03:02 +0000
@@ -679,7 +679,7 @@
filesystem be mounted.
If pty setup fails for any reason, an error message will be displayed
-and the jobs console value will be reset to
+and the job's console value will be reset to
.BR none "."
.RE
.RE
=== modified file 'init/tests/test_job_process.c'
--- init/tests/test_job_process.c 2012-03-16 08:56:38 +0000
+++ init/tests/test_job_process.c 2012-03-16 09:03:02 +0000
@@ -147,6 +147,7 @@
TEST_PWD,
TEST_ENVIRONMENT,
TEST_OUTPUT,
+ TEST_OUTPUT_WITH_STOP,
TEST_SIGNALS,
TEST_FDS
};
@@ -235,6 +236,16 @@
fprintf(stdout, "stdout\n");
fprintf(stderr, "stderr\n");
break;
+ case TEST_OUTPUT_WITH_STOP:
+ fprintf (stdout, "started\n");
+ fflush (NULL);
+
+ /* wait for signal */
+ raise (SIGSTOP);
+
+ fprintf(stdout, "ended\n");
+ fflush (NULL);
+ break;
case TEST_SIGNALS:
/* Write signal stats for child process to stdout */
in = fopen("/proc/self/status", "r");
@@ -3833,6 +3844,120 @@
}
/************************************************************/
+ TEST_FEATURE ("with multiple processes and log");
+
+ class = job_class_new (NULL, "aero", NULL);
+ TEST_NE_P (class, NULL);
+
+ TEST_EQ (setenv ("UPSTART_LOGDIR", dirname, 1), 0);
+
+ TEST_GT (sprintf (filename, "%s/aero.log", dirname), 0);
+
+ sprintf (function, "%d", TEST_OUTPUT_WITH_STOP);
+
+ /* Create a temporary filename for child() output. We don't care
+ * about this file as we're interested in childs() stdout/stderr
+ * output only.
+ */
+ TEST_FILENAME (filebuf);
+
+ class->console = CONSOLE_LOG;
+ class->process[PROCESS_MAIN] = process_new (class);
+ class->process[PROCESS_MAIN]->command = nih_sprintf (
+ class->process[PROCESS_MAIN],
+ "%s %s %s",
+ argv0, function, filebuf);
+ class->process[PROCESS_MAIN]->script = FALSE;
+
+ sprintf (function, "%d", TEST_OUTPUT);
+
+ class->process[PROCESS_POST_START] = process_new (class);
+ class->process[PROCESS_POST_START]->command = nih_sprintf (
+ class->process[PROCESS_POST_START],
+ "%s %s %s",
+ argv0, function, filebuf);
+ class->process[PROCESS_POST_START]->script = FALSE;
+
+ job = job_new (class, "");
+ job->goal = JOB_START;
+ job->state = JOB_SPAWNED;
+
+ ret = job_process_run (job, PROCESS_MAIN);
+ TEST_EQ (ret, 0);
+
+ pid = job->pid[PROCESS_MAIN];
+ TEST_GT (pid, 0);
+
+ TEST_FORCE_WATCH_UPDATE ();
+
+ TEST_EQ (stat (filename, &statbuf), 0);
+
+ output = fopen (filename, "r");
+ TEST_NE_P (output, NULL);
+
+ /* initial output from main process */
+ TEST_FILE_EQ (output, "started\r\n");
+ TEST_FILE_END (output);
+
+ TEST_EQ (fclose (output), 0);
+
+ ret = job_process_run (job, PROCESS_POST_START);
+ TEST_EQ (ret, 0);
+
+ pid = job->pid[PROCESS_POST_START];
+ TEST_GT (pid, 0);
+
+ /* wait for post-start to finish */
+ waitpid (pid, &status, 0);
+ TEST_TRUE (WIFEXITED (status));
+ TEST_EQ (WEXITSTATUS (status), 0);
+ TEST_FORCE_WATCH_UPDATE ();
+
+ output = fopen (filename, "r");
+ TEST_NE_P (output, NULL);
+
+ /* initial output from main process, followed by all output from
+ * post-start process.
+ */
+ TEST_FILE_EQ (output, "started\r\n");
+ TEST_FILE_EQ (output, "stdout\r\n");
+ TEST_FILE_EQ (output, "stderr\r\n");
+ TEST_FILE_END (output);
+
+ TEST_EQ (fclose (output), 0);
+
+ pid = job->pid[PROCESS_MAIN];
+
+ TEST_EQ (kill (pid, SIGCONT), 0);
+ waitpid (pid, &status, 0);
+ TEST_TRUE (WIFEXITED (status));
+ TEST_EQ (WEXITSTATUS (status), 0);
+
+ /* wait for post-start to finish */
+ waitpid (pid, &status, 0);
+ TEST_TRUE (WIFEXITED (status));
+ TEST_EQ (WEXITSTATUS (status), 0);
+
+ TEST_FORCE_WATCH_UPDATE ();
+
+ output = fopen (filename, "r");
+ TEST_NE_P (output, NULL);
+
+ /* initial output from main process, followed by all output from
+ * post-start process, followed by final data from main process.
+ */
+ TEST_FILE_EQ (output, "started\r\n");
+ TEST_FILE_EQ (output, "stdout\r\n");
+ TEST_FILE_EQ (output, "stderr\r\n");
+ TEST_FILE_EQ (output, "ended\r\n");
+ TEST_FILE_END (output);
+
+ TEST_EQ (fclose (output), 0);
+
+ TEST_EQ (unlink (filebuf), 0);
+ TEST_EQ (unlink (filename), 0);
+
+ /************************************************************/
/* Final clean-up */
TEST_EQ (rmdir (dirname), 0);
@@ -3869,6 +3994,11 @@
int status;
struct stat statbuf;
+ /* reset */
+ (void) umask (0);
+ TEST_FILENAME (dirname);
+ TEST_EQ (mkdir (dirname, 0755), 0);
+
/* Override default location to ensure job output goes to a
* writeable location
*/
@@ -4395,6 +4525,112 @@
nih_free (class);
/************************************************************/
+ TEST_FEATURE ("ensure multi process output logged");
+
+ TEST_FILENAME (dirname);
+ TEST_EQ (mkdir (dirname, 0755), 0);
+
+ TEST_EQ (setenv ("UPSTART_LOGDIR", dirname, 1), 0);
+
+ class = job_class_new (NULL, "multiproc", NULL);
+ TEST_NE_P (class, NULL);
+
+ class->console = CONSOLE_LOG;
+
+ TEST_GT (sprintf (filename, "%s/multiproc.log", dirname), 0);
+ job = job_new (class, "");
+ TEST_NE_P (job, NULL);
+
+ sprintf (function, "%d", TEST_OUTPUT_WITH_STOP);
+
+ /* Create a temporary filename for child() output. We don't care
+ * about this file as we're interested in childs() stdout/stderr
+ * output only.
+ */
+ TEST_FILENAME (filebuf);
+
+ args[0] = argv0;
+ args[1] = function;
+ args[2] = filebuf;
+ args[3] = NULL;
+
+ job->pid[PROCESS_MAIN] = job_process_spawn (job, args, NULL,
+ FALSE, -1, PROCESS_MAIN);
+ pid = job->pid[PROCESS_MAIN];
+ TEST_GT (pid, 0);
+
+ /* The main process is now running, but paused. It should have
+ * produced some output so check that now.
+ */
+ TEST_FORCE_WATCH_UPDATE ();
+
+ TEST_EQ (stat (filename, &statbuf), 0);
+
+ output = fopen (filename, "r");
+ TEST_NE_P (output, NULL);
+
+ TEST_FILE_EQ (output, "started\r\n");
+ TEST_FILE_END (output);
+ TEST_EQ (fclose (output), 0);
+
+ sprintf (function, "%d", TEST_OUTPUT);
+
+ args[0] = argv0;
+ args[1] = function;
+ args[2] = filebuf;
+ args[3] = NULL;
+
+ job->pid[PROCESS_POST_START] = job_process_spawn (job, args, NULL,
+ FALSE, -1, PROCESS_POST_START);
+ pid = job->pid[PROCESS_POST_START];
+ TEST_GT (pid, 0);
+
+ /* wait for post-start process to end */
+ waitpid (pid, &status, 0);
+ TEST_TRUE (WIFEXITED (status));
+ TEST_EQ (WEXITSTATUS (status), 0);
+
+ /* ensure log written */
+ nih_free (job->log[PROCESS_POST_START]);
+ job->log[PROCESS_POST_START] = NULL;
+
+ output = fopen (filename, "r");
+ TEST_NE_P (output, NULL);
+
+ TEST_FILE_EQ (output, "started\r\n"); /* from main process */
+ TEST_FILE_EQ (output, "stdout\r\n"); /* from post-start process */
+ TEST_FILE_EQ (output, "stderr\r\n"); /* from post-start process */
+ TEST_FILE_END (output);
+ fclose (output);
+
+ pid = job->pid[PROCESS_MAIN];
+ TEST_EQ (kill (pid, SIGCONT), 0);
+
+ /* wait for main process to end */
+ waitpid (pid, &status, 0);
+ TEST_TRUE (WIFEXITED (status));
+ TEST_EQ (WEXITSTATUS (status), 0);
+
+ /* ensure log written */
+ nih_free (job->log[PROCESS_MAIN]);
+ job->log[PROCESS_MAIN] = NULL;
+
+ output = fopen (filename, "r");
+ TEST_NE_P (output, NULL);
+
+ TEST_FILE_EQ (output, "started\r\n"); /* from main process */
+ TEST_FILE_EQ (output, "stdout\r\n"); /* from post-start process */
+ TEST_FILE_EQ (output, "stderr\r\n"); /* from post-start process */
+ TEST_FILE_EQ (output, "ended\r\n"); /* from main process */
+ TEST_FILE_END (output);
+ fclose (output);
+
+ TEST_EQ (unlink (filebuf), 0);
+ TEST_EQ (unlink (filename), 0);
+
+ TEST_EQ (unsetenv ("UPSTART_LOGDIR"), 0);
+
+ /************************************************************/
TEST_FEATURE ("simple test");
TEST_FILENAME (dirname);
--
upstart-devel mailing list
[email protected]
Modify settings or unsubscribe at:
https://lists.ubuntu.com/mailman/listinfo/upstart-devel