Ver código fonte

dpkg: Refactor out run_logger() from run_status_loggers()

Guillem Jover 12 anos atrás
pai
commit
5d62da287e
1 arquivos alterados com 27 adições e 18 exclusões
  1. 27 18
      src/main.c

+ 27 - 18
src/main.c

@@ -451,31 +451,40 @@ run_invoke_hooks(const char *action, struct invoke_hook *hook_head)
   unsetenv("DPKG_HOOK_ACTION");
 }
 
-static void
-run_status_loggers(struct invoke_hook *hook_head)
+static int
+run_logger(struct invoke_hook *hook, const char *name)
 {
-  struct invoke_hook *hook;
+  pid_t pid;
+  int p[2];
 
-  for (hook = hook_head; hook; hook = hook->next) {
-    pid_t pid;
-    int p[2];
+  m_pipe(p);
 
-    m_pipe(p);
+  pid = subproc_fork();
+  if (pid == 0) {
+    /* Setup stdin and stdout. */
+    m_dup2(p[0], 0);
+    close(1);
 
-    pid = subproc_fork();
-    if (pid == 0) {
-      /* Setup stdin and stdout. */
-      m_dup2(p[0], 0);
-      close(1);
+    close(p[0]);
+    close(p[1]);
 
-      close(p[0]);
-      close(p[1]);
+    command_shell(hook->command, name);
+  }
+  close(p[0]);
 
-      command_shell(hook->command, _("status logger"));
-    }
-    close(p[0]);
+  return p[1];
+}
+
+static void
+run_status_loggers(struct invoke_hook *hook_head)
+{
+  struct invoke_hook *hook;
+
+  for (hook = hook_head; hook; hook = hook->next) {
+    int fd;
 
-    statusfd_add(p[1]);
+    fd = run_logger(hook, _("status logger"));
+    statusfd_add(fd);
   }
 }