From 53d17a1be2f9a47cec9e663905fbe1ee3637e050 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Mon, 9 Jul 2007 10:26:02 +0000 Subject: Add an option to fork ldconfig in env-update, #182794. Also, preserve the entire line in /etc/env.d/foo if it begins with $ --- ChangeLog | 4 ++++ init.d/bootmisc | 2 +- src/env-update.c | 40 +++++++++++++++++++++++++++++++--------- src/librc-misc.c | 12 ++++++++---- 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index d7e92d3a..c7e01342 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,10 @@ # ChangeLog for Gentoo System Intialization ("rc") scripts # Copyright 1999-2007 Gentoo Foundation; Distributed under the GPLv2 + 09 Jul 2007; Roy Marples : + + Add an option to fork ldconfig in env-update, #182794 + 06 Jul 2007; Roy Marples : Add and delete IPv6 addresses and routes correctly on FreeBSD, #184430 diff --git a/init.d/bootmisc b/init.d/bootmisc index d35f6d00..6004a01c 100755 --- a/init.d/bootmisc +++ b/init.d/bootmisc @@ -42,7 +42,7 @@ start() { ebegin "Updating environment" # As runscript prefixes our path with /$LIBDIR/rcscripts/bin, our # version instead of the portage version should be found first. - env-update + env-update --fork-ldconfig eend $? # Take care of random stuff [ /var/lock | /var/run | pam ] diff --git a/src/env-update.c b/src/env-update.c index 463cdf45..49a07718 100644 --- a/src/env-update.c +++ b/src/env-update.c @@ -64,6 +64,7 @@ static char *applet = NULL; #include "_usage.h" #define getoptstring "L" getoptstring_COMMON static struct option longopts[] = { + { "fork-ldconfig", 0, NULL, 'l'}, { "no-ldconfig", 0, NULL, 'L'}, longopts_COMMON { NULL, 0, NULL, 0} @@ -89,6 +90,7 @@ int main (int argc, char **argv) char **myspaces = NULL; int opt; bool ldconfig = true; + bool fork_ldconfig = false; applet = argv[0]; @@ -96,6 +98,9 @@ int main (int argc, char **argv) longopts, (int *) 0)) != -1) { switch (opt) { + case 'l': + fork_ldconfig = true; + break; case 'L': ldconfig = false; break; @@ -219,8 +224,12 @@ int main (int argc, char **argv) char *tmpent = rc_xstrdup (env); char *value = tmpent; char *var = strsep (&value, "="); - if (strcmp (var, "LDPATH") != 0) - fprintf (fp, "export %s='%s'\n", var, value); + if (strcmp (var, "LDPATH") != 0) { + if (*value == '$') + fprintf (fp, "export %s=%s\n", var, value); + else + fprintf (fp, "export %s='%s'\n", var, value); + } free (tmpent); } fclose (fp); @@ -233,8 +242,12 @@ int main (int argc, char **argv) char *tmpent = rc_xstrdup (env); char *value = tmpent; char *var = strsep (&value, "="); - if (strcmp (var, "LDPATH") != 0) - fprintf (fp, "setenv %s '%s'\n", var, value); + if (strcmp (var, "LDPATH") != 0) { + if (*value == '$') + fprintf (fp, "setenv %s %s\n", var, value); + else + fprintf (fp, "setenv %s '%s'\n", var, value); + } free (tmpent); } fclose (fp); @@ -275,6 +288,7 @@ int main (int argc, char **argv) if (ld) { int retval = 0; + pid_t pid = getpid (); if ((fp = fopen (LDSOCONF, "w")) == NULL) eerrorx ("%s: fopen `%s': %s", applet, LDSOCONF, @@ -284,14 +298,22 @@ int main (int argc, char **argv) fprintf (fp, "%s\n", ldent); fclose (fp); + if (fork_ldconfig) { + if ((pid = fork ()) == -1) + eerror ("%s: failed to fork: %s", applet, + strerror (errno)); + } + + if (pid) { #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) - ebegin ("Regenerating /var/run/ld-elf.so.hints"); - retval = system ("/sbin/ldconfig -elf -i '" LDSOCONF "'"); + ebegin ("Regenerating /var/run/ld-elf.so.hints"); + retval = system ("/sbin/ldconfig -elf -i '" LDSOCONF "'"); #else - ebegin ("Regenerating /etc/ld.so.cache"); - retval = system ("/sbin/ldconfig"); + ebegin ("Regenerating /etc/ld.so.cache"); + retval = system ("/sbin/ldconfig"); #endif - eend (retval, NULL); + eend (retval, NULL); + } } } diff --git a/src/librc-misc.c b/src/librc-misc.c index f527ef11..6436e0b4 100644 --- a/src/librc-misc.c +++ b/src/librc-misc.c @@ -336,10 +336,14 @@ char **rc_get_config (char **list, const char *file) entry = rc_xstrdup (token); - do { - /* Bash variables are usually quoted */ - token = strsep (&p, "\"\'"); - } while ((token) && (strlen (token) == 0)); + /* Preserve shell coloring */ + if (*p == '$') + token = p; + else + do { + /* Bash variables are usually quoted */ + token = strsep (&p, "\"\'"); + } while ((token) && (strlen (token) == 0)); /* Drop a newline if that's all we have */ i = strlen (token) - 1; -- cgit v1.2.3