aboutsummaryrefslogtreecommitdiff
path: root/src/librc
diff options
context:
space:
mode:
authorRobin H. Johnson <robbat2@gentoo.org>2011-01-05 22:03:43 -0800
committerRobin H. Johnson <robbat2@gentoo.org>2011-01-05 22:09:34 -0800
commit09f990a7c835d75f67cfe696a35e8c46e67c612f (patch)
treeda69536cd225bad4028b01e88a0629bdca472dc1 /src/librc
parent6df531d33d0f3c3cad8edcafdcd62525ca30fc1f (diff)
Implement explicit selection of subsystem types.
- Fixes bugs #347583, #349389, both of which were triggered by cgroups being detected as the LXC subsystem type. - Makes it much easier to select "prefix" type. - "rc -S" will now print a warning if you have not configured rc_sys in /etc/rc.conf - All other semantics of rc_sys are unchanged in this patch. Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
Diffstat (limited to 'src/librc')
-rw-r--r--src/librc/librc.c55
-rw-r--r--src/librc/librc.h2
-rw-r--r--src/librc/rc.h.in11
-rw-r--r--src/librc/rc.map2
4 files changed, 69 insertions, 1 deletions
diff --git a/src/librc/librc.c b/src/librc/librc.c
index fe9e1b6b..6d823434 100644
--- a/src/librc/librc.c
+++ b/src/librc/librc.c
@@ -199,7 +199,51 @@ file_regex(const char *file, const char *regex)
#endif
const char *
-rc_sys(void)
+rc_sys_v2(void)
+{
+#define __STRING_SWITCH(x) { char* __string_switch = x; if(false) {}
+#define __STRING_CASE(y) else if(strcmp(__string_switch,y) == 0)
+#define __STRING_SWITCH_END() }
+ char* systype = rc_conf_value("rc_sys");
+ /* New sys identification code */
+ if(systype) {
+ char* s = systype;
+ // Convert to uppercase
+ while(s && *s) {
+ if(islower((unsigned char)*s))
+ *s = toupper((unsigned char)*s);
+ s++;
+ }
+ // Now do detection
+ __STRING_SWITCH(systype)
+ __STRING_CASE(RC_SYS_PREFIX) { return RC_SYS_PREFIX; }
+#ifdef __FreeBSD__
+ __STRING_CASE(RC_SYS_JAIL) { return RC_SYS_JAIL; }
+#endif /* __FreeBSD__ */
+#ifdef __NetBSD__
+ __STRING_CASE(RC_SYS_XEN0) { return RC_SYS_XEN0; }
+ __STRING_CASE(RC_SYS_XENU) { return RC_SYS_XENU; }
+#endif /* __NetBSD__ */
+#ifdef __linux__
+ __STRING_CASE(RC_SYS_XEN0) { return RC_SYS_XEN0; }
+ __STRING_CASE(RC_SYS_XENU) { return RC_SYS_XENU; }
+ __STRING_CASE(RC_SYS_UML) { return RC_SYS_UML; }
+ __STRING_CASE(RC_SYS_VSERVER) { return RC_SYS_VSERVER; }
+ __STRING_CASE(RC_SYS_OPENVZ) { return RC_SYS_OPENVZ; }
+ __STRING_CASE(RC_SYS_LXC) { return RC_SYS_LXC; }
+#endif /* __linux__ */
+ __STRING_SWITCH_END()
+ }
+#undef __STRING_SWITCH
+#undef __STRING_CASE
+#undef __STRING_SWITCH_END
+ return NULL;
+}
+librc_hidden_def(rc_sys_v2)
+
+/* Old sys identification code */
+const char *
+rc_sys_v1(void)
{
#ifdef PREFIX
return RC_SYS_PREFIX;
@@ -243,6 +287,15 @@ rc_sys(void)
return NULL;
#endif /* PREFIX */
}
+librc_hidden_def(rc_sys_v1)
+
+const char *
+rc_sys(void)
+{
+ const char *s = rc_sys_v2();
+ if(s) return s;
+ return rc_sys_v1();
+}
librc_hidden_def(rc_sys)
static const char *
diff --git a/src/librc/librc.h b/src/librc/librc.h
index fc87bb10..dc97f1d3 100644
--- a/src/librc/librc.h
+++ b/src/librc/librc.h
@@ -125,6 +125,8 @@ librc_hidden_proto(rc_stringlist_new)
librc_hidden_proto(rc_stringlist_split)
librc_hidden_proto(rc_stringlist_sort)
librc_hidden_proto(rc_sys)
+librc_hidden_proto(rc_sys_v1)
+librc_hidden_proto(rc_sys_v2)
librc_hidden_proto(rc_yesno)
#endif
diff --git a/src/librc/rc.h.in b/src/librc/rc.h.in
index d9d04539..3d0ffb42 100644
--- a/src/librc/rc.h.in
+++ b/src/librc/rc.h.in
@@ -274,8 +274,19 @@ bool rc_service_daemons_crashed(const char *);
#define RC_SYS_VSERVER "VSERVER"
#define RC_SYS_XEN0 "XEN0"
#define RC_SYS_XENU "XENU"
+
+/*! Returns the type of subsystem
+ * @return string from RC_SYS_* types or NULL if none detected */
const char *rc_sys(void);
+/*! Returns the type of subsystem using old automatic code
+ * @return string from RC_SYS_* types or NULL if none detected */
+const char *rc_sys_v1(void);
+
+/*! Returns the type of subsystem using new rc.conf rc_sys value
+ * @return string from RC_SYS_* types or NULL if none detected */
+const char *rc_sys_v2(void);
+
/*! @name Dependency options
* These options can change the services found by the rc_get_depinfo and
* rc_get_depends functions. */
diff --git a/src/librc/rc.map b/src/librc/rc.map
index 3f1e7e70..113f2d7d 100644
--- a/src/librc/rc.map
+++ b/src/librc/rc.map
@@ -55,6 +55,8 @@ global:
rc_stringlist_sort;
rc_stringlist_free;
rc_sys;
+ rc_sys_v1;
+ rc_sys_v2;
rc_yesno;
local: