Forráskód Böngészése

Use new dpkg_set_progname and dpkg_get_progname instead of thisname

The current implementation demanded libdpkg users to define thisname
themselves, which is not really a nice interface to offer to programs.

Closes: #631757
Guillem Jover 15 éve
szülő
commit
9fe0a1b16d

+ 3 - 0
debian/changelog

@@ -116,6 +116,9 @@ dpkg (1.16.1) UNRELEASED; urgency=low
     Thanks to Ludovic Brenta <ludovic@ludovic-brenta.org>. Closes: #630533
   * Do not fail to unpack shared directories missing on the file system
     from packages being replaced by other packages. Closes: #631808
+  * Do not require programs to define thisname, provide two new functions
+    to handle the program name (dpkg_set_progname and dpkg_get_progname).
+    Closes: #631757
 
   [ Bill Allombert]
   * Add support for Build-Features: build-arch. Closes: #229357

+ 1 - 1
dpkg-deb/main.c

@@ -125,7 +125,6 @@ usage(const struct cmdinfo *cip, const char *value)
   exit(0);
 }
 
-const char thisname[]= BACKEND;
 static const char printforhelp[] =
   N_("Type dpkg-deb --help for help about manipulating *.deb files;\n"
      "Type dpkg --help for help about installing and deinstalling packages.");
@@ -189,6 +188,7 @@ int main(int argc, const char *const *argv) {
   bindtextdomain(PACKAGE, LOCALEDIR);
   textdomain(PACKAGE);
 
+  dpkg_set_progname(BACKEND);
   standard_startup();
   myopt(&argv, cmdinfos, printforhelp);
 

+ 1 - 1
dpkg-split/main.c

@@ -100,7 +100,6 @@ usage(const struct cmdinfo *cip, const char *value)
   exit(0);
 }
 
-const char thisname[]= SPLITTER;
 static const char printforhelp[] = N_("Type dpkg-split --help for help.");
 
 struct partqueue *queue= NULL;
@@ -159,6 +158,7 @@ int main(int argc, const char *const *argv) {
   bindtextdomain(PACKAGE, LOCALEDIR);
   textdomain(PACKAGE);
 
+  dpkg_set_progname(SPLITTER);
   standard_startup();
   myopt(&argv, cmdinfos, printforhelp);
 

+ 2 - 1
dselect/main.cc

@@ -57,7 +57,6 @@
 #include "bindings.h"
 #include "pkglist.h"
 
-const char thisname[]= DSELECT;
 static const char printforhelp[] = N_("Type dselect --help for help.");
 
 modstatdb_rw readwrite;
@@ -514,6 +513,8 @@ main(int, const char *const *argv)
   bindtextdomain(DSELECT, LOCALEDIR);
   textdomain(DSELECT);
 
+  dpkg_set_progname(DSELECT);
+
   push_error_context_func(dselect_catch_fatal_error, print_fatal_error, 0);
 
   loadcfgfile(DSELECT, cmdinfos);

+ 1 - 0
lib/dpkg/dpkg.h

@@ -98,6 +98,7 @@ DPKG_BEGIN_DECLS
 
 #define FIND_EXPRSTARTCHARS "-(),!"
 
+#include <dpkg/progname.h>
 #include <dpkg/ehandle.h>
 
 /*** from startup.c ***/

+ 9 - 7
lib/dpkg/ehandle.c

@@ -31,6 +31,7 @@
 
 #include <dpkg/macros.h>
 #include <dpkg/i18n.h>
+#include <dpkg/progname.h>
 #include <dpkg/ehandle.h>
 
 /* 6x255 for inserted strings (%.255s &c in fmt; and %s with limited length arg)
@@ -91,13 +92,13 @@ run_error_handler(void)
      * abort. Hopefully the user can fix the situation (out of disk, out
      * of memory, etc). */
     fprintf(stderr, _("%s: unrecoverable fatal error, aborting:\n %s\n"),
-            thisname, errmsg);
+            dpkg_get_progname(), errmsg);
     exit(2);
   }
 
   if (econtext == NULL) {
     fprintf(stderr, _("%s: outside error context, aborting:\n %s\n"),
-            thisname, errmsg);
+            dpkg_get_progname(), errmsg);
     exit(2);
   } else if (econtext->handler_type == handler_type_func) {
     econtext->handler.func();
@@ -179,7 +180,8 @@ push_error_context(void)
 static void
 print_cleanup_error(const char *emsg, const char *contextstring)
 {
-  fprintf(stderr, _("%s: error while cleaning up:\n %s\n"),thisname,emsg);
+  fprintf(stderr, _("%s: error while cleaning up:\n %s\n"),
+          dpkg_get_progname(), emsg);
 }
 
 static void
@@ -197,7 +199,7 @@ run_cleanups(struct error_context *econ, int flagsetin)
   if (++preventrecurse > 3) {
     onerr_abort++;
     fprintf(stderr, _("%s: too many nested errors during error recovery!!\n"),
-            thisname);
+            dpkg_get_progname());
     flagset= 0;
   } else {
     flagset= flagsetin;
@@ -347,7 +349,7 @@ catch_fatal_error(void)
 void
 print_fatal_error(const char *emsg, const char *contextstring)
 {
-  fprintf(stderr, _("%s: error: %s\n"), thisname, emsg);
+  fprintf(stderr, _("%s: error: %s\n"), dpkg_get_progname(), emsg);
 }
 
 void
@@ -388,7 +390,7 @@ warningv(const char *fmt, va_list args)
 
   warn_count++;
   vsnprintf(buf, sizeof(buf), fmt, args);
-  fprintf(stderr, _("%s: warning: %s\n"), thisname, buf);
+  fprintf(stderr, _("%s: warning: %s\n"), dpkg_get_progname(), buf);
 }
 
 void
