Przeglądaj źródła

libdpkg: Namespace and reword subproc flags

Guillem Jover 11 lat temu
rodzic
commit
b8a6ab4c5c

+ 1 - 1
dpkg-deb/extract.c

@@ -359,7 +359,7 @@ extracthalf(const char *debar, const char *dir,
     subproc_reap(c3, "tar", 0);
     subproc_reap(c3, "tar", 0);
   }
   }
 
 
-  subproc_reap(c2, _("<decompress>"), PROCPIPE);
+  subproc_reap(c2, _("<decompress>"), SUBPROC_NOPIPE);
   if (c1 != -1)
   if (c1 != -1)
     subproc_reap(c1, _("paste"), 0);
     subproc_reap(c1, _("paste"), 0);
   if (version.major == 0 && admininfo) {
   if (version.major == 0 && admininfo) {

+ 1 - 1
dpkg-split/split.c

@@ -82,7 +82,7 @@ deb_field(const char *filename, const char *field)
 
 
 	close(p[0]);
 	close(p[0]);
 
 
-	subproc_reap(pid, _("package field value extraction"), PROCPIPE);
+	subproc_reap(pid, _("package field value extraction"), SUBPROC_NOPIPE);
 
 
 	/* Trim down trailing junk. */
 	/* Trim down trailing junk. */
 	for (end = buf.buf + strlen(buf.buf) - 1; end - buf.buf >= 1; end--)
 	for (end = buf.buf + strlen(buf.buf) - 1; end - buf.buf >= 1; end--)

+ 1 - 1
dselect/method.cc

@@ -150,7 +150,7 @@ falliblesubprocess(struct command *cmd)
 
 
   fprintf(stderr, "\n");
   fprintf(stderr, "\n");
 
 
-  i = subproc_reap(pid, cmd->name, PROCWARN);
+  i = subproc_reap(pid, cmd->name, SUBPROC_WARN);
 
 
   subproc_signals_restore();
   subproc_signals_restore();
 
 

+ 1 - 1
lib/dpkg/file.c

@@ -173,5 +173,5 @@ file_show(const char *filename)
 		command_add_arg(&cmd, filename);
 		command_add_arg(&cmd, filename);
 		command_exec(&cmd);
 		command_exec(&cmd);
 	}
 	}
-	subproc_reap(pid, _("showing file on pager"), PROCNOCHECK);
+	subproc_reap(pid, _("showing file on pager"), SUBPROC_NOCHECK);
 }
 }

+ 7 - 7
lib/dpkg/subproc.c

@@ -3,7 +3,7 @@
  * subproc.c - subprocess helper routines
  * subproc.c - subprocess helper routines
  *
  *
  * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
  * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
- * Copyright © 2008-2012 Guillem Jover <guillem@debian.org>
+ * Copyright © 2008-2014 Guillem Jover <guillem@debian.org>
  *
  *
  * This is free software; you can redistribute it and/or modify
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * it under the terms of the GNU General Public License as published by
@@ -119,12 +119,12 @@ subproc_fork(void)
 }
 }
 
 
 static int
 static int
-subproc_check(int status, const char *desc, int flags)
+subproc_check(int status, const char *desc, enum subproc_flags flags)
 {
 {
 	void (*out)(const char *fmt, ...) DPKG_ATTR_PRINTF(1);
 	void (*out)(const char *fmt, ...) DPKG_ATTR_PRINTF(1);
 	int n;
 	int n;
 
 
-	if (flags & PROCWARN)
+	if (flags & SUBPROC_WARN)
 		out = warning;
 		out = warning;
 	else
 	else
 		out = ohshit;
 		out = ohshit;
@@ -133,7 +133,7 @@ subproc_check(int status, const char *desc, int flags)
 		n = WEXITSTATUS(status);
 		n = WEXITSTATUS(status);
 		if (!n)
 		if (!n)
 			return 0;
 			return 0;
-		if (flags & PROCNOERR)
+		if (flags & SUBPROC_RETERROR)
 			return n;
 			return n;
 
 
 		out(_("subprocess %s returned error exit status %d"), desc, n);
 		out(_("subprocess %s returned error exit status %d"), desc, n);
@@ -141,7 +141,7 @@ subproc_check(int status, const char *desc, int flags)
 		n = WTERMSIG(status);
 		n = WTERMSIG(status);
 		if (!n)
 		if (!n)
 			return 0;
 			return 0;
-		if ((flags & PROCPIPE) && n == SIGPIPE)
+		if ((flags & SUBPROC_NOPIPE) && n == SIGPIPE)
 			return 0;
 			return 0;
 
 
 		if (n == SIGINT)
 		if (n == SIGINT)
@@ -175,13 +175,13 @@ subproc_wait(pid_t pid, const char *desc)
 }
 }
 
 
 int
 int
