From: Michael Schroeder Date: Tue, 2 Apr 2019 11:34:30 +0000 (+0200) Subject: Add solv_cloexec() function X-Git-Tag: 0.7.5~53 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e714b3a5e814c00f378a85b192134d4bb802ee92;p=thirdparty%2Flibsolv.git Add solv_cloexec() function Windows needs a different implementation, and with that solv_cloexec we need to patch just one place in the code. --- diff --git a/bindings/solv.i b/bindings/solv.i index ad265a58..0289adb5 100644 --- a/bindings/solv.i +++ b/bindings/solv.i @@ -1121,7 +1121,7 @@ SolvFp *solvfp_xfopen_fd(const char *fn, int fd, const char *mode = 0); fd = dup(fd); if (fd == -1) return 0; - fcntl(fd, F_SETFD, FD_CLOEXEC); + solv_setcloexec(fd, 1); fp = solv_xfopen_fd(fn, fd, mode); if (!fp) { close(fd); @@ -1138,7 +1138,7 @@ SolvFp *solvfp_xfopen_fd(const char *fn, int fd, const char *mode = 0); if (!fp) return 0; if (fileno(fp) != -1) - fcntl(fileno(fp), F_SETFD, FD_CLOEXEC); + solv_setcloexec(fileno(fp), 1); sfp = solv_calloc(1, sizeof(SolvFp)); sfp->fp = fp; return sfp; @@ -1220,7 +1220,7 @@ typedef struct { void cloexec(bool state) { if (!$self->fp || fileno($self->fp) == -1) return; - fcntl(fileno($self->fp), F_SETFD, state ? FD_CLOEXEC : 0); + solv_setcloexec(fileno($self->fp), state); } } diff --git a/src/libsolv.ver b/src/libsolv.ver index f0e86fff..58bc957e 100644 --- a/src/libsolv.ver +++ b/src/libsolv.ver @@ -291,6 +291,7 @@ SOLV_1.0 { solv_realloc; solv_realloc2; solv_replacebadutf8; + solv_setcloexec; solv_sort; solv_strdup; solv_timems; diff --git a/src/repopage.c b/src/repopage.c index 85d53eb9..33d148da 100644 --- a/src/repopage.c +++ b/src/repopage.c @@ -785,7 +785,7 @@ repopagestore_read_or_setup_pages(Repopagestore *store, FILE *fp, unsigned int p if (store->pagefd == -1) can_seek = 0; else - fcntl(store->pagefd, F_SETFD, FD_CLOEXEC); + solv_setcloexec(store->pagefd, 1); #ifdef DEBUG_PAGING fprintf(stderr, "can %sseek\n", can_seek ? "" : "NOT "); diff --git a/src/util.c b/src/util.c index 65c86294..ea013849 100644 --- a/src/util.c +++ b/src/util.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include "util.h" @@ -134,6 +135,12 @@ solv_timems(unsigned int subtract) return r - subtract; } +int +solv_setcloexec(int fd, int state) +{ + return fcntl(fd, F_SETFD, state ? FD_CLOEXEC : 0) == 0; +} + /* bsd's qsort_r has different arguments, so we define our own version in case we need to do some clever mapping diff --git a/src/util.h b/src/util.h index 5f7a93ab..1dc5f326 100644 --- a/src/util.h +++ b/src/util.h @@ -34,6 +34,7 @@ extern void *solv_free(void *); extern char *solv_strdup(const char *); extern void solv_oom(size_t, size_t); extern unsigned int solv_timems(unsigned int subtract); +extern int solv_setcloexec(int fd, int state); extern void solv_sort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *compard); extern char *solv_dupjoin(const char *str1, const char *str2, const char *str3); extern char *solv_dupappend(const char *str1, const char *str2, const char *str3);