[PATCH v2] Break out ldconfig parser
Yury Khrustalev
yury.khrustalev@arm.com
Wed Mar 11 13:24:27 GMT 2026
On Thu, Feb 26, 2026 at 09:49:04PM -0500, DJ Delorie wrote:
>
> Florian Weimer <fweimer@redhat.com> writes:
> > I think we should start giving the ldconfig files ldconfig- or similar
> > prefixes, so that things appear a bit less crowded in the elf directory.
>
> Renamed.
>
> > Do we need a separate parseconf.h file, or could we stick it into an
> > existing shared header?
>
> I moved it to ldconfig.h, which for some reason is in sysdeps...
>
> > And I think the function comment should be a bit more elaborate.
>
> Documented. I also cleaned up the API a bit.
>
> elf: factor out ld.conf parsing
Thanks for this, sorry I'm late with my comments and I see Adhemerval
has already added RB, but I have a few more questions.
I agree with Adhemerval that ldconfig_parse_config should be marked as hidden.
> diff --git a/elf/Makefile b/elf/Makefile
> index 1a0ed49bc3..21ea58b10b 100644
> --- a/elf/Makefile
> +++ b/elf/Makefile
> @@ -220,6 +220,7 @@ install-rootsbin += ldconfig
> ldconfig-modules := \
> cache \
> chroot_canon \
> + ldconfig-parse \
> readlib \
> static-stubs \
> stringtable \
OK
> diff --git a/elf/ldconfig-parse.c b/elf/ldconfig-parse.c
> new file mode 100644
> index 0000000000..9da5bd96e6
> --- /dev/null
> +++ b/elf/ldconfig-parse.c
>
> ...
>
> +static void
> +parse_conf_include (const char *config_file, unsigned int lineno,
> + bool do_chroot, const char *pattern,
> + char *opt_chroot, ldconfig_parse_config_cb *cb);
> +
> +static void
> +ldconfig_parse_config_1 (const char *filename, bool do_chroot,
> + char *opt_chroot,
> + ldconfig_parse_config_cb *callback);
> +
> +/* Parse a configuration file.
> +
> + Parameters:
> +
> + filename - The name of the file. It may be a full path or relative.
> +
> + opt_chroot - If non-NULL, all paths are relative to this.
> +
> + callback - for each non-blank line in the file, this function is called
> + with the line and it's location.
> + */
Maybe this should be in the header?
> +
> +void
> +ldconfig_parse_config (const char *filename, char *opt_chroot,
> + ldconfig_parse_config_cb *callback)
> +{
> + ldconfig_parse_config_1 (filename, true, opt_chroot, callback);
> +}
> +
> +static void
> +ldconfig_parse_config_1 (const char *filename, bool do_chroot,
> + char *opt_chroot, ldconfig_parse_config_cb *callback)
> +{
>
> ...
>
> + if (!strncmp (cp, "include", 7) && isblank (cp[7]))
> + {
> + char *dir;
> + cp += 8;
> + while ((dir = strsep (&cp, " \t")) != NULL)
> + if (dir[0] != '\0')
> + parse_conf_include (filename, lineno, do_chroot, dir, opt_chroot, callback);
There was this bit that seem to have disappeared:
else if (!strncasecmp (cp, "hwcap", 5) && isblank (cp[5]))
error (0, 0, _("%s:%u: hwcap directive ignored"), filename, lineno);
Was it on purpose?
> + }
> + else
> + (*callback) (cp, filename, lineno);
> + }
> + while (!feof_unlocked (file));
> +
> + /* Free buffer and close file. */
> + free (line);
> + fclose (file);
> +}
> +
>
> ...
>
> diff --git a/elf/ldconfig.c b/elf/ldconfig.c
> index aca967403a..070e933df6 100644
> --- a/elf/ldconfig.c
> +++ b/elf/ldconfig.c
> @@ -420,6 +420,16 @@ add_dir_1 (const char *line, const char *from_file, int from_line)
> free (path);
> }
>
>
> ...
>
> diff --git a/sysdeps/generic/ldconfig.h b/sysdeps/generic/ldconfig.h
> index 5913bf40fc..5a2a0f1d8d 100644
> --- a/sysdeps/generic/ldconfig.h
> +++ b/sysdeps/generic/ldconfig.h
> @@ -111,6 +111,13 @@ enum opt_format
>
> extern enum opt_format opt_format;
>
> +/* Declared in ldconfig-parse.c */
Nit: Defined? Though I see that "Declared" is used everywhere in this
header...
>
> ...
>
Thanks,
Yury
More information about the Libc-alpha
mailing list