Quellcode durchsuchen

Use push_error_context() instead of ad-hoc code

Guillem Jover vor 15 Jahren
Ursprung
Commit
b94d25d09f
10 geänderte Dateien mit 12 neuen und 33 gelöschten Zeilen
  1. 0 1
      TODO
  2. 1 2
      dpkg-deb/main.c
  3. 1 2
      dpkg-split/main.c
  4. 2 5
      lib/dpkg/dpkg.h
  5. 1 7
      lib/dpkg/test.h
  6. 1 2
      src/divertcmd.c
  7. 3 8
      src/main.c
  8. 1 2
      src/querycmd.c
  9. 1 2
      src/statcmd.c
  10. 1 2
      src/trigcmd.c

+ 0 - 1
TODO

@@ -31,7 +31,6 @@ TODO
  * Code cleanup / bug fixes:
    - Get rid of static variables inside functions.
    - Coalesce admindir / infodir / foodir generation.
-   - Get rid of setjmp (at least in the general case, keep for dpkg itself?)
    - Coalesce hash and checksum functions.
    - Split modstatdb_rw into mode and flags.
    - Move fd function out of mlib.

+ 1 - 2
dpkg-deb/main.c

@@ -183,7 +183,6 @@ static void setcompresstype(const struct cmdinfo *cip, const char *value) {
 }
 
 int main(int argc, const char *const *argv) {
-  jmp_buf ejbuf;
   dofunction *action;
 
   setlocale(LC_NUMERIC, "POSIX");
@@ -191,7 +190,7 @@ int main(int argc, const char *const *argv) {
   bindtextdomain(PACKAGE, LOCALEDIR);
   textdomain(PACKAGE);
 
-  standard_startup(&ejbuf);
+  standard_startup();
   myopt(&argv, cmdinfos);
 
   if (!cipaction) badusage(_("need an action option"));

+ 1 - 2
dpkg-split/main.c

@@ -148,7 +148,6 @@ static const struct cmdinfo cmdinfos[]= {
 };
 
 int main(int argc, const char *const *argv) {
-  jmp_buf ejbuf;
   int l;
   char *p;
   dofunction *action;
@@ -157,7 +156,7 @@ int main(int argc, const char *const *argv) {
   bindtextdomain(PACKAGE, LOCALEDIR);
   textdomain(PACKAGE);
 
-  standard_startup(&ejbuf);
+  standard_startup();
   myopt(&argv, cmdinfos);
 
   if (!cipaction) badusage(_("need an action option"));

+ 2 - 5
lib/dpkg/dpkg.h

@@ -106,11 +106,8 @@ DPKG_BEGIN_DECLS
 
 /*** from startup.c ***/
 
-#define standard_startup(ejbuf) do {\
-  if (setjmp(*ejbuf)) { /* expect warning about possible clobbering of argv */\
-    catch_fatal_error(); \
-  }\
-  push_error_handler(ejbuf, print_fatal_error, NULL); \
+#define standard_startup() do { \
+  push_error_context(); \
   umask(022); /* Make sure all our status databases are readable. */\
 } while (0)
 

+ 1 - 7
lib/dpkg/test.h

@@ -43,13 +43,7 @@ const char thisname[] = "test";
 int
 main(int argc, char **argv)
 {
-	jmp_buf ejbuf;
-
-	/* Initialize environment. */
-	if (setjmp(ejbuf)) {
-		catch_fatal_error();
-	}
-	push_error_handler(&ejbuf, print_fatal_error, NULL);
+	push_error_context();
 
 	test();
 

+ 1 - 2
src/divertcmd.c

@@ -704,7 +704,6 @@ static const struct cmdinfo cmdinfos[] = {
 int
 main(int argc, const char * const *argv)
 {
-	jmp_buf ejbuf;
 	const char *env_pkgname;
 	int (*actionfunction)(const char *const *argv);
 	int ret;
@@ -713,7 +712,7 @@ main(int argc, const char * const *argv)
 	bindtextdomain(PACKAGE, LOCALEDIR);
 	textdomain(PACKAGE);
 
-	standard_startup(&ejbuf);
+	standard_startup();
 	myopt(&argv, cmdinfos);
 
 	env_pkgname = getenv(MAINTSCRIPTPKGENVVAR);

+ 3 - 8
src/main.c

@@ -564,7 +564,6 @@ void execbackend(const char *const *argv) {
 }
 
 void commandfd(const char *const *argv) {
-  jmp_buf ejbuf;
   struct varbuf linevb = VARBUF_INIT;
   const char * pipein;
   const char **newargs = NULL;
@@ -587,15 +586,12 @@ void commandfd(const char *const *argv) {
   if ((in= fdopen(infd, "r")) == NULL)
     ohshite(_("couldn't open `%i' for stream"), (int) infd);
 
-  if (setjmp(ejbuf)) { /* expect warning about possible clobbering of argv */
-    catch_fatal_error();
-  }
-
   for (;;) {
     bool mode = false;
     int argc= 1;
     lno= 0;
-    push_error_handler(&ejbuf, print_fatal_error, NULL);
+
+    push_error_context();
 
     do { c= getc(in); if (c == '\n') lno++; } while (c != EOF && isspace(c));
     if (c == EOF) break;
@@ -665,14 +661,13 @@ void commandfd(const char *const *argv) {
 
 
 int main(int argc, const char *const *argv) {
-  jmp_buf ejbuf;
   void (*actionfunction)(const char *const *argv);
 
   setlocale(LC_ALL, "");
   bindtextdomain(PACKAGE, LOCALEDIR);
   textdomain(PACKAGE);
 
-  standard_startup(&ejbuf);
+  standard_startup();
   loadcfgfile(DPKG, cmdinfos);
   myopt(&argv, cmdinfos);
 

+ 1 - 2
src/querycmd.c

@@ -672,7 +672,6 @@ static const struct cmdinfo cmdinfos[]= {
 };
 
 int main(int argc, const char *const *argv) {
-  jmp_buf ejbuf;
   int (*actionfunction)(const char *const *argv);
   int ret;
 
@@ -680,7 +679,7 @@ int main(int argc, const char *const *argv) {
   bindtextdomain(PACKAGE, LOCALEDIR);
   textdomain(PACKAGE);
 
-  standard_startup(&ejbuf);
+  standard_startup();
   myopt(&argv, cmdinfos);
 
   if (!cipaction) badusage(_("need an action option"));

+ 1 - 2
src/statcmd.c

@@ -372,7 +372,6 @@ static const struct cmdinfo cmdinfos[] = {
 int
 main(int argc, const char *const *argv)
 {
-	jmp_buf ejbuf;
 	int (*actionfunction)(const char *const *argv);
 	int ret;
 
@@ -380,7 +379,7 @@ main(int argc, const char *const *argv)
 	bindtextdomain(PACKAGE, LOCALEDIR);
 	textdomain(PACKAGE);
 
-	standard_startup(&ejbuf);
+	standard_startup();
 	myopt(&argv, cmdinfos);
 
 	if (!cipaction)

+ 1 - 2
src/trigcmd.c

@@ -180,7 +180,6 @@ static const struct cmdinfo cmdinfos[] = {
 int
 main(int argc, const char *const *argv)
 {
-	jmp_buf ejbuf;
 	int uf;
 	const char *badname;
 	enum trigdef_updateflags tduf;
@@ -189,7 +188,7 @@ main(int argc, const char *const *argv)
 	bindtextdomain(PACKAGE, LOCALEDIR);
 	textdomain(PACKAGE);
 
-	standard_startup(&ejbuf);
+	standard_startup();
 	myopt(&argv, cmdinfos);
 
 	setvbuf(stdout, NULL, _IONBF, 0);