1 diff -urN busybox.old/include/applets.h busybox.dev/include/applets.h
2 --- busybox.old/include/applets.h 2006-03-14 09:46:09.000000000 +0100
3 +++ busybox.dev/include/applets.h 2006-03-14 09:49:17.000000000 +0100
6 APPLET(loadkmap, loadkmap_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
9 + APPLET_NOUSAGE("lock", lock_main, _BB_DIR_BIN, _BB_SUID_NEVER)
12 APPLET(logger, logger_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
14 diff -urN busybox.old/miscutils/Config.in busybox.dev/miscutils/Config.in
15 --- busybox.old/miscutils/Config.in 2004-08-27 01:12:59.000000000 +0200
16 +++ busybox.dev/miscutils/Config.in 2006-03-14 09:52:13.000000000 +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
27 config CONFIG_MAKEDEVS
30 diff -urN busybox.old/miscutils/Makefile.in busybox.dev/miscutils/Makefile.in
31 --- busybox.old/miscutils/Makefile.in 2004-10-08 09:45:39.000000000 +0200
32 +++ busybox.dev/miscutils/Makefile.in 2006-03-14 09:52:41.000000000 +0100
34 MISCUTILS-$(CONFIG_DEVFSD) += devfsd.o
35 MISCUTILS-$(CONFIG_HDPARM) += hdparm.o
36 MISCUTILS-$(CONFIG_LAST) += last.o
37 +MISCUTILS-$(CONFIG_LOCK) += lock.o
38 MISCUTILS-$(CONFIG_MAKEDEVS) += makedevs.o
39 MISCUTILS-$(CONFIG_MT) += mt.o
40 MISCUTILS-$(CONFIG_RX) += rx.o
41 diff -urN busybox.old/miscutils/lock.c busybox.dev/miscutils/lock.c
42 --- busybox.old/miscutils/lock.c 1970-01-01 01:00:00.000000000 +0100
43 +++ busybox.dev/miscutils/lock.c 2006-03-14 09:50:40.000000000 +0100
45 +#include <sys/types.h>
46 +#include <sys/file.h>
47 +#include <sys/stat.h>
54 +static int unlock = 0;
55 +static int shared = 0;
56 +static int waitonly = 0;
60 +static void usage(char *name)
62 + fprintf(stderr, "Usage: %s [-suw] <filename>\n"
63 + " -s Use shared locking\n"
65 + " -w Wait for the lock to become free, don't acquire lock\n"
70 +static void exit_unlock(int sig)
77 +static int do_unlock(void)
82 + if ((f = fopen(file, "r")) == NULL)
85 + fscanf(f, "%d", &i);
94 +static int do_lock(void)
99 + if ((fd = open(file, O_RDWR | O_CREAT | O_EXCL, 0700)) < 0) {
100 + if ((fd = open(file, O_RDWR)) < 0) {
101 + fprintf(stderr, "Can't open %s\n", file);
106 + if (flock(fd, (shared ? LOCK_SH : LOCK_EX)) < 0) {
107 + fprintf(stderr, "Can't lock %s\n", file);
117 + signal(SIGKILL, exit_unlock);
118 + signal(SIGTERM, exit_unlock);
119 + signal(SIGINT, exit_unlock);
127 + lseek(fd, 0, SEEK_SET);
129 + sprintf(pidstr, "%d\n", pid);
130 + write(fd, pidstr, strlen(pidstr));
139 +int main(int argc, char **argv)
141 +int lock_main(int argc, char **argv)
144 + char **args = &argv[1];
147 + while ((*args != NULL) && (*args)[0] == '-') {
149 + while (*(++ch) > 0) {
171 + return do_unlock();