The following commit has been merged in the master branch:
commit 7f9153a39ef306cb2181cd96c6e7a8f8513414b7
Author: Guillem Jover <[email protected]>
Date: Thu Nov 4 19:10:23 2010 +0100
libdpkg: Add new command_shell() to execute a shell instance
The function can invoke an interactive shell or a command through the
shell.
diff --git a/lib/dpkg/command.c b/lib/dpkg/command.c
index a16d5d6..98b4acd 100644
--- a/lib/dpkg/command.c
+++ b/lib/dpkg/command.c
@@ -181,3 +181,29 @@ command_exec(struct command *cmd)
execvp(cmd->filename, (char * const *)cmd->argv);
ohshite(_("unable to execute %s (%s)"), cmd->name, cmd->filename);
}
+
+/**
+ * Execute a shell with a possible command.
+ *
+ * @param cmd The command string to execute, if it's NULL an interactive
+ * shell will be executed instead.
+ * @param name The description of the command to execute.
+ */
+void
+command_shell(const char *cmd, const char *name)
+{
+ const char *shell;
+ const char *mode;
+
+ shell = getenv(SHELLENV);
+ if (shell == NULL || shell[0] == '\0')
+ shell = DEFAULTSHELL;
+
+ if (cmd == NULL)
+ mode = "-i";
+ else
+ mode = "-c";
+
+ execlp(shell, shell, mode, cmd, NULL);
+ ohshite(_("unable to execute %s (%s)"), name, cmd);
+}
diff --git a/lib/dpkg/command.h b/lib/dpkg/command.h
index 25e509f..a05cc52 100644
--- a/lib/dpkg/command.h
+++ b/lib/dpkg/command.h
@@ -48,6 +48,8 @@ void command_add_args(struct command *cmd, ...)
DPKG_ATTR_SENTINEL;
void command_exec(struct command *cmd) DPKG_ATTR_NORET;
+void command_shell(const char *cmd, const char *name);
+
DPKG_END_DECLS
#endif /* LIBDPKG_COMMAND_H */
--
dpkg's main repository
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]