index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
author | Allan McRae <allan@archlinux.org> | 2008-11-02 13:47:04 +1000 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2009-01-03 00:00:19 -0600 |
commit | b55f478042053dfb749da7ce0a48fc0e49112093 (patch) | |
tree | 984eb7e783645b9414ce5d5acda7657ab7f45581 | |
parent | e49adbea4c67b2fd49910697229682e0a85fe9b2 (diff) |
-rw-r--r-- | lib/libalpm/util.c | 15 |
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index da3463b0..4d682552 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -242,7 +242,8 @@ char *_alpm_strreplace(const char *str, const char *needle, const char *replace) int _alpm_lckmk() { int fd; - char *dir, *ptr; + pid_t pid; + char *dir, *ptr, *spid = NULL; const char *file = alpm_option_get_lockfile(); /* create the dir of the lockfile first */ @@ -256,7 +257,17 @@ int _alpm_lckmk() while((fd = open(file, O_WRONLY | O_CREAT | O_EXCL, 0000)) == -1 && errno == EINTR); - return(fd > 0 ? fd : -1); + if(fd > 0) { + pid = getpid(); + size_t len = snprintf(spid, 0, "%ld\n", (long)pid) + 1; + spid = malloc(len); + snprintf(spid, len, "%ld\n", (long)pid); + while(write(fd, (void *)spid, len) == -1 && errno == EINTR); + fsync(fd); + free(spid); + return(fd); + } + return(-1); } /* Remove a lock file */ |