Browse Source

reduce the possibility of race conditions when using the lock utility

SVN-Revision: 5297
Felix Fietkau 19 years ago
parent
commit
3d497ab62c
1 changed files with 6 additions and 4 deletions
  1. 6 4
      package/busybox/patches/340-lock_util.patch

+ 6 - 4
package/busybox/patches/340-lock_util.patch

@@ -33,7 +33,7 @@ diff -ruN busybox-1.2.0-old/miscutils/Config.in busybox-1.2.0-new/miscutils/Conf
 diff -ruN busybox-1.2.0-old/miscutils/lock.c busybox-1.2.0-new/miscutils/lock.c
 diff -ruN busybox-1.2.0-old/miscutils/lock.c busybox-1.2.0-new/miscutils/lock.c
 --- busybox-1.2.0-old/miscutils/lock.c	1970-01-01 01:00:00.000000000 +0100
 --- busybox-1.2.0-old/miscutils/lock.c	1970-01-01 01:00:00.000000000 +0100
 +++ busybox-1.2.0-new/miscutils/lock.c	2006-08-01 10:21:15.000000000 +0200
 +++ busybox-1.2.0-new/miscutils/lock.c	2006-08-01 10:21:15.000000000 +0200
-@@ -0,0 +1,133 @@
+@@ -0,0 +1,135 @@
 +/*
 +/*
 + * Copyright (C) 2006 Felix Fietkau <[email protected]>
 + * Copyright (C) 2006 Felix Fietkau <[email protected]>
 + *
 + *
@@ -93,9 +93,11 @@ diff -ruN busybox-1.2.0-old/miscutils/lock.c busybox-1.2.0-new/miscutils/lock.c
 +	int pid;
 +	int pid;
 +	char pidstr[8];
 +	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) {
 +	if (flock(fd, (shared ? LOCK_SH : LOCK_EX)) < 0) {