Remove coldplug and just have hotplug which is a list of allowed/disallowed services. Makes things much easier.

This commit is contained in:
Roy Marples 2008-10-10 09:08:59 +00:00
parent 72dcac8c55
commit 50b8aba8d9
7 changed files with 54 additions and 75 deletions

View File

@ -22,22 +22,20 @@ rc_interactive="YES"
# come up. # come up.
rc_depend_strict="YES" rc_depend_strict="YES"
# Do we allow services to be hotplugged? If not, set to rc_hotplug="NO" # rc_hotplug is a list of services that we allow to be hotplugged,
# NOTE: This does not affect anything hotplug/udev/devd related, just the # by default allow all.
# starting/stopping of the init.d service triggered by it. # A hotplugged service is one started by a dynamic dev manager when a matching
rc_hotplug="YES" # hardware device is found.
# This service is intrinsically included in the boot runlevel.
# Some people want a finer grain over hotplug. rc_plug_services is a # To disable services, prefix with a !
# list of services that are matched in order, either allowing or not. By # Example - rc_hotplug="net.wlan !net.*"
# default we allow services through as rc_hotplug has to be YES anyway.
# Example - rc_plug_services="net.wlan !net.*"
# This allows net.wlan and any service not matching net.* to be plugged. # This allows net.wlan and any service not matching net.* to be plugged.
rc_plug_services="" rc_hotplug="*"
# rc_logger launches a logging daemon to log the entire rc process to # rc_logger launches a logging daemon to log the entire rc process to
# /var/log/rc.log # /var/log/rc.log
# NOTE: Linux systems require the devfs service to be started before # NOTE: Linux systems require the devfs service to be started before
# logging can take place. # logging can take place and as such cannot log the sysinit runlevel.
rc_logger="NO" rc_logger="NO"
# By default we filter the environment for our running scripts. To allow other # By default we filter the environment for our running scripts. To allow other

View File

