2 Copyright (C) 2006 OpenWrt.org
4 diff -urN busybox.old/include/applets.h busybox.dev/include/applets.h
5 --- busybox.old/include/applets.h 2006-04-05 01:06:29.000000000 +0200
6 +++ busybox.dev/include/applets.h 2006-04-05 01:19:09.000000000 +0200
8 USE_LN(APPLET(ln, ln_main, _BB_DIR_BIN, _BB_SUID_NEVER))
9 USE_LOADFONT(APPLET(loadfont, loadfont_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
10 USE_LOADKMAP(APPLET(loadkmap, loadkmap_main, _BB_DIR_SBIN, _BB_SUID_NEVER))
11 +USE_LOCK(APPLET_NOUSAGE(lock, lock_main, _BB_DIR_BIN, _BB_SUID_NEVER))
12 USE_LOGGER(APPLET(logger, logger_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
13 USE_LOGIN(APPLET(login, login_main, _BB_DIR_BIN, _BB_SUID_ALWAYS))
14 USE_LOGNAME(APPLET(logname, logname_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
15 diff -urN busybox.old/miscutils/Config.in busybox.dev/miscutils/Config.in
16 --- busybox.old/miscutils/Config.in 2006-03-22 22:16:24.000000000 +0100
17 +++ busybox.dev/miscutils/Config.in 2006-04-05 01:07:12.000000000 +0200
19 Enables the 'hdparm -d' option to get/set using_dma flag.
20 This is dangerous stuff, so you should probably say N.
26 + Small utility for using locks in scripts
28 config CONFIG_MAKEDEVS
31 diff -urN busybox.old/miscutils/Makefile.in busybox.dev/miscutils/Makefile.in
32 --- busybox.old/miscutils/Makefile.in 2006-03-22 22:16:24.000000000 +0100
33 +++ busybox.dev/miscutils/Makefile.in 2006-04-05 01:10:50.000000000 +0200
35 MISCUTILS-$(CONFIG_EJECT) += eject.o
36 MISCUTILS-$(CONFIG_HDPARM) += hdparm.o
37 MISCUTILS-$(CONFIG_LAST) += last.o
38 +MISCUTILS-$(CONFIG_LOCK) += lock.o
39 MISCUTILS-${CONFIG_LESS} += less.o
40 MISCUTILS-$(CONFIG_MAKEDEVS) += makedevs.o
41 MISCUTILS-$(CONFIG_MOUNTPOINT) += mountpoint.o
42 diff -urN busybox.old/miscutils/lock.c busybox.dev/miscutils/lock.c
43 --- busybox.old/miscutils/lock.c 1970-01-01 01:00:00.000000000 +0100
44 +++ busybox.dev/miscutils/lock.c 2006-04-05 01:07:12.000000000 +0200
47 + * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
49 + * This is free software, licensed under the GNU General Public License v2.
51 +#include <sys/types.h>
52 +#include <sys/file.h>
53 +#include <sys/stat.h>
60 +static int unlock = 0;
61 +static int shared = 0;
62 +static int waitonly = 0;
66 +static void usage(char *name)
68 + fprintf(stderr, "Usage: %s [-suw] <filename>\n"
69 + " -s Use shared locking\n"
71 + " -w Wait for the lock to become free, don't acquire lock\n"
76 +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, 0700)) < 0) {
106 + fprintf(stderr, "Can't open %s\n", file);
110 + if (flock(fd, (shared ? LOCK_SH : LOCK_EX)) < 0) {
111 + fprintf(stderr, "Can't lock %s\n", file);
121 + signal(SIGKILL, exit_unlock);
122 + signal(SIGTERM, exit_unlock);
123 + signal(SIGINT, exit_unlock);
131 + lseek(fd, 0, SEEK_SET);
133 + sprintf(pidstr, "%d\n", pid);
134 + 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();