summaryrefslogtreecommitdiff
authorDenys Vlasenko <dvlasenk@redhat.com>2010-10-13 10:53:27 (GMT)
committer Denys Vlasenko <dvlasenk@redhat.com>2010-10-13 10:53:27 (GMT)
commit05e8605ab8a01120af7c9f011c2334ab34381fdf (patch)
treef200589bc4e66c649788cc58d5a6f4fc013dbe45
parentb1db09be5a19f814ed5dc7e0ab095c3355926da6 (diff)
downloadbusybox-05e8605ab8a01120af7c9f011c2334ab34381fdf.zip
busybox-05e8605ab8a01120af7c9f011c2334ab34381fdf.tar.gz
busybox-05e8605ab8a01120af7c9f011c2334ab34381fdf.tar.bz2
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
-rw-r--r--runit/Kbuild.src8
-rw-r--r--runit/runit_lib.c275
-rw-r--r--runit/runit_lib.h53
-rw-r--r--runit/runsv.c6
-rw-r--r--runit/runsvdir.c2
-rw-r--r--runit/sv.c11
-rw-r--r--runit/svlogd.c50
7 files changed, 63 insertions, 342 deletions
diff --git a/runit/Kbuild.src b/runit/Kbuild.src
index d38bad2..0fce955 100644
--- a/runit/Kbuild.src
+++ b/runit/Kbuild.src
@@ -8,10 +8,10 @@ lib-y:=
INSERT
-lib-$(CONFIG_RUNSV) += runsv.o runit_lib.o
-lib-$(CONFIG_RUNSVDIR) += runsvdir.o runit_lib.o
-lib-$(CONFIG_SV) += sv.o runit_lib.o
-lib-$(CONFIG_SVLOGD) += svlogd.o runit_lib.o
+lib-$(CONFIG_RUNSV) += runsv.o
+lib-$(CONFIG_RUNSVDIR) += runsvdir.o
+lib-$(CONFIG_SV) += sv.o
+lib-$(CONFIG_SVLOGD) += svlogd.o
lib-$(CONFIG_CHPST) += chpst.o
lib-$(CONFIG_ENVDIR) += chpst.o
diff --git a/runit/runit_lib.c b/runit/runit_lib.c
deleted file mode 100644
index 8182a90..0000000
--- a/runit/runit_lib.c
+++ b/dev/null
@@ -1,275 +0,0 @@
-/*
-Copyright (c) 2001-2006, Gerrit Pape
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products
- derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
-WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
-EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-/* Busyboxed by Denys Vlasenko <vda.linux@googlemail.com> */
-/* Collected into one file from runit's many tiny files */
-/* TODO: review, eliminate unneeded stuff, move good stuff to libbb */
-
-#include <sys/poll.h>
-#include <sys/file.h>
-#include "libbb.h"
-#include "runit_lib.h"
-
-#ifdef UNUSED
-unsigned byte_chr(char *s,unsigned n,int c)
-{
- char ch;
- char *t;
-
- ch = c;
- t = s;
- for (;;) {
- if (!n) break;
- if (*t == ch) break;
- ++t;
- --n;
- }
- return t - s;
-}
-
-static /* as it isn't used anywhere else */
-void tai_pack(char *s, const struct tai *t)
-{
- uint64_t x;
-
- x = t->x;
- s[7] = x & 255; x >>= 8;
- s[6] = x & 255; x >>= 8;
- s[5] = x & 255; x >>= 8;
- s[4] = x & 255; x >>= 8;
- s[3] = x & 255; x >>= 8;
- s[2] = x & 255; x >>= 8;
- s[1] = x & 255; x >>= 8;
- s[0] = x;
-}
-
-void tai_unpack(const char *s,struct tai *t)
-{
- uint64_t x;
-
- x = (unsigned char) s[0];
- x <<= 8; x += (unsigned char) s[1];
- x <<= 8; x += (unsigned char) s[2];
- x <<= 8; x += (unsigned char) s[3];
- x <<= 8; x += (unsigned char) s[4];
- x <<= 8; x += (unsigned char) s[5];
- x <<= 8; x += (unsigned char) s[6];
- x <<= 8; x += (unsigned char) s[7];
- t->x = x;
-}
-
-
-void taia_add(struct taia *t,const struct taia *u,const struct taia *v)
-{
- t->sec.x = u->sec.x + v->sec.x;
- t->nano = u->nano + v->nano;
- t->atto = u->atto + v->atto;
- if (t->atto > 999999999UL) {
- t->atto -= 1000000000UL;
- ++t->nano;
- }
- if (t->nano > 999999999UL) {
- t->nano -= 1000000000UL;
- ++t->sec.x;
- }
-}
-
-int taia_less(const struct taia *t, const struct taia *u)
-{
- if (t->sec.x < u->sec.x) return 1;
- if (t->sec.x > u->sec.x) return 0;
- if (t->nano < u->nano) return 1;
- if (t->nano > u->nano) return 0;
- return t->atto < u->atto;
-}
-
-void taia_now(struct taia *t)
-{
- struct timeval now;
- gettimeofday(&now, NULL);
- tai_unix(&t->sec, now.tv_sec);
- t->nano = 1000 * now.tv_usec + 500;
- t->atto = 0;
-}
-
-/* UNUSED
-void taia_pack(char *s, const struct taia *t)
-{
- unsigned long x;
-
- tai_pack(s, &t->sec);
- s += 8;
-
- x = t->atto;
- s[7] = x & 255; x >>= 8;
- s[6] = x & 255; x >>= 8;
- s[5] = x & 255; x >>= 8;
- s[4] = x;
- x = t->nano;
- s[3] = x & 255; x >>= 8;
- s[2] = x & 255; x >>= 8;
- s[1] = x & 255; x >>= 8;
- s[0] = x;
-}
-*/
-
-void taia_sub(struct taia *t, const struct taia *u, const struct taia *v)
-{
- unsigned long unano = u->nano;
- unsigned long uatto = u->atto;
-
- t->sec.x = u->sec.x - v->sec.x;
- t->nano = unano - v->nano;
- t->atto = uatto - v->atto;
- if (t->atto > uatto) {
- t->atto += 1000000000UL;
- --t->nano;
- }
- if (t->nano > unano) {
- t->nano += 1000000000UL;
- --t->sec.x;
- }
-}
-
-/* XXX: breaks tai encapsulation */
-void taia_uint(struct taia *t, unsigned s)
-{
- t->sec.x = s;
- t->nano = 0;
- t->atto = 0;
-}
-
-static
-uint64_t taia2millisec(const struct taia *t)
-{
- return (t->sec.x * 1000) + (t->nano / 1000000);
-}
-
-void iopause(iopause_fd *x, unsigned len, struct taia *deadline, struct taia *stamp)
-{
- int millisecs;
- int i;
-
- if (taia_less(deadline, stamp))
- millisecs = 0;
- else {
- uint64_t m;
- struct taia t;
- t = *stamp;
- taia_sub(&t, deadline, &t);
- millisecs = m = taia2millisec(&t);
- if (m > 1000) millisecs = 1000;
- millisecs += 20;
- }
-
- for (i = 0; i < len; ++i)
- x[i].revents = 0;
-
- poll(x, len, millisecs);
- /* XXX: some kernels apparently need x[0] even if len is 0 */
- /* XXX: how to handle EAGAIN? are kernels really this dumb? */
- /* XXX: how to handle EINVAL? when exactly can this happen? */
-}
-#endif
-
-int lock_ex(int fd)
-{
- return flock(fd, LOCK_EX);
-}
-
-int lock_exnb(int fd)
-{
- return flock(fd, LOCK_EX | LOCK_NB);
-}
-
-#ifdef UNUSED
-int open_append(const char *fn)
-{
- return open(fn, O_WRONLY | O_NDELAY | O_APPEND | O_CREAT, 0600);
-}
-
-int open_trunc(const char *fn)
-{
- return open(fn, O_WRONLY | O_NDELAY | O_TRUNC | O_CREAT, 0644);
-}
-#endif
-
-int open_read(const char *fn)
-{
- return open(fn, O_RDONLY|O_NDELAY);
-}
-
-int open_write(const char *fn)
-{
- return open(fn, O_WRONLY|O_NDELAY);
-}
-
-unsigned FAST_FUNC pmatch(const char *p, const char *s, unsigned len)
-{
- for (;;) {
- char c = *p++;
- if (!c) return !len;
- switch (c) {
- case '*':
- c = *p;
- if (!c) return 1;
- for (;;) {
- if (!len) return 0;
- if (*s == c) break;
- ++s;
- --len;
- }
- continue;
- case '+':
- c = *p++;
- if (c != *s) return 0;
- for (;;) {
- if (!len) return 1;
- if (*s != c) break;
- ++s;
- --len;
- }
- continue;
- /*
- case '?':
- if (*p == '?') {
- if (*s != '?') return 0;
- ++p;
- }
- ++s; --len;
- continue;
- */
- default:
- if (!len) return 0;
- if (*s != c) return 0;
- ++s;
- --len;
- continue;
- }
- }
- return 0;
-}
diff --git a/runit/runit_lib.h b/runit/runit_lib.h
index d8304ac..c36ea4c 100644
--- a/runit/runit_lib.h
+++ b/runit/runit_lib.h
@@ -27,59 +27,6 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
-//extern unsigned byte_chr(char *s,unsigned n,int c);
-//
-//struct tai {
-// uint64_t x;
-//};
-//
-//#define tai_unix(t,u) ((void) ((t)->x = 0x400000000000000aULL + (uint64_t) (u)))
-//
-//#define TAI_PACK 8
-//extern void tai_unpack(const char *,struct tai *);
-//
-//extern void tai_uint(struct tai *,unsigned);
-//
-//struct taia {
-// struct tai sec;
-// unsigned long nano; /* 0...999999999 */
-// unsigned long atto; /* 0...999999999 */
-//};
-//
-//extern void taia_now(struct taia *);
-//
-//extern void taia_add(struct taia *,const struct taia *,const struct taia *);
-//extern void taia_addsec(struct taia *,const struct taia *,int);
-//extern void taia_sub(struct taia *,const struct taia *,const struct taia *);
-//extern void taia_half(struct taia *,const struct taia *);
-//extern int taia_less(const struct taia *,const struct taia *);
-//
-//#define TAIA_PACK 16
-//extern void taia_pack(char *,const struct taia *);
-//
-//extern void taia_uint(struct taia *,unsigned);
-//
-//typedef struct pollfd iopause_fd;
-//#define IOPAUSE_READ POLLIN
-//#define IOPAUSE_WRITE POLLOUT
-//
-//extern void iopause(iopause_fd *,unsigned,struct taia *,struct taia *);
-
-extern int lock_ex(int);
-//extern int lock_un(int);
-extern int lock_exnb(int);
-
-extern int open_read(const char *);
-extern int open_write(const char *);
-//extern int open_excl(const char *);
-//extern int open_append(const char *);
-//extern int open_trunc(const char *);
-
-extern unsigned FAST_FUNC pmatch(const char *, const char *, unsigned);
-
-//#define str_diff(s,t) strcmp((s), (t))
-#define str_equal(s,t) (!strcmp((s), (t)))
-
/*
* runsv / supervise / sv stuff
*/
diff --git a/runit/runsv.c b/runit/runsv.c
index 6bb6ec8..ebb0318 100644
--- a/runit/runsv.c
+++ b/runit/runsv.c
@@ -524,7 +524,7 @@ int runsv_main(int argc UNUSED_PARAM, char **argv)
}
svd[0].fdlock = xopen3("log/supervise/lock"+4,
O_WRONLY|O_NDELAY|O_APPEND|O_CREAT, 0600);
- if (lock_exnb(svd[0].fdlock) == -1)
+ if (flock(svd[0].fdlock, LOCK_EX | LOCK_NB) == -1)
fatal_cannot("lock supervise/lock");
close_on_exec_on(svd[0].fdlock);
if (haslog) {
@@ -548,7 +548,7 @@ int runsv_main(int argc UNUSED_PARAM, char **argv)
}
svd[1].fdlock = xopen3("log/supervise/lock",
O_WRONLY|O_NDELAY|O_APPEND|O_CREAT, 0600);
- if (lock_ex(svd[1].fdlock) == -1)
+ if (flock(svd[1].fdlock, LOCK_EX) == -1)
fatal_cannot("lock log/supervise/lock");
close_on_exec_on(svd[1].fdlock);
}
@@ -618,7 +618,7 @@ int runsv_main(int argc UNUSED_PARAM, char **argv)
pidchanged = 1;
svd[0].ctrl &= ~C_TERM;
if (svd[0].state != S_FINISH) {
- fd = open_read("finish");
+ fd = open("finish", O_RDONLY|O_NDELAY);
if (fd != -1) {
close(fd);
svd[0].state = S_FINISH;
diff --git a/runit/runsvdir.c b/runit/runsvdir.c
index 71fde75..e77eeff 100644
--- a/runit/runsvdir.c
+++ b/runit/runsvdir.c
@@ -276,7 +276,7 @@ int runsvdir_main(int argc UNUSED_PARAM, char **argv)
}
run:
#endif
- curdir = open_read(".");
+ curdir = open(".", O_RDONLY|O_NDELAY);
if (curdir == -1)
fatal2_cannot("open current directory", "");
close_on_exec_on(curdir);
diff --git a/runit/sv.c b/runit/sv.c
index 3f76a2d..c420a91 100644
--- a/runit/sv.c
+++ b/runit/sv.c
@@ -176,6 +176,9 @@ struct globals {
#define INIT_G() do { } while (0)
+#define str_equal(s,t) (!strcmp((s), (t)))
+
+
static void fatal_cannot(const char *m1) NORETURN;
static void fatal_cannot(const char *m1)
{
@@ -221,7 +224,7 @@ static int svstatus_get(void)
{
int fd, r;
- fd = open_write("supervise/ok");
+ fd = open("supervise/ok", O_WRONLY|O_NDELAY);
if (fd == -1) {
if (errno == ENODEV) {
*acts == 'x' ? ok("runsv not running")
@@ -232,7 +235,7 @@ static int svstatus_get(void)
return -1;
}
close(fd);
- fd = open_read("supervise/status");
+ fd = open("supervise/status", O_RDONLY|O_NDELAY);
if (fd == -1) {
warn("can't open supervise/status");
return -1;
@@ -397,7 +400,7 @@ static int control(const char *a)
if (svstatus.want == *a)
return 0;
*/
- fd = open_write("supervise/control");
+ fd = open("supervise/control", O_WRONLY|O_NDELAY);
if (fd == -1) {
if (errno != ENODEV)
warn("can't open supervise/control");
@@ -446,7 +449,7 @@ int sv_main(int argc UNUSED_PARAM, char **argv)
tnow = time(NULL) + 0x400000000000000aULL;
tstart = tnow;
- curdir = open_read(".");
+ curdir = open(".", O_RDONLY|O_NDELAY);
if (curdir == -1)
fatal_cannot("open current directory");
diff --git a/runit/svlogd.c b/runit/svlogd.c
index 1f0a77c..052806c 100644
--- a/runit/svlogd.c
+++ b/runit/svlogd.c
@@ -261,6 +261,52 @@ static char* wstrdup(const char *str)
return s;
}
+static unsigned pmatch(const char *p, const char *s, unsigned len)
+{
+ for (;;) {
+ char c = *p++;
+ if (!c) return !len;
+ switch (c) {
+ case '*':
+ c = *p;
+ if (!c) return 1;
+ for (;;) {
+ if (!len) return 0;
+ if (*s == c) break;
+ ++s;
+ --len;
+ }
+ continue;
+ case '+':
+ c = *p++;
+ if (c != *s) return 0;
+ for (;;) {
+ if (!len) return 1;
+ if (*s != c) break;
+ ++s;
+ --len;
+ }
+ continue;
+ /*
+ case '?':
+ if (*p == '?') {
+ if (*s != '?') return 0;
+ ++p;
+ }
+ ++s; --len;
+ continue;
+ */
+ default:
+ if (!len) return 0;
+ if (*s != c) return 0;
+ ++s;
+ --len;
+ continue;
+ }
+ }
+ return 0;
+}
+
/*** ex fmt_ptime.[ch] ***/
/* NUL terminated */
@@ -342,7 +388,7 @@ static void processorstart(struct logdir *ld)
ld->fnsave[26] = 't'; /* <- that's why we need sv_ch! */
fd = xopen(ld->fnsave, O_WRONLY|O_NDELAY|O_TRUNC|O_CREAT);
xmove_fd(fd, 1);
- fd = open_read("state");
+ fd = open("state", O_RDONLY|O_NDELAY);
if (fd == -1) {
if (errno != ENOENT)
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)
}
ld->fdlock = open("lock", O_WRONLY|O_NDELAY|O_APPEND|O_CREAT, 0600);
if ((ld->fdlock == -1)
- || (lock_exnb(ld->fdlock) == -1)
+ || (flock(ld->fdlock, LOCK_EX | LOCK_NB) == -1)
) {
logdir_close(ld);
warn2("can't lock directory", (char*)fn);