- Replace

parse-etc-insserv.conf-and-adds-dependencies-accordingly.patch
  patch with insserv-generator.patch: no longer patch systemd main
  binary but generate systemd drop-in files using a generator, for
  insserv.conf compatibility.

OBS-URL: https://build.opensuse.org/package/show/Base:System/systemd?expand=0&rev=410
This commit is contained in:
Dr. Werner Fink 2013-07-02 20:42:56 +00:00 committed by Git OBS Bridge
parent 71a4694eea
commit 1c2e12b639
6 changed files with 416 additions and 139 deletions

394
insserv-generator.patch Normal file
View File

@ -0,0 +1,394 @@
From a8cbe79c77836cc2466e3534157864abc98ef3ef Mon Sep 17 00:00:00 2001
From: Frederic Crozat <fcrozat@suse.com>
Date: Fri, 28 Jun 2013 17:54:41 +0200
Subject: [PATCH] insserv.conf generator
parse /etc/insserv.conf.dd content and /etc/insserv.conf and generate
systemd unit drop-in files to add dependencies
---
Makefile.am | 9 +
src/insserv-generator/Makefile | 28 +++
src/insserv-generator/insserv-generator.c | 309 ++++++++++++++++++++++++++++++
3 files changed, 346 insertions(+)
create mode 100644 src/insserv-generator/Makefile
create mode 100644 src/insserv-generator/insserv-generator.c
diff --git a/Makefile.am b/Makefile.am
index 016d7da..9f8319d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -315,6 +315,7 @@ rootlibexec_PROGRAMS = \
systemd-sleep
systemgenerator_PROGRAMS = \
+ systemd-insserv-generator \
systemd-getty-generator \
systemd-fstab-generator \
systemd-system-update-generator
@@ -1549,6 +1550,14 @@ systemd_delta_LDADD = \
libsystemd-shared.la
# ------------------------------------------------------------------------------
+systemd_insserv_generator_SOURCES = \
+ src/insserv-generator/insserv-generator.c
+
+systemd_insserv_generator_LDADD = \
+ libsystemd-label.la \
+ libsystemd-shared.la
+
+# ------------------------------------------------------------------------------
systemd_getty_generator_SOURCES = \
src/getty-generator/getty-generator.c
diff --git a/src/insserv-generator/Makefile b/src/insserv-generator/Makefile
new file mode 100644
index 0000000..9d07505
--- /dev/null
+++ b/src/insserv-generator/Makefile
@@ -0,0 +1,28 @@
+# This file is part of systemd.
+#
+# Copyright 2010 Lennart Poettering
+#
+# systemd is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+#
+# systemd is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with systemd; If not, see <http://www.gnu.org/licenses/>.
+
+# This file is a dirty trick to simplify compilation from within
+# emacs. This file is not intended to be distributed. So, don't touch
+# it, even better ignore it!
+
+all:
+ $(MAKE) -C ..
+
+clean:
+ $(MAKE) -C .. clean
+
+.PHONY: all clean
diff --git a/src/insserv-generator/insserv-generator.c b/src/insserv-generator/insserv-generator.c
new file mode 100644
index 0000000..067ee2f
--- /dev/null
+++ b/src/insserv-generator/insserv-generator.c
@@ -0,0 +1,309 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2012 Lennart Poettering
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+ ***/
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/stat.h>
+
+#include "mkdir.h"
+#include "log.h"
+#include "fileio.h"
+#include "unit-name.h"
+#include "special.h"
+#include "path-util.h"
+#include "util.h"
+#include "strv.h"
+
+static const char *arg_dest = "/tmp";
+
+static char *sysv_translate_name(const char *name) {
+ char *r;
+
+ r = new(char, strlen(name) + sizeof(".service"));
+ if (!r)
+ return NULL;
+
+ if (endswith(name, ".sh"))
+ /* Drop .sh suffix */
+ strcpy(stpcpy(r, name) - 3, ".service");
+ else
+ /* Normal init script name */
+ strcpy(stpcpy(r, name), ".service");
+
+ return r;
+}
+
+static int sysv_translate_facility(const char *name, const char *filename, char **_r) {
+
+ /* We silently ignore the $ prefix here. According to the LSB
+ * spec it simply indicates whether something is a
+ * standardized name or a distribution-specific one. Since we
+ * just follow what already exists and do not introduce new
+ * uses or names we don't care who introduced a new name. */
+
+ static const char * const table[] = {
+ /* LSB defined facilities */
+ "local_fs", NULL,
+ "network", SPECIAL_NETWORK_TARGET,
+ "named", SPECIAL_NSS_LOOKUP_TARGET,
+ "portmap", SPECIAL_RPCBIND_TARGET,
+ "remote_fs", SPECIAL_REMOTE_FS_TARGET,
+ "syslog", NULL,
+ "time", SPECIAL_TIME_SYNC_TARGET,
+ };
+
+ unsigned i;
+ char *r;
+ const char *n;
+
+ assert(name);
+ assert(_r);
+
+ n = *name == '$' ? name + 1 : name;
+
+ for (i = 0; i < ELEMENTSOF(table); i += 2) {
+
+ if (!streq(table[i], n))
+ continue;
+
+ if (!table[i+1])
+ return 0;
+
+ r = strdup(table[i+1]);
+ if (!r)
+ return log_oom();
+
+ goto finish;
+ }
+
+ /* If we don't know this name, fallback heuristics to figure
+ * out whether something is a target or a service alias. */
+
+ if (*name == '$') {
+ if (!unit_prefix_is_valid(n))
+ return -EINVAL;
+
+ /* Facilities starting with $ are most likely targets */
+ r = unit_name_build(n, NULL, ".target");
+ } else if (filename && streq(name, filename))
+ /* Names equaling the file name of the services are redundant */
+ return 0;
+ else
+ /* Everything else we assume to be normal service names */
+ r = sysv_translate_name(n);
+
+ if (!r)
+ return -ENOMEM;
+
+finish:
+ *_r = r;
+
+ return 1;
+}
+
+
+
+static int parse_insserv_conf(const char* filename) {
+ _cleanup_fclose_ FILE *f = NULL;
+ int r;
+
+ if (!(f = fopen(filename, "re"))) {
+ log_debug("Failed to open file %s", filename);
+ r = errno == ENOENT ? 0 : -errno;
+ return r;
+ }
+
+ while (!feof(f)) {
+ char l[LINE_MAX], *t;
+ _cleanup_strv_free_ char **parsed = NULL;
+
+ if (!fgets(l, sizeof(l), f)) {
+ if (feof(f))
+ break;
+
+ r = -errno;
+ log_error("Failed to read configuration file '%s': %s", filename, strerror(-r));
+ return -r;
+ }
+
+ t = strstrip(l);
+ if (*t != '$' && *t != '<')
+ continue;
+
+ parsed = strv_split(t,WHITESPACE);
+ /* we ignore <interactive>, not used, equivalent to X-Interactive */
+ if (parsed && !startswith_no_case (parsed[0], "<interactive>")) {
+ _cleanup_free_ char *facility = NULL;
+ if (sysv_translate_facility(parsed[0], NULL, &facility) < 0)
+ continue;
+ if (streq(facility, SPECIAL_REMOTE_FS_TARGET)) {
+ _cleanup_free_ char *unit = NULL;
+ /* insert also a Wants dependency from remote-fs-pre on remote-fs */
+ unit = strjoin(arg_dest, "/remote-fs.target.d/50-",path_get_file_name(filename),".conf", NULL);
+ if (!unit)
+ return log_oom();
+
+ mkdir_parents_label(unit, 0755);
+
+ r = write_string_file(unit,
+ "# Automatically generated by systemd-insserv-generator\n\n"
+ "[Unit]\n"
+ "Wants=remote-fs-pre.target\n");
+ if (r)
+ return r;
+ free (facility);
+ facility=strdup(SPECIAL_REMOTE_FS_PRE_TARGET);
+ }
+ if (facility && endswith(facility, ".target")) {
+ char *name, **j;
+ FILE *file = NULL;
+
+ STRV_FOREACH (j, parsed+1) {
+ _cleanup_free_ char *unit = NULL;
+ _cleanup_free_ char *dep = NULL;
+
+ if (*j[0] == '+')
+ name = *j+1;
+ else
+ name = *j;
+ if (streq(name, "boot.localfs") ||
+ streq(name, "boot.crypto"))
+ continue;
+ if ((sysv_translate_facility(name, NULL, &dep) < 0) || !dep)
+ continue;
+
+ unit = strjoin(arg_dest, "/", dep, ".d/50-",path_get_file_name(filename),"-",parsed[0],".conf", NULL);
+ if (!unit)
+ return log_oom();
+
+ mkdir_parents_label(unit, 0755);
+
+ file = fopen(unit, "wxe");
+ if (!file) {
+ if (errno == EEXIST)
+ log_error("Failed to create drop-in file %s", unit);
+ else
+ log_error("Failed to create drop-in file %s: %m", unit);
+ return -errno;
+ }
+
+ fprintf(file,
+ "# Automatically generated by systemd-insserv-generator\n\n"
+ "[Unit]\n"
+ "Wants=%s\n"
+ "Before=%s\n",
+ facility, facility);
+
+ fflush(file);
+ if (ferror(file)) {
+ log_error("Failed to write unit file %s: %m", unit);
+ return -errno;
+ }
+ fclose(file);
+
+ if (*j[0] != '+') {
+ free (unit);
+ unit = strjoin(arg_dest, "/", facility, ".d/50-hard-dependency-",path_get_file_name(filename),"-",parsed[0],".conf", NULL);
+ if (!unit)
+ return log_oom();
+
+ mkdir_parents_label(unit, 0755);
+
+ file = fopen(unit, "wxe");
+ if (!file) {
+ if (errno == EEXIST)
+ log_error("Failed to create drop-in file %s, as it already exists", unit);
+ else
+ log_error("Failed to create drop-in file %s: %m", unit);
+ return -errno;
+ }
+
+
+ fprintf(file,
+ "# Automatically generated by systemd-insserv-generator\n\n"
+ "[Unit]\n"
+ "SourcePath=%s\n"
+ "Requires=%s\n",
+ filename, dep);
+ fflush(file);
+ if (ferror(file)) {
+ log_error("Failed to write unit file %s: %m", unit);
+ return -errno;
+ }
+ fclose(file);
+ }
+ }
+ }
+ }
+ }
+ return r;
+}
+
+static int parse_insserv(void) {
+ DIR *d = NULL;
+ struct dirent *de;
+ int r = 0;
+
+ if (!(d = opendir("/etc/insserv.conf.d/"))) {
+ if (errno != ENOENT) {
+ log_debug("opendir() failed on /etc/insserv.conf.d/ %s", strerror(errno));
+ }
+ } else {
+
+ while ((de = readdir(d))) {
+ char *path = NULL;
+ if (ignore_file(de->d_name))
+ continue;
+
+ path = strjoin("/etc/insserv.conf.d/", de->d_name, NULL);
+ parse_insserv_conf(path);
+ free(path);
+ }
+ closedir (d);
+ }
+
+ r = parse_insserv_conf("/etc/insserv.conf");
+
+ return r;
+}
+
+int main(int argc, char *argv[]) {
+ int r = 0;
+
+ if (argc > 1 && argc != 4) {
+ log_error("This program takes three or no arguments.");
+ return EXIT_FAILURE;
+ }
+
+ if (argc > 1)
+ arg_dest = argv[1];
+
+ log_set_target(LOG_TARGET_SAFE);
+ log_parse_environment();
+ log_open();
+
+ umask(0022);
+
+ r = parse_insserv();
+
+ return (r < 0) ? EXIT_FAILURE : EXIT_SUCCESS;
+}
--
1.8.1.4

