1 Purpose: Add support for upstart jobs.
3 Status: Work in progress, not submitted upstream yet.
6 Index: insserv/insserv.8.in
7 ===================================================================
8 --- insserv.orig/insserv.8.in 2009-09-26 22:35:39.000000000 +0200
9 +++ insserv/insserv.8.in 2009-09-26 22:35:42.000000000 +0200
12 Ignore if a required service is missed.
14 +.BR \-u\ <path> ,\ \-\-upstart-job\ <path>
15 +Path to replace existing upstart job path. (default path is
16 +.IR /lib/init/upstart-job ).
19 Print out short usage message.
22 name as the boot or init script in the directory
23 .IR /etc/insserv/overrides/ .
25 +.SH UPSTART JOB COMPATIBILITY
26 +To allow upstart jobs to work as init.d scripts, insserv will
27 +recognize a symlink from path/to/init.d/script to
28 +/lib/init/upstart-job as upstart jobs, and instead of reading the
29 +header from the file will run the script with the argument lsb-header
30 +to get the script header.
32 The exit codes have the following conditions:
34 Index: insserv/insserv.c
35 ===================================================================
36 --- insserv.orig/insserv.c 2009-09-26 22:35:39.000000000 +0200
37 +++ insserv/insserv.c 2009-09-26 22:35:43.000000000 +0200
39 # define INSCONF "/etc/insserv.conf"
42 +const char *upstartjob_path = "/lib/init/upstart-job";
45 * For a description of regular expressions see regex(7).
47 @@ -1154,6 +1156,43 @@
48 xreset(script_inf.interactive);
51 +static char *is_upstart_job_recursive(const char *path,
52 + const char *basenamestr)
54 + struct stat statbuf;
55 + if (-1 == lstat(path, &statbuf)) {
58 + if (S_ISLNK(statbuf.st_mode)) {
60 + int len = readlink(path, buf, sizeof(buf)-1);
63 + if (0 == strcmp(buf, upstartjob_path)) {
64 + /* upstart job, return base name of original symlink */
65 + return strdup(basenamestr);
67 + return is_upstart_job_recursive(buf, basenamestr);
74 + * return name of upstart job if the script is a symlink to
75 + * /lib/init/upstart-job, or NULL if path do not point to an
78 +static char* is_upstart_job(const char *path)
81 + char *basenamestr = basename(path); /* GNU basename */
82 + char *retval = is_upstart_job_recursive(path, basenamestr);
84 + info("script '%s' is upstart job\n", basenamestr);
88 #define FOUND_LSB_HEADER 0x01
89 #define FOUND_LSB_DEFAULT 0x02
90 #define FOUND_LSB_OVERRIDE 0x04
97 + char *upstart_job = NULL;
99 #define provides script_inf.provides
100 #define required_start script_inf.required_start
101 @@ -1186,12 +1226,23 @@
103 info("Loading %s\n", path);
105 - if ((fd = xopen(dfd, path, o_flags)) < 0 || (script = fdopen(fd, "r")) == (FILE*)0)
106 - error("fopen(%s): %s\n", path, strerror(errno));
107 + if (NULL != (upstart_job = is_upstart_job(path))) {
110 + len = snprintf(cmd, sizeof(cmd),
111 + "%s %s lsb-header", upstartjob_path, upstart_job);
112 + if (len < 0 || sizeof(cmd) == len)
113 + error("snprintf: insufficient buffer for %s\n", path);
114 + if ((FILE*)0 == (script = popen(cmd, "r")))
115 + error("popen(%s): %s\n", path, strerror(errno));
117 + if ((fd = xopen(dfd, path, o_flags)) < 0 || (script = fdopen(fd, "r")) == (FILE*)0)
118 + error("fopen(%s): %s\n", path, strerror(errno));
120 #if defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) >= 600
121 - (void)posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL);
122 + (void)posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL);
126 #define COMMON_ARGS buf, SUBNUM, subloc, 0
127 #define COMMON_SHD_ARGS buf, SUBNUM_SHD, subloc, 0
128 @@ -1303,7 +1354,12 @@
129 (void)posix_fadvise(fd, 0, 0, POSIX_FADV_NOREUSE);
141 ret |= FOUND_LSB_HEADER;
142 @@ -2224,6 +2280,7 @@
143 {"force", 0, (int*)0, 'f'},
144 {"path", 1, (int*)0, 'p'},
145 {"override",1, (int*)0, 'o'},
146 + {"upstart-job",1, (int*)0, 'u'},
147 {"help", 0, (int*)0, 'h'},
148 { 0, 0, (int*)0, 0 },
150 @@ -2277,7 +2334,7 @@
151 for (c = 0; c < argc; c++)
154 - while ((c = getopt_long(argc, argv, "c:dfrhvno:p:", long_options, (int *)0)) != -1) {
155 + while ((c = getopt_long(argc, argv, "c:dfrhvno:p:u:", long_options, (int *)0)) != -1) {
159 @@ -2317,6 +2374,11 @@
160 override_path = optarg;
164 + if (optarg == (char*)0 || *optarg == '\0')
166 + upstartjob_path = optarg;
170 error("For help use: %s -h\n", myname);