소스 검색

Refactor setpipe() into statusfd_add() to stop exposing status_pipes

Guillem Jover 15 년 전
부모
커밋
94e25a0380
4개의 변경된 파일23개의 추가작업 그리고 18개의 파일을 삭제
  1. 1 7
      lib/dpkg/dpkg.h
  2. 1 1
      lib/dpkg/libdpkg.Versions
  3. 19 1
      lib/dpkg/log.c
  4. 2 9
      src/main.c

+ 1 - 7
lib/dpkg/dpkg.h

@@ -121,13 +121,7 @@ DPKG_BEGIN_DECLS
 extern const char *log_file;
 void log_message(const char *fmt, ...) DPKG_ATTR_PRINTF(1);
 
-/* FIXME: pipef and status_pipes should not be publicly exposed. */
-struct pipef {
-  int fd;
-  struct pipef *next;
-};
-extern struct pipef *status_pipes;
-
+void statusfd_add(int fd);
 void statusfd_send(const char *fmt, ...) DPKG_ATTR_PRINTF(1);
 
 /*** cleanup.c ***/

+ 1 - 1
lib/dpkg/libdpkg.Versions

@@ -139,7 +139,7 @@ LIBDPKG_PRIVATE {
 	log_message;
 
 	# Action logging
-	status_pipes;		# XXX variable, do not export
+	statusfd_add;
 	statusfd_send;
 
 	# Progress report support

+ 19 - 1
lib/dpkg/log.c

@@ -70,7 +70,25 @@ log_message(const char *fmt, ...)
 	fprintf(logfd, "%s %s\n", time_str, log.buf);
 }
 
-struct pipef *status_pipes = NULL;
+struct pipef {
+	struct pipef *next;
+	int fd;
+};
+
+static struct pipef *status_pipes = NULL;
+
+void
+statusfd_add(int fd)
+{
+	struct pipef *pipe_new;
+
+	setcloexec(fd, _("<package status and progress file descriptor>"));
+
+	pipe_new = nfmalloc(sizeof(struct pipef));
+	pipe_new->fd = fd;
+	pipe_new->next = status_pipes;
+	status_pipes = pipe_new;
+}
 
 void
 statusfd_send(const char *fmt, ...)

+ 2 - 9
src/main.c

@@ -306,8 +306,6 @@ static void setinteger(const struct cmdinfo *cip, const char *value) {
 }
 
 static void setpipe(const struct cmdinfo *cip, const char *value) {
-  struct pipef **pipe_head = cip->parg;
-  struct pipef *pipe_new;
   unsigned long v;
   char *ep;
 
@@ -315,12 +313,7 @@ static void setpipe(const struct cmdinfo *cip, const char *value) {
   if (value == ep || *ep || v > INT_MAX)
     badusage(_("invalid integer for --%s: `%.250s'"),cip->olong,value);
 
-  setcloexec(v, _("<package status and progress file descriptor>"));
-
-  pipe_new = nfmalloc(sizeof(struct pipef));
-  pipe_new->fd = v;
-  pipe_new->next = *pipe_head;
-  *pipe_head = pipe_new;
+  statusfd_add(v);
 }
 
 static bool
@@ -494,7 +487,7 @@ static const struct cmdinfo cmdinfos[]= {
   { "post-invoke",       0,   1, NULL,          NULL,      set_invoke_hook, 0, &post_invoke_hooks_tail },
   { "path-exclude",      0,   1, NULL,          NULL,      setfilter,     0 },
   { "path-include",      0,   1, NULL,          NULL,      setfilter,     1 },
-  { "status-fd",         0,   1, NULL,          NULL,      setpipe, 0, &status_pipes },
+  { "status-fd",         0,   1, NULL,          NULL,      setpipe, 0 },
   { "log",               0,   1, NULL,          &log_file, NULL,    0 },
   { "pending",           'a', 0, &f_pending,    NULL,      NULL,    1 },
   { "recursive",         'R', 0, &f_recursive,  NULL,      NULL,    1 },