Le vendredi 01 juillet 2011 à 23:30 +0200, Lennart Poettering a écrit :
> On Fri, 01.07.11 11:20, Frederic Crozat ([email protected]) wrote:
> 
> > Hi,
> 
> Heya,
> > 
> > as discussed on irc, I've implemented parsing /etc/insserv.conf, which,
> > on SUSE (and maybe on Debian), provides LSB System Facilities (instead
> > of using Provides: in LSB initscripts, for things like $network,
> > $portmap, etc..).
> 
> Michael, Tollef, can you comment on this too, plz? Would be good to have
> some input from you if this is useful for Debian, too.

Please note that I didn't put parsing of /etc/insserv.d in the current
patch, as it is not used on openSUSE (but I can add it, if requested ;)

> > I didn't implement the <interactive> part of insserv.conf, since
> > X-Interactive is currently broken in systemd and we'd like to keep
> > sysvinit for openSUSE 12.1 (so, we could just remove X-Interactive flags
> > from legacy initscripts on openSUSE, but when booting with old sysvinit,
> > <interactive> list would be used to tell boot scripts which one are
> > interactive).
> 
> I think the idea of X-Interactive is unfixably broken, i.e. if you end
> up starting a service after boot-up at which time tty1 is blocked by a
> getty, then this will necessarily deadlock. I am not sure how this could
> ever be fixed.

This is why I excluded parsing the list ;)

> > +                t = strstrip(l);
> > +                if ((*t != '$') && (*t != '<'))
> 
> Please don't place redundant brackets here. 

Fixed.
> 
> > +                        continue;
> > +
> > +                parsed = strv_split (t,WHITESPACE);
> 
> Please no spaces between a function and the opening bracket. This is
> good: sin(x), this is bad: sin (x).

Oops, missed this.. Fixed.

> > +                /* 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 ((u = manager_get_unit (mgr, facility)) && 
> > (u->meta.type == UNIT_TARGET)) {
> > +                                UnitDependency e;
> > +                                char *dep = NULL, *name;
> > +                                int j;
> > +
> > +                                for (j=1;parsed[j]; j++) {
> 
> Please use STRV_FOREACH for iterating through string arrays.

Forgot about it.. Fixed.

Here is new version attached

-- 
Frederic Crozat <[email protected]>
SUSE
>From c4f60bddda53704ed4601b8af28a1e628b405674 Mon Sep 17 00:00:00 2001
From: Frederic Crozat <[email protected]>
Date: Wed, 29 Jun 2011 13:59:34 +0200
Subject: [PATCH] parse insserv.conf and plugs its system facilities into systemd.

---
 src/service.c |   70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 70 insertions(+), 0 deletions(-)

diff --git a/src/service.c b/src/service.c
index d59c4cb..96baa82 100644
--- a/src/service.c
+++ b/src/service.c
@@ -2950,6 +2950,72 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags) {
 }
 
 #ifdef HAVE_SYSV_COMPAT
+
+#ifdef TARGET_SUSE
+static void sysv_facility_in_insserv_conf(Manager *mgr) {
+        FILE *f=NULL;
+        int r;
+
+        if (!(f = fopen("/etc/insserv.conf", "re"))) {
+                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 '/etc/insserv.conf': %s", 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 ((u = manager_get_unit(mgr, facility)) && (u->meta.type == UNIT_TARGET)) {
+                                UnitDependency e;
+                                char *dep = NULL, *name, **j;
+
+                                STRV_FOREACH (j, parsed+1) {
+                                        if (*j[0]=='+') {
+                                                e = UNIT_WANTS;
+                                                name = *j+1;
+                                        }
+                                        else {
+                                                e = UNIT_REQUIRES;
+                                                name = *j;
+                                        }
+                                        if (sysv_translate_facility(name, NULL, &dep) < 0)
+                                                continue;
+
+                                        r = unit_add_two_dependencies_by_name(u, UNIT_BEFORE, e, dep, NULL, true);
+                                        free(dep);
+                                }
+                        }
+                        free(facility);
+                }
+                strv_free(parsed);
+        }
+finish:
+        if (f)
+                fclose(f);
+
+}
+#endif
+
 static int service_enumerate(Manager *m) {
         char **p;
         unsigned i;
@@ -3095,6 +3161,10 @@ static int service_enumerate(Manager *m) {
 
         r = 0;
 
+#ifdef TARGET_SUSE
+	sysv_facility_in_insserv_conf (m);
+#endif
+
 finish:
         free(path);
         free(fpath);
-- 
1.7.3.4

_______________________________________________
systemd-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to