-subproc_reap(pid_t pid, const char *desc, int flags)
+subproc_reap(pid_t pid, const char *desc, enum subproc_flags flags)
 {
 {
 	int status, rc;
 	int status, rc;
 
 
 	status = subproc_wait(pid, desc);
 	status = subproc_wait(pid, desc);
 
 
-	if (flags & PROCNOCHECK)
+	if (flags & SUBPROC_NOCHECK)
 		rc = status;
 		rc = status;
 	else
 	else
 		rc = subproc_check(status, desc, flags);
 		rc = subproc_check(status, desc, flags);

+ 15 - 7
lib/dpkg/subproc.h

@@ -2,7 +2,7 @@
  * libdpkg - Debian packaging suite library routines
  * libdpkg - Debian packaging suite library routines
  * subproc.h - sub-process handling routines
  * subproc.h - sub-process handling routines
  *
  *
- * Copyright © 2008 Guillem Jover <guillem@debian.org>
+ * Copyright © 2008-2014 Guillem Jover <guillem@debian.org>
  *
  *
  * This is free software; you can redistribute it and/or modify
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * it under the terms of the GNU General Public License as published by
@@ -33,17 +33,25 @@ DPKG_BEGIN_DECLS
  * @{
  * @{
  */
  */
 
 
+enum subproc_flags {
+	/** Default subprocess flags. */
+	SUBPROC_NORMAL		= 0,
+	/** Emit a warning instead of an error. */
+	SUBPROC_WARN		= DPKG_BIT(0),
+	/** Ignore SIGPIPE, and make it return 0. */
+	SUBPROC_NOPIPE		= DPKG_BIT(1),
+	/** Do not check the subprocess status. */
+	SUBPROC_NOCHECK		= DPKG_BIT(2),
+	/** Do not emit errors, just return the exit status. */
+	SUBPROC_RETERROR	= DPKG_BIT(3),
+};
+
 void subproc_signals_ignore(const char *name);
 void subproc_signals_ignore(const char *name);
 void subproc_signals_cleanup(int argc, void **argv);
 void subproc_signals_cleanup(int argc, void **argv);
 void subproc_signals_restore(void);
 void subproc_signals_restore(void);
 
 
-#define PROCPIPE 1
-#define PROCWARN 2
-#define PROCNOERR 4
-#define PROCNOCHECK 8
-
 pid_t subproc_fork(void);
 pid_t subproc_fork(void);
-int subproc_reap(pid_t pid, const char *desc, int flags);
+int subproc_reap(pid_t pid, const char *desc, enum subproc_flags flags);
 
 
 /** @} */
 /** @} */
 
 

+ 1 - 1
lib/dpkg/test/t-command.c

@@ -197,7 +197,7 @@ test_command_shell(void)
 	pid = subproc_fork();
 	pid = subproc_fork();
 	if (pid == 0)
 	if (pid == 0)
 		command_shell("false", "command shell fail test");
 		command_shell("false", "command shell fail test");
-	ret = subproc_reap(pid, "command shell fail test", PROCNOERR);
+	ret = subproc_reap(pid, "command shell fail test", SUBPROC_RETERROR);
 	test_fail(ret == 0);
 	test_fail(ret == 0);
 
 
 	unsetenv("SHELL");
 	unsetenv("SHELL");

+ 7 - 6
lib/dpkg/test/t-subproc.c

@@ -41,38 +41,39 @@ test_subproc_fork(void)
 	pid = subproc_fork();
 	pid = subproc_fork();
 	if (pid == 0)
 	if (pid == 0)
 		exit(0);
 		exit(0);
-	ret = subproc_reap(pid, "subproc exit pass", PROCNOERR);
+	ret = subproc_reap(pid, "subproc exit pass", SUBPROC_RETERROR);
 	test_pass(ret == 0);
 	test_pass(ret == 0);
 
 
 	pid = subproc_fork();
 	pid = subproc_fork();
 	if (pid == 0)
 	if (pid == 0)
 		exit(128);
 		exit(128);
-	ret = subproc_reap(pid, "subproc exit fail", PROCNOERR);
+	ret = subproc_reap(pid, "subproc exit fail", SUBPROC_RETERROR);
 	test_pass(ret == 128);
 	test_pass(ret == 128);
 
 
 	/* Test signals. */
 	/* Test signals. */
 	pid = subproc_fork();
 	pid = subproc_fork();
 	if (pid == 0)
 	if (pid == 0)
 		raise(SIGINT);
 		raise(SIGINT);
-	ret = subproc_reap(pid, "subproc signal", PROCWARN);
+	ret = subproc_reap(pid, "subproc signal", SUBPROC_WARN);
 	test_pass(ret == -1);
 	test_pass(ret == -1);
 
 
 	pid = subproc_fork();
 	pid = subproc_fork();
 	if (pid == 0)
 	if (pid == 0)
 		raise(SIGTERM);
 		raise(SIGTERM);
-	ret = subproc_reap(pid, "subproc signal", PROCWARN);
+	ret = subproc_reap(pid, "subproc signal", SUBPROC_WARN);
 	test_pass(ret == -1);
 	test_pass(ret == -1);
 
 
 	pid = subproc_fork();
 	pid = subproc_fork();
 	if (pid == 0)
 	if (pid == 0)
 		raise(SIGPIPE);
 		raise(SIGPIPE);
-	ret = subproc_reap(pid, "subproc SIGPIPE", PROCWARN | PROCPIPE);
+	ret = subproc_reap(pid, "subproc SIGPIPE",
+	                   SUBPROC_WARN | SUBPROC_NOPIPE);
 	test_pass(ret == 0);
 	test_pass(ret == 0);
 
 
 	pid = subproc_fork();
 	pid = subproc_fork();
 	if (pid == 0)
 	if (pid == 0)
 		raise(SIGPIPE);
 		raise(SIGPIPE);
-	ret = subproc_reap(pid, "subproc SIGPIPE", PROCWARN);
+	ret = subproc_reap(pid, "subproc SIGPIPE", SUBPROC_WARN);
 	test_pass(ret == -1);
 	test_pass(ret == -1);
 }
 }
 
 

+ 1 - 1
src/archives.c

@@ -1616,7 +1616,7 @@ archivefiles(const char *const *argv)
     }
     }
     if (ferror(pf)) ohshite(_("error reading find's pipe"));
     if (ferror(pf)) ohshite(_("error reading find's pipe"));
     if (fclose(pf)) ohshite(_("error closing find's pipe"));
     if (fclose(pf)) ohshite(_("error closing find's pipe"));
