#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/wait.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
g_kbdfd = -1;
}
-int main(int argc, char *argv[])
+static void do_exec(char * const argv[])
{
- pthread_t tid;
- char *cmd, *p;
- int len = 0;
- int ret;
- int i;
+ int ret, status;
+ pid_t pid;
- for (i = 1; i < argc; i++)
- len += strlen(argv[i]) + 1;
+ pid = fork();
+ if (pid == -1) {
+ perror(PFX "fork");
+ return;
+ }
- cmd = malloc(len);
- if (cmd == NULL)
- {
- fprintf(stderr, PFX "OOM\n");
- return 1;
+ if (pid == 0) {
+ /* child */
+ execvp(argv[0], argv);
+ perror(PFX "execvp");
+ exit(1);
}
- /* rebuild command line for program we launch */
- for (p = cmd, i = 1; i < argc; i++) {
- strcpy(p, argv[i]);
- p += strlen(p);
+ ret = waitpid(pid, &status, 0);
+ if (ret < 0)
+ perror(PFX "waitpid");
+}
- if (i < argc - 1)
- *p++ = ' ';
- }
+int main(int argc, char *argv[])
+{
+ pthread_t tid;
+ int ret;
ret = pthread_create(&tid, NULL, x11_handler, NULL);
if (ret != 0) {
hidecon_start();
- ret = system(cmd);
- if (ret == -1)
- perror(PFX "system");
- free(cmd);
+ do_exec(argv + 1);
hidecon_end();