/[baselayout]/trunk/src/env-update.c
Gentoo

Diff of /trunk/src/env-update.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 2754 Revision 2755
62static char *applet = NULL; 62static char *applet = NULL;
63 63
64#include "_usage.h" 64#include "_usage.h"
65#define getoptstring "L" getoptstring_COMMON 65#define getoptstring "L" getoptstring_COMMON
66static struct option longopts[] = { 66static struct option longopts[] = {
67 { "fork-ldconfig", 0, NULL, 'l'},
67 { "no-ldconfig", 0, NULL, 'L'}, 68 { "no-ldconfig", 0, NULL, 'L'},
68 longopts_COMMON 69 longopts_COMMON
69 { NULL, 0, NULL, 0} 70 { NULL, 0, NULL, 0}
70}; 71};
71#include "_usage.c" 72#include "_usage.c"
87 char *entry; 88 char *entry;
88 char **mycolons = NULL; 89 char **mycolons = NULL;
89 char **myspaces = NULL; 90 char **myspaces = NULL;
90 int opt; 91 int opt;
91 bool ldconfig = true; 92 bool ldconfig = true;
93 bool fork_ldconfig = false;
92 94
93 applet = argv[0]; 95 applet = argv[0];
94 96
95 while ((opt = getopt_long (argc, argv, getoptstring, 97 while ((opt = getopt_long (argc, argv, getoptstring,
96 longopts, (int *) 0)) != -1) 98 longopts, (int *) 0)) != -1)
97 { 99 {
98 switch (opt) { 100 switch (opt) {
101 case 'l':
102 fork_ldconfig = true;
103 break;
99 case 'L': 104 case 'L':
100 ldconfig = false; 105 ldconfig = false;
101 break; 106 break;
102 107
103 case_RC_COMMON_GETOPT 108 case_RC_COMMON_GETOPT
217 222
218 STRLIST_FOREACH (envs, env, i) { 223 STRLIST_FOREACH (envs, env, i) {
219 char *tmpent = rc_xstrdup (env); 224 char *tmpent = rc_xstrdup (env);
220 char *value = tmpent; 225 char *value = tmpent;
221 char *var = strsep (&value, "="); 226 char *var = strsep (&value, "=");
222 if (strcmp (var, "LDPATH") != 0) 227 if (strcmp (var, "LDPATH") != 0) {
228 if (*value == '$')
229 fprintf (fp, "export %s=%s\n", var, value);
230 else
223 fprintf (fp, "export %s='%s'\n", var, value); 231 fprintf (fp, "export %s='%s'\n", var, value);
232 }
224 free (tmpent); 233 free (tmpent);
225 } 234 }
226 fclose (fp); 235 fclose (fp);
227 236
228 if ((fp = fopen (CSH_ENV, "w")) == NULL) 237 if ((fp = fopen (CSH_ENV, "w")) == NULL)
231 240
232 STRLIST_FOREACH (envs, env, i) { 241 STRLIST_FOREACH (envs, env, i) {
233 char *tmpent = rc_xstrdup (env); 242 char *tmpent = rc_xstrdup (env);
234 char *value = tmpent; 243 char *value = tmpent;
235 char *var = strsep (&value, "="); 244 char *var = strsep (&value, "=");
236 if (strcmp (var, "LDPATH") != 0) 245 if (strcmp (var, "LDPATH") != 0) {
246 if (*value == '$')
247 fprintf (fp, "setenv %s %s\n", var, value);
248 else
237 fprintf (fp, "setenv %s '%s'\n", var, value); 249 fprintf (fp, "setenv %s '%s'\n", var, value);
250 }
238 free (tmpent); 251 free (tmpent);
239 } 252 }
240 fclose (fp); 253 fclose (fp);
241 254
242 ldent = rc_get_config_entry (envs, "LDPATH"); 255 ldent = rc_get_config_entry (envs, "LDPATH");
273 ld = true; 286 ld = true;
274 } 287 }
275 288
276 if (ld) { 289 if (ld) {
277 int retval = 0; 290 int retval = 0;
291 pid_t pid = getpid ();
278 292
279 if ((fp = fopen (LDSOCONF, "w")) == NULL) 293 if ((fp = fopen (LDSOCONF, "w")) == NULL)
280 eerrorx ("%s: fopen `%s': %s", applet, LDSOCONF, 294 eerrorx ("%s: fopen `%s': %s", applet, LDSOCONF,
281 strerror (errno)); 295 strerror (errno));
282 fprintf (fp, LDNOTICE); 296 fprintf (fp, LDNOTICE);
283 STRLIST_FOREACH (ldents, ldent, i) 297 STRLIST_FOREACH (ldents, ldent, i)
284 fprintf (fp, "%s\n", ldent); 298 fprintf (fp, "%s\n", ldent);
285 fclose (fp); 299 fclose (fp);
286 300
301 if (fork_ldconfig) {
302 if ((pid = fork ()) == -1)
303 eerror ("%s: failed to fork: %s", applet,
304 strerror (errno));
305 }
306
307 if (pid) {
287#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) 308#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
288 ebegin ("Regenerating /var/run/ld-elf.so.hints"); 309 ebegin ("Regenerating /var/run/ld-elf.so.hints");
289 retval = system ("/sbin/ldconfig -elf -i '" LDSOCONF "'"); 310 retval = system ("/sbin/ldconfig -elf -i '" LDSOCONF "'");
290#else 311#else
291 ebegin ("Regenerating /etc/ld.so.cache"); 312 ebegin ("Regenerating /etc/ld.so.cache");
292 retval = system ("/sbin/ldconfig"); 313 retval = system ("/sbin/ldconfig");
293#endif 314#endif
294 eend (retval, NULL); 315 eend (retval, NULL);
316 }
295 } 317 }
296 } 318 }
297 319
298 rc_strlist_free (ldents); 320 rc_strlist_free (ldents);
299 rc_strlist_free (envs); 321 rc_strlist_free (envs);

Legend:
Removed from v.2754  
changed lines
  Added in v.2755

  ViewVC Help
Powered by ViewVC 1.1.20