aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2007-07-16 07:19:32 +0000
committerRoy Marples <roy@marples.name>2007-07-16 07:19:32 +0000
commit5154d19238be8d2c17ee83d8bd05dbc06c689603 (patch)
tree0d7c0d9cf6d6d21a779f089157c99a72f96b2dec
parent56e51080ce251af470513f12f818ddd839e107fa (diff)
env-update --fork-ldconfig really forks ldconfig and works now
-rw-r--r--src/env-update.c39
1 files changed, 26 insertions, 13 deletions
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 <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);
}
}