Implemented --gnokiid arguments for child spawning, not tested yet
authorshort <>
Sun, 3 Mar 2002 02:08:41 +0000 (02:08 +0000)
committershort <>
Sun, 3 Mar 2002 02:08:41 +0000 (02:08 +0000)
common/data/virtmodem.c
gnokii/gnokii.c
include/data/virtmodem.h
include/uccompat.h

index 6b6d61a..bcedc7e 100644 (file)
@@ -64,7 +64,6 @@ int           PtyWRFD;        /* pty interface - only different in debug mode. */
 static bool    UseSTDIO;       /* Use STDIO for debugging purposes instead of pty */
 bool   CommandMode;
 
-static bool    VM_ThreadLoop(void);
 static GSM_Error       VM_GSMInitialise(char *model, char *port, char *initlength, GSM_ConnectionType connection, char *synchronizetime);
 static int             VM_PtySetup(char *bindir);
 
@@ -114,7 +113,7 @@ bool VM_Initialise(char *model,char *port, char *initlength, GSM_ConnectionType
 
 static void    VM_CharHandler(void);
 
-static bool VM_ThreadLoop(void)
+bool VM_ThreadLoop(void)
 {
        int res;
        fd_set readfds;
index fd5adad..9b94644 100644 (file)
@@ -948,7 +948,7 @@ static int usage(void)
 
 #ifdef UCLINUX
   fprintf(stdout, _(
-"          gnokii --gnokiid [--debug]\n"
+"          gnokii --gnokiid [--debug] [<child to run> [<child args>...]]\n"
   ));
 #endif
 
@@ -1232,7 +1232,7 @@ int main(int argc, char *argv[])
 #endif /* UCLINUX */
 
 #ifdef UCLINUX
-    { OPT_GNOKIID,           0, 1, 0 },
+    { OPT_GNOKIID,           0, INT_MAX, 0 },
 #endif /* UCLINUX */
 
     { 0, 0, 0, 0 },
@@ -1280,6 +1280,7 @@ int main(int argc, char *argv[])
 
     for(i = 2; i < argc; i++)
       nargv[i-2] = argv[i];
+               nargv[argc] = NULL;     /* required by gnokiid() for execv(3) */
        
     if(checkargs(c, gals, nargc)) {
 
@@ -4129,17 +4130,16 @@ static int gnokiid(int argc, char *argv[])
        DebugMode = false;
        if(argc>0)
        {
-               if( strcmp(argv[0],"--debug" ))
+               if( !strcmp(argv[0],"--debug" ))
                {
-                       usage();
-                       return -1;
-               }
-               else
                        DebugMode = true;
+                       argv++;
+                       argc--;
+               }
        }
 
 #ifdef DEBUG
-  fprintf (stderr, _("Entering gnokiid mode...\n"));
+  fprintf (stderr, _("Initializing gnokiid mode...\n"));
 #endif
 
        if (CFG_ReadConfig(&Model, &Port, &Initlength, &Connection, &BinDir, true) < 0)
@@ -4148,6 +4148,33 @@ static int gnokiid(int argc, char *argv[])
   if (VM_Initialise(Model, Port, Initlength, GCT_FBUS, BinDir, DebugMode, true, ""/*SynchronizeTime*/) == false)
                return (-1);
 
+       if (argc>0) {
+#ifdef DEBUG
+               fprintf (stderr, _("Spawning gnokiid startup child process \"%s\"...\n"), *argv);
+#endif
+               /* default action for SIGCHLD is SIG_IGN, should be OK */
+               errno=0;
+               switch (vfork()) {
+                       case -1: /* vfork() failure */
+                               fprintf (stderr, _("vfork() failed! (%m)\n"));
+                               return -1;
+                       case 0: /* child */
+                               execv(*argv,argv);
+                               fprintf (stderr, _("Spawn of child process failed! (%m)\n"));
+                               _exit(9);
+                               break;
+                       default: /* parent */
+                               /* PASSTHRU */
+                               break;
+                       }
+               }
+
+#ifdef DEBUG
+  fprintf (stderr, _("Entering gnokiid virtual modem main loop...\n"));
+#endif
+
+       VM_ThreadLoop();
+
        VM_Terminate();
 
   return 0;
index a619e54..1d80fc6 100644 (file)
@@ -24,5 +24,6 @@ extern bool VM_Initialise(char *model,
                   bool GSM_Init,
                   char *synchronizetime);
 extern void VM_Terminate(void);
+extern bool    VM_ThreadLoop(void);
 
 #endif /* __virtmodem_h */
index 2dab590..fa3a2b7 100644 (file)
@@ -34,6 +34,7 @@ extern char * strchr __P ((const char *, int));
 extern char * strrchr __P ((const char *, int));
 
 extern pid_t getpid(void);
+extern int execv(const char *path, char *const argv[]);
 
 
 #endif /* UCCOMPAT */