From 5154d19238be8d2c17ee83d8bd05dbc06c689603 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Mon, 16 Jul 2007 07:19:32 +0000 Subject: env-update --fork-ldconfig really forks ldconfig and works now --- src/env-update.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/env-update.c b/src/env-update.c index 49a07718..07a9b0b2 100644 --- a/src/env-update.c +++ b/src/env-update.c @@ -10,7 +10,10 @@ #define APPLET "env-update" +#include +#include #include +#include #include #include #include @@ -36,6 +39,14 @@ #define LDNOTICE "# ld.so.conf autogenerated by env-update; make all\n" \ "# changes to contents of /etc/env.d directory\n" +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) +#define LD_MESSAGE "Regenerating /var/run/ld-elf.so.hints" +#define LD_SYSTEM "/sbin/ldconfig -elf -i '" LDSOCONF "'"; +#else +#define LD_MESSAGE "Regenerating /etc/ld.so.cache" +#define LD_SYSTEM "/sbin/ldconfig" +#endif + static const char *colon_separated[] = { "ADA_INCLUDE_PATH", "ADA_OBJECTS_PATH", @@ -62,7 +73,7 @@ static const char *space_separated[] = { static char *applet = NULL; #include "_usage.h" -#define getoptstring "L" getoptstring_COMMON +#define getoptstring "lL" getoptstring_COMMON static struct option longopts[] = { { "fork-ldconfig", 0, NULL, 'l'}, { "no-ldconfig", 0, NULL, 'L'}, @@ -288,7 +299,7 @@ int main (int argc, char **argv) if (ld) { int retval = 0; - pid_t pid = getpid (); + pid_t pid = 0; if ((fp = fopen (LDSOCONF, "w")) == NULL) eerrorx ("%s: fopen `%s': %s", applet, LDSOCONF, @@ -298,22 +309,24 @@ int main (int argc, char **argv) fprintf (fp, "%s\n", ldent); fclose (fp); + ebegin (LD_MESSAGE); if (fork_ldconfig) { if ((pid = fork ()) == -1) eerror ("%s: failed to fork: %s", applet, strerror (errno)); + else if (pid == 0) { + /* Become a proper daemon for a little bit */ + int fd = open ("/dev/null", O_RDWR); + setsid (); + dup2 (fd, fileno (stdin)); + dup2 (fd, fileno (stdout)); + dup2 (fd, fileno (stderr)); + } } - - if (pid) { -#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) - 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"); -#endif - eend (retval, NULL); - } + + if (pid == 0) + retval = system (LD_SYSTEM); + eend (retval, NULL); } } -- cgit v1.2.3