diff options
author | Denys Vlasenko <dvlasenk@redhat.com> | 2010-10-13 12:53:27 +0200 |
---|---|---|
committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-10-13 12:53:27 +0200 |
commit | 05e8605ab8a01120af7c9f011c2334ab34381fdf (patch) | |
tree | f200589bc4e66c649788cc58d5a6f4fc013dbe45 /runit | |
parent | b1db09be5a19f814ed5dc7e0ab095c3355926da6 (diff) | |
download | busybox-w32-05e8605ab8a01120af7c9f011c2334ab34381fdf.tar.gz busybox-w32-05e8605ab8a01120af7c9f011c2334ab34381fdf.tar.bz2 busybox-w32-05e8605ab8a01120af7c9f011c2334ab34381fdf.zip |
remove runit/runit_lib.c
function old new delta
runsv_main 1770 1786 +16
svstatus_get 176 188 +12
sv_main 1180 1186 +6
runsvdir_main 683 689 +6
processorstart 385 391 +6
control 126 132 +6
logdir_open 1184 1187 +3
lock_exnb 14 - -14
lock_ex 14 - -14
open_write 17 - -17
open_read 17 - -17
------------------------------------------------------------------------------
(add/remove: 0/5 grow/shrink: 7/0 up/down: 55/-62) Total: -7 bytes
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'runit')
-rw-r--r-- | runit/Kbuild.src | 8 | ||||
-rw-r--r-- | runit/runit_lib.c | 275 | ||||
-rw-r--r-- | runit/runit_lib.h | 53 | ||||
-rw-r--r-- | runit/runsv.c | 6 | ||||
-rw-r--r-- | runit/runsvdir.c | 2 | ||||
-rw-r--r-- | runit/sv.c | 11 | ||||
-rw-r--r-- | runit/svlogd.c | 50 |
7 files changed, 63 insertions, 342 deletions
diff --git a/runit/Kbuild.src b/runit/Kbuild.src index d38bad20f..0fce95507 100644 --- a/runit/Kbuild.src +++ b/runit/Kbuild.src | |||
@@ -8,10 +8,10 @@ lib-y:= | |||
8 | 8 | ||
9 | INSERT | 9 | INSERT |
10 | 10 | ||
11 | lib-$(CONFIG_RUNSV) += runsv.o runit_lib.o | 11 | lib-$(CONFIG_RUNSV) += runsv.o |
12 | lib-$(CONFIG_RUNSVDIR) += runsvdir.o runit_lib.o | 12 | lib-$(CONFIG_RUNSVDIR) += runsvdir.o |
13 | lib-$(CONFIG_SV) += sv.o runit_lib.o | 13 | lib-$(CONFIG_SV) += sv.o |
14 | lib-$(CONFIG_SVLOGD) += svlogd.o runit_lib.o | 14 | lib-$(CONFIG_SVLOGD) += svlogd.o |
15 | lib-$(CONFIG_CHPST) += chpst.o | 15 | lib-$(CONFIG_CHPST) += chpst.o |
16 | 16 | ||
17 | lib-$(CONFIG_ENVDIR) += chpst.o | 17 | lib-$(CONFIG_ENVDIR) += chpst.o |
diff --git a/runit/runit_lib.c b/runit/runit_lib.c deleted file mode 100644 index 8182a909a..000000000 --- a/runit/runit_lib.c +++ /dev/null | |||
@@ -1,275 +0,0 @@ | |||
1 | /* | ||
2 | Copyright (c) 2001-2006, Gerrit Pape | ||
3 | All rights reserved. | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without | ||
6 | modification, are permitted provided that the following conditions are met: | ||
7 | |||
8 | 1. Redistributions of source code must retain the above copyright notice, | ||
9 | this list of conditions and the following disclaimer. | ||
10 | 2. Redistributions in binary form must reproduce the above copyright | ||
11 | notice, this list of conditions and the following disclaimer in the | ||
12 | documentation and/or other materials provided with the distribution. | ||
13 | 3. The name of the author may not be used to endorse or promote products | ||
14 | derived from this software without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | ||
17 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
18 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | ||
19 | EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
20 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
21 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
22 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
23 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
24 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
25 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | /* Busyboxed by Denys Vlasenko <vda.linux@googlemail.com> */ | ||
29 | /* Collected into one file from runit's many tiny files */ | ||
30 | /* TODO: review, eliminate unneeded stuff, move good stuff to libbb */ | ||
31 | |||
32 | #include <sys/poll.h> | ||
33 | #include <sys/file.h> | ||
34 | #include "libbb.h" | ||
35 | #include "runit_lib.h" | ||
36 | |||
37 | #ifdef UNUSED | ||
38 | unsigned byte_chr(char *s,unsigned n,int c) | ||
39 | { | ||
40 | char ch; | ||
41 | char *t; | ||
42 | |||
43 | ch = c; | ||
44 | t = s; | ||
45 | for (;;) { | ||
46 | if (!n) break; | ||
47 | if (*t == ch) break; | ||
48 | ++t; | ||
49 | --n; | ||
50 | } | ||
51 | return t - s; | ||
52 | } | ||
53 | |||
54 | static /* as it isn't used anywhere else */ | ||
55 | void tai_pack(char *s, const struct tai *t) | ||
56 | { | ||
57 | uint64_t x; | ||
58 | |||
59 | x = t->x; | ||
60 | s[7] = x & 255; x >>= 8; | ||
61 | s[6] = x & 255; x >>= 8; | ||
62 | s[5] = x & 255; x >>= 8; | ||
63 | s[4] = x & 255; x >>= 8; | ||
64 | s[3] = x & 255; x >>= 8; | ||
65 | s[2] = x & 255; x >>= 8; | ||
66 | s[1] = x & 255; x >>= 8; | ||
67 | s[0] = x; | ||
68 | } | ||
69 | |||
70 | void tai_unpack(const char *s,struct tai *t) | ||
71 | { | ||
72 | uint64_t x; | ||
73 | |||
74 | x = (unsigned char) s[0]; | ||
75 | x <<= 8; x += (unsigned char) s[1]; | ||
76 | x <<= 8; x += (unsigned char) s[2]; | ||
77 | x <<= 8; x += (unsigned char) s[3]; | ||
78 | x <<= 8; x += (unsigned char) s[4]; | ||
79 | x <<= 8; x += (unsigned char) s[5]; | ||
80 | x <<= 8; x += (unsigned char) s[6]; | ||
81 | x <<= 8; x += (unsigned char) s[7]; | ||
82 | t->x = x; | ||
83 | } | ||
84 | |||
85 | |||
86 | void taia_add(struct taia *t,const struct taia *u,const struct taia *v) | ||
87 | { | ||
88 | t->sec.x = u->sec.x + v->sec.x; | ||
89 | t->nano = u->nano + v->nano; | ||
90 | t->atto = u->atto + v->atto; | ||
91 | if (t->atto > 999999999UL) { | ||
92 | t->atto -= 1000000000UL; | ||
93 | ++t->nano; | ||
94 | } | ||
95 | if (t->nano > 999999999UL) { | ||
96 | t->nano -= 1000000000UL; | ||
97 | ++t->sec.x; | ||
98 | } | ||
99 | } | ||
100 | |||
101 | int taia_less(const struct taia *t, const struct taia *u) | ||
102 | { | ||
103 | if (t->sec.x < u->sec.x) return 1; | ||
104 | if (t->sec.x > u->sec.x) return 0; | ||
105 | if (t->nano < u->nano) return 1; | ||
106 | if (t->nano > u->nano) return 0; | ||
107 | return t->atto < u->atto; | ||
108 | } | ||
109 | |||
110 | void taia_now(struct taia *t) | ||
111 | { | ||
112 | struct timeval now; | ||
113 | gettimeofday(&now, NULL); | ||
114 | tai_unix(&t->sec, now.tv_sec); | ||
115 | t->nano = 1000 * now.tv_usec + 500; | ||
116 | t->atto = 0; | ||
117 | } | ||
118 | |||
119 | /* UNUSED | ||
120 | void taia_pack(char *s, const struct taia *t) | ||
121 | { | ||
122 | unsigned long x; | ||
123 | |||
124 | tai_pack(s, &t->sec); | ||
125 | s += 8; | ||
126 | |||
127 | x = t->atto; | ||
128 | s[7] = x & 255; x >>= 8; | ||
129 | s[6] = x & 255; x >>= 8; | ||
130 | s[5] = x & 255; x >>= 8; | ||
131 | s[4] = x; | ||
132 | x = t->nano; | ||
133 | s[3] = x & 255; x >>= 8; | ||
134 | s[2] = x & 255; x >>= 8; | ||
135 | s[1] = x & 255; x >>= 8; | ||
136 | s[0] = x; | ||
137 | } | ||
138 | */ | ||
139 | |||
140 | void taia_sub(struct taia *t, const struct taia *u, const struct taia *v) | ||
141 | { | ||
142 | unsigned long unano = u->nano; | ||
143 | unsigned long uatto = u->atto; | ||
144 | |||
145 | t->sec.x = u->sec.x - v->sec.x; | ||
146 | t->nano = unano - v->nano; | ||
147 | t->atto = uatto - v->atto; | ||
148 | if (t->atto > uatto) { | ||
149 | t->atto += 1000000000UL; | ||
150 | --t->nano; | ||
151 | } | ||
152 | if (t->nano > unano) { | ||
153 | t->nano += 1000000000UL; | ||
154 | --t->sec.x; | ||
155 | } | ||
156 | } | ||
157 | |||
158 | /* XXX: breaks tai encapsulation */ | ||
159 | void taia_uint(struct taia *t, unsigned s) | ||
160 | { | ||
161 | t->sec.x = s; | ||
162 | t->nano = 0; | ||
163 | t->atto = 0; | ||
164 | } | ||
165 | |||
166 | static | ||
167 | uint64_t taia2millisec(const struct taia *t) | ||
168 | { | ||
169 | return (t->sec.x * 1000) + (t->nano / 1000000); | ||
170 | } | ||
171 | |||
172 | void iopause(iopause_fd *x, unsigned len, struct taia *deadline, struct taia *stamp) | ||
173 | { | ||
174 | int millisecs; | ||
175 | int i; | ||
176 | |||
177 | if (taia_less(deadline, stamp)) | ||
178 | millisecs = 0; | ||
179 | else { | ||
180 | uint64_t m; | ||
181 | struct taia t; | ||
182 | t = *stamp; | ||
183 | taia_sub(&t, deadline, &t); | ||
184 | millisecs = m = taia2millisec(&t); | ||
185 | if (m > 1000) millisecs = 1000; | ||
186 | millisecs += 20; | ||
187 | } | ||
188 | |||
189 | for (i = 0; i < len; ++i) | ||
190 | x[i].revents = 0; | ||
191 | |||
192 | poll(x, len, millisecs); | ||
193 | /* XXX: some kernels apparently need x[0] even if len is 0 */ | ||
194 | /* XXX: how to handle EAGAIN? are kernels really this dumb? */ | ||
195 | /* XXX: how to handle EINVAL? when exactly can this happen? */ | ||
196 | } | ||
197 | #endif | ||
198 | |||
199 | int lock_ex(int fd) | ||
200 | { | ||
201 | return flock(fd, LOCK_EX); | ||
202 | } | ||
203 | |||
204 | int lock_exnb(int fd) | ||
205 | { | ||
206 | return flock(fd, LOCK_EX | LOCK_NB); | ||
207 | } | ||
208 | |||
209 | #ifdef UNUSED | ||
210 | int open_append(const char *fn) | ||
211 | { | ||
212 | return open(fn, O_WRONLY | O_NDELAY | O_APPEND | O_CREAT, 0600); | ||
213 | } | ||
214 | |||
215 | int open_trunc(const char *fn) | ||
216 | { | ||
217 | return open(fn, O_WRONLY | O_NDELAY | O_TRUNC | O_CREAT, 0644); | ||
218 | } | ||
219 | #endif | ||
220 | |||
221 | int open_read(const char *fn) | ||
222 | { | ||
223 | return open(fn, O_RDONLY|O_NDELAY); | ||
224 | } | ||
225 | |||
226 | int open_write(const char *fn) | ||
227 | { | ||
228 | return open(fn, O_WRONLY|O_NDELAY); | ||
229 | } | ||
230 | |||
231 | unsigned FAST_FUNC pmatch(const char *p, const char *s, unsigned len) | ||
232 | { | ||
233 | for (;;) { | ||
234 | char c = *p++; | ||
235 | if (!c) return !len; | ||
236 | switch (c) { | ||
237 | case '*': | ||
238 | c = *p; | ||
239 | if (!c) return 1; | ||
240 | for (;;) { | ||
241 | if (!len) return 0; | ||
242 | if (*s == c) break; | ||
243 | ++s; | ||
244 | --len; | ||
245 | } | ||
246 | continue; | ||
247 | case '+': | ||
248 | c = *p++; | ||
249 | if (c != *s) return 0; | ||
250 | for (;;) { | ||
251 | if (!len) return 1; | ||
252 | if (*s != c) break; | ||
253 | ++s; | ||
254 | --len; | ||
255 | } | ||
256 | continue; | ||
257 | /* | ||
258 | case '?': | ||
259 | if (*p == '?') { | ||
260 | if (*s != '?') return 0; | ||
261 | ++p; | ||
262 | } | ||
263 | ++s; --len; | ||
264 | continue; | ||
265 | */ | ||
266 | default: | ||
267 | if (!len) return 0; | ||
268 | if (*s != c) return 0; | ||
269 | ++s; | ||
270 | --len; | ||
271 | continue; | ||
272 | } | ||
273 | } | ||
274 | return 0; | ||
275 | } | ||
diff --git a/runit/runit_lib.h b/runit/runit_lib.h index d8304aca6..c36ea4ca5 100644 --- a/runit/runit_lib.h +++ b/runit/runit_lib.h | |||
@@ -27,59 +27,6 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
27 | 27 | ||
28 | PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN | 28 | PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN |
29 | 29 | ||
30 | //extern unsigned byte_chr(char *s,unsigned n,int c); | ||
31 | // | ||
32 | //struct tai { | ||
33 | // uint64_t x; | ||
34 | //}; | ||
35 | // | ||
36 | //#define tai_unix(t,u) ((void) ((t)->x = 0x400000000000000aULL + (uint64_t) (u))) | ||
37 | // | ||
38 | //#define TAI_PACK 8 | ||
39 | //extern void tai_unpack(const char *,struct tai *); | ||
40 | // | ||
41 | //extern void tai_uint(struct tai *,unsigned); | ||
42 | // | ||
43 | //struct taia { | ||
44 | // struct tai sec; | ||
45 | // unsigned long nano; /* 0...999999999 */ | ||
46 | // unsigned long atto; /* 0...999999999 */ | ||
47 | //}; | ||
48 | // | ||
49 | //extern void taia_now(struct taia *); | ||
50 | // | ||
51 | //extern void taia_add(struct taia *,const struct taia *,const struct taia *); | ||
52 | //extern void taia_addsec(struct taia *,const struct taia *,int); | ||
53 | //extern void taia_sub(struct taia *,const struct taia *,const struct taia *); | ||
54 | //extern void taia_half(struct taia *,const struct taia *); | ||
55 | //extern int taia_less(const struct taia *,const struct taia *); | ||
56 | // | ||
57 | //#define TAIA_PACK 16 | ||
58 | //extern void taia_pack(char *,const struct taia *); | ||
59 | // | ||
60 | //extern void taia_uint(struct taia *,unsigned); | ||
61 | // | ||
62 | //typedef struct pollfd iopause_fd; | ||
63 | //#define IOPAUSE_READ POLLIN | ||
64 | //#define IOPAUSE_WRITE POLLOUT | ||
65 | // | ||
66 | //extern void iopause(iopause_fd *,unsigned,struct taia *,struct taia *); | ||
67 | |||
68 | extern int lock_ex(int); | ||
69 | //extern int lock_un(int); | ||
70 | extern int lock_exnb(int); | ||
71 | |||
72 | extern int open_read(const char *); | ||
73 | extern int open_write(const char *); | ||
74 | //extern int open_excl(const char *); | ||
75 | //extern int open_append(const char *); | ||
76 | //extern int open_trunc(const char *); | ||
77 | |||
78 | extern unsigned FAST_FUNC pmatch(const char *, const char *, unsigned); | ||
79 | |||
80 | //#define str_diff(s,t) strcmp((s), (t)) | ||
81 | #define str_equal(s,t) (!strcmp((s), (t))) | ||
82 | |||
83 | /* | 30 | /* |
84 | * runsv / supervise / sv stuff | 31 | * runsv / supervise / sv stuff |
85 | */ | 32 | */ |
diff --git a/runit/runsv.c b/runit/runsv.c index 6bb6ec886..ebb031837 100644 --- a/runit/runsv.c +++ b/runit/runsv.c | |||
@@ -524,7 +524,7 @@ int runsv_main(int argc UNUSED_PARAM, char **argv) | |||
524 | } | 524 | } |
525 | svd[0].fdlock = xopen3("log/supervise/lock"+4, | 525 | svd[0].fdlock = xopen3("log/supervise/lock"+4, |
526 | O_WRONLY|O_NDELAY|O_APPEND|O_CREAT, 0600); | 526 | O_WRONLY|O_NDELAY|O_APPEND|O_CREAT, 0600); |
527 | if (lock_exnb(svd[0].fdlock) == -1) | 527 | if (flock(svd[0].fdlock, LOCK_EX | LOCK_NB) == -1) |
528 | fatal_cannot("lock supervise/lock"); | 528 | fatal_cannot("lock supervise/lock"); |
529 | close_on_exec_on(svd[0].fdlock); | 529 | close_on_exec_on(svd[0].fdlock); |
530 | if (haslog) { | 530 | if (haslog) { |
@@ -548,7 +548,7 @@ int runsv_main(int argc UNUSED_PARAM, char **argv) | |||
548 | } | 548 | } |
549 | svd[1].fdlock = xopen3("log/supervise/lock", | 549 | svd[1].fdlock = xopen3("log/supervise/lock", |
550 | O_WRONLY|O_NDELAY|O_APPEND|O_CREAT, 0600); | 550 | O_WRONLY|O_NDELAY|O_APPEND|O_CREAT, 0600); |
551 | if (lock_ex(svd[1].fdlock) == -1) | 551 | if (flock(svd[1].fdlock, LOCK_EX) == -1) |
552 | fatal_cannot("lock log/supervise/lock"); | 552 | fatal_cannot("lock log/supervise/lock"); |
553 | close_on_exec_on(svd[1].fdlock); | 553 | close_on_exec_on(svd[1].fdlock); |
554 | } | 554 | } |
@@ -618,7 +618,7 @@ int runsv_main(int argc UNUSED_PARAM, char **argv) | |||
618 | pidchanged = 1; | 618 | pidchanged = 1; |
619 | svd[0].ctrl &= ~C_TERM; | 619 | svd[0].ctrl &= ~C_TERM; |
620 | if (svd[0].state != S_FINISH) { | 620 | if (svd[0].state != S_FINISH) { |
621 | fd = open_read("finish"); | 621 | fd = open("finish", O_RDONLY|O_NDELAY); |
622 | if (fd != -1) { | 622 | if (fd != -1) { |
623 | close(fd); | 623 | close(fd); |
624 | svd[0].state = S_FINISH; | 624 | svd[0].state = S_FINISH; |
diff --git a/runit/runsvdir.c b/runit/runsvdir.c index 71fde757e..e77eeff04 100644 --- a/runit/runsvdir.c +++ b/runit/runsvdir.c | |||
@@ -276,7 +276,7 @@ int runsvdir_main(int argc UNUSED_PARAM, char **argv) | |||
276 | } | 276 | } |
277 | run: | 277 | run: |
278 | #endif | 278 | #endif |
279 | curdir = open_read("."); | 279 | curdir = open(".", O_RDONLY|O_NDELAY); |
280 | if (curdir == -1) | 280 | if (curdir == -1) |
281 | fatal2_cannot("open current directory", ""); | 281 | fatal2_cannot("open current directory", ""); |
282 | close_on_exec_on(curdir); | 282 | close_on_exec_on(curdir); |
diff --git a/runit/sv.c b/runit/sv.c index 3f76a2d47..c420a91a6 100644 --- a/runit/sv.c +++ b/runit/sv.c | |||
@@ -176,6 +176,9 @@ struct globals { | |||
176 | #define INIT_G() do { } while (0) | 176 | #define INIT_G() do { } while (0) |
177 | 177 | ||
178 | 178 | ||
179 | #define str_equal(s,t) (!strcmp((s), (t))) | ||
180 | |||
181 | |||
179 | static void fatal_cannot(const char *m1) NORETURN; | 182 | static void fatal_cannot(const char *m1) NORETURN; |
180 | static void fatal_cannot(const char *m1) | 183 | static void fatal_cannot(const char *m1) |
181 | { | 184 | { |
@@ -221,7 +224,7 @@ static int svstatus_get(void) | |||
221 | { | 224 | { |
222 | int fd, r; | 225 | int fd, r; |
223 | 226 | ||
224 | fd = open_write("supervise/ok"); | 227 | fd = open("supervise/ok", O_WRONLY|O_NDELAY); |
225 | if (fd == -1) { | 228 | if (fd == -1) { |
226 | if (errno == ENODEV) { | 229 | if (errno == ENODEV) { |
227 | *acts == 'x' ? ok("runsv not running") | 230 | *acts == 'x' ? ok("runsv not running") |
@@ -232,7 +235,7 @@ static int svstatus_get(void) | |||
232 | return -1; | 235 | return -1; |
233 | } | 236 | } |
234 | close(fd); | 237 | close(fd); |
235 | fd = open_read("supervise/status"); | 238 | fd = open("supervise/status", O_RDONLY|O_NDELAY); |
236 | if (fd == -1) { | 239 | if (fd == -1) { |
237 | warn("can't open supervise/status"); | 240 | warn("can't open supervise/status"); |
238 | return -1; | 241 | return -1; |
@@ -397,7 +400,7 @@ static int control(const char *a) | |||
397 | if (svstatus.want == *a) | 400 | if (svstatus.want == *a) |
398 | return 0; | 401 | return 0; |
399 | */ | 402 | */ |
400 | fd = open_write("supervise/control"); | 403 | fd = open("supervise/control", O_WRONLY|O_NDELAY); |
401 | if (fd == -1) { | 404 | if (fd == -1) { |
402 | if (errno != ENODEV) | 405 | if (errno != ENODEV) |
403 | warn("can't open supervise/control"); | 406 | warn("can't open supervise/control"); |
@@ -446,7 +449,7 @@ int sv_main(int argc UNUSED_PARAM, char **argv) | |||
446 | 449 | ||
447 | tnow = time(NULL) + 0x400000000000000aULL; | 450 | tnow = time(NULL) + 0x400000000000000aULL; |
448 | tstart = tnow; | 451 | tstart = tnow; |
449 | curdir = open_read("."); | 452 | curdir = open(".", O_RDONLY|O_NDELAY); |
450 | if (curdir == -1) | 453 | if (curdir == -1) |
451 | fatal_cannot("open current directory"); | 454 | fatal_cannot("open current directory"); |
452 | 455 | ||
diff --git a/runit/svlogd.c b/runit/svlogd.c index 1f0a77cc2..052806c25 100644 --- a/runit/svlogd.c +++ b/runit/svlogd.c | |||
@@ -261,6 +261,52 @@ static char* wstrdup(const char *str) | |||
261 | return s; | 261 | return s; |
262 | } | 262 | } |
263 | 263 | ||
264 | static unsigned pmatch(const char *p, const char *s, unsigned len) | ||
265 | { | ||
266 | for (;;) { | ||
267 | char c = *p++; | ||
268 | if (!c) return !len; | ||
269 | switch (c) { | ||
270 | case '*': | ||
271 | c = *p; | ||
272 | if (!c) return 1; | ||
273 | for (;;) { | ||
274 | if (!len) return 0; | ||
275 | if (*s == c) break; | ||
276 | ++s; | ||
277 | --len; | ||
278 | } | ||
279 | continue; | ||
280 | case '+': | ||
281 | c = *p++; | ||
282 | if (c != *s) return 0; | ||
283 | for (;;) { | ||
284 | if (!len) return 1; | ||
285 | if (*s != c) break; | ||
286 | ++s; | ||
287 | --len; | ||
288 | } | ||
289 | continue; | ||
290 | /* | ||
291 | case '?': | ||
292 | if (*p == '?') { | ||
293 | if (*s != '?') return 0; | ||
294 | ++p; | ||
295 | } | ||
296 | ++s; --len; | ||
297 | continue; | ||
298 | */ | ||
299 | default: | ||
300 | if (!len) return 0; | ||
301 | if (*s != c) return 0; | ||
302 | ++s; | ||
303 | --len; | ||
304 | continue; | ||
305 | } | ||
306 | } | ||
307 | return 0; | ||
308 | } | ||
309 | |||
264 | /*** ex fmt_ptime.[ch] ***/ | 310 | /*** ex fmt_ptime.[ch] ***/ |
265 | 311 | ||
266 | /* NUL terminated */ | 312 | /* NUL terminated */ |
@@ -342,7 +388,7 @@ static void processorstart(struct logdir *ld) | |||
342 | ld->fnsave[26] = 't'; /* <- that's why we need sv_ch! */ | 388 | ld->fnsave[26] = 't'; /* <- that's why we need sv_ch! */ |
343 | fd = xopen(ld->fnsave, O_WRONLY|O_NDELAY|O_TRUNC|O_CREAT); | 389 | fd = xopen(ld->fnsave, O_WRONLY|O_NDELAY|O_TRUNC|O_CREAT); |
344 | xmove_fd(fd, 1); | 390 | xmove_fd(fd, 1); |
345 | fd = open_read("state"); | 391 | fd = open("state", O_RDONLY|O_NDELAY); |
346 | if (fd == -1) { | 392 | if (fd == -1) { |
347 | if (errno != ENOENT) | 393 | if (errno != ENOENT) |
348 | bb_perror_msg_and_die(FATAL"can't %s processor %s", "open state for", ld->name); | 394 | bb_perror_msg_and_die(FATAL"can't %s processor %s", "open state for", ld->name); |
@@ -626,7 +672,7 @@ static NOINLINE unsigned logdir_open(struct logdir *ld, const char *fn) | |||
626 | } | 672 | } |
627 | ld->fdlock = open("lock", O_WRONLY|O_NDELAY|O_APPEND|O_CREAT, 0600); | 673 | ld->fdlock = open("lock", O_WRONLY|O_NDELAY|O_APPEND|O_CREAT, 0600); |
628 | if ((ld->fdlock == -1) | 674 | if ((ld->fdlock == -1) |
629 | || (lock_exnb(ld->fdlock) == -1) | 675 | || (flock(ld->fdlock, LOCK_EX | LOCK_NB) == -1) |
630 | ) { | 676 | ) { |
631 | logdir_close(ld); | 677 | logdir_close(ld); |
632 | warn2("can't lock directory", (char*)fn); | 678 | warn2("can't lock directory", (char*)fn); |