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

Diff of /trunk/src/runscript.c

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

Revision 2762 Revision 2763
1180 exit (EXIT_FAILURE); 1180 exit (EXIT_FAILURE);
1181 1181
1182 if (strcmp (optarg, "status") != 0 && 1182 if (strcmp (optarg, "status") != 0 &&
1183 strcmp (optarg, "help") != 0) { 1183 strcmp (optarg, "help") != 0) {
1184 /* Only root should be able to run us */ 1184 /* Only root should be able to run us */
1185 if (geteuid () != 0)
1186 eerrorx ("%s: root access required", applet);
1187 } 1185 }
1188 1186
1189 /* Export the command we're running. 1187 /* Export the command we're running.
1190 This is important as we stamp on the restart function now but 1188 This is important as we stamp on the restart function now but
1191 some start/stop routines still need to behave differently if 1189 some start/stop routines still need to behave differently if
1192 restarting. */ 1190 restarting. */
1193 unsetenv ("RC_CMD"); 1191 unsetenv ("RC_CMD");
1194 setenv ("RC_CMD", optarg, 1); 1192 setenv ("RC_CMD", optarg, 1);
1195 1193
1196 doneone = true; 1194 doneone = true;
1197 if (strcmp (optarg, "conditionalrestart") == 0 ||
1198 strcmp (optarg, "condrestart") == 0)
1199 {
1200 if (rc_service_state (service, rc_service_started))
1201 svc_restart (deps);
1202 }
1203 else if (strcmp (optarg, "restart") == 0)
1204 svc_restart (deps);
1205 else if (strcmp (optarg, "start") == 0)
1206 svc_start (deps);
1207 else if (strcmp (optarg, "status") == 0) {
1208 rc_service_state_t r = svc_status (service);
1209 retval = (int) r;
1210 } else if (strcmp (optarg, "stop") == 0) {
1211 if (in_background)
1212 get_started_services ();
1213
1214 svc_stop (deps);
1215
1216 if (! in_background &&
1217 ! rc_runlevel_stopping () &&
1218 rc_service_state (service, rc_service_stopped))
1219 uncoldplug ();
1220
1221 if (in_background &&
1222 rc_service_state (service, rc_service_inactive))
1223 {
1224 int j;
1225 STRLIST_FOREACH (restart_services, svc, j)
1226 if (rc_service_state (svc, rc_service_stopped))
1227 rc_schedule_start_service (service, svc);
1228 }
1229 } else if (strcmp (optarg, "zap") == 0) {
1230 einfo ("Manually resetting %s to stopped state", applet);
1231 rc_mark_service (applet, rc_service_stopped);
1232 uncoldplug ();
1233 } else if (strcmp (optarg, "help") == 0) { 1195 if (strcmp (optarg, "help") == 0) {
1234 execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, "help", (char *) NULL); 1196 execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, "help", (char *) NULL);
1235 eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s", 1197 eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s",
1236 applet, strerror (errno)); 1198 applet, strerror (errno));
1237 } else if (strcmp (optarg, "ineed") == 0 || 1199 } else if (strcmp (optarg, "ineed") == 0 ||
1238 strcmp (optarg, "iuse") == 0 || 1200 strcmp (optarg, "iuse") == 0 ||
1239 strcmp (optarg, "needsme") == 0 || 1201 strcmp (optarg, "needsme") == 0 ||
1240 strcmp (optarg, "usesme") == 0 || 1202 strcmp (optarg, "usesme") == 0 ||
1241 strcmp (optarg, "iafter") == 0 || 1203 strcmp (optarg, "iafter") == 0 ||
1242 strcmp (optarg, "ibefore") == 0 1204 strcmp (optarg, "ibefore") == 0 ||
1243 strcmp (optorg, "iprovide") == 0) { 1205 strcmp (optarg, "iprovide") == 0) {
1244 if (! deptree && ((deptree = rc_load_deptree ()) == NULL)) 1206 if (! deptree && ((deptree = rc_load_deptree ()) == NULL))
1245 eerrorx ("failed to load deptree"); 1207 eerrorx ("failed to load deptree");
1246 1208
1247 rc_strlist_free (types); 1209 rc_strlist_free (types);
1248 types = rc_strlist_add (NULL, optarg); 1210 types = rc_strlist_add (NULL, optarg);
1251 rc_strlist_free (services); 1213 rc_strlist_free (services);
1252 services = rc_get_depends (deptree, types, svclist, softlevel, 0); 1214 services = rc_get_depends (deptree, types, svclist, softlevel, 0);
1253 STRLIST_FOREACH (services, svc, i) 1215 STRLIST_FOREACH (services, svc, i)
1254 printf ("%s%s", i == 1 ? "" : " ", svc); 1216 printf ("%s%s", i == 1 ? "" : " ", svc);
1255 printf ("\n"); 1217 printf ("\n");
1218 } else if (strcmp (optarg, "status") == 0) {
1219 rc_service_state_t r = svc_status (service);
1220 retval = (int) r;
1221 } else if (strcmp (optarg, "help") == 0) {
1222 execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, "help", (char *) NULL);
1223 eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s",
1224 applet, strerror (errno));
1225 } else {
1226 if (geteuid () != 0)
1227 eerrorx ("%s: root access required", applet);
1228
1229 if (strcmp (optarg, "conditionalrestart") == 0 ||
1230 strcmp (optarg, "condrestart") == 0)
1231 {
1232 if (rc_service_state (service, rc_service_started))
1233 svc_restart (deps);
1234 } else if (strcmp (optarg, "restart") == 0) {
1235 svc_restart (deps);
1236 } else if (strcmp (optarg, "start") == 0) {
1237 svc_start (deps);
1238 } else if (strcmp (optarg, "stop") == 0) {
1239 if (in_background)
1240 get_started_services ();
1241
1242 svc_stop (deps);
1243
1244 if (! in_background &&
1245 ! rc_runlevel_stopping () &&
1246 rc_service_state (service, rc_service_stopped))
1247 uncoldplug ();
1248
1249 if (in_background &&
1250 rc_service_state (service, rc_service_inactive))
1251 {
1252 int j;
1253 STRLIST_FOREACH (restart_services, svc, j)
1254 if (rc_service_state (svc, rc_service_stopped))
1255 rc_schedule_start_service (service, svc);
1256 }
1257 } else if (strcmp (optarg, "zap") == 0) {
1258 einfo ("Manually resetting %s to stopped state", applet);
1259 rc_mark_service (applet, rc_service_stopped);
1260 uncoldplug ();
1256 }else 1261 }else
1257 svc_exec (optarg, NULL); 1262 svc_exec (optarg, NULL);
1258 1263
1259 /* Flush our buffered output if any */ 1264 /* Flush our buffered output if any */
1260 eflush (); 1265 eflush ();
1261 1266
1262 /* We should ensure this list is empty after an action is done */ 1267 /* We should ensure this list is empty after an action is done */
1263 rc_strlist_free (restart_services); 1268 rc_strlist_free (restart_services);
1264 restart_services = NULL; 1269 restart_services = NULL;
1265 } 1270 }
1266 1271
1267 if (! doneone) { 1272 if (! doneone) {
1268 execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, (char *) NULL); 1273 execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, (char *) NULL);
1269 eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s", 1274 eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s",
1270 applet, strerror (errno)); 1275 applet, strerror (errno));
1276 }
1271 } 1277 }
1272 1278
1273 return (retval); 1279 return (retval);
1274} 1280}

Legend:
Removed from v.2762  
changed lines
  Added in v.2763

  ViewVC Help
Powered by ViewVC 1.1.20