reduce the possibility of race conditions when using the lock utility
authorFelix Fietkau <nbd@openwrt.org>
Thu, 26 Oct 2006 01:32:49 +0000 (01:32 +0000)
committerFelix Fietkau <nbd@openwrt.org>
Thu, 26 Oct 2006 01:32:49 +0000 (01:32 +0000)
SVN-Revision: 5297

openwrt/package/busybox/patches/340-lock_util.patch

index 9e2075da1761bfb0c76f06245f28b26d2c18e9f9..c9c3753937528e44ac37811d5f9e4c110693badc 100644 (file)
@@ -41,7 +41,7 @@ diff -urN busybox.old/miscutils/Makefile.in busybox.dev/miscutils/Makefile.in
 diff -urN busybox.old/miscutils/lock.c busybox.dev/miscutils/lock.c
 --- busybox.old/miscutils/lock.c       1970-01-01 01:00:00.000000000 +0100
 +++ busybox.dev/miscutils/lock.c       2006-03-14 09:50:40.000000000 +0100
-@@ -0,0 +1,128 @@
+@@ -0,0 +1,130 @@
 +#include <sys/types.h>
 +#include <sys/file.h>
 +#include <sys/stat.h>
@@ -96,9 +96,11 @@ diff -urN busybox.old/miscutils/lock.c busybox.dev/miscutils/lock.c
 +      int pid;
 +      char pidstr[8];
 +
-+      if ((fd = open(file, O_RDWR | O_CREAT, 0700)) < 0) {
-+              fprintf(stderr, "Can't open %s\n", file);
-+              return 1;
++      if ((fd = open(file, O_RDWR | O_CREAT | O_EXCL, 0700)) < 0) {
++              if ((fd = open(file, O_RDWR)) < 0) {
++                      fprintf(stderr, "Can't open %s\n", file);
++                      return 1;
++              }
 +      }
 +
 +      if (flock(fd, (shared ? LOCK_SH : LOCK_EX)) < 0) {