@ -197,7 +197,7 @@ valid_service(const char *runlevel, const char *service, const char *type)
} }
state = rc_service_state(service); state = rc_service_state(service);
if (state & RC_SERVICE_COLDPLUGGED || if (state & RC_SERVICE_HOTPLUGGED ||
state & RC_SERVICE_STARTED) state & RC_SERVICE_STARTED)
return true; return true;
@ -207,7 +207,7 @@ valid_service(const char *runlevel, const char *service, const char *type)
static bool static bool
get_provided1(const char *runlevel, RC_STRINGLIST *providers, get_provided1(const char *runlevel, RC_STRINGLIST *providers,
RC_DEPTYPE *deptype, const char *level, RC_DEPTYPE *deptype, const char *level,
bool coldplugged, RC_SERVICE state) bool hotplugged, RC_SERVICE state)
{ {
RC_STRING *service; RC_STRING *service;
RC_SERVICE st; RC_SERVICE st;
@ -222,8 +222,8 @@ get_provided1(const char *runlevel, RC_STRINGLIST *providers,
if (level) if (level)
ok = rc_service_in_runlevel(svc, level); ok = rc_service_in_runlevel(svc, level);
else if (coldplugged) else if (hotplugged)
ok = (st & RC_SERVICE_COLDPLUGGED && ok = (st & RC_SERVICE_HOTPLUGGED &&
!rc_service_in_runlevel(svc, runlevel) && !rc_service_in_runlevel(svc, runlevel) &&
!rc_service_in_runlevel(svc, bootlevel)); !rc_service_in_runlevel(svc, bootlevel));
if (!ok) if (!ok)
@ -281,13 +281,13 @@ get_provided(const RC_DEPINFO *depinfo, const char *runlevel, int options)
} }
/* If we're strict or starting, then only use what we have in our /* If we're strict or starting, then only use what we have in our
* runlevel and bootlevel. If we starting then check cold-plugged too. */ * runlevel and bootlevel. If we starting then check hotplugged too. */
if (options & RC_DEP_STRICT || options & RC_DEP_START) { if (options & RC_DEP_STRICT || options & RC_DEP_START) {
TAILQ_FOREACH(service, dt->services, entries) TAILQ_FOREACH(service, dt->services, entries)
if (rc_service_in_runlevel(service->value, runlevel) || if (rc_service_in_runlevel(service->value, runlevel) ||
rc_service_in_runlevel(service->value, bootlevel) || rc_service_in_runlevel(service->value, bootlevel) ||
(options & RC_DEP_START && (options & RC_DEP_START &&
rc_service_state(service->value) & RC_SERVICE_COLDPLUGGED)) rc_service_state(service->value) & RC_SERVICE_HOTPLUGGED))
rc_stringlist_add(providers, service->value); rc_stringlist_add(providers, service->value);
if (TAILQ_FIRST(providers)) if (TAILQ_FIRST(providers))
return providers; return providers;
@ -301,7 +301,7 @@ get_provided(const RC_DEPINFO *depinfo, const char *runlevel, int options)
* We apply this to these states in order:- * We apply this to these states in order:-
* started, starting | stopping | inactive, stopped * started, starting | stopping | inactive, stopped
* Our sub preference in each of these is in order:- * Our sub preference in each of these is in order:-
* runlevel, coldplugged, bootlevel, any * runlevel, hotplugged, bootlevel, any
*/ */
#define DO \ #define DO \
if (TAILQ_FIRST(providers)) { \ if (TAILQ_FIRST(providers)) { \
@ -515,7 +515,7 @@ rc_deptree_order(const RC_DEPTREE *deptree, const char *runlevel, int options)
list2 = rc_services_in_runlevel(runlevel); list2 = rc_services_in_runlevel(runlevel);
TAILQ_CONCAT(list, list2, entries); TAILQ_CONCAT(list, list2, entries);
free(list2); free(list2);
list2 = rc_services_in_state(RC_SERVICE_COLDPLUGGED); list2 = rc_services_in_state(RC_SERVICE_HOTPLUGGED);
TAILQ_CONCAT(list, list2, entries); TAILQ_CONCAT(list, list2, entries);
free(list2); free(list2);
/* If we're not the boot runlevel then add that too */ /* If we're not the boot runlevel then add that too */
@ -626,7 +626,7 @@ static const char *const depdirs[] =
RC_SVCDIR "/inactive", RC_SVCDIR "/inactive",
RC_SVCDIR "/wasinactive", RC_SVCDIR "/wasinactive",
RC_SVCDIR "/failed", RC_SVCDIR "/failed",
RC_SVCDIR "/coldplugged", RC_SVCDIR "/hotplugged",
RC_SVCDIR "/daemons", RC_SVCDIR "/daemons",
RC_SVCDIR "/options", RC_SVCDIR "/options",
RC_SVCDIR "/exclusive", RC_SVCDIR "/exclusive",

View File

@ -59,7 +59,7 @@ static const rc_service_state_name_t rc_service_state_names[] = {
{ RC_SERVICE_STOPPING, "stopping" }, { RC_SERVICE_STOPPING, "stopping" },
{ RC_SERVICE_INACTIVE, "inactive" }, { RC_SERVICE_INACTIVE, "inactive" },
{ RC_SERVICE_WASINACTIVE, "wasinactive" }, { RC_SERVICE_WASINACTIVE, "wasinactive" },
{ RC_SERVICE_COLDPLUGGED, "coldplugged" }, { RC_SERVICE_HOTPLUGGED, "hotplugged" },
{ RC_SERVICE_FAILED, "failed" }, { RC_SERVICE_FAILED, "failed" },
{ RC_SERVICE_SCHEDULED, "scheduled"}, { RC_SERVICE_SCHEDULED, "scheduled"},
{ 0, NULL} { 0, NULL}
@ -529,7 +529,7 @@ rc_service_mark(const char *service, const RC_SERVICE state)
skip_state = state; skip_state = state;
} }
if (state == RC_SERVICE_COLDPLUGGED || state == RC_SERVICE_FAILED) { if (state == RC_SERVICE_HOTPLUGGED || state == RC_SERVICE_FAILED) {
free(init); free(init);
return true; return true;
} }
@ -540,7 +540,7 @@ rc_service_mark(const char *service, const RC_SERVICE state)
if ((s != skip_state && if ((s != skip_state &&
s != RC_SERVICE_STOPPED && s != RC_SERVICE_STOPPED &&
s != RC_SERVICE_COLDPLUGGED && s != RC_SERVICE_HOTPLUGGED &&
s != RC_SERVICE_SCHEDULED) && s != RC_SERVICE_SCHEDULED) &&
(! skip_wasinactive || s != RC_SERVICE_WASINACTIVE)) (! skip_wasinactive || s != RC_SERVICE_WASINACTIVE))
{ {

View File

@ -115,8 +115,8 @@ typedef enum
RC_SERVICE_STARTING = 0x0008, RC_SERVICE_STARTING = 0x0008,
RC_SERVICE_INACTIVE = 0x0010, RC_SERVICE_INACTIVE = 0x0010,
/* Service may or may not have been coldplugged */ /* Service may or may not have been hotplugged */
RC_SERVICE_COLDPLUGGED = 0x0100, RC_SERVICE_HOTPLUGGED = 0x0100,
/* Optional states service could also be in */ /* Optional states service could also be in */
RC_SERVICE_FAILED = 0x0200, RC_SERVICE_FAILED = 0x0200,

View File

@ -276,8 +276,8 @@ static int do_service(int argc, char **argv)
ok = (rc_service_state(service) & RC_SERVICE_STARTING); ok = (rc_service_state(service) & RC_SERVICE_STARTING);
else if (strcmp(applet, "service_stopping") == 0) else if (strcmp(applet, "service_stopping") == 0)
ok = (rc_service_state(service) & RC_SERVICE_STOPPING); ok = (rc_service_state(service) & RC_SERVICE_STOPPING);
else if (strcmp(applet, "service_coldplugged") == 0) else if (strcmp(applet, "service_hotplugged") == 0)
ok = (rc_service_state(service) & RC_SERVICE_COLDPLUGGED); ok = (rc_service_state(service) & RC_SERVICE_HOTPLUGGED);
else if (strcmp(applet, "service_wasinactive") == 0) else if (strcmp(applet, "service_wasinactive") == 0)
ok = (rc_service_state(service) & RC_SERVICE_WASINACTIVE); ok = (rc_service_state(service) & RC_SERVICE_WASINACTIVE);
else if (strcmp(applet, "service_started_daemon") == 0) { else if (strcmp(applet, "service_started_daemon") == 0) {
@ -329,8 +329,8 @@ static int do_mark_service(int argc, char **argv)
ok = rc_service_mark(service, RC_SERVICE_STARTING); ok = rc_service_mark(service, RC_SERVICE_STARTING);
else if (strcmp(applet, "mark_service_stopping") == 0) else if (strcmp(applet, "mark_service_stopping") == 0)
ok = rc_service_mark(service, RC_SERVICE_STOPPING); ok = rc_service_mark(service, RC_SERVICE_STOPPING);
else if (strcmp(applet, "mark_service_coldplugged") == 0) else if (strcmp(applet, "mark_service_hotplugged") == 0)
ok = rc_service_mark(service, RC_SERVICE_COLDPLUGGED); ok = rc_service_mark(service, RC_SERVICE_HOTPLUGGED);
else if (strcmp(applet, "mark_service_failed") == 0) else if (strcmp(applet, "mark_service_failed") == 0)
ok = rc_service_mark(service, RC_SERVICE_FAILED); ok = rc_service_mark(service, RC_SERVICE_FAILED);
else else

View File

@ -87,7 +87,7 @@ static char *PREVLEVEL = NULL;
const char *applet = NULL; const char *applet = NULL;
static char *runlevel = NULL; static char *runlevel = NULL;
static RC_STRINGLIST *coldplugged_services = NULL; static RC_STRINGLIST *hotplugged_services = NULL;
static RC_STRINGLIST *stop_services = NULL; static RC_STRINGLIST *stop_services = NULL;
static RC_STRINGLIST *start_services = NULL; static RC_STRINGLIST *start_services = NULL;
static RC_STRINGLIST *types_n = NULL; static RC_STRINGLIST *types_n = NULL;
@ -162,7 +162,7 @@ static void cleanup(void)
p1 = p2; p1 = p2;
} }
rc_stringlist_free(coldplugged_services); rc_stringlist_free(hotplugged_services);
rc_stringlist_free(stop_services); rc_stringlist_free(stop_services);
rc_stringlist_free(start_services); rc_stringlist_free(start_services);
rc_stringlist_free(types_n); rc_stringlist_free(types_n);
@ -738,20 +738,13 @@ interactive_option:
} }
pid = service_start(service->value); pid = service_start(service->value);
/* Remember the pid if we're running in parallel */ /* Remember the pid if we're running in parallel */
if (pid > 0) { if (pid > 0) {
add_pid(pid); add_pid(pid);
if (! parallel) { if (! parallel) {
rc_waitpid(pid); rc_waitpid(pid);
remove_pid(pid); remove_pid(pid);
/* Attempt to open the logger as a service may
* mount the needed /dev/pts for this to work */
if (rc_logger_tty == -1)
rc_logger_open(runlevel);
} }
} }
} }
@ -1024,8 +1017,8 @@ int main(int argc, char **argv)
stop_services = tmplist; stop_services = tmplist;
} }
/* Load our list of coldplugged services */ /* Load our list of hotplugged services */
coldplugged_services = rc_services_in_state(RC_SERVICE_COLDPLUGGED); hotplugged_services = rc_services_in_state(RC_SERVICE_HOTPLUGGED);
if (strcmp(newlevel ? newlevel : runlevel, RC_LEVEL_SINGLE) != 0 && if (strcmp(newlevel ? newlevel : runlevel, RC_LEVEL_SINGLE) != 0 &&
strcmp(newlevel ? newlevel : runlevel, RC_LEVEL_SHUTDOWN) != 0 && strcmp(newlevel ? newlevel : runlevel, RC_LEVEL_SHUTDOWN) != 0 &&
strcmp(newlevel ? newlevel : runlevel, RC_LEVEL_REBOOT) != 0) strcmp(newlevel ? newlevel : runlevel, RC_LEVEL_REBOOT) != 0)
@ -1048,10 +1041,10 @@ int main(int argc, char **argv)
free(tmplist); free(tmplist);
} }
if (coldplugged_services) { if (hotplugged_services) {
if (!start_services) if (!start_services)
start_services = rc_stringlist_new(); start_services = rc_stringlist_new();
TAILQ_FOREACH(service, coldplugged_services, entries) TAILQ_FOREACH(service, hotplugged_services, entries)
rc_stringlist_addu(start_services, service->value); rc_stringlist_addu(start_services, service->value);
} }
} }
@ -1102,10 +1095,10 @@ int main(int argc, char **argv)
rc_plugin_run(RC_HOOK_RUNLEVEL_START_IN, runlevel); rc_plugin_run(RC_HOOK_RUNLEVEL_START_IN, runlevel);
hook_out = RC_HOOK_RUNLEVEL_START_OUT; hook_out = RC_HOOK_RUNLEVEL_START_OUT;
/* Re-add our coldplugged services if they stopped */ /* Re-add our hotplugged services if they stopped */
if (coldplugged_services) if (hotplugged_services)
TAILQ_FOREACH(service, coldplugged_services, entries) TAILQ_FOREACH(service, hotplugged_services, entries)
rc_service_mark(service->value, RC_SERVICE_COLDPLUGGED); rc_service_mark(service->value, RC_SERVICE_HOTPLUGGED);
/* Order the services to start */ /* Order the services to start */
if (start_services) { if (start_services) {
@ -1132,7 +1125,7 @@ int main(int argc, char **argv)
do_start_services(parallel); do_start_services(parallel);
/* FIXME: If we skip the boot runlevel and go straight /* FIXME: If we skip the boot runlevel and go straight
* to default from sysinit, we should now re-evaluate our * to default from sysinit, we should now re-evaluate our
* start services + coldplugged services and call * start services + hotplugged services and call
* do_start_services a second time. */ * do_start_services a second time. */
/* Wait for our services to finish */ /* Wait for our services to finish */

View File

@ -39,6 +39,7 @@
#include <dlfcn.h> #include <dlfcn.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <fnmatch.h>
#include <getopt.h> #include <getopt.h>
#include <libgen.h> #include <libgen.h>
#include <limits.h> #include <limits.h>
@ -246,11 +247,11 @@ in_control()
} }
static void static void
uncoldplug() unhotplug()
{ {
char file[PATH_MAX]; char file[PATH_MAX];
snprintf(file, sizeof(file), RC_SVCDIR "/coldplugged/%s", applet); snprintf(file, sizeof(file), RC_SVCDIR "/hotplugged/%s", applet);
if (exists(file) && unlink(file) != 0) if (exists(file) && unlink(file) != 0)
eerror("%s: unlink `%s': %s", applet, file, strerror(errno)); eerror("%s: unlink `%s': %s", applet, file, strerror(errno));
} }
@ -702,7 +703,7 @@ svc_start(bool deps)
! state & RC_SERVICE_STOPPED) ! state & RC_SERVICE_STOPPED)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
background = true; background = true;
rc_service_mark(service, RC_SERVICE_COLDPLUGGED); rc_service_mark(service, RC_SERVICE_HOTPLUGGED);
if (rc_runlevel_starting()) if (rc_runlevel_starting())
ewarnx("WARNING: %s will be started when the runlevel" ewarnx("WARNING: %s will be started when the runlevel"
" has finished.", applet); " has finished.", applet);
@ -1103,14 +1104,12 @@ svc_restart(bool deps)
static bool static bool
service_plugable(void) service_plugable(void)
{ {
char *list; char *list, *p, *token;
char *p; bool allow = true, truefalse;
char *star; char *match = rc_conf_value("rc_hotplug");
char *token;
bool allow = true;
char *match = rc_conf_value("rc_plug_services");
bool truefalse;
if (!match)
match = rc_conf_value("rc_plug_services");
if (!match) if (!match)
return true; return true;
@ -1123,22 +1122,11 @@ service_plugable(void)
} else } else
truefalse = true; truefalse = true;
star = strchr(token, '*'); if (fnmatch(token, applet, 0) == 0) {
if (star) {
if (strncmp(applet, token,
(size_t)(star - token)) == 0)
{
allow = truefalse;
break;
}
} else {
if (strcmp(applet, token) == 0) {
allow = truefalse; allow = truefalse;
break; break;
} }
} }
}
#ifdef DEBUG_MEMORY #ifdef DEBUG_MEMORY
free(list); free(list);
#endif #endif
@ -1308,7 +1296,7 @@ runscript(int argc, char **argv)
} }
if (rc_yesno(getenv("IN_HOTPLUG"))) { if (rc_yesno(getenv("IN_HOTPLUG"))) {
if (!rc_conf_yesno("rc_hotplug") || !service_plugable()) if (!service_plugable())
eerrorx("%s: not allowed to be hotplugged", applet); eerrorx("%s: not allowed to be hotplugged", applet);
} }
@ -1405,7 +1393,7 @@ runscript(int argc, char **argv)
! rc_runlevel_stopping() && ! rc_runlevel_stopping() &&
rc_service_state(service) & rc_service_state(service) &
RC_SERVICE_STOPPED) RC_SERVICE_STOPPED)
uncoldplug(); unhotplug();
if (in_background && if (in_background &&
rc_service_state(service) & rc_service_state(service) &
@ -1426,7 +1414,7 @@ runscript(int argc, char **argv)
RC_SERVICE_STOPPED)) RC_SERVICE_STOPPED))
eerrorx("rc_service_mark: %s", eerrorx("rc_service_mark: %s",
strerror(errno)); strerror(errno));
uncoldplug(); unhotplug();
} else } else
svc_exec(optarg, NULL); svc_exec(optarg, NULL);