1 diff -ruN busybox-1.3.1-old/include/applets.h busybox-1.3.1/include/applets.h
2 --- busybox-1.3.1-old/include/applets.h 2006-12-28 07:43:24.000000000 +0100
3 +++ busybox-1.3.1/include/applets.h 2006-12-28 03:11:36.000000000 +0100
5 USE_LN(APPLET(ln, _BB_DIR_BIN, _BB_SUID_NEVER))
6 USE_LOADFONT(APPLET(loadfont, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
7 USE_LOADKMAP(APPLET(loadkmap, _BB_DIR_SBIN, _BB_SUID_NEVER))
8 +USE_LOCK(APPLET_NOUSAGE(lock, lock, _BB_DIR_BIN, _BB_SUID_NEVER))
9 USE_LOGGER(APPLET(logger, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
10 USE_LOGIN(APPLET(login, _BB_DIR_BIN, _BB_SUID_ALWAYS))
11 USE_LOGNAME(APPLET(logname, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
12 diff -ruN busybox-1.3.1-old/miscutils/Config.in busybox-1.3.1/miscutils/Config.in
13 --- busybox-1.3.1-old/miscutils/Config.in 2006-12-27 05:56:09.000000000 +0100
14 +++ busybox-1.3.1/miscutils/Config.in 2006-12-28 03:14:16.000000000 +0100
16 Enables the 'hdparm -d' option to get/set using_dma flag.
17 This is dangerous stuff, so you should probably say N.
23 + Small utility for using locks in scripts
28 diff -ruN busybox-1.3.1-old/miscutils/Kbuild busybox-1.3.1/miscutils/Kbuild
29 --- busybox-1.3.1-old/miscutils/Kbuild 2006-12-27 05:56:09.000000000 +0100
30 +++ busybox-1.3.1/miscutils/Kbuild 2006-12-28 03:15:47.000000000 +0100
32 lib-$(CONFIG_HDPARM) += hdparm.o
33 lib-$(CONFIG_LAST) += last.o
34 lib-$(CONFIG_LESS) += less.o
35 +lib-$(CONFIG_LOCK) += lock.o
36 lib-$(CONFIG_MAKEDEVS) += makedevs.o
37 lib-$(CONFIG_MOUNTPOINT) += mountpoint.o
38 lib-$(CONFIG_MT) += mt.o
39 diff -ruN busybox-1.3.1-old/miscutils/lock.c busybox-1.3.1/miscutils/lock.c
40 --- busybox-1.3.1-old/miscutils/lock.c 1970-01-01 01:00:00.000000000 +0100
41 +++ busybox-1.3.1/miscutils/lock.c 2006-12-28 03:11:36.000000000 +0100
44 + * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
46 + * This is free software, licensed under the GNU General Public License v2.
48 +#include <sys/types.h>
49 +#include <sys/file.h>
50 +#include <sys/stat.h>
57 +static int unlock = 0;
58 +static int shared = 0;
59 +static int waitonly = 0;
63 +static void usage(char *name)
65 + fprintf(stderr, "Usage: %s [-suw] <filename>\n"
66 + " -s Use shared locking\n"
68 + " -w Wait for the lock to become free, don't acquire lock\n"
73 +static void exit_unlock(int sig)
80 +static int do_unlock(void)
85 + if ((f = fopen(file, "r")) == NULL)
88 + fscanf(f, "%d", &i);
97 +static int do_lock(void)
102 + if ((fd = open(file, O_RDWR | O_CREAT | O_EXCL, 0700)) < 0) {
103 + if ((fd = open(file, O_RDWR)) < 0) {
104 + fprintf(stderr, "Can't open %s\n", file);
109 + if (flock(fd, (shared ? LOCK_SH : LOCK_EX)) < 0) {
110 + fprintf(stderr, "Can't lock %s\n", file);
120 + signal(SIGKILL, exit_unlock);
121 + signal(SIGTERM, exit_unlock);
122 + signal(SIGINT, exit_unlock);
130 + lseek(fd, 0, SEEK_SET);
132 + sprintf(pidstr, "%d\n", pid);
133 + write(fd, pidstr, strlen(pidstr));
143 +int main(int argc, char **argv)
145 +int lock_main(int argc, char **argv)
148 + char **args = &argv[1];
151 + while ((*args != NULL) && (*args)[0] == '-') {
153 + while (*(++ch) > 0) {
175 + return do_unlock();