librc: comsolidate rc_sys_v1 and rc_sys_v2 into rc_sys

These functions were never meant to be used outside of OpenRC, and they
were added when we thought we were going to do away with the automatic
detection of subsystems. Since the autodetection is not going away, we
can combine these functions into rc_sys.
This commit is contained in:
William Hubbs 2015-12-01 17:39:04 -06:00
parent bd9456ff31
commit 635e33cdc8
4 changed files with 30 additions and 66 deletions

View File

@ -210,14 +210,14 @@ found:
} }
#endif #endif
/* New sys identification code
* Not to be used for any binaries outside of openrc. */
const char * const char *
rc_sys_v2(void) rc_sys(void)
{ {
#define __STRING_SWITCH(x) { char *__string_switch = x; if (false) {} #ifdef PREFIX
#define __STRING_CASE(y) else if (strcmp(__string_switch,y) == 0) return RC_SYS_PREFIX;
#define __STRING_SWITCH_END() } #endif
char *systype = rc_conf_value("rc_sys"); char *systype = rc_conf_value("rc_sys");
if (systype) { if (systype) {
char *s = systype; char *s = systype;
@ -227,43 +227,11 @@ rc_sys_v2(void)
*s = toupper((unsigned char) *s); *s = toupper((unsigned char) *s);
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.
* Not to be used for any binaries outside of openrc. */
const char *
rc_sys_v1(void)
{
#ifdef PREFIX
return RC_SYS_PREFIX;
#else
#ifdef __FreeBSD__ #ifdef __FreeBSD__
if (systype && strcmp(systype, RC_SYS_JAIL) == 0)
return RC_SYS_JAIL;
int jailed = 0; int jailed = 0;
size_t len = sizeof(jailed); size_t len = sizeof(jailed);
@ -273,6 +241,12 @@ rc_sys_v1(void)
#endif #endif
#ifdef __NetBSD__ #ifdef __NetBSD__
if (systype) {
if(strcmp(systype, RC_SYS_XEN0) == 0)
return RC_SYS_XEN0;
if (strcmp(systype, RC_SYS_XENU) == 0)
return RC_SYS_XENU;
}
if (exists("/kern/xen/privcmd")) if (exists("/kern/xen/privcmd"))
return RC_SYS_XEN0; return RC_SYS_XEN0;
if (exists("/kern/xen")) if (exists("/kern/xen"))
@ -280,6 +254,22 @@ rc_sys_v1(void)
#endif #endif
#ifdef __linux__ #ifdef __linux__
if (systype) {
if (strcmp(systype, RC_SYS_XEN0) == 0)
return RC_SYS_XEN0;
if (strcmp(systype, RC_SYS_XENU) == 0)
return RC_SYS_XENU;
if (strcmp(systype, RC_SYS_UML) == 0)
return RC_SYS_UML;
if (strcmp(systype, RC_SYS_VSERVER) == 0)
return RC_SYS_VSERVER;
if (strcmp(systype, RC_SYS_OPENVZ) == 0)
return RC_SYS_OPENVZ;
if (strcmp(systype, RC_SYS_LXC) == 0)
return RC_SYS_LXC;
if (strcmp(systype, RC_SYS_SYSTEMD_NSPAWN) == 0)
return RC_SYS_SYSTEMD_NSPAWN;
}
if (exists("/proc/xen")) { if (exists("/proc/xen")) {
if (file_regex("/proc/xen/capabilities", "control_d")) if (file_regex("/proc/xen/capabilities", "control_d"))
return RC_SYS_XEN0; return RC_SYS_XEN0;
@ -301,18 +291,6 @@ rc_sys_v1(void)
#endif #endif
return NULL; return NULL;
#endif /* PREFIX */
}
librc_hidden_def(rc_sys_v1)
const char *
rc_sys(void)
{
if (rc_conf_value("rc_sys")) {
return rc_sys_v2();
} else {
return rc_sys_v1();
}
} }
librc_hidden_def(rc_sys) librc_hidden_def(rc_sys)

View File

@ -130,8 +130,6 @@ librc_hidden_proto(rc_stringlist_new)
librc_hidden_proto(rc_stringlist_split) librc_hidden_proto(rc_stringlist_split)
librc_hidden_proto(rc_stringlist_sort) librc_hidden_proto(rc_stringlist_sort)
librc_hidden_proto(rc_sys) librc_hidden_proto(rc_sys)
librc_hidden_proto(rc_sys_v1)
librc_hidden_proto(rc_sys_v2)
librc_hidden_proto(rc_yesno) librc_hidden_proto(rc_yesno)
#endif #endif

View File

@ -343,14 +343,6 @@ bool rc_service_daemons_crashed(const char *);
* @return string from RC_SYS_* types or NULL if none detected */ * @return string from RC_SYS_* types or NULL if none detected */
const char *rc_sys(void); 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 /*! @name Dependency options
* These options can change the services found by the rc_get_depinfo and * These options can change the services found by the rc_get_depinfo and
* rc_get_depends functions. */ * rc_get_depends functions. */

View File

@ -112,9 +112,5 @@ rc_stringlist_split
rc_stringlist_split@@RC_1.0 rc_stringlist_split@@RC_1.0
rc_sys rc_sys
rc_sys@@RC_1.0 rc_sys@@RC_1.0
rc_sys_v1
rc_sys_v1@@RC_1.0
rc_sys_v2
rc_sys_v2@@RC_1.0
rc_yesno rc_yesno
rc_yesno@@RC_1.0 rc_yesno@@RC_1.0