View File

@ -1,131 +0,0 @@
From: Frederic Crozat <fcrozat@suse.com>
Date: Fri, 30 Sep 2011 13:55:31 +0000
Subject: parse /etc/insserv.conf and adds dependencies accordingly
(bnc#721428)
---
src/core/service.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 104 insertions(+)
diff --git a/src/core/service.c b/src/core/service.c
index 3617c24..3c66cdb 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -3443,6 +3443,108 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags) {
}
#ifdef HAVE_SYSV_COMPAT
+static void sysv_parse_insserv_conf(Manager *mgr, const char* filename) {
+ FILE *f = NULL;
+ int r;
+
+ if (!(f = fopen(filename, "re"))) {
+ log_debug("Failed to open file %s", filename);
+ r = errno == ENOENT ? 0 : -errno;
+ goto finish;
+ }
+
+ while (!feof(f)) {
+ char l[LINE_MAX], *t;
+ char **parsed = NULL;
+
+ if (!fgets(l, sizeof(l), f)) {
+ if (feof(f))
+ break;
+
+ r = -errno;
+ log_error("Failed to read configuration file '%s': %s", filename, strerror(-r));
+ goto finish;
+ }
+
+ t = strstrip(l);
+ if (*t != '$' && *t != '<')
+ continue;
+
+ parsed = strv_split(t,WHITESPACE);
+ /* we ignore <interactive>, not used, equivalent to X-Interactive */
+ if (parsed && !startswith_no_case (parsed[0], "<interactive>")) {
+ char *facility;
+ Unit *u;
+ if (sysv_translate_facility(parsed[0], NULL, &facility) < 0)
+ continue;
+ if (streq(facility, SPECIAL_REMOTE_FS_TARGET)) {
+ /* insert also a Wants dependency from remote-fs-pre on remote-fs */
+ u = manager_get_unit(mgr, SPECIAL_REMOTE_FS_TARGET);
+ if (u) {
+ unit_add_dependency_by_name(u, UNIT_WANTS, SPECIAL_REMOTE_FS_PRE_TARGET, NULL, true);
+ free (facility);
+ facility=strdup(SPECIAL_REMOTE_FS_PRE_TARGET);
+ }
+ }
+ u = manager_get_unit(mgr, facility);
+ if (u && (u->type == UNIT_TARGET)) {
+ char *dep = NULL, *name, **j;
+
+ STRV_FOREACH (j, parsed+1) {
+ if (*j[0] == '+')
+ name = *j+1;
+ else
+ name = *j;
+ if (streq(name, "boot.localfs") ||
+ streq(name, "boot.crypto"))
+ continue;
+ if ((sysv_translate_facility(name, NULL, &dep) < 0) || !dep)
+ continue;
+
+ r = unit_add_two_dependencies_by_name_inverse(u, UNIT_WANTS, UNIT_BEFORE, dep, NULL, true);
+ if (*j[0] != '+')
+ r = unit_add_dependency_by_name(u, UNIT_REQUIRES, dep, NULL, true);
+ free(dep);
+ }
+ }
+ free(facility);
+ }
+ strv_free(parsed);
+ }
+finish:
+ if (f)
+ fclose(f);
+
+}
+
+static void sysv_facility_in_insserv_conf(Manager *mgr) {
+ DIR *d =NULL;
+ struct dirent *de;
+
+#ifdef TARGET_DEBIAN
+ if (!(d = opendir("/etc/insserv.conf.d/")))
+ if (errno != ENOENT) {
+ log_warning("opendir() failed on /etc/insserv.conf.d/ %s", strerror(errno));
+ goto finish;
+ }
+
+ while ((de = readdir(d))) {
+ char *path = NULL;
+ if (ignore_file(de->d_name))
+ continue;
+
+ path = join("/etc/insserv.conf.d/", de->d_name, NULL);
+ sysv_parse_insserv_conf(mgr, path);
+ free(path);
+ }
+finish:
+ if (d)
+ closedir(d);
+#endif
+
+ sysv_parse_insserv_conf(mgr, "/etc/insserv.conf");
+}
+
static int service_enumerate(Manager *m) {
char **p;
@@ -3603,6 +3705,8 @@ static int service_enumerate(Manager *m) {
r = 0;
+ sysv_facility_in_insserv_conf (m);
+
finish:
for (i = 0; i < ELEMENTSOF(rcnd_table); i++)

View File

@ -1,3 +1,12 @@
-------------------------------------------------------------------
Mon Jul 1 13:43:31 UTC 2013 - fcrozat@suse.com
- Replace
parse-etc-insserv.conf-and-adds-dependencies-accordingly.patch
patch with insserv-generator.patch: no longer patch systemd main
binary but generate systemd drop-in files using a generator, for
insserv.conf compatibility.
-------------------------------------------------------------------
Mon Jul 1 09:14:55 UTC 2013 - coolo@suse.com

View File

@ -106,7 +106,6 @@ Source1: systemd-rpmlintrc
Source2: localfs.service
Source3: systemd-sysv-convert
Source4: macros.systemd
Source5: systemd-insserv_conf
Source6: baselibs.conf
Source7: libgcrypt.m4
Source8: systemd-journald.init
@ -124,7 +123,7 @@ Patch1: optionally-warn-if-nss-myhostname-is-called.patch
# handle SUSE specific kbd settings
Patch3: handle-disable_caplock-and-compose_table-and-kbd_rate.patch
Patch4: handle-numlock-value-in-etc-sysconfig-keyboard.patch
Patch6: parse-etc-insserv.conf-and-adds-dependencies-accordingly.patch
Patch6: insserv-generator.patch
Patch7: service-flags-sysv-service-with-detected-pid-as-RemainAfte.patch
Patch8: module-load-handle-SUSE-etc-sysconfig-kernel-module-list.patch
Patch9: remain_after_exit-initscript-heuristic-and-add-new-LSB-hea.patch
@ -507,8 +506,6 @@ find %{buildroot} -type f -name '*.la' -delete
mkdir -p %{buildroot}/{sbin,var/lib/systemd/sysv-convert,var/lib/systemd/migrated} %{buildroot}/usr/lib/systemd/{system-generators,user-generators,system-preset,user-preset,system/halt.target.wants,system/kexec.target.wants,system/poweroff.target.wants,system/reboot.target.wants}
install -m755 %{S:3} -D %{buildroot}%{_sbindir}/systemd-sysv-convert
# do not install, code has been fixed, might be useful in the future
#install -m755 %{S:5} %{buildroot}/usr/lib/systemd/system-generators
ln -s ../usr/lib/systemd/systemd %{buildroot}/bin/systemd
ln -s ../usr/lib/systemd/systemd %{buildroot}/sbin/init
ln -s ../usr/bin/systemctl %{buildroot}/sbin/reboot
@ -849,6 +846,7 @@ fi
%{_prefix}/lib/systemd/system-generators/systemd-rc-local-generator
%{_prefix}/lib/systemd/system-generators/systemd-fstab-generator
%{_prefix}/lib/systemd/system-generators/systemd-system-update-generator
%{_prefix}/lib/systemd/system-generators/systemd-insserv-generator
/%{_lib}/security/pam_systemd.so
%dir %{_libexecdir}/modules-load.d

View File

@ -1,3 +1,12 @@
-------------------------------------------------------------------
Mon Jul 1 13:43:31 UTC 2013 - fcrozat@suse.com
- Replace
parse-etc-insserv.conf-and-adds-dependencies-accordingly.patch
patch with insserv-generator.patch: no longer patch systemd main
binary but generate systemd drop-in files using a generator, for
insserv.conf compatibility.
-------------------------------------------------------------------
Mon Jul 1 09:14:55 UTC 2013 - coolo@suse.com

View File

@ -101,7 +101,6 @@ Source1: systemd-rpmlintrc
Source2: localfs.service
Source3: systemd-sysv-convert
Source4: macros.systemd
Source5: systemd-insserv_conf
Source6: baselibs.conf
Source7: libgcrypt.m4
Source8: systemd-journald.init
@ -119,7 +118,7 @@ Patch1: optionally-warn-if-nss-myhostname-is-called.patch
# handle SUSE specific kbd settings
Patch3: handle-disable_caplock-and-compose_table-and-kbd_rate.patch
Patch4: handle-numlock-value-in-etc-sysconfig-keyboard.patch
Patch6: parse-etc-insserv.conf-and-adds-dependencies-accordingly.patch
Patch6: insserv-generator.patch
Patch7: service-flags-sysv-service-with-detected-pid-as-RemainAfte.patch
Patch8: module-load-handle-SUSE-etc-sysconfig-kernel-module-list.patch
Patch9: remain_after_exit-initscript-heuristic-and-add-new-LSB-hea.patch
@ -502,8 +501,6 @@ find %{buildroot} -type f -name '*.la' -delete
mkdir -p %{buildroot}/{sbin,var/lib/systemd/sysv-convert,var/lib/systemd/migrated} %{buildroot}/usr/lib/systemd/{system-generators,user-generators,system-preset,user-preset,system/halt.target.wants,system/kexec.target.wants,system/poweroff.target.wants,system/reboot.target.wants}
install -m755 %{S:3} -D %{buildroot}%{_sbindir}/systemd-sysv-convert
# do not install, code has been fixed, might be useful in the future
#install -m755 %{S:5} %{buildroot}/usr/lib/systemd/system-generators
ln -s ../usr/lib/systemd/systemd %{buildroot}/bin/systemd
ln -s ../usr/lib/systemd/systemd %{buildroot}/sbin/init
ln -s ../usr/bin/systemctl %{buildroot}/sbin/reboot
@ -844,6 +841,7 @@ fi
%{_prefix}/lib/systemd/system-generators/systemd-rc-local-generator
%{_prefix}/lib/systemd/system-generators/systemd-fstab-generator
%{_prefix}/lib/systemd/system-generators/systemd-system-update-generator
%{_prefix}/lib/systemd/system-generators/systemd-insserv-generator
/%{_lib}/security/pam_systemd.so
%dir %{_libexecdir}/modules-load.d