summaryrefslogtreecommitdiff
path: root/src/collect
diff options
context:
space:
mode:
Diffstat (limited to 'src/collect')
-rw-r--r--src/collect/collect.c33
1 files changed, 12 insertions, 21 deletions
diff --git a/src/collect/collect.c b/src/collect/collect.c
index 05d6517a54..323d56a82d 100644
--- a/src/collect/collect.c
+++ b/src/collect/collect.c
@@ -87,8 +87,6 @@ static void usage(void)
* prepare
*
* Prepares the database file
- * returns file descriptor on success
- * returns errno on failure
*/
static int prepare(char *dir, char *filename)
{
@@ -102,22 +100,21 @@ static int prepare(char *dir, char *filename)
snprintf(buf, sizeof(buf), "%s/%s", dir, filename);
fd = open(buf,O_RDWR|O_CREAT|O_CLOEXEC, S_IRUSR|S_IWUSR);
- if (fd < 0) {
+ if (fd < 0)
fprintf(stderr, "Cannot open %s: %m\n", buf);
- return errno;
- }
+
if (lockf(fd,F_TLOCK,0) < 0) {
if (debug)
- fprintf(stderr, "Lock aquisition failed, retry in %d seconds\n"
- , UDEV_ALARM_TIMEOUT);
- alarm(UDEV_ALARM_TIMEOUT);
- if(lockf(fd, F_LOCK, 0)<0){
+ fprintf(stderr, "Lock taken, wait for %d seconds\n", UDEV_ALARM_TIMEOUT);
+ if (errno == EAGAIN || errno == EACCES) {
+ alarm(UDEV_ALARM_TIMEOUT);
+ lockf(fd, F_LOCK, 0);
+ if (debug)
+ fprintf(stderr, "Acquired lock on %s\n", buf);
+ } else {
if (debug)
fprintf(stderr, "Could not get lock on %s: %m\n", buf);
- return errno;
- }
- if (debug)
- fprintf(stderr, "Acquired lock on %s\n", buf);
+ }
}
return fd;
@@ -483,16 +480,10 @@ int main(int argc, char **argv)
kickout();
lseek(fd, 0, SEEK_SET);
- if(ftruncate(fd, 0)!=0) {
- ret = errno;
- goto out;
- }
+ ftruncate(fd, 0);
ret = missing(fd);
- if(lockf(fd, F_ULOCK, 0) !=0 ) {
- ret = errno;
- goto out;
- }
+ lockf(fd, F_ULOCK, 0);
close(fd);
out:
if (debug)