Pārlūkot izejas kodu

Merge branch 'maint'

* maint:
  Prefer vfork(2) for confedit and simple_exec
  Support FreeBSD closefrom(2)
  Detect closefrom(2) support
Bryan Drewery 9 gadi atpakaļ
vecāks
revīzija
4edea9d3cc
6 mainītis faili ar 23 papildinājumiem un 8 dzēšanām
  1. 1 1
      build/autotools/configure.ac
  2. 1 1
      configure
  3. 2 0
      doc/UPDATES.md
  4. 3 3
      src/conf.cc
  5. 3 0
      src/config.h.in
  6. 13 3
      src/shell.cc

+ 1 - 1
build/autotools/configure.ac

@@ -222,7 +222,7 @@ AC_CHECK_FUNCS([getrusage getpassphrase posix_madvise madvise])
 AC_CHECK_FUNCS([memmem random snprintf srandom gettime])
 #checkpoint
 AC_CACHE_SAVE
-AC_CHECK_FUNCS([vsnprintf prctl procctl])
+AC_CHECK_FUNCS([vsnprintf prctl procctl closefrom])
 
 #autoscan suggested this....
 #These are recommended by autoscan, but no code supports it currently

+ 1 - 1
configure

@@ -8321,7 +8321,7 @@ $as_echo "$as_me: not updating unwritable cache $cache_file" >&6;}
   fi
 fi
 rm -f confcache
-for ac_func in vsnprintf prctl procctl
+for ac_func in vsnprintf prctl procctl closefrom
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_cxx_check_func "$LINENO" "$ac_func" "$as_ac_var"

+ 2 - 0
doc/UPDATES.md

@@ -10,6 +10,8 @@
     [1] http://clang.llvm.org/docs/AddressSanitizer.html
   * Fix './wraith -C' file being immediately modified when saving on
     FreeBSD (#94)
+  * Support FreeBSD closefrom(2)
+  * Use vfork(2) in some places
 
 # 1.4.7
   * Update server list, 'set -yes servers -' and 'set -yes servers6 -' to get new list.

+ 3 - 3
src/conf.cc

@@ -223,7 +223,7 @@ confedit()
   signal(SIGCONT, SIG_DFL);
 
   my_gettime(&ts1);
-  switch (pid = fork()) {
+  switch (pid = vfork()) {
     case -1:
       fatal(STR("Cannot fork"), 0);
     case 0:
@@ -231,8 +231,8 @@ confedit()
       /* child */
       execlp(editor, editor, tmpconf.file, (char*)NULL);
       perror(editor);
-      exit(1);
-     /*NOTREACHED*/}
+      _exit(127);
+    }
     default:
       /* parent */
       break;

+ 3 - 0
src/config.h.in

@@ -22,6 +22,9 @@
 /* Define to 1 if you have the <arpa/inet.h> header file. */
 #undef HAVE_ARPA_INET_H
 
+/* Define to 1 if you have the `closefrom' function. */
+#undef HAVE_CLOSEFROM
+
 /* define if the compiler supports basic C++11 syntax */
 #undef HAVE_CXX11
 

+ 13 - 3
src/shell.cc

@@ -537,7 +537,12 @@ int shell_exec(char *cmdline, char *input, char **output, char **erroutput, bool
     }
 
     // Close all sockets
-    for (int fd = 3; fd < MAX_SOCKETS; ++fd) close(fd);
+#ifdef HAVE_CLOSEFROM
+    closefrom(3);
+#else
+    for (int fd = 3; fd < MAX_SOCKETS; ++fd)
+      close(fd);
+#endif
 
     char *argv[15];
     if (simple) {
@@ -565,12 +570,17 @@ int simple_exec(const char* argv[]) {
   pid_t pid, savedpid;
   int status;
 
-  switch ((pid = fork())) {
+  switch ((pid = vfork())) {
     case -1:
       return -1;
     case 0:		//child
       // Close all sockets
-      for (int fd = 3; fd < MAX_SOCKETS; ++fd) close(fd);
+#ifdef HAVE_CLOSEFROM
+      closefrom(3);
+#else
+      for (int fd = 3; fd < MAX_SOCKETS; ++fd)
+        close(fd);
+#endif
       execvp(argv[0], (char* const*) &argv[0]);
       _exit(127);
     default:		//parent