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.
rc_depend_strict="YES"
# Do we allow services to be hotplugged? If not, set to rc_hotplug="NO"
# NOTE: This does not affect anything hotplug/udev/devd related, just the
# starting/stopping of the init.d service triggered by it.
rc_hotplug="YES"
# Some people want a finer grain over hotplug. rc_plug_services is a
# list of services that are matched in order, either allowing or not. By
# default we allow services through as rc_hotplug has to be YES anyway.
# Example - rc_plug_services="net.wlan !net.*"
# rc_hotplug is a list of services that we allow to be hotplugged,
# by default allow all.
# A hotplugged service is one started by a dynamic dev manager when a matching
# hardware device is found.
# This service is intrinsically included in the boot runlevel.
# To disable services, prefix with a !
# Example - rc_hotplug="net.wlan !net.*"
# 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
# /var/log/rc.log
# 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"
# 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);
if (state & RC_SERVICE_COLDPLUGGED ||
if (state & RC_SERVICE_HOTPLUGGED ||
state & RC_SERVICE_STARTED)
return true;
@ -207,7 +207,7 @@ valid_service(const char *runlevel, const char *service, const char *type)
static bool
get_provided1(const char *runlevel, RC_STRINGLIST *providers,
RC_DEPTYPE *deptype, const char *level,
bool coldplugged, RC_SERVICE state)
bool hotplugged, RC_SERVICE state)
{
RC_STRING *service;
RC_SERVICE st;
@ -222,8 +222,8 @@ get_provided1(const char *runlevel, RC_STRINGLIST *providers,
if (level)
ok = rc_service_in_runlevel(svc, level);
else if (coldplugged)
ok = (st & RC_SERVICE_COLDPLUGGED &&
else if (hotplugged)
ok = (st & RC_SERVICE_HOTPLUGGED &&
!rc_service_in_runlevel(svc, runlevel) &&
!rc_service_in_runlevel(svc, bootlevel));
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
* 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) {
TAILQ_FOREACH(service, dt->services, entries)
if (rc_service_in_runlevel(service->value, runlevel) ||
rc_service_in_runlevel(service->value, bootlevel) ||
(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);
if (TAILQ_FIRST(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:-
* started, starting | stopping | inactive, stopped
* Our sub preference in each of these is in order:-
* runlevel, coldplugged, bootlevel, any
* runlevel, hotplugged, bootlevel, any
*/
#define DO \
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);
TAILQ_CONCAT(list, list2, entries);
free(list2);
list2 = rc_services_in_state(RC_SERVICE_COLDPLUGGED);
list2 = rc_services_in_state(RC_SERVICE_HOTPLUGGED);
TAILQ_CONCAT(list, list2, entries);
free(list2);
/* 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 "/wasinactive",
RC_SVCDIR "/failed",
RC_SVCDIR "/coldplugged",
RC_SVCDIR "/hotplugged",
RC_SVCDIR "/daemons",
RC_SVCDIR "/options",
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_INACTIVE, "inactive" },
{ RC_SERVICE_WASINACTIVE, "wasinactive" },
{ RC_SERVICE_COLDPLUGGED, "coldplugged" },
{ RC_SERVICE_HOTPLUGGED, "hotplugged" },
{ RC_SERVICE_FAILED, "failed" },
{ RC_SERVICE_SCHEDULED, "scheduled"},
{ 0, NULL}
@ -529,7 +529,7 @@ rc_service_mark(const char *service, const RC_SERVICE state)
skip_state = state;
}
if (state == RC_SERVICE_COLDPLUGGED || state == RC_SERVICE_FAILED) {
if (state == RC_SERVICE_HOTPLUGGED || state == RC_SERVICE_FAILED) {
free(init);
return true;
}
@ -540,7 +540,7 @@ rc_service_mark(const char *service, const RC_SERVICE state)
if ((s != skip_state &&
s != RC_SERVICE_STOPPED &&
s != RC_SERVICE_COLDPLUGGED &&
s != RC_SERVICE_HOTPLUGGED &&
s != RC_SERVICE_SCHEDULED) &&
(! skip_wasinactive || s != RC_SERVICE_WASINACTIVE))
{

View File

@ -115,8 +115,8 @@ typedef enum
RC_SERVICE_STARTING = 0x0008,
RC_SERVICE_INACTIVE = 0x0010,
/* Service may or may not have been coldplugged */
RC_SERVICE_COLDPLUGGED = 0x0100,
/* Service may or may not have been hotplugged */
RC_SERVICE_HOTPLUGGED = 0x0100,
/* Optional states service could also be in */
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);
else if (strcmp(applet, "service_stopping") == 0)
ok = (rc_service_state(service) & RC_SERVICE_STOPPING);
else if (strcmp(applet, "service_coldplugged") == 0)
ok = (rc_service_state(service) & RC_SERVICE_COLDPLUGGED);
else if (strcmp(applet, "service_hotplugged") == 0)
ok = (rc_service_state(service) & RC_SERVICE_HOTPLUGGED);
else if (strcmp(applet, "service_wasinactive") == 0)
ok = (rc_service_state(service) & RC_SERVICE_WASINACTIVE);
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);
else if (strcmp(applet, "mark_service_stopping") == 0)
ok = rc_service_mark(service, RC_SERVICE_STOPPING);
else if (strcmp(applet, "mark_service_coldplugged") == 0)
ok = rc_service_mark(service, RC_SERVICE_COLDPLUGGED);
else if (strcmp(applet, "mark_service_hotplugged") == 0)
ok = rc_service_mark(service, RC_SERVICE_HOTPLUGGED);
else if (strcmp(applet, "mark_service_failed") == 0)
ok = rc_service_mark(service, RC_SERVICE_FAILED);
else

View File

@ -87,7 +87,7 @@ static char *PREVLEVEL = NULL;
const char *applet = 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 *start_services = NULL;
static RC_STRINGLIST *types_n = NULL;
@ -162,7 +162,7 @@ static void cleanup(void)
p1 = p2;
}
rc_stringlist_free(coldplugged_services);
rc_stringlist_free(hotplugged_services);
rc_stringlist_free(stop_services);
rc_stringlist_free(start_services);
rc_stringlist_free(types_n);
@ -738,20 +738,13 @@ interactive_option:
}
pid = service_start(service->value);
/* Remember the pid if we're running in parallel */
if (pid > 0) {
add_pid(pid);
if (! parallel) {
rc_waitpid(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;
}
/* Load our list of coldplugged services */
coldplugged_services = rc_services_in_state(RC_SERVICE_COLDPLUGGED);
/* Load our list of hotplugged services */
hotplugged_services = rc_services_in_state(RC_SERVICE_HOTPLUGGED);
if (strcmp(newlevel ? newlevel : runlevel, RC_LEVEL_SINGLE) != 0 &&
strcmp(newlevel ? newlevel : runlevel, RC_LEVEL_SHUTDOWN) != 0 &&
strcmp(newlevel ? newlevel : runlevel, RC_LEVEL_REBOOT) != 0)
@ -1048,10 +1041,10 @@ int main(int argc, char **argv)
free(tmplist);
}
if (coldplugged_services) {
if (hotplugged_services) {
if (!start_services)
start_services = rc_stringlist_new();
TAILQ_FOREACH(service, coldplugged_services, entries)
TAILQ_FOREACH(service, hotplugged_services, entries)
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);
hook_out = RC_HOOK_RUNLEVEL_START_OUT;
/* Re-add our coldplugged services if they stopped */
if (coldplugged_services)
TAILQ_FOREACH(service, coldplugged_services, entries)
rc_service_mark(service->value, RC_SERVICE_COLDPLUGGED);
/* Re-add our hotplugged services if they stopped */
if (hotplugged_services)
TAILQ_FOREACH(service, hotplugged_services, entries)
rc_service_mark(service->value, RC_SERVICE_HOTPLUGGED);
/* Order the services to start */
if (start_services) {
@ -1132,7 +1125,7 @@ int main(int argc, char **argv)
do_start_services(parallel);
/* FIXME: If we skip the boot runlevel and go straight
* 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. */
/* Wait for our services to finish */

View File

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