-    rc = subproc_reap(pid, "find", PROCNOERR);
+    rc = subproc_reap(pid, "find", SUBPROC_RETERROR);
     if (rc != 0)
     if (rc != 0)
       ohshit(_("find for --recursive returned unhandled error %i"), rc);
       ohshit(_("find for --recursive returned unhandled error %i"), rc);
 
 

+ 2 - 2
src/configure.c

@@ -212,7 +212,7 @@ show_diff(const char *old, const char *new)
 	}
 	}
 
 
 	/* Parent process. */
 	/* Parent process. */
-	subproc_reap(pid, _("conffile difference visualizer"), PROCNOCHECK);
+	subproc_reap(pid, _("conffile difference visualizer"), SUBPROC_NOCHECK);
 }
 }
 
 
 /**
 /**
@@ -242,7 +242,7 @@ spawn_shell(const char *confold, const char *confnew)
 	}
 	}
 
 
 	/* Parent process. */
 	/* Parent process. */
-	subproc_reap(pid, _("conffile shell"), PROCNOCHECK);
+	subproc_reap(pid, _("conffile shell"), SUBPROC_NOCHECK);
 }
 }
 
 
 /**
 /**

+ 1 - 1
src/script.c

@@ -328,7 +328,7 @@ maintscript_fallback(struct pkginfo *pkg,
 		warning(_("unable to stat %s '%.250s': %s"),
 		warning(_("unable to stat %s '%.250s': %s"),
 		        cmd.name, oldscriptpath, strerror(errno));
 		        cmd.name, oldscriptpath, strerror(errno));
 	} else {
 	} else {
-		if (!maintscript_exec(pkg, &pkg->installed, &cmd, &stab, PROCWARN)) {
+		if (!maintscript_exec(pkg, &pkg->installed, &cmd, &stab, SUBPROC_WARN)) {
 			command_destroy(&cmd);
 			command_destroy(&cmd);
 			post_script_tasks();
 			post_script_tasks();
 			return 1;
 			return 1;

+ 3 - 3
src/unpack.c

@@ -103,7 +103,7 @@ deb_reassemble(const char **filename, const char **pfilename)
     ohshite(_("unable to execute %s (%s)"),
     ohshite(_("unable to execute %s (%s)"),
             _("split package reassembly"), SPLITTER);
             _("split package reassembly"), SPLITTER);
   }
   }
-  status = subproc_reap(pid, SPLITTER, PROCNOERR);
+  status = subproc_reap(pid, SPLITTER, SUBPROC_RETERROR);
   switch (status) {
   switch (status) {
   case 0:
   case 0:
     /* It was a part - is it complete? */
     /* It was a part - is it complete? */
@@ -145,7 +145,7 @@ deb_verify(const char *filename)
   } else {
   } else {
     int status;
     int status;
 
 
-    status = subproc_reap(pid, "debsig-verify", PROCNOCHECK);
+    status = subproc_reap(pid, "debsig-verify", SUBPROC_NOCHECK);
     if (!(WIFEXITED(status) && WEXITSTATUS(status) == 0)) {
     if (!(WIFEXITED(status) && WEXITSTATUS(status) == 0)) {
       if (!fc_badverify)
       if (!fc_badverify)
         ohshit(_("verification on package %s failed!"), filename);
         ohshit(_("verification on package %s failed!"), filename);
@@ -978,7 +978,7 @@ void process_archive(const char *filename) {
     ohshit(_("cannot zap possible trailing zeros from dpkg-deb: %s"), err.str);
     ohshit(_("cannot zap possible trailing zeros from dpkg-deb: %s"), err.str);
   close(p1[0]);
   close(p1[0]);
   p1[0] = -1;
   p1[0] = -1;
-  subproc_reap(pid, BACKEND " --fsys-tarfile", PROCPIPE);
+  subproc_reap(pid, BACKEND " --fsys-tarfile", SUBPROC_NOPIPE);
 
 
   tar_deferred_extract(newfileslist, pkg);
   tar_deferred_extract(newfileslist, pkg);