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

Thomas H.P. Andersen phomes at gmail.com
Wed Jul 16 03:48:23 PDT 2014


On Wed, Jul 16, 2014 at 11:57 AM, Jon Severinsson <jon at severinsson.net> wrote:
> ---
>  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;
> +
Any reason that we should not just put the native_unit_exists check in
enumerate_sysv instead and skip generating a unit at all?

>          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;
>          }
> --
> 2.0.1
>
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel


More information about the systemd-devel mailing list