Procházet zdrojové kódy

libdpkg: Move m_fork and helpers to the subproc module

Guillem Jover před 16 roky
rodič
revize
692d67e4d0
4 změnil soubory, kde provedl 38 přidání a 23 odebrání
  1. 0 1
      lib/dpkg/dpkg.h
  2. 0 22
      lib/dpkg/mlib.c
  3. 37 0
      lib/dpkg/subproc.c
  4. 1 0
      lib/dpkg/subproc.h

+ 0 - 1
lib/dpkg/dpkg.h

@@ -198,7 +198,6 @@ void setcloexec(int fd, const char* fn);
 void *m_malloc(size_t);
 void *m_malloc(size_t);
 void *m_realloc(void*, size_t);
 void *m_realloc(void*, size_t);
 char *m_strdup(const char *str);
 char *m_strdup(const char *str);
-int m_fork(void);
 void m_dup2(int oldfd, int newfd);
 void m_dup2(int oldfd, int newfd);
 void m_pipe(int fds[2]);
 void m_pipe(int fds[2]);
 void m_output(FILE *f, const char *name);
 void m_output(FILE *f, const char *name);

+ 0 - 22
lib/dpkg/mlib.c

@@ -75,28 +75,6 @@ m_strdup(const char *str)
   return new_str;
   return new_str;
 }
 }
 
 
-static void print_error_forked(const char *emsg, const char *contextstring) {
-  fprintf(stderr, _("%s (subprocess): %s\n"), thisname, emsg);
-}
-
-static void cu_m_fork(int argc, void **argv) DPKG_ATTR_NORET;
-static void cu_m_fork(int argc, void **argv) {
-  exit(2);
-  /* Don't do the other cleanups, because they'll be done by/in the parent
-   * process.
-   */
-}
-
-int m_fork(void) {
-  pid_t r;
-  r= fork();
-  if (r == -1) { onerr_abort++; ohshite(_("fork failed")); }
-  if (r > 0) return r;
-  push_cleanup(cu_m_fork,~0, NULL,0, 0);
-  set_error_display(print_error_forked,NULL);
-  return r;
-}
-
 void m_dup2(int oldfd, int newfd) {
 void m_dup2(int oldfd, int newfd) {
   const char *const stdstrings[]= { "in", "out", "err" };
   const char *const stdstrings[]= { "in", "out", "err" };
   
   

+ 37 - 0
lib/dpkg/subproc.c

@@ -27,6 +27,8 @@
 #include <errno.h>
 #include <errno.h>
 #include <string.h>
 #include <string.h>
 #include <signal.h>
 #include <signal.h>
+#include <unistd.h>
+#include <stdlib.h>
 #include <stdio.h>
 #include <stdio.h>
 
 
 #include <dpkg/i18n.h>
 #include <dpkg/i18n.h>
@@ -69,6 +71,41 @@ subproc_signals_cleanup(int argc, void **argv)
 	}
 	}
 }
 }
 
 
+static void
+print_error_forked(const char *emsg, const char *contextstring)
+{
+	fprintf(stderr, _("%s (subprocess): %s\n"), thisname, emsg);
+}
+
+static void cu_m_fork(int argc, void **argv) DPKG_ATTR_NORET;
+
+static void
+cu_m_fork(int argc, void **argv)
+{
+	/* Don't do the other cleanups, because they'll be done by/in the
+	 * parent process. */
+	exit(2);
+}
+
+int
+m_fork(void)
+{
+	pid_t r;
+
+	r = fork();
+	if (r == -1) {
+		onerr_abort++;
+		ohshite(_("fork failed"));
+	}
+	if (r > 0)
+		return r;
+
+	push_cleanup(cu_m_fork, ~0, NULL, 0, 0);
+	set_error_display(print_error_forked, NULL);
+
+	return r;
+}
+
 int
 int
 subproc_check(int status, const char *desc, int flags)
 subproc_check(int status, const char *desc, int flags)
 {
 {

+ 1 - 0
lib/dpkg/subproc.h

@@ -34,6 +34,7 @@ void subproc_signals_cleanup(int argc, void **argv);
 #define PROCWARN 2
 #define PROCWARN 2
 #define PROCNOERR 4
 #define PROCNOERR 4
 
 
+int m_fork(void);
 int subproc_wait(pid_t pid, const char *desc);
 int subproc_wait(pid_t pid, const char *desc);
 int subproc_check(int status, const char *desc, int flags);
 int subproc_check(int status, const char *desc, int flags);
 int subproc_wait_check(pid_t pid, const char *desc, int flags);
 int subproc_wait_check(pid_t pid, const char *desc, int flags);