]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
Add solv_cloexec() function
authorMichael Schroeder <mls@suse.de>
Tue, 2 Apr 2019 11:34:30 +0000 (13:34 +0200)
committerMichael Schroeder <mls@suse.de>
Tue, 2 Apr 2019 11:34:30 +0000 (13:34 +0200)
Windows needs a different implementation, and with that solv_cloexec
we need to patch just one place in the code.

bindings/solv.i
src/libsolv.ver
src/repopage.c
src/util.c
src/util.h

index ad265a5861a9c4b5373beb653e88471b3e83e02c..0289adb53a692eaa26f7db379e8c7d0a6b0a3660 100644 (file)
@@ -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);
   }
 }
 
index f0e86fff9e6ed595a27fd21cbfd92df6936044af..58bc957ec2a3ac1a1d55d9e423f8be436e53cfc2 100644 (file)
@@ -291,6 +291,7 @@ SOLV_1.0 {
                solv_realloc;
                solv_realloc2;
                solv_replacebadutf8;
+               solv_setcloexec;
                solv_sort;
                solv_strdup;
                solv_timems;
index 85d53eb90dbe339531aef4732a9569d8c92e1c9f..33d148da53baca61bd90e31eb5b5fe6840862805 100644 (file)
@@ -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 ");
index 65c86294c1ab7ee1b4fbec9f206b81d87c0ce689..ea01384951f9c5315aa6328e58beaf00709d2dca 100644 (file)
@@ -11,6 +11,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
+#include <fcntl.h>
 #include <sys/time.h>
 
 #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
 
index 5f7a93ab1e17adf473f520a95c0a76fa47593036..1dc5f3265a394cd95b2bb713ae3d9402ac885e7e 100644 (file)
@@ -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);