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);
static void VM_CharHandler(void);
-static bool VM_ThreadLoop(void)
+bool VM_ThreadLoop(void)
{
int res;
fd_set readfds;
#ifdef UCLINUX
fprintf(stdout, _(
-" gnokii --gnokiid [--debug]\n"
+" gnokii --gnokiid [--debug] [<child to run> [<child args>...]]\n"
));
#endif
#endif /* UCLINUX */
#ifdef UCLINUX
- { OPT_GNOKIID, 0, 1, 0 },
+ { OPT_GNOKIID, 0, INT_MAX, 0 },
#endif /* UCLINUX */
{ 0, 0, 0, 0 },
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)) {
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)
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;