mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Util
- Made arg vector const. - Applied coding conventions.
This commit is contained in:
parent
ff8bc79b8f
commit
820c327a81
2 changed files with 19 additions and 21 deletions
38
src/util.cpp
38
src/util.cpp
|
@ -389,44 +389,42 @@ void combine (std::vector <int>& dest, const std::vector <int>& source)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Run an external executable with execvp. This means stdio goes to
|
||||
// Run an external executable with execvp. This means stdio goes to
|
||||
// the child process, so that it can receive user input (e.g. passwords).
|
||||
//
|
||||
int execute(const std::string& executable, std::vector<std::string> arguments)
|
||||
int execute (const std::string& executable, const std::vector<std::string>& arguments)
|
||||
{
|
||||
if (executable == "")
|
||||
return -1;
|
||||
|
||||
// create command line before forking because the parent process also needs this for
|
||||
// calling context.debug()
|
||||
char shell[] = "sh";
|
||||
char opt[] = "-c";
|
||||
// create command line before forking because the parent process also needs this for
|
||||
// calling context.debug ()
|
||||
char shell [] = "sh";
|
||||
char opt [] = "-c";
|
||||
|
||||
std::string cmdline = executable;
|
||||
|
||||
std::vector <std::string>::iterator it;
|
||||
for (it = arguments.begin(); it != arguments.end(); ++it)
|
||||
{
|
||||
cmdline += " " + (std::string)*it;
|
||||
}
|
||||
std::vector <std::string>::const_iterator it;
|
||||
for (it = arguments.begin (); it != arguments.end (); ++it)
|
||||
cmdline += " " + (std::string) *it;
|
||||
|
||||
context.debug ("Executing: " + std::string(shell) + " " + std::string(opt) + " " + cmdline);
|
||||
context.debug ("Executing: " + std::string (shell) + " " + std::string (opt) + " " + cmdline);
|
||||
|
||||
pid_t child_pid = fork();
|
||||
pid_t child_pid = fork ();
|
||||
|
||||
if (child_pid == 0)
|
||||
{
|
||||
// this is done by the child process
|
||||
char** argv = new char*[4];
|
||||
argv[0] = shell; // sh
|
||||
argv[1] = opt; // -c
|
||||
argv[2] = (char*)cmdline.c_str(); // e.g. scp undo.data user@host:.task/
|
||||
argv[3] = NULL; // required by execv
|
||||
argv[0] = shell; // sh
|
||||
argv[1] = opt; // -c
|
||||
argv[2] = (char*) cmdline.c_str (); // e.g. scp undo.data user@host:.task/
|
||||
argv[3] = NULL; // required by execv
|
||||
|
||||
int ret = execvp(shell, argv);
|
||||
int ret = execvp (shell, argv);
|
||||
delete[] argv;
|
||||
|
||||
exit(ret);
|
||||
exit (ret);
|
||||
}
|
||||
else if (child_pid == -1)
|
||||
{
|
||||
|
@ -437,7 +435,7 @@ int execute(const std::string& executable, std::vector<std::string> arguments)
|
|||
// this is done by the parent process
|
||||
int child_status;
|
||||
|
||||
pid_t pid = waitpid(child_pid, &child_status, 0);
|
||||
pid_t pid = waitpid (child_pid, &child_status, 0);
|
||||
|
||||
if (pid == -1)
|
||||
return -1;
|
||||
|
|
|
@ -52,7 +52,7 @@ void uuid_unparse_lower (uuid_t uu, char *out);
|
|||
#endif
|
||||
const std::string uuid ();
|
||||
|
||||
int execute (const std::string&, std::vector<std::string>);
|
||||
int execute (const std::string&, const std::vector <std::string>&);
|
||||
|
||||
#ifdef SOLARIS
|
||||
#define LOCK_SH 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue