mirror of
https://github.com/moparisthebest/pacman
synced 2024-11-13 12:55:08 -05:00
libalpm: clean up lock function
We were doing a lot of manual work; leverage the standard library a bit to do more for us. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
6e312220ec
commit
4828d9ef7c
@ -200,8 +200,7 @@ char *_alpm_strtrim(char *str)
|
|||||||
int _alpm_lckmk()
|
int _alpm_lckmk()
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
pid_t pid;
|
char *dir, *ptr;
|
||||||
char *dir, *ptr, *spid = NULL;
|
|
||||||
const char *file = alpm_option_get_lockfile();
|
const char *file = alpm_option_get_lockfile();
|
||||||
|
|
||||||
/* create the dir of the lockfile first */
|
/* create the dir of the lockfile first */
|
||||||
@ -216,13 +215,11 @@ int _alpm_lckmk()
|
|||||||
while((fd = open(file, O_WRONLY | O_CREAT | O_EXCL, 0000)) == -1
|
while((fd = open(file, O_WRONLY | O_CREAT | O_EXCL, 0000)) == -1
|
||||||
&& errno == EINTR);
|
&& errno == EINTR);
|
||||||
if(fd > 0) {
|
if(fd > 0) {
|
||||||
pid = getpid();
|
FILE *f = fdopen(fd, "w");
|
||||||
size_t len = snprintf(spid, 0, "%ld\n", (long)pid) + 1;
|
fprintf(f, "%ld\n", (long)getpid());
|
||||||
spid = malloc(len);
|
fflush(f);
|
||||||
snprintf(spid, len, "%ld\n", (long)pid);
|
|
||||||
while(write(fd, (void *)spid, len) == -1 && errno == EINTR);
|
|
||||||
fsync(fd);
|
fsync(fd);
|
||||||
free(spid);
|
fclose(f);
|
||||||
return(fd);
|
return(fd);
|
||||||
}
|
}
|
||||||
return(-1);
|
return(-1);
|
||||||
|
Loading…
Reference in New Issue
Block a user