Просмотр исходного кода

dpkg: Use command_shell() instead of ad-hoc code to execute shells

Guillem Jover лет назад: 15
Родитель
Сommit
a7df7bc856
2 измененных файлов с 5 добавлено и 21 удалено
  1. 2 3
      dpkg-deb/extract.c
  2. 3 18
      src/configure.c

+ 2 - 3
dpkg-deb/extract.c

@@ -42,6 +42,7 @@
 #include <dpkg/dpkg.h>
 #include <dpkg/buffer.h>
 #include <dpkg/subproc.h>
+#include <dpkg/command.h>
 #include <dpkg/compress.h>
 #include <dpkg/ar.h>
 #include <dpkg/myopt.h>
@@ -55,9 +56,7 @@ static void movecontrolfiles(const char *thing) {
   sprintf(buf, "mv %s/* . && rmdir %s", thing, thing);
   c1 = subproc_fork();
   if (!c1) {
-    execlp("sh", "sh", "-c", buf, NULL);
-    ohshite(_("unable to execute %s (%s)"),
-            _("shell command to move files"), buf);
+    command_shell(buf, _("shell command to move files"));
   }
   subproc_wait_check(c1, _("shell command to move files"), 0);
 }

+ 3 - 18
src/configure.c

@@ -45,6 +45,7 @@
 #include <dpkg/buffer.h>
 #include <dpkg/file.h>
 #include <dpkg/subproc.h>
+#include <dpkg/command.h>
 #include <dpkg/triglib.h>
 
 #include "filesdb.h"
@@ -502,7 +503,6 @@ showdiff(const char *old, const char *new)
 	if (!pid) {
 		/* Child process. */
 		const char *pager;
-		const char *shell;
 		char cmdbuf[1024];
 
 		pager = getenv(PAGERENV);
@@ -512,13 +512,7 @@ showdiff(const char *old, const char *new)
 		sprintf(cmdbuf, DIFF " -Nu %.250s %.250s | %.250s",
 		        old, new, pager);
 
-		shell = getenv(SHELLENV);
-		if (!shell || !*shell)
-			shell = DEFAULTSHELL;
-
-		execlp(shell, shell, "-c", cmdbuf, NULL);
-		ohshite(_("unable to execute %s (%s)"),
-		        _("conffile difference visualizer"), cmdbuf);
+		command_shell(cmdbuf, _("conffile difference visualizer"));
 	}
 
 	/* Parent process. */
@@ -543,21 +537,12 @@ spawn_shell(const char *confold, const char *confnew)
 
 	pid = subproc_fork();
 	if (!pid) {
-		/* Child process */
-		const char *shell;
-
-		shell = getenv(SHELLENV);
-		if (!shell || !*shell)
-			shell = DEFAULTSHELL;
-
 		/* Set useful variables for the user. */
 		setenv("DPKG_SHELL_REASON", "conffile-prompt", 1);
 		setenv("DPKG_CONFFILE_OLD", confold, 1);
 		setenv("DPKG_CONFFILE_NEW", confnew, 1);
 
-		execlp(shell, shell, "-i", NULL);
-		ohshite(_("unable to execute %s (%s)"),
-		        _("conffile shell"), shell);
+		command_shell(NULL, _("conffile shell"));
 	}
 
 	/* Parent process. */