@@ -412,7 +414,7 @@ do_internerr(const char *file, int line, const char *fmt, ...)
   va_end(args);
 
   fprintf(stderr, _("%s:%s:%d: internal error: %s\n"),
-          thisname, file, line, buf);
+          dpkg_get_progname(), file, line, buf);
 
   abort();
 }

+ 0 - 3
lib/dpkg/ehandle.h

@@ -30,9 +30,6 @@
 
 DPKG_BEGIN_DECLS
 
-/* Defined separately in each program. */
-extern const char thisname[];
-
 extern volatile int onerr_abort;
 
 enum {

+ 0 - 1
lib/dpkg/libdpkg.Versions

@@ -138,7 +138,6 @@ LIBDPKG_PRIVATE {
 	loadcfgfile;
 	myopt;
 	badusage;
-	# thisname;		# XXX variable, do not require external
 	cipaction;		# XXX variable, do not export
 	setaction;
 	setobsolete;

+ 1 - 1
lib/dpkg/subproc.c

@@ -74,7 +74,7 @@ subproc_signals_cleanup(int argc, void **argv)
 static void
 print_subproc_error(const char *emsg, const char *contextstring)
 {
-	fprintf(stderr, _("%s (subprocess): %s\n"), thisname, emsg);
+	fprintf(stderr, _("%s (subprocess): %s\n"), dpkg_get_progname(), emsg);
 }
 
 pid_t

+ 0 - 2
lib/dpkg/test.h

@@ -38,8 +38,6 @@
 #ifndef TEST_MAIN_PROVIDED
 static void test(void);
 
-const char thisname[] = "test";
-
 int
 main(int argc, char **argv)
 {

+ 4 - 3
src/divertcmd.c

@@ -46,7 +46,6 @@
 #include "filesdb.h"
 
 
-const char thisname[] = "dpkg-divert";
 static const char printforhelp[] = N_(
 "Use --help for help about querying packages.");
 
@@ -64,7 +63,8 @@ static int opt_rename = 0;
 static void
 printversion(const struct cmdinfo *cip, const char *value)
 {
-	printf(_("Debian %s version %s.\n"), thisname, DPKG_VERSION_ARCH);
+	printf(_("Debian %s version %s.\n"), dpkg_get_progname(),
+	       DPKG_VERSION_ARCH);
 
 	printf(_(
 "Copyright (C) 1995 Ian Jackson.\n"
@@ -85,7 +85,7 @@ usage(const struct cmdinfo *cip, const char *value)
 {
 	printf(_(
 "Usage: %s [<option> ...] <command>\n"
-"\n"), thisname);
+"\n"), dpkg_get_progname());
 
 	printf(_(
 "Commands:\n"
@@ -698,6 +698,7 @@ main(int argc, const char * const *argv)
 	bindtextdomain(PACKAGE, LOCALEDIR);
 	textdomain(PACKAGE);
 
+	dpkg_set_progname("dpkg-divert");
 	standard_startup();
 	myopt(&argv, cmdinfos, printforhelp);
 

+ 3 - 3
src/errors.c

@@ -58,7 +58,7 @@ void print_error_perpackage(const char *emsg, const char *arg) {
   struct error_report *nr;
 
   fprintf(stderr, _("%s: error processing %s (--%s):\n %s\n"),
-          thisname, arg, cipaction->olong, emsg);
+          dpkg_get_progname(), arg, cipaction->olong, emsg);
 
   statusfd_send("status: %s : %s : %s", arg, "error", emsg);
 
@@ -66,7 +66,7 @@ void print_error_perpackage(const char *emsg, const char *arg) {
   if (!nr) {
     fprintf(stderr,
             _("%s: failed to allocate memory for new entry in list of failed packages: %s"),
-            thisname, strerror(errno));
+            dpkg_get_progname(), strerror(errno));
     abort_processing = true;
     nr= &emergency;
   }
@@ -76,7 +76,7 @@ void print_error_perpackage(const char *emsg, const char *arg) {
   lastreport= &nr->next;
 
   if (nerrs++ < errabort) return;
-  fprintf(stderr, _("%s: too many errors, stopping\n"), thisname);
+  fprintf(stderr, _("%s: too many errors, stopping\n"), dpkg_get_progname());
   abort_processing = true;
 }
 

+ 1 - 1
src/main.c

@@ -165,7 +165,6 @@ usage(const struct cmdinfo *ci, const char *value)
   exit(0);
 }
 
-const char thisname[]= "dpkg";
 const char native_arch[] = ARCHITECTURE;
 static const char printforhelp[] = N_(
 "Type dpkg --help for help about installing and deinstalling packages [*];\n"
@@ -734,6 +733,7 @@ int main(int argc, const char *const *argv) {
   bindtextdomain(PACKAGE, LOCALEDIR);
   textdomain(PACKAGE);
 
+  dpkg_set_progname("dpkg");
   standard_startup();
   loadcfgfile(DPKG, cmdinfos);
   myopt(&argv, cmdinfos, printforhelp);

+ 3 - 3
src/querycmd.c

@@ -347,8 +347,8 @@ searchfiles(const char *const *argv)
       iterfileend(it);
     }
     if (!found) {
-      fprintf(stderr, _("%s: no path found matching pattern %s.\n"), thisname,
-              thisarg);
+      fprintf(stderr, _("%s: no path found matching pattern %s.\n"),
+              dpkg_get_progname(), thisarg);
       failures++;
       m_output(stderr, _("<standard error>"));
     } else {
@@ -652,7 +652,6 @@ usage(const struct cmdinfo *ci, const char *value)
   exit(0);
 }
 
-const char thisname[]= "dpkg-query";
 static const char printforhelp[] = N_(
 "Use --help for help about querying packages.");
 
@@ -684,6 +683,7 @@ int main(int argc, const char *const *argv) {
   bindtextdomain(PACKAGE, LOCALEDIR);
   textdomain(PACKAGE);
 
+  dpkg_set_progname("dpkg-query");
   standard_startup();
   myopt(&argv, cmdinfos, printforhelp);
 

+ 4 - 3
src/statcmd.c

@@ -48,14 +48,14 @@
 #include "main.h"
 #include "filesdb.h"
 
-const char thisname[] = "dpkg-statoverride";
 static const char printforhelp[] = N_(
 "Use --help for help about querying packages.");
 
 static void DPKG_ATTR_NORET
 printversion(const struct cmdinfo *cip, const char *value)
 {
-	printf(_("Debian %s version %s.\n"), thisname, DPKG_VERSION_ARCH);
+	printf(_("Debian %s version %s.\n"), dpkg_get_progname(),
+	       DPKG_VERSION_ARCH);
 
 	printf(_(
 "Copyright (C) 2000, 2001 Wichert Akkerman.\n"
@@ -75,7 +75,7 @@ usage(const struct cmdinfo *cip, const char *value)
 {
 	printf(_(
 "Usage: %s [<option> ...] <command>\n"
-"\n"), thisname);
+"\n"), dpkg_get_progname());
 
 	printf(_(
 "Commands:\n"
@@ -369,6 +369,7 @@ main(int argc, const char *const *argv)
 	bindtextdomain(PACKAGE, LOCALEDIR);
 	textdomain(PACKAGE);
 
+	dpkg_set_progname("dpkg-statoverride");
 	standard_startup();
 	myopt(&argv, cmdinfos, printforhelp);
 

+ 5 - 6
src/trigcmd.c

@@ -42,8 +42,6 @@
 #include <dpkg/trigdeferred.h>
 #include <dpkg/triglib.h>
 
-const char thisname[] = "dpkg-trigger";
-
 static const char printforhelp[] = N_(
 "Type dpkg-trigger --help for help about this utility.");
 
@@ -51,7 +49,7 @@ static void DPKG_ATTR_NORET
 printversion(const struct cmdinfo *ci, const char *value)
 {
 	printf(_("Debian %s package trigger utility version %s.\n"),
-	       thisname, DPKG_VERSION_ARCH);
+	       dpkg_get_progname(), DPKG_VERSION_ARCH);
 
 	printf(_(
 "This is free software; see the GNU General Public License version 2 or\n"
@@ -68,7 +66,7 @@ usage(const struct cmdinfo *ci, const char *value)
 	printf(_(
 "Usage: %s [<options> ...] <trigger-name>\n"
 "       %s [<options> ...] <command>\n"
-"\n"), thisname, thisname);
+"\n"), dpkg_get_progname(), dpkg_get_progname());
 
 	printf(_(
 "Commands:\n"
@@ -152,11 +150,11 @@ do_check(void)
 	switch (uf) {
 	case tdus_error_no_dir:
 		fprintf(stderr, _("%s: triggers data directory not yet created\n"),
-		        thisname);
+		        dpkg_get_progname());
 		exit(1);
 	case tdus_error_no_deferred:
 		fprintf(stderr, _("%s: trigger records not yet in existence\n"),
-		        thisname);
+		        dpkg_get_progname());
 		exit(1);
 	case tdus_ok:
 	case tdus_error_empty_deferred:
@@ -188,6 +186,7 @@ main(int argc, const char *const *argv)
 	bindtextdomain(PACKAGE, LOCALEDIR);
 	textdomain(PACKAGE);
 
+	dpkg_set_progname("dpkg-trigger");
 	standard_startup();
 	myopt(&argv, cmdinfos, printforhelp);
 

+ 1 - 1
src/trigproc.c

@@ -249,7 +249,7 @@ check_trigger_cycle(struct pkginfo *processing_now)
 	 * progress. */
 	fprintf(stderr, _("%s: cycle found while processing triggers:\n chain of"
 	        " packages whose triggers are or may be responsible:\n"),
-	        thisname);
+	        dpkg_get_progname());
 	sep = "  ";
 	for (tcn = tortoise; tcn; tcn = tcn->next) {
 		fprintf(stderr, "%s%s", sep, tcn->then_processed->name);