Browse Source

libdpkg: Refactor report output buffering setup into a new function

Guillem Jover 12 years ago
parent
commit
3b786cf079
10 changed files with 18 additions and 13 deletions
  1. 1 2
      dpkg-split/main.c
  2. 1 1
      dselect/main.cc
  3. 1 0
      lib/dpkg/libdpkg.map
  4. 7 1
      lib/dpkg/report.c
  5. 3 0
      lib/dpkg/report.h
  6. 1 2
      src/divertcmd.c
  7. 1 2
      src/main.c
  8. 1 1
      src/querycmd.c
  9. 1 2
      src/statcmd.c
  10. 1 2
      src/trigcmd.c

+ 1 - 2
dpkg-split/main.c

@@ -161,6 +161,7 @@ int main(int argc, const char *const *argv) {
   textdomain(PACKAGE);
 
   dpkg_set_progname(SPLITTER);
+  dpkg_set_report_buffer(stdout);
   standard_startup();
   myopt(&argv, cmdinfos, printforhelp);
 
@@ -170,8 +171,6 @@ int main(int argc, const char *const *argv) {
 
   if (!cipaction) badusage(_("need an action option"));
 
-  setvbuf(stdout,NULL,_IONBF,0);
-
   ret = cipaction->action(argv);
 
   m_output(stderr, _("<standard error>"));

+ 1 - 1
dselect/main.cc

@@ -229,7 +229,7 @@ extern "C" {
     fp = fopen(v, "a");
     if (!fp)
       ohshite(_("couldn't open debug file `%.255s'\n"), v);
-    setvbuf(fp, 0, _IONBF, 0);
+    dpkg_set_report_buffer(fp);
 
     debug_set_output(fp);
     debug_set_mask(dbg_general | dbg_depcon);

+ 1 - 0
lib/dpkg/libdpkg.map

@@ -31,6 +31,7 @@ LIBDPKG_PRIVATE {
 	ohshite;
 	ohshit;
 	do_internerr;
+	dpkg_set_report_buffer;
 	warning_get_count;
 	warningv;
 	warning;

+ 7 - 1
lib/dpkg/report.c

@@ -3,7 +3,7 @@
  * reoport.c - message reporting
  *
  * Copyright © 2004-2005 Scott James Remnant <scott@netsplit.com>
- * Copyright © 2008-2012 Guillem Jover <guillem@debian.org>
+ * Copyright © 2008-2013 Guillem Jover <guillem@debian.org>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -30,6 +30,12 @@
 #include <dpkg/progname.h>
 #include <dpkg/report.h>
 
+void
+dpkg_set_report_buffer(FILE *fp)
+{
+	setvbuf(fp, NULL, _IONBF, 0);
+}
+
 static int warn_count = 0;
 
 int

+ 3 - 0
lib/dpkg/report.h

@@ -23,6 +23,7 @@
 #define LIBDPKG_REPORT_H
 
 #include <stdarg.h>
+#include <stdio.h>
 
 #include <dpkg/macros.h>
 
@@ -34,6 +35,8 @@ DPKG_BEGIN_DECLS
  * @{
  */
 
+void dpkg_set_report_buffer(FILE *fp);
+
 int warning_get_count(void);
 void warningv(const char *fmt, va_list args) DPKG_ATTR_VPRINTF(1);
 void warning(const char *fmt, ...) DPKG_ATTR_PRINTF(1);

+ 1 - 2
src/divertcmd.c

@@ -772,6 +772,7 @@ main(int argc, const char * const *argv)
 	textdomain(PACKAGE);
 
 	dpkg_set_progname("dpkg-divert");
+	dpkg_set_report_buffer(stdout);
 	standard_startup();
 	myopt(&argv, cmdinfos, printforhelp);
 
@@ -784,8 +785,6 @@ main(int argc, const char * const *argv)
 	if (!cipaction)
 		setaction(&cmdinfo_add, NULL);
 
-	setvbuf(stdout, NULL, _IONBF, 0);
-
 	modstatdb_open(msdbrw_readonly);
 	filesdbinit();
 	ensure_diversions();

+ 1 - 2
src/main.c

@@ -842,6 +842,7 @@ int main(int argc, const char *const *argv) {
   textdomain(PACKAGE);
 
   dpkg_set_progname("dpkg");
+  dpkg_set_report_buffer(stdout);
   standard_startup();
   loadcfgfile(DPKG, cmdinfos);
   myopt(&argv, cmdinfos, printforhelp);
@@ -857,8 +858,6 @@ int main(int argc, const char *const *argv) {
   if (!f_triggers)
     f_triggers = (cipaction->arg_int == act_triggers && *argv) ? -1 : 1;
 
-  setvbuf(stdout, NULL, _IONBF, 0);
-
   if (is_invoke_action(cipaction->arg_int)) {
     run_invoke_hooks(cipaction->olong, pre_invoke_hooks);
     run_status_loggers(status_loggers);

+ 1 - 1
src/querycmd.c

@@ -866,6 +866,7 @@ int main(int argc, const char *const *argv) {
   textdomain(PACKAGE);
 
   dpkg_set_progname("dpkg-query");
+  dpkg_set_report_buffer(stdout);
   standard_startup();
   myopt(&argv, cmdinfos, printforhelp);
 
@@ -873,7 +874,6 @@ int main(int argc, const char *const *argv) {
 
   if (!cipaction) badusage(_("need an action option"));
 
-  setvbuf(stdout, NULL, _IONBF, 0);
   filesdbinit();
 
   ret = cipaction->action(argv);

+ 1 - 2
src/statcmd.c

@@ -351,6 +351,7 @@ main(int argc, const char *const *argv)
 	textdomain(PACKAGE);
 
 	dpkg_set_progname("dpkg-statoverride");
+	dpkg_set_report_buffer(stdout);
 	standard_startup();
 	myopt(&argv, cmdinfos, printforhelp);
 
@@ -359,8 +360,6 @@ main(int argc, const char *const *argv)
 	if (!cipaction)
 		badusage(_("need an action option"));
 
-	setvbuf(stdout, NULL, _IONBF, 0);
-
 	filesdbinit();
 	ensure_statoverrides();
 

+ 1 - 2
src/trigcmd.c

@@ -216,13 +216,12 @@ main(int argc, const char *const *argv)
 	textdomain(PACKAGE);
 
 	dpkg_set_progname("dpkg-trigger");
+	dpkg_set_report_buffer(stdout);
 	standard_startup();
 	myopt(&argv, cmdinfos, printforhelp);
 
 	admindir = dpkg_db_set_dir(admindir);
 
-	setvbuf(stdout, NULL, _IONBF, 0);
-
 	if (f_check) {
 		if (*argv)
 			badusage(_("--%s takes no arguments"),