env-update --fork-ldconfig really forks ldconfig and works now

This commit is contained in:
Roy Marples 2007-07-16 07:19:32 +00:00
parent 56e51080ce
commit 5154d19238

View File

@ -10,7 +10,10 @@
#define APPLET "env-update"
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <limits.h>
#include <stdbool.h>
@ -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);
}
}