[Superkb-devel] [PATCH] Change system() to execvp() for command execution.
Status: Alpha
Brought to you by:
alvarezp
|
From: Eduardo A. B. L. <ebu...@du...> - 2010-12-11 04:06:08
|
The system() call disables the calling process until the command
is executed. This behavior generated a superkb child process
for each command executed. With execvp(), the child process is
replaced with the user's command.
---
main.c | 16 ++++++++++++----
1 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/main.c b/main.c
index 11f4dc6..7da5100 100755
--- a/main.c
+++ b/main.c
@@ -279,6 +279,10 @@ int kbwin_init(Display * dpy)
void __Superkb_Action(KeyCode keycode, unsigned int state)
{
unsigned int i;
+ char *argv [4];
+ argv[0] = "/bin/sh";
+ argv[1] = "-c";
+ argv[3] = NULL;
for (i = 0; i < config->key_bindings_n; i++) {
if (config->key_bindings[i].keycode == keycode &&
config->key_bindings[i].state == state) {
@@ -292,10 +296,12 @@ void __Superkb_Action(KeyCode keycode, unsigned int state)
strcat (cmdline, " ");
strcat (cmdline, config->key_bindings[i].feedback_string);
strcat (cmdline, " &");
- system(cmdline);
+ argv[2] = cmdline;
+ execvp(*argv, argv);
}
}
- system(config->key_bindings[i].action.command);
+ argv[2] = config->key_bindings[i].action.command;
+ execvp(*argv, argv);
exit(EXIT_SUCCESS);
}
break;
@@ -308,7 +314,8 @@ void __Superkb_Action(KeyCode keycode, unsigned int state)
strcat (cmdline, " ");
strcat (cmdline, config->key_bindings[i].feedback_string);
strcat (cmdline, " &");
- system(cmdline);
+ argv[2] = cmdline;
+ execvp(*argv, argv);
}
}
char *cmdline = malloc(strlen(config->document_handler) + strlen(config->key_bindings[i].action.document) + 2);
@@ -316,7 +323,8 @@ void __Superkb_Action(KeyCode keycode, unsigned int state)
strcpy (cmdline, config->document_handler);
strcat (cmdline, " ");
strcat (cmdline, config->key_bindings[i].action.document);
- system(cmdline);
+ argv[2] = cmdline;
+ execvp(*argv, argv);
}
exit(EXIT_SUCCESS);
}
--
1.7.2.3
|