X-Git-Url: https://git.jankratochvil.net/?p=gnokii.git;a=blobdiff_plain;f=gnokii%2Fgnokii.c;h=9b94644078a2cb38e3ca6e4e339ee81d8886a57e;hp=fd5adadc74848bb14fe79b1313b117354bf73ce7;hb=e434e7467e6c831f5b00f166483764f6f7649828;hpb=945be3cc1ae0f7739a3d28722d07f7d17b2690bf diff --git a/gnokii/gnokii.c b/gnokii/gnokii.c index fd5adad..9b94644 100644 --- a/gnokii/gnokii.c +++ b/gnokii/gnokii.c @@ -948,7 +948,7 @@ static int usage(void) #ifdef UCLINUX fprintf(stdout, _( -" gnokii --gnokiid [--debug]\n" +" gnokii --gnokiid [--debug] [ [...]]\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;