Improve processing of service directories and conf.d files

symbolic links should not be followed in an attempt to work out the name
of the service we are running. Also, @sysconfdir@/conf.d should be tried
as a backup directory for configuration files.

I would like to thank Robin Johnson for his input on this change.

X-Gentoo-Bug: 350910
X-Gentoo-Bug-URL: http://bugs.gentoo.org/show_bug.cgi?id=350910
This commit is contained in:
William Hubbs 2011-07-27 11:02:23 -05:00
parent 3688c85163
commit 0c8bea2152
3 changed files with 21 additions and 56 deletions

View File

@ -462,12 +462,6 @@ show()
.Ed .Ed
.Sh BUGS .Sh BUGS
Because of the way we load our configuration files and the need to handle
more than one service directory, you can only use symlinks in service
directories to other services in the same directory.
You cannot symlink to a service in a different directory even if it is
another service directory.
.Pp
is_older_than should return 0 on success. is_older_than should return 0 on success.
Instead we return 1 to be compliant with Gentoo baselayout. Instead we return 1 to be compliant with Gentoo baselayout.
Users are encouraged to use the is_newer_than function which returns correctly. Users are encouraged to use the is_newer_than function which returns correctly.

View File

@ -16,6 +16,23 @@ sourcex()
fi fi
} }
loadconfig()
{
# If we're net.eth0 or openvpn.work then load net or openvpn config
_c=${RC_SVCNAME%%.*}
if [ -n "$_c" -a "$_c" != "$RC_SVCNAME" ]; then
if ! sourcex -e "$1/$_c.$RC_RUNLEVEL"; then
sourcex -e "$1/$_c"
fi
fi
unset _c
# Overlay with our specific config
if ! sourcex -e "$1/$RC_SVCNAME.$RC_RUNLEVEL"; then
sourcex -e "$1/$RC_SVCNAME"
fi
}
if [ ! -e ${RC_SVCDIR}/softlevel ]; then if [ ! -e ${RC_SVCDIR}/softlevel ]; then
eerror "You are attempting to run an openrc service on a" eerror "You are attempting to run an openrc service on a"
eerror "system which openrc did not boot." eerror "system which openrc did not boot."
@ -165,21 +182,9 @@ status()
yesno $RC_DEBUG && set -x yesno $RC_DEBUG && set -x
_conf_d=${RC_SERVICE%/*}/../conf.d if ! loadconfig "${RC_SERVICE%/*}/../conf.d"; then
# If we're net.eth0 or openvpn.work then load net or openvpn config loadconfig "@SYSCONFDIR@/conf.d"
_c=${RC_SVCNAME%%.*}
if [ -n "$_c" -a "$_c" != "$RC_SVCNAME" ]; then
if ! sourcex -e "$_conf_d/$_c.$RC_RUNLEVEL"; then
sourcex -e "$_conf_d/$_c"
fi
fi fi
unset _c
# Overlay with our specific config
if ! sourcex -e "$_conf_d/$RC_SVCNAME.$RC_RUNLEVEL"; then
sourcex -e "$_conf_d/$RC_SVCNAME"
fi
unset _conf_d
# Load any system overrides # Load any system overrides
sourcex -e "@SYSCONFDIR@/rc.conf" sourcex -e "@SYSCONFDIR@/rc.conf"

View File

@ -1100,8 +1100,7 @@ runscript(int argc, char **argv)
bool doneone = false; bool doneone = false;
int retval, opt, depoptions = RC_DEP_TRACE; int retval, opt, depoptions = RC_DEP_TRACE;
RC_STRING *svc; RC_STRING *svc;
char path[PATH_MAX], lnk[PATH_MAX]; char *save = NULL;
char *dir, *save = NULL, *saveLnk = NULL;
char pidstr[10]; char pidstr[10];
size_t l = 0, ll; size_t l = 0, ll;
const char *file; const char *file;
@ -1121,40 +1120,7 @@ runscript(int argc, char **argv)
atexit(cleanup); atexit(cleanup);
/* We need to work out the real full path to our service. service = xstrdup(argv[1]);
* This works fine, provided that we ONLY allow multiplexed services
* to exist in the same directory as the master link.
* Also, the master link as to be a real file in the init dir. */
if (!realpath(argv[1], path)) {
fprintf(stderr, "realpath: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
memset(lnk, 0, sizeof(lnk));
if (readlink(argv[1], lnk, sizeof(lnk)-1)) {
dir = dirname(path);
if (strchr(lnk, '/')) {
save = xstrdup(dir);
saveLnk = xstrdup(lnk);
dir = dirname(saveLnk);
if (strcmp(dir, save) == 0)
file = basename_c(argv[1]);
else
file = basename_c(lnk);
dir = save;
} else
file = basename_c(argv[1]);
ll = strlen(dir) + strlen(file) + 2;
service = xmalloc(ll);
snprintf(service, ll, "%s/%s", dir, file);
if (stat(service, &stbuf) != 0) {
free(service);
service = xstrdup(lnk);
}
free(save);
free(saveLnk);
}
if (!service)
service = xstrdup(path);
applet = basename_c(service); applet = basename_c(service);
if (argc < 3) if (argc < 3)