summaryrefslogtreecommitdiffstats
path: root/lib/libalpm
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2009-10-11 21:15:27 +0200
committerDan McGee <dan@archlinux.org>2009-10-11 21:42:04 +0200
commit4828d9ef7c7dc04eb4ad909f9204e909fbaae48f (patch)
tree702e5081b1b75ba1d2ad8080159fe60e167f55c6 /lib/libalpm
parent6e312220ec6668d6fc9ef37dbf581ca155511697 (diff)
downloadpacman-4828d9ef7c7dc04eb4ad909f9204e909fbaae48f.tar.gz
pacman-4828d9ef7c7dc04eb4ad909f9204e909fbaae48f.tar.xz
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>
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/util.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index f608a2c6..c5485925 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -200,8 +200,7 @@ char *_alpm_strtrim(char *str)
int _alpm_lckmk()
{
int fd;
- pid_t pid;
- char *dir, *ptr, *spid = NULL;
+ char *dir, *ptr;
const char *file = alpm_option_get_lockfile();
/* 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
&& errno == EINTR);
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);
+ FILE *f = fdopen(fd, "w");
+ fprintf(f, "%ld\n", (long)getpid());
+ fflush(f);
fsync(fd);
- free(spid);
+ fclose(f);
return(fd);
}
return(-1);