[systemd-devel] [PATCH] sysv-generator: do not generate 'Wants' symlinks to generated service files that will be shadowed by a native unit.

Lennart Poettering lennart at poettering.net
Wed Jul 16 08:17:40 PDT 2014


On Wed, 16.07.14 11:57, Jon Severinsson (jon at severinsson.net) wrote:

I am a bit concerned about this, as we will never be able to find all
the units that PID 1 will find, for example because generated units are
not included in the client's search paths...

What's the precise issue that this fixes? Aren't there better fixes for
that? For example by ensuring that chkconfig always also runs systemctl
enable/disable and vice versa, so that it never happens that a unit
might be enabled by one, but not by the other?

> ---
>  src/sysv-generator/sysv-generator.c | 29 +++++++++++++++++++++++++++--
>  1 file changed, 27 insertions(+), 2 deletions(-)
> 
> diff --git a/src/sysv-generator/sysv-generator.c b/src/sysv-generator/sysv-generator.c
> index 5206279..aff5fd6 100644
> --- a/src/sysv-generator/sysv-generator.c
> +++ b/src/sysv-generator/sysv-generator.c
> @@ -113,7 +113,26 @@ static int add_symlink(const char *service, const char *where) {
>          return 1;
>  }
>  
> -static int generate_unit_file(SysvStub *s) {
> +static int native_unit_exists(LookupPaths lp, char *name) {
> +        char **p;
> +
> +        STRV_FOREACH(p, lp.unit_path) {
> +                struct stat st;
> +                _cleanup_free_ char *path = NULL;
> +
> +                path = strjoin(*p, "/", name, NULL);
> +                if (!path)
> +                        return -ENOMEM;
> +
> +                if (lstat(path, &st) < 0)
> +                        continue;
> +
> +                return 1;
> +        }
> +        return 0;
> +}
> +
> +static int generate_unit_file(LookupPaths lp, SysvStub *s) {
>          char *unit;
>          char **p;
>          _cleanup_fclose_ FILE *f = NULL;
> @@ -190,6 +209,12 @@ static int generate_unit_file(SysvStub *s) {
>          if (s->reload)
>                  fprintf(f, "ExecReload=%s reload\n", s->path);
>  
> +        /* Do not generate 'Wants' symlinks to the generated service file if it
> +         * will be shadowed by an existing native unit, as the symlinks would
> +         * not be shadowed but would pull the native unit instead. */
> +        if (native_unit_exists(lp, s->name))
> +                return 0;
> +
>          STRV_FOREACH(p, s->wanted_by) {
>                  r = add_symlink(s->name, *p);
>                  if (r < 0)
> @@ -918,7 +943,7 @@ int main(int argc, char *argv[]) {
>                  if (q < 0)
>                          continue;
>  
> -                q = generate_unit_file(service);
> +                q = generate_unit_file(lp, service);
>                  if (q < 0)
>                          continue;
>          }


Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list