1 Index: busybox-1.8.1/include/applets.h
2 ===================================================================
3 --- busybox-1.8.1.orig/include/applets.h 2007-11-10 16:54:28.318054115 +0100
4 +++ busybox-1.8.1/include/applets.h 2007-11-10 17:39:21.487529096 +0100
6 USE_LOAD_POLICY(APPLET(load_policy, _BB_DIR_USR_SBIN, _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_NOFORK(logname, logname, _BB_DIR_USR_BIN, _BB_SUID_NEVER, logname))
13 Index: busybox-1.8.1/miscutils/Config.in
14 ===================================================================
15 --- busybox-1.8.1.orig/miscutils/Config.in 2007-11-10 16:54:16.477379354 +0100
16 +++ busybox-1.8.1/miscutils/Config.in 2007-11-10 16:54:28.366056851 +0100
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.8.1/miscutils/Kbuild
31 ===================================================================
32 --- busybox-1.8.1.orig/miscutils/Kbuild 2007-11-10 16:54:16.481379580 +0100
33 +++ busybox-1.8.1/miscutils/Kbuild 2007-11-10 16:54:28.370057076 +0100
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_MICROCOM) += microcom.o
41 lib-$(CONFIG_MOUNTPOINT) += mountpoint.o
42 Index: busybox-1.8.1/miscutils/lock.c
43 ===================================================================
44 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
45 +++ busybox-1.8.1/miscutils/lock.c 2007-11-10 17:40:37.203843924 +0100
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));
145 +int lock_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
146 +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();