mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-22 15:58:50 -05:00
libalpm: add PID to db.lck
This is the first step in being able to automatically remove phantom lock files. Signed-off-by: Allan McRae <allan@archlinux.org> [Dan: fix compilation warnings] Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
e49adbea4c
commit
b55f478042
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user