flasher: use nanddump to avoid dep on mtdblock
[pandora-misc.git] / op_runfbapp.c
index 2e480e4..8488aaa 100644 (file)
@@ -33,6 +33,7 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/wait.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/ioctl.h>
@@ -167,32 +168,33 @@ static void hidecon_end(void)
        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) {
@@ -203,10 +205,7 @@ int main(int argc, char *argv[])
 
        hidecon_start();
 
-       ret = system(cmd);
-       if (ret == -1)
-               perror(PFX "system");
-       free(cmd);
+       do_exec(argv + 1);
 
        hidecon_end();