--- a/include/applets.src.h
+++ b/include/applets.src.h
-@@ -212,6 +212,7 @@ IF_LN(APPLET_NOEXEC(ln, ln, BB_DIR_BIN,
+@@ -211,6 +211,7 @@ IF_LN(APPLET_NOEXEC(ln, ln, BB_DIR_BIN,
IF_LOAD_POLICY(APPLET(load_policy, BB_DIR_USR_SBIN, BB_SUID_DROP))
IF_LOADFONT(APPLET(loadfont, BB_DIR_USR_SBIN, BB_SUID_DROP))
IF_LOADKMAP(APPLET(loadkmap, BB_DIR_SBIN, BB_SUID_DROP))
IF_LOGIN(APPLET(login, BB_DIR_BIN, BB_SUID_REQUIRE))
--- a/miscutils/Config.src
+++ b/miscutils/Config.src
-@@ -419,6 +419,12 @@ config FEATURE_HDPARM_HDIO_GETSET_DMA
+@@ -385,6 +385,12 @@ config FEATURE_HDPARM_HDIO_GETSET_DMA
help
Enables the 'hdparm -d' option to get/set using_dma flag.
default y
--- a/miscutils/Kbuild.src
+++ b/miscutils/Kbuild.src
-@@ -29,6 +29,7 @@ lib-$(CONFIG_INOTIFYD) += inotifyd.o
+@@ -28,6 +28,7 @@ lib-$(CONFIG_INOTIFYD) += inotifyd.o
lib-$(CONFIG_FEATURE_LAST_SMALL)+= last.o
lib-$(CONFIG_FEATURE_LAST_FANCY)+= last_fancy.o
lib-$(CONFIG_LESS) += less.o
lib-$(CONFIG_MICROCOM) += microcom.o
--- /dev/null
+++ b/miscutils/lock.c
-@@ -0,0 +1,135 @@
+@@ -0,0 +1,144 @@
+/*
-+ * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
++ * Copyright (C) 2006 Felix Fietkau <nbd@nbd.name>
+ *
+ * This is free software, licensed under the GNU General Public License v2.
+ */
+static int unlock = 0;
+static int shared = 0;
+static int waitonly = 0;
++static int try_lock = 0;
+static int fd;
+static char *file;
+
+ " -s Use shared locking\n"
+ " -u Unlock\n"
+ " -w Wait for the lock to become free, don't acquire lock\n"
++ " -n Don't wait for the lock to become free. Fail with exit code\n"
+ "\n", name);
+ exit(1);
+}
+static int do_lock(void)
+{
+ int pid;
++ int flags;
+ char pidstr[8];
+
+ if ((fd = open(file, O_RDWR | O_CREAT | O_EXCL, 0700)) < 0) {
+ }
+ }
+
-+ if (flock(fd, (shared ? LOCK_SH : LOCK_EX)) < 0) {
++ flags = shared ? LOCK_SH : LOCK_EX;
++ flags |= try_lock ? LOCK_NB : 0;
++
++ if (flock(fd, flags) < 0) {
+ fprintf(stderr, "Can't lock %s\n", file);
+ return 1;
+ }
+ case 'u':
+ unlock = 1;
+ break;
++ case 'n':
++ try_lock = 1;
++ break;
+ }
+ }
+ c--;