From ea364affc8ce6866334365866cae859dc27b01e9 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Wed, 15 Apr 2015 21:02:38 +0200 Subject: [PATCH] libxbps: open fds with O_CLOEXEC to avoid warnings of leaked fds. --- lib/pkgdb.c | 2 +- lib/repo.c | 4 ++-- lib/util_hash.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/pkgdb.c b/lib/pkgdb.c index 091f6b45..92ff1325 100644 --- a/lib/pkgdb.c +++ b/lib/pkgdb.c @@ -89,7 +89,7 @@ xbps_pkgdb_lock(struct xbps_handle *xhp) return rv; } } - if ((pkgdb_fd = open(xhp->pkgdb_plist, O_CREAT|O_RDWR, 0664)) == -1) { + if ((pkgdb_fd = open(xhp->pkgdb_plist, O_CREAT|O_RDWR|O_CLOEXEC, 0664)) == -1) { rv = errno; xbps_dbg_printf(xhp, "[pkgdb] cannot open pkgdb for locking " "%s: %s\n", xhp->pkgdb_plist, strerror(rv)); diff --git a/lib/repo.c b/lib/repo.c index 45644b93..89cd8e87 100644 --- a/lib/repo.c +++ b/lib/repo.c @@ -91,7 +91,7 @@ xbps_repo_lock(struct xbps_handle *xhp, const char *repodir, free(repofile); for (;;) { - fd = open(lockfile, O_WRONLY|O_CREAT|O_EXCL, 0660); + fd = open(lockfile, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0660); rv = errno; if (fd != -1) break; @@ -265,7 +265,7 @@ xbps_repo_open(struct xbps_handle *xhp, const char *url) /* * Open the repository archive. */ - repo->fd = open(repofile, O_RDONLY); + repo->fd = open(repofile, O_RDONLY|O_CLOEXEC); if (repo->fd == -1) { int rv = errno; xbps_dbg_printf(xhp, "[repo] `%s' open repodata %s\n", diff --git a/lib/util_hash.c b/lib/util_hash.c index 80acd94f..0c03c3c0 100644 --- a/lib/util_hash.c +++ b/lib/util_hash.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2008-2014 Juan Romero Pardines. + * Copyright (c) 2008-2015 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -69,7 +69,7 @@ xbps_mmap_file(const char *file, void **mmf, size_t *mmflen, size_t *filelen) assert(file); - if ((fd = open(file, O_RDONLY)) == -1) + if ((fd = open(file, O_RDONLY|O_CLOEXEC)) == -1) return false; if (fstat(fd, &st) == -1) {