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" #define APPLET "env-update"
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h>
#include <getopt.h> #include <getopt.h>
#include <limits.h> #include <limits.h>
#include <stdbool.h> #include <stdbool.h>
@ -36,6 +39,14 @@
#define LDNOTICE "# ld.so.conf autogenerated by env-update; make all\n" \ #define LDNOTICE "# ld.so.conf autogenerated by env-update; make all\n" \
"# changes to contents of /etc/env.d directory\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[] = { static const char *colon_separated[] = {
"ADA_INCLUDE_PATH", "ADA_INCLUDE_PATH",
"ADA_OBJECTS_PATH", "ADA_OBJECTS_PATH",
@ -62,7 +73,7 @@ static const char *space_separated[] = {
static char *applet = NULL; static char *applet = NULL;
#include "_usage.h" #include "_usage.h"
#define getoptstring "L" getoptstring_COMMON #define getoptstring "lL" getoptstring_COMMON
static struct option longopts[] = { static struct option longopts[] = {
{ "fork-ldconfig", 0, NULL, 'l'}, { "fork-ldconfig", 0, NULL, 'l'},
{ "no-ldconfig", 0, NULL, 'L'}, { "no-ldconfig", 0, NULL, 'L'},
@ -288,7 +299,7 @@ int main (int argc, char **argv)
if (ld) { if (ld) {
int retval = 0; int retval = 0;
pid_t pid = getpid (); pid_t pid = 0;
if ((fp = fopen (LDSOCONF, "w")) == NULL) if ((fp = fopen (LDSOCONF, "w")) == NULL)
eerrorx ("%s: fopen `%s': %s", applet, LDSOCONF, eerrorx ("%s: fopen `%s': %s", applet, LDSOCONF,
@ -298,24 +309,26 @@ int main (int argc, char **argv)
fprintf (fp, "%s\n", ldent); fprintf (fp, "%s\n", ldent);
fclose (fp); fclose (fp);
ebegin (LD_MESSAGE);
if (fork_ldconfig) { if (fork_ldconfig) {
if ((pid = fork ()) == -1) if ((pid = fork ()) == -1)
eerror ("%s: failed to fork: %s", applet, eerror ("%s: failed to fork: %s", applet,
strerror (errno)); 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 (pid == 0)
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) retval = system (LD_SYSTEM);
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); eend (retval, NULL);
} }
} }
}
rc_strlist_free (ldents); rc_strlist_free (ldents);
rc_strlist_free (envs); rc_strlist_free (envs);