/[baselayout]/trunk/src/runscript.c
Gentoo

Diff of /trunk/src/runscript.c

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

Revision 2765 Revision 2768
235static void cleanup (void) 235static void cleanup (void)
236{ 236{
237 if (! rc_in_plugin && prefix_locked) 237 if (! rc_in_plugin && prefix_locked)
238 unlink (PREFIX_LOCK); 238 unlink (PREFIX_LOCK);
239 239
240 /* Flush our buffered output if any */
241 eclose ();
242
243 if (hook_out) 240 if (hook_out)
244 rc_plugin_run (hook_out, applet); 241 rc_plugin_run (hook_out, applet);
245 rc_plugin_unload (); 242 rc_plugin_unload ();
246 243
247 if (restart_services ) { 244 if (restart_services ) {
315 312
316 if (! *prefixed) { 313 if (! *prefixed) {
317 ret += write (fd, ec, strlen (ec)); 314 ret += write (fd, ec, strlen (ec));
318 ret += write (fd, prefix, strlen (prefix)); 315 ret += write (fd, prefix, strlen (prefix));
319 ret += write (fd, ec_normal, strlen (ec_normal)); 316 ret += write (fd, ec_normal, strlen (ec_normal));
320 ret += write (fd, "|", 2); 317 ret += write (fd, "|", 1);
321 *prefixed = true; 318 *prefixed = true;
322 } 319 }
323 320
324 if (buffer[i] == '\n') 321 if (buffer[i] == '\n')
325 *prefixed = false; 322 *prefixed = false;
333{ 330{
334 bool execok; 331 bool execok;
335 int stdout_pipes[2]; 332 int stdout_pipes[2];
336 int stderr_pipes[2]; 333 int stderr_pipes[2];
337 334
338 /* To ensure any output has hit our ebuffer */
339 fflush (stdout);
340 fflush (stderr);
341
342 /* Setup our pipes for prefixed output */ 335 /* Setup our pipes for prefixed output */
343 if (rc_is_env ("RC_PREFIX", "yes")) { 336 if (prefix) {
344 if (pipe (stdout_pipes)) 337 if (pipe (stdout_pipes))
345 eerror ("pipe: %s", strerror (errno)); 338 eerror ("pipe: %s", strerror (errno));
346 if (pipe (stderr_pipes)) 339 if (pipe (stderr_pipes))
347 eerror ("pipe: %s", strerror (errno)); 340 eerror ("pipe: %s", strerror (errno));
348 } 341 }
354 service_pid = vfork(); 347 service_pid = vfork();
355 348
356 if (service_pid == -1) 349 if (service_pid == -1)
357 eerrorx ("%s: vfork: %s", service, strerror (errno)); 350 eerrorx ("%s: vfork: %s", service, strerror (errno));
358 if (service_pid == 0) { 351 if (service_pid == 0) {
359 if (rc_is_env ("RC_PREFIX", "yes")) { 352 if (prefix) {
360 int flags; 353 int flags;
361 354
362 if (dup2 (stdout_pipes[1], fileno (stdout)) == -1) 355 if (dup2 (stdout_pipes[1], fileno (stdout)) == -1)
363 eerror ("dup2 stdout: %s", strerror (errno)); 356 eerror ("dup2 stdout: %s", strerror (errno));
364 close (stdout_pipes[0]); 357 close (stdout_pipes[0]);
389 _exit (EXIT_FAILURE); 382 _exit (EXIT_FAILURE);
390 } 383 }
391 } 384 }
392 385
393 /* Prefix our piped output */ 386 /* Prefix our piped output */
394 if (rc_is_env ("RC_PREFIX", "yes")) { 387 if (prefix) {
395 bool stdout_done = false; 388 bool stdout_done = false;
396 bool stdout_prefix_shown = false; 389 bool stdout_prefix_shown = false;
397 bool stderr_done = false; 390 bool stderr_done = false;
398 bool stderr_prefix_shown = false; 391 bool stderr_prefix_shown = false;
399 char buffer[RC_LINEBUFFER]; 392 char buffer[RC_LINEBUFFER];
956 } 949 }
957 950
958 if (! rc_service_state (service, rc_service_stopped)) { 951 if (! rc_service_state (service, rc_service_stopped)) {
959 get_started_services (); 952 get_started_services ();
960 svc_stop (deps); 953 svc_stop (deps);
961
962 /* Flush our buffered output if any */
963 eflush ();
964 } 954 }
965 955
966 svc_start (deps); 956 svc_start (deps);
967 start_services (restart_services); 957 start_services (restart_services);
968 rc_strlist_free (restart_services); 958 rc_strlist_free (restart_services);
1077 functions can always instruct us of this change */ 1067 functions can always instruct us of this change */
1078 snprintf (pid, sizeof (pid), "%d", (int) getpid ()); 1068 snprintf (pid, sizeof (pid), "%d", (int) getpid ());
1079 setenv ("RC_RUNSCRIPT_PID", pid, 1); 1069 setenv ("RC_RUNSCRIPT_PID", pid, 1);
1080 1070
1081 /* eprefix is kinda klunky, but it works for our purposes */ 1071 /* eprefix is kinda klunky, but it works for our purposes */
1082 if (rc_is_env ("RC_PREFIX", "yes")) { 1072 if (rc_is_env ("RC_PARALLEL", "yes")) {
1083 int l = 0; 1073 int l = 0;
1084 int ll; 1074 int ll;
1085 1075
1086 /* Get the longest service name */ 1076 /* Get the longest service name */
1087 services = rc_services_in_runlevel (NULL); 1077 services = rc_services_in_runlevel (NULL);
1096 ll = strlen (applet); 1086 ll = strlen (applet);
1097 memcpy (prefix, applet, ll); 1087 memcpy (prefix, applet, ll);
1098 memset (prefix + ll, ' ', l - ll); 1088 memset (prefix + ll, ' ', l - ll);
1099 memset (prefix + l, 0, 1); 1089 memset (prefix + l, 0, 1);
1100 eprefix (prefix); 1090 eprefix (prefix);
1101 }
1102
1103 /* If we're in parallel and we're not prefixing then we need the ebuffer */
1104 if (rc_is_env ("RC_PARALLEL", "yes") && ! rc_is_env ("RC_PREFIX", "yes")) {
1105 char ebname[PATH_MAX];
1106 char *eb;
1107
1108 snprintf (ebname, sizeof (ebname), "%s.%s", applet, pid);
1109 eb = rc_strcatpaths (RC_SVCDIR "ebuffer", ebname, (char *) NULL);
1110 ebuffer (eb);
1111 free (eb);
1112 } 1091 }
1113 1092
1114#ifdef __linux__ 1093#ifdef __linux__
1115 /* Ok, we are ready to go, so setup selinux if applicable */ 1094 /* Ok, we are ready to go, so setup selinux if applicable */
1116 setup_selinux (argc, argv); 1095 setup_selinux (argc, argv);
1263 rc_mark_service (applet, rc_service_stopped); 1242 rc_mark_service (applet, rc_service_stopped);
1264 uncoldplug (); 1243 uncoldplug ();
1265 } else 1244 } else
1266 svc_exec (optarg, NULL); 1245 svc_exec (optarg, NULL);
1267 1246
1268 /* Flush our buffered output if any */
1269 eflush ();
1270
1271 /* We should ensure this list is empty after an action is done */ 1247 /* We should ensure this list is empty after an action is done */
1272 rc_strlist_free (restart_services); 1248 rc_strlist_free (restart_services);
1273 restart_services = NULL; 1249 restart_services = NULL;
1274 } 1250 }
1275 1251

Legend:
Removed from v.2765  
changed lines
  Added in v.2768

  ViewVC Help
Powered by ViewVC 1.1.20