X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fservice.c;h=9f2ee4192fff506d099539a8b450ca4e1fa9351d;hb=ec14911e0d6b9473f4f1d6b43d7fcd67c48c2ffc;hp=620f2b307ab20e345c7b2db1a340442fec5a3af2;hpb=65530632c7e40bc369edcba8f014ec9136c8eb02;p=elogind.git diff --git a/src/service.c b/src/service.c index 620f2b307..9f2ee4192 100644 --- a/src/service.c +++ b/src/service.c @@ -237,19 +237,23 @@ static char *sysv_translate_name(const char *name) { if (!(r = new(char, strlen(name) + sizeof(".service")))) return NULL; +#if defined(TARGET_DEBIAN) || defined(TARGET_UBUNTU) + if (endswith(name, ".sh")) + /* Drop Debian-style .sh suffix */ + strcpy(stpcpy(r, name) - 3, ".service"); +#endif +#ifdef TARGET_SUSE if (startswith(name, "boot.")) /* Drop SuSE-style boot. prefix */ strcpy(stpcpy(r, name + 5), ".service"); - else if (endswith(name, ".sh")) - /* Drop Debian-style .sh suffix */ - strcpy(stpcpy(r, name) - 3, ".service"); +#endif #ifdef TARGET_ARCH - else if (startswith(name, "@")) + if (startswith(name, "@")) /* Drop Arch-style background prefix */ strcpy(stpcpy(r, name + 1), ".service"); #endif #ifdef TARGET_FRUGALWARE - else if (startswith(name, "rc.")) + if (startswith(name, "rc.")) /* Drop Frugalware-style rc. prefix */ strcpy(stpcpy(r, name + 3), ".service"); #endif @@ -855,11 +859,22 @@ static int service_load_sysv_name(Service *s, const char *name) { assert(s); assert(name); - /* For SysV services we strip the boot. or .sh + /* For SysV services we strip the boot.*, rc.* and *.sh * prefixes/suffixes. */ - if (startswith(name, "boot.") || - endswith(name, ".sh.service")) +#if defined(TARGET_DEBIAN) || defined(TARGET_UBUNTU) + if (endswith(name, ".sh.service")) + return -ENOENT; +#endif + +#ifdef TARGET_SUSE + if (startswith(name, "boot.")) return -ENOENT; +#endif + +#ifdef TARGET_FRUGALWARE + if (startswith(name, "rc.")) + return -ENOENT; +#endif STRV_FOREACH(p, s->meta.manager->lookup_paths.sysvinit_path) { char *path; @@ -873,36 +888,42 @@ static int service_load_sysv_name(Service *s, const char *name) { r = service_load_sysv_path(s, path); +#if defined(TARGET_DEBIAN) || defined(TARGET_UBUNTU) if (r >= 0 && s->meta.load_state == UNIT_STUB) { - /* Try Debian style xxx.sh source'able init scripts */ + /* Try Debian style *.sh source'able init scripts */ strcat(path, ".sh"); r = service_load_sysv_path(s, path); } - +#endif free(path); +#ifdef TARGET_SUSE if (r >= 0 && s->meta.load_state == UNIT_STUB) { - /* Try SUSE style boot.xxx init scripts */ + /* Try SUSE style boot.* init scripts */ if (asprintf(&path, "%s/boot.%s", *p, name) < 0) return -ENOMEM; + /* Drop .service suffix */ path[strlen(path)-8] = 0; r = service_load_sysv_path(s, path); free(path); } +#endif +#ifdef TARGET_FRUGALWARE if (r >= 0 && s->meta.load_state == UNIT_STUB) { - /* Try Frugalware style rc.xxx init scripts */ + /* Try Frugalware style rc.* init scripts */ if (asprintf(&path, "%s/rc.%s", *p, name) < 0) return -ENOMEM; - /* Drop .service suffix */ + /* Drop .service suffix */ path[strlen(path)-8] = 0; r = service_load_sysv_path(s, path); free(path); } +#endif if (r < 0) return r;