summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/calcurse.h2
-rw-r--r--src/day.c3
-rw-r--r--src/todo.c3
-rw-r--r--src/utils.c43
4 files changed, 45 insertions, 6 deletions
diff --git a/src/calcurse.h b/src/calcurse.h
index 5165f25..dad9f44 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -930,7 +930,7 @@ void str_toupper (char *);
void file_close (FILE *, const char *);
void psleep (unsigned);
int fork_exec (int *, int *, const char *, const char *const *);
-int shell_exec (int *, int *, const char *);
+int shell_exec (int *, int *, const char *, const char *const *);
int child_wait (int *, int *, int);
void press_any_key (void);
void print_apoint (const char *, long, struct apoint *);
diff --git a/src/day.c b/src/day.c
index 43a5aec..ab362c0 100644
--- a/src/day.c
+++ b/src/day.c
@@ -1180,6 +1180,7 @@ void
day_pipe_item (void)
{
char cmd[BUFSIZ] = "";
+ char const *arg[] = { cmd, NULL };
int pout;
int pid;
FILE *fpout;
@@ -1196,7 +1197,7 @@ day_pipe_item (void)
return;
wins_prepare_external ();
- if ((pid = shell_exec (NULL, &pout, cmd)))
+ if ((pid = shell_exec (NULL, &pout, *arg, arg)))
{
fpout = fdopen (pout, "w");
diff --git a/src/todo.c b/src/todo.c
index 24bcec6..50180f4 100644
--- a/src/todo.c
+++ b/src/todo.c
@@ -469,6 +469,7 @@ void
todo_pipe_item (void)
{
char cmd[BUFSIZ] = "";
+ char const *arg[] = { cmd, NULL };
int pout;
int pid;
FILE *fpout;
@@ -479,7 +480,7 @@ todo_pipe_item (void)
return;
wins_prepare_external ();
- if ((pid = shell_exec (NULL, &pout, cmd)))
+ if ((pid = shell_exec (NULL, &pout, *arg, arg)))
{
fpout = fdopen (pout, "w");
diff --git a/src/utils.c b/src/utils.c
index d9f3737..36abb30 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -1015,10 +1015,47 @@ fork_exec (int *pfdin, int *pfdout, const char *path, const char *const *arg)
/* Execute an external program in a shell. */
int
-shell_exec (int *pfdin, int *pfdout, const char *cmd)
+shell_exec (int *pfdin, int *pfdout, const char *path, const char *const *arg)
{
- const char *arg[] = { "/bin/sh", "-c", cmd, NULL };
- return fork_exec (pfdin, pfdout, *arg, arg);
+ int argc, i;
+ const char **narg;
+ char *arg0 = NULL;
+ int ret;
+
+ for (argc = 0; arg[argc]; argc++)
+ ;
+
+ if (argc < 1)
+ return -1;
+
+ narg = mem_calloc (argc + 4, sizeof (const char *));
+
+ narg[0] = "sh";
+ narg[1] = "-c";
+
+ if (argc > 1)
+ {
+ arg0 = mem_malloc (strlen (path) + 6);
+ sprintf (arg0, "%s \"$@\"", path);
+ narg[2] = arg0;
+
+ for (i = 0; i < argc; i++)
+ narg[i + 3] = arg[i];
+ narg[argc + 3] = NULL;
+ }
+ else
+ {
+ narg[2] = path;
+ narg[3] = NULL;
+ }
+
+ ret = fork_exec (pfdin, pfdout, *narg, narg);
+
+ if (arg0)
+ mem_free (arg0);
+ mem_free (narg);
+
+ return ret;
}
/* Wait for a child process to terminate. */