Compare commits

..

5 commits

Author SHA1 Message Date
Fedora Release Engineering
5c7176b0e0 dist-git conversion 2010-07-29 14:46:25 +00:00
Bill Nottingham
77de159c1c Fix typo that causes a failure to update the common directory. (releng
#2781)
2009-11-26 01:15:33 +00:00
41112708a3 Update to upstream 0.3.11 version 2009-07-22 09:18:49 +00:00
Bill Nottingham
52d5d6fa7b Apply the audit patch correctly (#470661)
Also, rediff/rework everything else, so we don't end up re-running the
    autotools, which only causes pain.
2009-04-27 20:06:59 +00:00
Jesse Keating
14e78bcebb Initialize branch F-11 for upstart 2009-04-15 05:42:31 +00:00
14 changed files with 3009 additions and 8 deletions

8
.gitignore vendored
View file

@ -1,7 +1 @@
upstart-0.6.6.tar.gz
/initjobs-20101206.tar.gz
/upstart-0.6.7.tar.gz
/upstart-1.0.tar.gz
/upstart-1.1.tar.gz
/upstart-1.2.tar.gz
/initjobs-20110502.tar.gz
upstart-0.3.11.tar.bz2

View file

@ -1 +0,0 @@
This package was retired on 2012-08-06 due to no active maintainers for the package.

286
events.5 Normal file
View file

@ -0,0 +1,286 @@
.TH events 5 "April 2008" "Upstart"
.\"
.SH NAME
events \- format of event files used by the upstart init system
.\"
.SH DESCRIPTION
upstart works on the basis of \fBevent\fP files that describe jobs
that should be managed. This includes the particulars about what binary
or shell script code should executed while the job is running, and
which events can cause the job to be started or stopped.
Event files are stored in the \fI/etc/event.d\fP directory.
.\"
.SH SYNTAX
Event files can contain the following stanzaz.
.TP
.BI "exec <command> <arguments>"
When the event is started by \fBinit\fR, execute the following arguments.
Example: exec /bin/dbus-daemon --system
.TP
.BI "script ..."
Like \fBexec\fR but instead of executing a single program, execute
the following shell code. \fBscript\fR sections are closed with a
\fBend script\fR marker.
Example:
.nf
script
rm -f /var/run/sshd.pid
sshd
end script
.ni
Only one of \fBexec\fR and \fBscript\fR can be used at a time. If both
are bspecifed, \fBexec\fR takes priority.
.TP
.BI pre-start
Execute the command/script before actually starting the process.
\fBpre-start\fR can be invoked as \fBpre-start exec\fR or \fBpre-start script\fR
in the same way that a start action can be handled by either
\fBexec\fR or \fBscript\fR.
.TP
.BI post-start
Execute the command/script after starting the process.
The format is similar to \fBpre-start\fR.
.TP
.BI pre-stop
Execute the command/script before stopping the process.
The format is similar to \fBpre-start\fR.
.TP
.BI post-stop
Execute the command/script after stopping the process.
The format is similar to \fBpre-start\fR.
.TP
.BI "start on <event>"
Describes on what condition to start this job. Without this
section, the job can only be manually started with the
\fBinitctl(8)\fR command.
Examples:
.nf
start on startup
This starts immediately after boot.
start on stopped rc3
This starts when the 'rc3' event has stopped.
.ni
Events are matched via globbing. So a stanza of the form
.nf
start on runlevel [2345]
.ni
would match any of runlevels 2, 3, 4, or 5.
.TP
.BI "stop on <event>"
Describes on what condition to stop this job. Without this
section, the job can only be manually stopped with the
\fBinitctl\fR command.
Examples:
.nf
stop on runlevel 0
This stops the job when runlevel 0 is entered.
stop on stopping dbus ok
This stops the job when the 'dbus' job is stopped.
.ni
Events are matched via globbing. So a stanza of the form
.nf
stop on runlevel [!5]
.ni
would match any runlevel other than 5.
.TP
.BI daemon
Sets the daemon flag for the job. This means that the job will
fork in the background and that its PID needs to be obtained.
.TP
.BI respawn
This sets the daemon, service, and respawn flags for the job.
The respawn flag means that the process will be restarted when
it ends.
.TP
.BI "respawn limit [count [timeout]]"
This configures respawn limits. Respawn limits only apply
if the \fBrespawn\fR flag is set for the job; setting a limit
does not automatically set respawning capability. If the
process is respawned more than \fIcount\fR times within an
interval of \fItimeout\fR seconds, the job will be stopped
automatically, andn ot restarted. The limit defaults to 10
times within 5 seconds.
Example: respawn limit 10 120
This sets the limit for respawn to ten times within two
minutes, the historical behavior for System V init.
.TP
.BI service
\fBservice\fR means that the job has reached its goal when running.
\fBservice\fR is implied by the \fBrespawn\fR flag.
.TP
.BI instance
\fBinstance\fR means that the job starts new instances every time
it is started, even if there is another instance running. It
is the converse of \fBdaemon\fR.
.TP
.BI "kill timeout <time>"
Sets the time to wait between sending TERM and KILL signals to
\fItime\fR seconds.
.TP
.BI "normal exit <status>"
When used with \fBrespawn\fR any exit codes denoted in \fIstatus\fR will
prevent a respawn of the process.
.TP
.BI "console {logged|output|owner|none}"
Describes what to do with the job's output. Valid values are:
.I logged
Redirect to logger. (the default setting)
.I output
Direct to the current stdout
.I owner
The process becomes the owner of the console, allowing it to
receive signals from the keyboard
.I none
Output is redirected to /dev/null
.TP
.BI "env <name>=<value>"
Sets an environment variable for the job.
Example: env LD_LIBRARY_PATH=/opt/app/lib
.TP
.BI "umask <umask>"
Sets the umask of the job to \fIumask\fR.
Example: umask 0755
.TP
.BI "nice <value>"
Sets the nice level of the job to \fIvalue\fR.
Example: nice 5
.TP
.BI "chroot <path>"
Changes the job's root directory to \fIpath\fR.
Example: chroot /var/empty
.TP
.BI "chdir <path>"
Changes the working directory of the job to \fIpath\fR.
Example: chdir /var/tmp
.TP
.BI "limit {as|core|cpu|data|fsize|memlock|msgqueue|nice|nofile|nproc|rss|rtprio|sigpending|stack} {unlimited|<value>}"
Changes the limit of the process to whatever is specfied.
Examples:
.nf
limit nproc 10
limit core unlimited
.ni
.TP
.BI "description <text>"
Describes the job. Not currently used by any \fBinit(8)\fR tools.
Example: descripton "This is a test job."
.TP
.BI "author <text>"
Author of the job. Not currently used by any \fBinit(8)\fR tools.
Example: author "Obi-wan Kennedy <bidy@whitehouse.gov>"
.TP
.BI "version <version>"
Version of the job. Not currently used by any \fBinit(8)\fR tools.
Example: version "0.0.0.0.1 test"
.TP
.BI "emits <signals>"
Describes signals emitted by the job. Not currently used by
any \fBinit(8)\fR tools. For more information on signals, see the
\fBinitctl(8)\fR man page and the \fBemit\fR option.
Example: emits spam egg ham
.\"
.SH EVENTS
A wide array of events can be emitted by the system (see
\fBinitctl(8)\fR) but the following events are generated by
upstart itself, or are usually seen on a typical install.
.TP
.BI "stalled"
No jobs are running and no events are pending.
.TP
.BI "control-alt-delete"
Control-Alt-Delete has been pressed.
.TP
.BI "kbdrequest"
A kbdrequest event has occurred.
.TP
.BI "power-status-changed"
Init received SIGPWR.
.TP
.BI "starting <job>"
The given job is being started.
.TP
.BI "started <job>"
The given job has successfully been started.
.TP
.BI "stopping <job>"
The given job is being stopped.
.TP
.BI "stopped <job>"
The given job has been stopped successfully.
.TP
.BI "startup"
Emitted when the system boots.
.TP
.BI "runlevel <runlevel>"
Init has been asked to move to the given runlevel.
.\"
.SH FILES
.I /etc/event.d
The directory where event files are stored.
.\"
.SH SEE ALSO
.BR initctl (8)
.BR telinit (8)
.BR init (8)
.BR http://upstart.ubuntu.com/getting-started.html

1
sources Normal file
View file

@ -0,0 +1 @@
a9e475e1458c876add0441d9d4cfe9c0 upstart-0.3.11.tar.bz2

199
upstart-audit-events.patch Normal file
View file

@ -0,0 +1,199 @@
diff -urp upstart-0.3.9.orig/compat/sysv/reboot.c upstart-0.3.9/compat/sysv/reboot.c
--- upstart-0.3.9.orig/compat/sysv/reboot.c 2008-11-03 12:29:30.000000000 -0500
+++ upstart-0.3.9/compat/sysv/reboot.c 2008-11-05 08:16:22.000000000 -0500
@@ -37,6 +37,9 @@
#include <string.h>
#include <unistd.h>
#include <utmp.h>
+#if 1 /* HAVE_LIBAUDIT */
+#include <libaudit.h>
+#endif
#include <linux/if.h>
#include <linux/hdreg.h>
@@ -87,6 +90,7 @@ enum {
/* Prototypes for static functions */
static void down_drives (void);
static void down_interfaces (void);
+static void send_audit_event(void);
/**
@@ -277,6 +281,7 @@ main (int argc,
*/
reboot (RB_ENABLE_CAD);
kill (1, SIGTSTP);
+ send_audit_event ();
/* Sync the disks */
chdir ("/");
@@ -315,6 +320,23 @@ main (int argc,
return 0;
}
+/**
+ * send_audit_event
+ *
+ * Send system shutdown audit event
+ **/
+static void
+send_audit_event (void)
+{
+#if 1 /* HAVE_LIBAUDIT */
+ int fd = audit_open ();
+ if (fd < 0)
+ return;
+ audit_log_user_message (fd, AUDIT_SYSTEM_SHUTDOWN, "init",
+ NULL, NULL, NULL, 1);
+ close (fd);
+#endif
+}
/**
* down_drives:
diff -urp upstart-0.3.9.orig/compat/sysv/runlevel.c upstart-0.3.9/compat/sysv/runlevel.c
--- upstart-0.3.9.orig/compat/sysv/runlevel.c 2008-11-03 12:29:30.000000000 -0500
+++ upstart-0.3.9/compat/sysv/runlevel.c 2008-11-05 08:22:17.000000000 -0500
@@ -33,6 +33,9 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#if 1 /* HAVE_LIBAUDIT */
+#include <libaudit.h>
+#endif
#include <nih/macros.h>
#include <nih/alloc.h>
@@ -44,6 +47,7 @@
/* Prototypes for static functions */
static void store (short type, pid_t pid, const char *user);
+static void send_audit_event (int old, int level);
/**
@@ -109,6 +113,7 @@ main (int argc,
/* Store the reboot time? */
if (reboot) {
store (BOOT_TIME, 0, "reboot");
+ send_audit_event (0, 0);
exit (0);
}
@@ -143,6 +148,7 @@ main (int argc,
prev = cur;
if (! prev)
prev = 'N';
+ send_audit_event (prev, set[0]);
cur = set[0];
}
@@ -203,3 +209,35 @@ store (short type,
/* Write wtmp entry */
updwtmp (WTMP_FILE, &utmp);
}
+
+/**
+ * send_audit_event
+ * @old: current run level
+ * @level: new run level
+ *
+ * Send system runlevel change audit event. If level is 0, then
+ * we consider this to be a reboot event.
+ **/
+static void
+send_audit_event (int old, int level)
+{
+#if 1 /* HAVE_LIBAUDIT */
+ int fd = audit_open ();
+
+ if (fd < 0)
+ return;
+
+ if (level) {
+ char buf[64];
+
+ snprintf (buf, sizeof (buf),
+ "old-level=%c new-level=%c", old, level);
+ audit_log_user_message (fd, AUDIT_SYSTEM_RUNLEVEL, buf,
+ NULL, NULL, NULL, 1);
+ } else
+ audit_log_user_message (fd, AUDIT_SYSTEM_BOOT, "init",
+ NULL, NULL, NULL, 1);
+ close (fd);
+#endif
+}
+
diff -urp upstart-0.3.9.orig/compat/sysv/shutdown.c upstart-0.3.9/compat/sysv/shutdown.c
--- upstart-0.3.9.orig/compat/sysv/shutdown.c 2008-11-03 12:29:30.000000000 -0500
+++ upstart-0.3.9/compat/sysv/shutdown.c 2008-11-05 08:16:22.000000000 -0500
@@ -38,6 +38,9 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#if 1 /* HAVE_LIBAUDIT */
+#include <libaudit.h>
+#endif
#include <nih/macros.h>
#include <nih/alloc.h>
@@ -452,6 +455,23 @@ runlevel_setter (NihOption *option,
return 0;
}
+/**
+ * send_audit_event
+ *
+ * Send system shutdown audit event
+ **/
+static void
+send_audit_event (void)
+{
+#if 1 /* HAVE_LIBAUDIT */
+ int fd = audit_open ();
+ if (fd < 0)
+ return;
+ audit_log_user_message (fd, AUDIT_SYSTEM_SHUTDOWN, "init",
+ NULL, NULL, NULL, 1);
+ close (fd);
+#endif
+}
/**
* shutdown_now:
@@ -496,6 +516,7 @@ shutdown_now (void)
NIH_MUST (message = upstart_message_new (NULL, UPSTART_INIT_DAEMON,
UPSTART_EVENT_EMIT,
"runlevel", args, env));
+ send_audit_event ();
/* Send the message */
if (nih_io_message_send (message, sock) < 0) {
@@ -513,7 +534,6 @@ shutdown_now (void)
nih_fatal (_("Unable to send message: %s"), err->message);
exit (1);
}
-
unlink (ETC_NOLOGIN);
nih_main_unlink_pidfile ();
diff -up upstart-0.3.9/compat/sysv/Makefile.in.foo upstart-0.3.9/compat/sysv/Makefile.in
--- upstart-0.3.9/compat/sysv/Makefile.in.foo 2009-04-27 15:53:35.000000000 -0400
+++ upstart-0.3.9/compat/sysv/Makefile.in 2009-04-27 15:53:55.000000000 -0400
@@ -280,13 +280,13 @@ EXTRA_DIST = $(manpages)
@COMPAT_SYSV_TRUE@man_MANS = $(manpages)
reboot_SOURCES = reboot.c
reboot_LDFLAGS = -static
-reboot_LDADD = ../../upstart/libupstart.la ../../nih/libnih.la $(LTLIBINTL)
+reboot_LDADD = ../../upstart/libupstart.la ../../nih/libnih.la $(LTLIBINTL) -laudit
runlevel_SOURCES = runlevel.c
runlevel_LDFLAGS = -static
-runlevel_LDADD = ../../nih/libnih.la $(LTLIBINTL)
+runlevel_LDADD = ../../nih/libnih.la $(LTLIBINTL) -laudit
shutdown_SOURCES = shutdown.c
shutdown_LDFLAGS = -static
-shutdown_LDADD = ../../upstart/libupstart.la ../../nih/libnih.la $(LTLIBINTL)
+shutdown_LDADD = ../../upstart/libupstart.la ../../nih/libnih.la $(LTLIBINTL) -laudit
telinit_SOURCES = telinit.c
telinit_LDFLAGS = -static
telinit_LDADD = ../../upstart/libupstart.la ../../nih/libnih.la $(LTLIBINTL)

View file

@ -0,0 +1,20 @@
--- upstart-0.3.11/configure 2009-06-19 20:03:59.000000000 +0200
+++ upstart-0.3.11-adj/configure 2009-06-22 14:51:40.000000000 +0200
@@ -749,7 +749,7 @@
PACKAGE_TARNAME='upstart'
PACKAGE_VERSION='0.3.11'
PACKAGE_STRING='upstart 0.3.11'
-PACKAGE_BUGREPORT='upstart-devel@lists.ubuntu.com'
+PACKAGE_BUGREPORT='fedora-devel-list@redhat.com'
ac_unique_file="init/main.c"
# Factoring default headers for most tests.
@@ -1655,7 +1655,7 @@
Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.
-Report bugs to <upstart-devel@lists.ubuntu.com>.
+Report bugs to <fedora-devel-list@redhat.com>.
_ACEOF
ac_status=$?
fi

View file

@ -0,0 +1,56 @@
diff -up upstart-0.3.9/compat/sysv/reboot.c.foo upstart-0.3.9/compat/sysv/reboot.c
--- upstart-0.3.9/compat/sysv/reboot.c.foo 2008-02-15 16:52:30.000000000 -0500
+++ upstart-0.3.9/compat/sysv/reboot.c 2008-02-15 17:47:37.000000000 -0500
@@ -36,6 +36,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <utmp.h>
#include <linux/if.h>
#include <linux/hdreg.h>
@@ -158,12 +159,31 @@ static NihOption options[] = {
NIH_OPTION_LAST
};
+static char get_runlevel(void)
+{
+ struct utmp utmp, *lvl;
+ char *rl, runlevel = 0;
+
+ if ((rl = getenv("RUNLEVEL")) != NULL)
+ return *rl;
+
+ memset(&utmp, 0, sizeof(utmp));
+ utmp.ut_type = RUN_LVL;
+ setutent();
+ lvl = getutid(&utmp);
+ if (lvl)
+ runlevel = lvl->ut_pid % 256;
+ endutent();
+ return runlevel;
+}
+
int
main (int argc,
char *argv[])
{
char **args;
+ char level;
int mode;
nih_main_init (argv[0]);
@@ -211,6 +231,12 @@ main (int argc,
if (exit_only)
exit (0);
+
+ level = get_runlevel();
+ if (level) {
+ if (level == '0' || level == '6')
+ force = TRUE;
+ }
/* Normally we just exec shutdown, which notifies everyone and
* signals init.

11
upstart-gcc43.patch Normal file
View file

@ -0,0 +1,11 @@
diff -up upstart-0.3.9/upstart/wire.c.foo upstart-0.3.9/upstart/wire.c
--- upstart-0.3.9/upstart/wire.c.foo 2008-02-01 13:35:33.000000000 -0500
+++ upstart-0.3.9/upstart/wire.c 2008-02-01 13:35:33.000000000 -0500
@@ -28,6 +28,7 @@
#include <stdarg.h>
#include <string.h>
+#include <limits.h>
#include <nih/macros.h>
#include <nih/alloc.h>

11
upstart-initctl-man.patch Normal file
View file

@ -0,0 +1,11 @@
--- upstart-0.3.9/util/man/initctl.8-orig 2008-04-09 16:52:23.000000000 -0400
+++ upstart-0.3.9/util/man/initctl.8 2008-04-24 01:42:57.000000000 -0400
@@ -14,7 +14,7 @@
.IR COMMAND .
Normally it is invoked directly with the command specified as the first
-non-option argument, however symbolic or hard links may be used so that
+non-option argument; however, symbolic or hard links may be used so that
it is invoked as the name of a command, in which case it behaves
accordingly.
.\"

23
upstart-rpm.patch Normal file
View file

@ -0,0 +1,23 @@
=== modified file 'nih/file.c'
--- nih/file.c 2007-06-03 12:32:56 +0000
+++ nih/file.c 2008-03-17 02:47:17 +0000
@@ -375,6 +375,18 @@
if (ptr && (! strncmp (ptr, ".dpkg-", 6)))
return TRUE;
+ /* Matches rpm temp files */
+ if (ptr && (! strncmp (ptr, ".rpmsave",9)))
+ return TRUE;
+ if (ptr && (! strncmp (ptr, ".rpmorig",9)))
+ return TRUE;
+ if (ptr && (! strncmp (ptr, ".rpmnew",8)))
+ return TRUE;
+
+ /* More rpm temp file matching */
+ ptr = strrchr (path, ';');
+ if (ptr && strspn (ptr + 1, "abcdefABCDEF0123456789") == 8 && !ptr[9])
+ return TRUE;
return FALSE;
}

View file

@ -0,0 +1,429 @@
diff -uNr upstart-0.3.9.orig/init/main.c upstart-0.3.9/init/main.c
--- upstart-0.3.9.orig/init/main.c 2009-01-23 13:44:32.000000000 -0500
+++ upstart-0.3.9/init/main.c 2009-01-23 13:44:54.000000000 -0500
@@ -59,6 +59,7 @@
#include "cfgfile.h"
#include "paths.h"
#include "tty.h"
+#include "restore.h"
/* Prototypes for static functions */
@@ -278,6 +279,10 @@
exit (1);
}
+ /* Restore the state of previously active jobs, if re-exec'd by
+ * a previously running init. */
+
+ if (restart) restore_configuration(args);
/* Generate and run the startup event or read the state from the
* init daemon that exec'd us
@@ -534,6 +539,8 @@
NihError *err;
const char *loglevel;
sigset_t mask, oldmask;
+ char **args;
+ size_t len;
nih_assert (argv0 != NULL);
nih_assert (signal != NULL);
@@ -559,7 +566,20 @@
} else {
loglevel = NULL;
}
- execl (argv0, argv0, "--restart", loglevel, NULL);
+ args = nih_str_array_new(NULL);
+ len = 0;
+ if (args) args = nih_str_array_add(&args, NULL, &len, argv0);
+ if (args) args = nih_str_array_add(&args, NULL, &len, "--restart");
+ if (args && loglevel)
+ args = nih_str_array_add(&args, NULL, &len, loglevel);
+ if (args) save_current_configuration(&args, NULL, &len);
+ if (args) {
+ execv (argv0, args);
+ nih_free(args);
+ } else {
+ nih_warn (_("Unable to save list of currently running jobs"));
+ execl(argv0, argv0, "--restart", loglevel, NULL);
+ }
nih_error_raise_system ();
err = nih_error_get ();
diff -uNr upstart-0.3.9.orig/init/Makefile.in upstart-0.3.9/init/Makefile.in
--- upstart-0.3.9.orig/init/Makefile.in 2009-01-23 13:44:32.000000000 -0500
+++ upstart-0.3.9/init/Makefile.in 2009-01-23 13:44:54.000000000 -0500
@@ -72,7 +72,7 @@
PROGRAMS = $(sbin_PROGRAMS)
am_init_OBJECTS = main.$(OBJEXT) tty.$(OBJEXT) process.$(OBJEXT) \
job.$(OBJEXT) event.$(OBJEXT) control.$(OBJEXT) \
- notify.$(OBJEXT) cfgfile.$(OBJEXT)
+ notify.$(OBJEXT) cfgfile.$(OBJEXT) restore.$(OBJEXT)
init_OBJECTS = $(am_init_OBJECTS)
am__DEPENDENCIES_1 =
init_DEPENDENCIES = ../upstart/libupstart.la ../nih/libnih.la \
@@ -315,7 +315,8 @@
event.c event.h \
control.c control.h \
notify.c notify.h \
- cfgfile.c cfgfile.h
+ cfgfile.c cfgfile.h \
+ restore.c restore.h
init_LDFLAGS = -static
init_LDADD = \
diff -uNr upstart-0.3.9.orig/init/restore.c upstart-0.3.9/init/restore.c
--- upstart-0.3.9.orig/init/restore.c 1969-12-31 19:00:00.000000000 -0500
+++ upstart-0.3.9/init/restore.c 2009-01-23 13:44:54.000000000 -0500
@@ -0,0 +1,333 @@
+/* Modifications to upstart to allow passing of the state of currently
+ * running jobs when upstart re-execs itself.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif /* HAVE_CONFIG_H */
+
+
+#include <sys/types.h>
+#include <string.h>
+#include <nih/string.h>
+#include <nih/logging.h>
+#include <nih/alloc.h>
+#include "job.h"
+#include "restore.h"
+
+
+/**
+ * store_pid:
+ * @proc: pointer to a JobProcess structure or NULL
+ * @args: array of arguments
+ * @parent: parent of @args
+ * @len: current length of @args
+ *
+ * Does nothing if @args is null.
+ * Pushes "X" onto @args if @args is non-null but @process is null.
+ * Otherwise: extracts the pid from @process, creates a hexadecimal string
+ * form of it, pushes a copy onto the array @args, then frees the original.
+ */
+
+void store_pid(JobProcess *proc, char ***args, const void *parent, size_t *len)
+{
+ char *pidstr;
+ if (! *args) return;
+ pidstr = (proc ? nih_sprintf(NULL, "%x", proc->pid) : "X");
+
+ if (! pidstr) {
+ nih_error("Unable to allocate storage to save process id");
+ *args = NULL;
+ return;
+ }
+ if (! nih_str_array_add(args, parent, len, pidstr)) {
+ nih_error("Unable to add process id to argument list");
+ *args = NULL;
+ }
+
+ if (proc) nih_free(pidstr);
+}
+
+/**
+ * unpack_pid:
+ * @pidstr: hexadecimal string created by pack_pid
+ * @err: pointer to flag to set if error occurs
+ *
+ * Returns the process id corresponding to the string passed in pidstr.
+ * If an error occurs, returns 0 and sets the flag pointed to by @err.
+ **/
+
+pid_t unpack_pid(char *pidstr, int *err) {
+ pid_t result = 0;
+ while (*pidstr) {
+ unsigned char c = *pidstr++;
+ result <<= 4;
+ if (c >= '0' && c <= '9') result += (c-'0');
+ else if (c >= 'a' && c <= 'f') result += 10 + (c-'a');
+ else {
+ *err = 1;
+ return 0;
+ }
+ }
+ return result;
+}
+
+/**
+ * retrieve_pid:
+ * @arg: pointer to array of arguments from which to read pid string
+ * @jobname: name of job whose pids are being retrieved
+ * @err: pointer to flag to set if error occurs
+ * @pid: pointer to location to hold the retrieved process id
+ * @present: pointer to a location to hold 1 if the process id was present
+ *
+ * Reads a process id or no-process-present indicator from the hexadecimal
+ * string pointed to by @arg, increments @arg to point to the next string in
+ * the array unless it already points to a null string, and stores into
+ * @present a value of 0 or 1 indicating whether or not a process id is
+ * present, and stores into @pid the unpacked process id (or zero if there
+ * is no process present or an error occurred). If an error occured, sets
+ * the flag pointed to by @err and printes an error message.
+ **/
+
+void retrieve_pid(char ***arg, char *jobname, int *err,
+ pid_t *pid, int *present)
+{
+ *pid = 0;
+ *present = 0;
+ char *str;
+ if (! arg || ! *arg || ! **arg) {
+ nih_error("Ran out of arguments when restoring job %s",
+ jobname);
+ *err = 1;
+ return;
+ }
+ str = **arg;
+ if (str) ++(*arg);
+ if (strcmp(str, "X")==0) return;
+ *present = 1;
+ *pid = unpack_pid(str, err);
+ if (*err) nih_error("Cannot parse pid %s for job %s", str, jobname);
+}
+
+/**
+ * restore_pid:
+ * @proc: pointer to a JobProcess structure, or NULL
+ * @pid: process id
+ * @present: integer which is 1 if process id is applicable
+ * @jobname: name of job whose process ids are being restored
+ *
+ * Checks that the non-null status of @proc matches the true/false
+ * status of @present. If there is a mismatch, prints an error message.
+ * If @present is true and @proc is non-null, stores the process id from
+ * @pid into the JobProcess structure pointed to by @proc.
+ */
+
+void restore_pid(JobProcess *proc, pid_t pid, int present, char *jobname)
+{
+ if (proc == NULL && ! present) return;
+ if (proc != NULL && present) {
+ proc->pid = pid;
+ return;
+ }
+ nih_error("Unable to restore process id for job %s", jobname);
+}
+
+/**
+ * save_current_configuration:
+ * @args: array of arguments to pass to new init
+ * @parent: parent of @args
+ * @len: current length of @args
+ *
+ * Pushes, onto the array @args, information about currently running
+ * jobs. Each job consists of seven arguments:
+ * (1) The job name
+ * (2) A 3-character state/goal string:
+ * First character for the goal: 0=goal JOB_STOP, 1=goal JOB_START
+ * Second character for the current state:
+ * W=JOB_WAITING,
+ * S=JOB_STARTING, A=JOB_PRE_START, B=JOB_SPAWNED, C=JOB_POST_START,
+ * R=JOB_RUNNING,
+ * T=JOB_STOPPING, X=JOB_PRE_STOP, Y=JOB_KILLED, Z=JOB_POST_STOP
+ * Third character: N=normal job, I=instance job
+ * (3) The associated PROCESS_MAIN process id
+ * (4) The associated PROCESS_PRE_START process id
+ * (5) The associated PROCESS_POST_START process id
+ * (6) The associated PROCESS_PRE_STOP process id
+ * (7) The associated PROCESS_POST_STOP process id
+ * Process ids are in hexadecimal using lower-case letters (0-9,a-f),
+ * or 0 if there is a JobProcess structure but no running process, or
+ * "X" if there is no JobProcess structure.
+ *
+ */
+
+void save_current_configuration(char ***args, const void *parent, size_t *len)
+{
+ NIH_HASH_FOREACH(jobs, iter) {
+ Job *job = (Job *) iter;
+ char goal_state[4];
+ JobProcess **pids;
+
+
+ if (job->replacement_for != NULL) continue;
+ if (job->state == JOB_DELETED) continue;
+ if (job->instance && ! job->instance_of) continue;
+
+ if (! nih_str_array_add(args, parent, len, job->name))
+ return;
+
+ if (job->goal == JOB_START) goal_state[0] = '1';
+ else goal_state[0] = '0';
+
+ switch (job->state)
+ {
+ case JOB_WAITING: goal_state[1] = 'W'; break;
+ case JOB_STARTING: goal_state[1] = 'S'; break;
+ case JOB_PRE_START: goal_state[1] = 'A'; break;
+ case JOB_SPAWNED: goal_state[1] = 'B'; break;
+ case JOB_POST_START: goal_state[1] = 'C'; break;
+ case JOB_RUNNING: goal_state[1] = 'R'; break;
+ case JOB_STOPPING: goal_state[1] = 'T'; break;
+ case JOB_PRE_STOP: goal_state[1] = 'X'; break;
+ case JOB_KILLED: goal_state[1] = 'Y'; break;
+ case JOB_POST_STOP: goal_state[1] = 'Z'; break;
+ default: goal_state[1] = '?';
+ }
+ if (job->instance_of) goal_state[2] = 'I';
+ else goal_state[2] = 'N';
+ goal_state[3] = 0;
+
+ if (! nih_str_array_add(args, parent, len, goal_state))
+ return;
+
+ pids = job->process;
+ store_pid(pids[PROCESS_MAIN], args, parent, len);
+ store_pid(pids[PROCESS_PRE_START], args, parent, len);
+ store_pid(pids[PROCESS_POST_START], args, parent, len);
+ store_pid(pids[PROCESS_PRE_STOP], args, parent, len);
+ store_pid(pids[PROCESS_POST_STOP], args, parent, len);
+ }
+}
+
+/**
+ * restore_job_state:
+ * @jobname: name of job whose state we are to restore
+ * @goal_state: the goal/state string generated by save_current_configuration
+ * @pids: array of five process ids
+ * @presents: array of five integers indicating which process ids are applicable
+ */
+
+void restore_job_state (char *jobname, char *goal_state,
+ pid_t *pids, int *presents)
+{
+ Job *job;
+ JobGoal goal = JOB_STOP;
+ JobState state = JOB_WAITING;
+ int is_instance = 0;
+ int is_invalid = 0;
+ JobProcess **procs;
+
+ if (jobname == NULL) {
+ nih_error("Missing name for restored job");
+ return;
+ }
+
+ if (goal_state == NULL) {
+ nih_error("Missing goal/state for restored job %s", jobname);
+ return;
+ }
+
+ if (strlen(goal_state) != 3) {
+ nih_error("Invalid length goal/state %s for restored job %s",
+ goal_state, jobname);
+ return;
+ }
+
+ switch (goal_state[0])
+ {
+ case '0': goal = JOB_STOP; break;
+ case '1': goal = JOB_START; break;
+ default: is_invalid = 1; break;
+ }
+
+ switch (goal_state[1])
+ {
+ case 'W': state = JOB_WAITING; break;
+ case 'S': state = JOB_STARTING; break;
+ case 'A': state = JOB_PRE_START; break;
+ case 'B': state = JOB_SPAWNED; break;
+ case 'C': state = JOB_POST_START; break;
+ case 'R': state = JOB_RUNNING; break;
+ case 'T': state = JOB_STOPPING; break;
+ case 'X': state = JOB_PRE_STOP; break;
+ case 'Y': state = JOB_KILLED; break;
+ case 'Z': state = JOB_POST_STOP; break;
+ default: is_invalid = 1;
+ }
+
+ switch (goal_state[2])
+ {
+ case 'N': break;
+ case 'I': is_instance = 1; break;
+ default: is_invalid = 1;
+ }
+
+ if (is_invalid) {
+ nih_error("Invalid goal/state %s for restored job %s",
+ goal_state, jobname);
+ return;
+ }
+ job = job_find_by_name(jobname);
+ if (! job) {
+ nih_error("Unknown job %s passed to re-exec", jobname);
+ return;
+ }
+ if (is_instance) {
+ if (! job->instance) {
+ nih_error("Can not restore job %s as instance job",
+ jobname);
+ return;
+ }
+ job = job_instance(job);
+ } else {
+ if (job->instance) {
+ nih_error("Can not restore job %s as non-instance job",
+ jobname);
+ return;
+ }
+ }
+ job->goal = goal;
+ job->state = state;
+ procs=job->process;
+ restore_pid(procs[PROCESS_MAIN], pids[0], presents[0], jobname);
+ restore_pid(procs[PROCESS_PRE_START], pids[1], presents[1], jobname);
+ restore_pid(procs[PROCESS_POST_START], pids[2], presents[2], jobname);
+ restore_pid(procs[PROCESS_PRE_STOP], pids[3], presents[3], jobname);
+ restore_pid(procs[PROCESS_POST_STOP], pids[4], presents[4], jobname);
+}
+
+/**
+ * restore_current_configuration:
+ * @args: non-option arguments that were passed to the new init
+ */
+
+void restore_configuration(char **args)
+{
+ if (! args) return;
+
+ char **arg = args;
+ while (arg && *arg) {
+ char *jobname = *(arg++);
+ char *goal_state = *arg;
+ pid_t pids[5];
+ int presents[5];
+ int is_invalid = 0;
+
+ if (*arg) ++arg;
+ for (int i = 0; i < 5; i++)
+ retrieve_pid(&arg, jobname, &is_invalid,
+ &pids[i], &presents[i]);
+
+ if (! is_invalid)
+ restore_job_state (jobname, goal_state, pids, presents);
+ }
+}
diff -uNr upstart-0.3.9.orig/init/restore.h upstart-0.3.9/init/restore.h
--- upstart-0.3.9.orig/init/restore.h 1969-12-31 19:00:00.000000000 -0500
+++ upstart-0.3.9/init/restore.h 2009-01-23 13:44:54.000000000 -0500
@@ -0,0 +1,13 @@
+#ifndef INIT_RESTORE_H
+#define INIT_RESTORE_H
+
+#include <nih/string.h>
+
+NIH_BEGIN_EXTERN
+
+void save_current_configuration(char ***args, const void *parent, size_t *len);
+void restore_configuration(char **args);
+
+NIH_END_EXTERN
+
+#endif /* INIT_RESTORE_H */

113
upstart-telinit-u.patch Normal file
View file

@ -0,0 +1,113 @@
diff -urN upstart-0.3.9-old/compat/sysv/telinit.c upstart-0.3.9/compat/sysv/telinit.c
--- upstart-0.3.9-old/compat/sysv/telinit.c 2008-04-09 00:52:06.000000000 -0400
+++ upstart-0.3.9/compat/sysv/telinit.c 2008-04-09 01:02:39.000000000 -0400
@@ -113,9 +113,11 @@
NULL, UPSTART_INIT_DAEMON,
UPSTART_EVENT_EMIT, "runlevel", args, NULL));
break;
- case 'u':
- kill (UPSTART_INIT_DAEMON, SIGTERM);
- exit (0);
+ case 'u':
+ NIH_MUST (message = upstart_message_new (
+ NULL, UPSTART_INIT_DAEMON,
+ UPSTART_RESTART, NULL));
+ break;
default:
/* Ignore other arguments */
exit (0);
diff -urN upstart-0.3.9-old/init/control.c upstart-0.3.9/init/control.c
--- upstart-0.3.9-old/init/control.c 2008-04-09 00:52:06.000000000 -0400
+++ upstart-0.3.9/init/control.c 2008-04-09 01:01:41.000000000 -0400
@@ -29,6 +29,7 @@
#include <errno.h>
#include <unistd.h>
+#include <signal.h>
#include <fnmatch.h>
#include <nih/macros.h>
@@ -52,6 +53,8 @@
static void control_error_handler (void *data, NihIo *io);
static int control_version_query (void *data, pid_t pid,
UpstartMessageType type);
+static int control_restart (void *data, pid_t pid,
+ UpstartMessageType type);
static int control_log_priority (void *data, pid_t pid,
UpstartMessageType type,
NihLogLevel priority);
@@ -102,6 +105,8 @@
static UpstartMessage message_handlers[] = {
{ -1, UPSTART_VERSION_QUERY,
(UpstartMessageHandler)control_version_query },
+ { -1, UPSTART_RESTART,
+ (UpstartMessageHandler)control_restart },
{ -1, UPSTART_PUSH_TTY,
(UpstartMessageHandler)control_push_tty },
{ -1, UPSTART_POP_TTY,
@@ -319,6 +324,32 @@
}
/**
+ * control_restart:
+ * @data: data pointer,
+ * @pid: origin process id,
+ * @type: message type received.
+ *
+ * This function is called when another process on the system asks us to
+ * re-execute
+ *
+ * Returns: zero on success, negative value on raised error.
+ **/
+static int
+control_restart (void *data,
+ pid_t pid,
+ UpstartMessageType type)
+{
+ nih_assert (pid > 0);
+ nih_assert (type == UPSTART_RESTART);
+
+ nih_info (_("Control request to restart daemon"));
+
+ kill(getpid(), SIGTERM);
+
+ return 0;
+}
+
+/**
* control_push_tty:
* @data: data pointer,
* @pid: origin process id,
diff -urN upstart-0.3.9-old/upstart/message.c upstart-0.3.9/upstart/message.c
--- upstart-0.3.9-old/upstart/message.c 2008-04-09 00:52:06.000000000 -0400
+++ upstart-0.3.9/upstart/message.c 2008-04-09 00:55:03.000000000 -0400
@@ -259,6 +259,8 @@
switch (type) {
case UPSTART_NO_OP:
break;
+ case UPSTART_RESTART:
+ break;
case UPSTART_VERSION_QUERY:
break;
case UPSTART_POP_TTY:
@@ -564,6 +566,9 @@
case UPSTART_VERSION_QUERY:
ret = handler (data, cred.pid, type);
break;
+ case UPSTART_RESTART:
+ ret = handler (data, cred.pid, type);
+ break;
case UPSTART_POP_TTY:
ret = handler (data, cred.pid, type);
break;
diff -urN upstart-0.3.9-old/upstart/message.h upstart-0.3.9/upstart/message.h
--- upstart-0.3.9-old/upstart/message.h 2008-04-09 00:52:06.000000000 -0400
+++ upstart-0.3.9/upstart/message.h 2008-04-09 00:55:58.000000000 -0400
@@ -67,6 +67,7 @@
UPSTART_NO_OP = 0x0000,
UPSTART_VERSION_QUERY = 0x0001,
UPSTART_LOG_PRIORITY = 0x0002,
+ UPSTART_RESTART = 0x0005,
UPSTART_VERSION = 0x0010,
UPSTART_PUSH_TTY = 0x0011,
UPSTART_POP_TTY = 0x0012,

1684
upstart-tty-stack.patch Normal file

File diff suppressed because it is too large Load diff

175
upstart.spec Normal file
View file

@ -0,0 +1,175 @@
Name: upstart
Version: 0.3.11
Release: 1%{?dist}
Summary: An event-driven init system
Group: System Environment/Base
License: GPLv2+
URL: http://upstart.ubuntu.com
Source0: http://upstart.ubuntu.com/download/0.3/upstart-%{version}.tar.bz2
Source1: events.5
Patch0: upstart-force-on-shutdown-reboot.patch
Patch1: upstart-tty-stack.patch
Patch2: upstart-fedora-buglist.patch
Patch3: upstart-telinit-u.patch
Patch4: upstart-initctl-man.patch
Patch5: upstart-save-state-across-reexec.patch
Patch6: upstart-audit-events.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Obsoletes: SysVinit < 2.86-24, sysvinit < 2.86-24
Provides: SysVinit = 2.86-24, sysvinit = 2.86-24
BuildRequires: gettext audit-libs-devel
%description
Upstart is an event-based replacement for the /sbin/init daemon which
handles starting of tasks and services during boot, stopping them
during shutdown and supervising them while the system is running.
%prep
%setup -q
%patch0 -p1
%patch1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%build
%configure --enable-compat=sysv --sbindir=/sbin --libdir=/%{_lib}
make %{?_smp_mflags}
%install
rm -rf %{buildroot}
make install DESTDIR=%{buildroot}
mkdir -p %{buildroot}/%{_mandir}/man5
install -m 644 %{SOURCE1} %{buildroot}/%{_mandir}/man5/events.5
# libupstart and libnih aren't shipped
rm -f %{buildroot}/%{_lib}/libupstart.*
rm -f %{buildroot}/%{_lib}/libnih.*
rm -f %{buildroot}/%{_includedir}/libnih.h
rm -f %{buildroot}/%{_includedir}/libupstart.h
rm -rf %{buildroot}/%{_includedir}/nih
rm -rf %{buildroot}/%{_includedir}/upstart
rm -rf %{buildroot}/%{_datadir}/aclocal/compiler.m4
rm -rf %{buildroot}/%{_datadir}/aclocal/linker.m4
rm -rf %{buildroot}/%{_datadir}/aclocal/misc.m4
%find_lang %{name}
%clean
rm -rf %{buildroot}
%files -f %{name}.lang
%defattr(-,root,root,-)
%doc AUTHORS
%doc COPYING
%doc NEWS
%doc README
%doc TODO
%doc HACKING
%{_sysconfdir}/event.d/
%config(noreplace) %{_sysconfdir}/event.d/logd
/sbin/halt
/sbin/init
/sbin/initctl
/sbin/logd
/sbin/poweroff
/sbin/reboot
/sbin/runlevel
/sbin/shutdown
/sbin/start
/sbin/status
/sbin/stop
/sbin/telinit
%{_mandir}/man5/events.5.gz
%{_mandir}/man8/halt.8.gz
%{_mandir}/man8/init.8.gz
%{_mandir}/man8/initctl.8.gz
%{_mandir}/man8/logd.8.gz
%{_mandir}/man8/poweroff.8.gz
%{_mandir}/man8/reboot.8.gz
%{_mandir}/man8/runlevel.8.gz
%{_mandir}/man8/shutdown.8.gz
%{_mandir}/man8/start.8.gz
%{_mandir}/man8/status.8.gz
%{_mandir}/man8/stop.8.gz
%{_mandir}/man8/telinit.8.gz
%changelog
* Wed Jul 22 2009 Petr Lautrbach <plautrba@redhat.com> - 0.3.11-1
- Update to 0.3.11
* Mon Apr 27 2009 Bill Nottingham <notting@redhat.com> - 0.3.9-24
- Apply the audit patch correctly (#470661)
* Fri Apr 3 2009 Casey Dahlin <cdahlin@redhat.com> - 0.3.9-23
- Add audit events patch from Steve Grubb <sgrubb@redhat.com> (Bug #470661)
* Fri Jan 23 2009 Casey Dahlin <cdahlin@redhat.com> - 0.3.9-22
- Re-add 'telinit u' support along with patch to fix it (#450488). Patch due to
<pspencer@fields.utoronto.ca>
* Mon Jan 12 2009 Bill Nottingham <notting@redhat.com> - 0.3.9-21
- Remove 'telinit u' support as it is broken (#450488, <cjdahlin@ncsu.edu>)
* Fri Apr 25 2008 Bill Nottingham <notting@redhat.com> - 0.3.9-19
- with the merge of event-compat-sysv, move the sysvinit obsoletes/provides here
* Thu Apr 24 2008 Bill Nottingham <notting@redhat.com> - 0.3.9-18
- fix some man page typos (#444008, <archimerged@gmail.com>)
* Wed Apr 09 2008 Casey Dahlin <cjdahlin@ncsu.edu> - 0.3.9-17
- Added list of stock events to events(5)
* Tue Apr 08 2008 Casey Dahlin <cjdahlin@ncsu.edu> - 0.3.9-16
- Add telinit u support
* Fri Apr 04 2008 Bill Nottingham <notting@redhat.com> - 0.3.9-15
- Add a events(5) manpage that describes event syntax
* Thu Apr 03 2008 Casey Dahlin <cjdahlin@ncsu.edu> - 0.3.9-14
- Change bug report email address to fedora-devel-list@redhat.com
* Thu Mar 14 2008 Bill Nottingham <notting@redhat.com> - 0.3.9-13
- Ignore rpm temporary files of the foo;<somehex> format
- Make ignores of .rpm{new,orig,save} match only at the end of the name
* Wed Mar 13 2008 Bill Nottingham <notting@redhat.com> - 0.3.9-12
- forgot about rpmorig too (ugh)
* Wed Mar 13 2008 Casey Dahlin <cjdahlin@ncsu.edu> - 0.3.9-11
- Make logd a noreplace
* Wed Mar 13 2008 Casey Dahlin <cjdahlin@ncsu.edu> - 0.3.9-10
- Add patch to ignore .rpm{new,save} files
* Sun Mar 03 2008 Casey Dahlin <cjdahlin@ncsu.edu> - 0.3.9-9
- Remove automake dependency, build Makefile.in changes into patch
* Sun Mar 03 2008 Casey Dahlin <cjdahlin@ncsu.edu> - 0.3.9-8
- Run automake after patching
* Sun Mar 03 2008 Casey Dahlin <cjdahlin@ncsu.edu> - 0.3.9-7
- Added BuildRequires: automake
* Sun Mar 03 2008 Casey Dahlin <cjdahlin@ncsu.edu> - 0.3.9-6
- Added patch to allow runtime tty changes
* Fri Feb 15 2008 Casey Dahlin <cjdahlin@ncsu.edu> - 0.3.9-5
- Added patch to imply --force on runlevels 0 and 6
* Wed Feb 06 2008 Casey Dahlin <cjdahlin@ncsu.edu> - 0.3.9-4
- Patched for GCC 4.3
* Thu Jan 31 2008 Casey Dahlin <cjdahlin@ncsu.edu> - 0.3.9-3
- Added AUTHORS, COPYING, etc.
- Made config --libdir option relative
* Mon Jan 21 2008 Casey Dahlin <cjdahlin@ncsu.edu> - 0.3.9-2
- Remove libnih and libupstart
* Sun Jan 13 2008 Casey Dahlin <cjdahlin@ncsu.edu> - 0.3.9-1
- Initial packaging