1 Index: busybox-1.4.2/include/applets.h
2 ===================================================================
3 --- busybox-1.4.2.orig/include/applets.h 2007-06-04 13:21:34.188779184 +0200
4 +++ busybox-1.4.2/include/applets.h 2007-06-04 13:21:34.786688288 +0200
6 USE_LN(APPLET(ln, _BB_DIR_BIN, _BB_SUID_NEVER))
7 USE_LOADFONT(APPLET(loadfont, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
8 USE_LOADKMAP(APPLET(loadkmap, _BB_DIR_SBIN, _BB_SUID_NEVER))
9 +USE_LOCK(APPLET_NOUSAGE(lock, lock, _BB_DIR_BIN, _BB_SUID_NEVER))
10 USE_LOGGER(APPLET(logger, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
11 USE_LOGIN(APPLET(login, _BB_DIR_BIN, _BB_SUID_ALWAYS))
12 USE_LOGNAME(APPLET(logname, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
13 Index: busybox-1.4.2/miscutils/Config.in
14 ===================================================================
15 --- busybox-1.4.2.orig/miscutils/Config.in 2007-06-04 13:21:32.136091240 +0200
16 +++ busybox-1.4.2/miscutils/Config.in 2007-06-04 13:21:34.786688288 +0200
18 Enables the 'hdparm -d' option to get/set using_dma flag.
19 This is dangerous stuff, so you should probably say N.
25 + Small utility for using locks in scripts
30 Index: busybox-1.4.2/miscutils/Kbuild
31 ===================================================================
32 --- busybox-1.4.2.orig/miscutils/Kbuild 2007-06-04 13:21:32.142090328 +0200
33 +++ busybox-1.4.2/miscutils/Kbuild 2007-06-04 13:21:34.786688288 +0200
35 lib-$(CONFIG_HDPARM) += hdparm.o
36 lib-$(CONFIG_LAST) += last.o
37 lib-$(CONFIG_LESS) += less.o
38 +lib-$(CONFIG_LOCK) += lock.o
39 lib-$(CONFIG_MAKEDEVS) += makedevs.o
40 lib-$(CONFIG_MOUNTPOINT) += mountpoint.o
41 lib-$(CONFIG_MT) += mt.o
42 Index: busybox-1.4.2/miscutils/lock.c
43 ===================================================================
44 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
45 +++ busybox-1.4.2/miscutils/lock.c 2007-06-04 13:21:34.787688136 +0200
48 + * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
50 + * This is free software, licensed under the GNU General Public License v2.
52 +#include <sys/types.h>
53 +#include <sys/file.h>
54 +#include <sys/stat.h>
61 +static int unlock = 0;
62 +static int shared = 0;
63 +static int waitonly = 0;
67 +static void usage(char *name)
69 + fprintf(stderr, "Usage: %s [-suw] <filename>\n"
70 + " -s Use shared locking\n"
72 + " -w Wait for the lock to become free, don't acquire lock\n"
77 +static void exit_unlock(int sig)
83 +static int do_unlock(void)
88 + if ((f = fopen(file, "r")) == NULL)
91 + fscanf(f, "%d", &i);
100 +static int do_lock(void)
105 + if ((fd = open(file, O_RDWR | O_CREAT | O_EXCL, 0700)) < 0) {
106 + if ((fd = open(file, O_RDWR)) < 0) {
107 + fprintf(stderr, "Can't open %s\n", file);
112 + if (flock(fd, (shared ? LOCK_SH : LOCK_EX)) < 0) {
113 + fprintf(stderr, "Can't lock %s\n", file);
123 + signal(SIGKILL, exit_unlock);
124 + signal(SIGTERM, exit_unlock);
125 + signal(SIGINT, exit_unlock);
133 + lseek(fd, 0, SEEK_SET);
135 + sprintf(pidstr, "%d\n", pid);
136 + write(fd, pidstr, strlen(pidstr));
146 +int main(int argc, char **argv)
148 +int lock_main(int argc, char **argv)
151 + char **args = &argv[1];
154 + while ((*args != NULL) && (*args)[0] == '-') {
156 + while (*(++ch) > 0) {
178 + return do_unlock();