Gentoo Archives: gentoo-commits

From: William Hubbs <williamh@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/openrc:master commit in: man/, sh/, src/rc/
Date: Sun, 31 Jul 2011 15:02:30
Message-Id: 0c8bea21524c22856fdb8528298b43d6fb20451d.WilliamH@gentoo
1 commit: 0c8bea21524c22856fdb8528298b43d6fb20451d
2 Author: William Hubbs <williamh <AT> gentoo <DOT> org>
3 AuthorDate: Wed Jul 27 16:02:23 2011 +0000
4 Commit: William Hubbs <williamh <AT> gentoo <DOT> org>
5 CommitDate: Sun Jul 31 15:00:48 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=0c8bea21
7
8 Improve processing of service directories and conf.d files
9
10 symbolic links should not be followed in an attempt to work out the name
11 of the service we are running. Also, @sysconfdir <AT> /conf.d should be tried
12 as a backup directory for configuration files.
13
14 I would like to thank Robin Johnson for his input on this change.
15
16 X-Gentoo-Bug: 350910
17 X-Gentoo-Bug-URL: http://bugs.gentoo.org/show_bug.cgi?id=350910
18
19 ---
20 man/runscript.8 | 6 ------
21 sh/runscript.sh.in | 33 +++++++++++++++++++--------------
22 src/rc/runscript.c | 38 ++------------------------------------
23 3 files changed, 21 insertions(+), 56 deletions(-)
24
25 diff --git a/man/runscript.8 b/man/runscript.8
26 index 253b349..bf06d7b 100644
27 --- a/man/runscript.8
28 +++ b/man/runscript.8
29 @@ -462,12 +462,6 @@ show()
30
31 .Ed
32 .Sh BUGS
33 -Because of the way we load our configuration files and the need to handle
34 -more than one service directory, you can only use symlinks in service
35 -directories to other services in the same directory.
36 -You cannot symlink to a service in a different directory even if it is
37 -another service directory.
38 -.Pp
39 is_older_than should return 0 on success.
40 Instead we return 1 to be compliant with Gentoo baselayout.
41 Users are encouraged to use the is_newer_than function which returns correctly.
42
43 diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in
44 index df34b5e..fe30a03 100644
45 --- a/sh/runscript.sh.in
46 +++ b/sh/runscript.sh.in
47 @@ -16,6 +16,23 @@ sourcex()
48 fi
49 }
50
51 +loadconfig()
52 +{
53 + # If we're net.eth0 or openvpn.work then load net or openvpn config
54 + _c=${RC_SVCNAME%%.*}
55 + if [ -n "$_c" -a "$_c" != "$RC_SVCNAME" ]; then
56 + if ! sourcex -e "$1/$_c.$RC_RUNLEVEL"; then
57 + sourcex -e "$1/$_c"
58 + fi
59 + fi
60 + unset _c
61 +
62 + # Overlay with our specific config
63 + if ! sourcex -e "$1/$RC_SVCNAME.$RC_RUNLEVEL"; then
64 + sourcex -e "$1/$RC_SVCNAME"
65 + fi
66 +}
67 +
68 if [ ! -e ${RC_SVCDIR}/softlevel ]; then
69 eerror "You are attempting to run an openrc service on a"
70 eerror "system which openrc did not boot."
71 @@ -165,21 +182,9 @@ status()
72
73 yesno $RC_DEBUG && set -x
74
75 -_conf_d=${RC_SERVICE%/*}/../conf.d
76 -# If we're net.eth0 or openvpn.work then load net or openvpn config
77 -_c=${RC_SVCNAME%%.*}
78 -if [ -n "$_c" -a "$_c" != "$RC_SVCNAME" ]; then
79 - if ! sourcex -e "$_conf_d/$_c.$RC_RUNLEVEL"; then
80 - sourcex -e "$_conf_d/$_c"
81 - fi
82 -fi
83 -unset _c
84 -
85 -# Overlay with our specific config
86 -if ! sourcex -e "$_conf_d/$RC_SVCNAME.$RC_RUNLEVEL"; then
87 - sourcex -e "$_conf_d/$RC_SVCNAME"
88 +if ! loadconfig "${RC_SERVICE%/*}/../conf.d"; then
89 + loadconfig "@SYSCONFDIR@/conf.d"
90 fi
91 -unset _conf_d
92
93 # Load any system overrides
94 sourcex -e "@SYSCONFDIR@/rc.conf"
95
96 diff --git a/src/rc/runscript.c b/src/rc/runscript.c
97 index 02d9e7e..8278f5b 100644
98 --- a/src/rc/runscript.c
99 +++ b/src/rc/runscript.c
100 @@ -1100,8 +1100,7 @@ runscript(int argc, char **argv)
101 bool doneone = false;
102 int retval, opt, depoptions = RC_DEP_TRACE;
103 RC_STRING *svc;
104 - char path[PATH_MAX], lnk[PATH_MAX];
105 - char *dir, *save = NULL, *saveLnk = NULL;
106 + char *save = NULL;
107 char pidstr[10];
108 size_t l = 0, ll;
109 const char *file;
110 @@ -1121,40 +1120,7 @@ runscript(int argc, char **argv)
111
112 atexit(cleanup);
113
114 - /* We need to work out the real full path to our service.
115 - * This works fine, provided that we ONLY allow multiplexed services
116 - * to exist in the same directory as the master link.
117 - * Also, the master link as to be a real file in the init dir. */
118 - if (!realpath(argv[1], path)) {
119 - fprintf(stderr, "realpath: %s\n", strerror(errno));
120 - exit(EXIT_FAILURE);
121 - }
122 - memset(lnk, 0, sizeof(lnk));
123 - if (readlink(argv[1], lnk, sizeof(lnk)-1)) {
124 - dir = dirname(path);
125 - if (strchr(lnk, '/')) {
126 - save = xstrdup(dir);
127 - saveLnk = xstrdup(lnk);
128 - dir = dirname(saveLnk);
129 - if (strcmp(dir, save) == 0)
130 - file = basename_c(argv[1]);
131 - else
132 - file = basename_c(lnk);
133 - dir = save;
134 - } else
135 - file = basename_c(argv[1]);
136 - ll = strlen(dir) + strlen(file) + 2;
137 - service = xmalloc(ll);
138 - snprintf(service, ll, "%s/%s", dir, file);
139 - if (stat(service, &stbuf) != 0) {
140 - free(service);
141 - service = xstrdup(lnk);
142 - }
143 - free(save);
144 - free(saveLnk);
145 - }
146 - if (!service)
147 - service = xstrdup(path);
148 + service = xstrdup(argv[1]);
149 applet = basename_c(service);
150
151 if (argc < 3)