X-Git-Url: https://git.jankratochvil.net/?p=gnokii.git;a=blobdiff_plain;f=gnokii%2Fgnokii.c;h=e6692ab28b6201b78f99f899b4efa2693b604a04;hp=fd5adadc74848bb14fe79b1313b117354bf73ce7;hb=2b49c944a1e05f99e21dff60e02bb9f2866c14a3;hpb=43f66b7662ed5c83d1cfefb84b122499b08675c3 diff --git a/gnokii/gnokii.c b/gnokii/gnokii.c index fd5adad..e6692ab 100644 --- a/gnokii/gnokii.c +++ b/gnokii/gnokii.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include #ifdef UCLINUX /* or "getopt.h" would include insufficient getopt.h from uClinux */ @@ -948,7 +950,7 @@ static int usage(void) #ifdef UCLINUX fprintf(stdout, _( -" gnokii --gnokiid [--debug]\n" +" gnokii --gnokiid [--debug] [ [...]]\n" )); #endif @@ -1232,7 +1234,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 +1282,7 @@ int main(int argc, char *argv[]) for(i = 2; i < argc; i++) nargv[i-2] = argv[i]; + nargv[argc-2] = NULL; /* required by gnokiid() for execv(3) */ if(checkargs(c, gals, nargc)) { @@ -4116,6 +4119,12 @@ int monitormode(int argc, char *argv[]) #ifdef UCLINUX +static void gnokiid_SIGCHLD(int signo) +{ + fprintf (stderr, _("Child process exited, aborting...\n")); + exit(2); +} + static int gnokiid(int argc, char *argv[]) { bool DebugMode; /* When true, run in debug mode */ @@ -4129,17 +4138,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 +4156,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 + signal(SIGCHLD,gnokiid_SIGCHLD); + errno=0; + switch (vfork()) { + case -1: /* vfork() failure */ + fprintf (stderr, _("vfork() failed! (%s)\n"),strerror(errno)); + return -1; + case 0: /* child */ + execv(*argv,argv); + fprintf (stderr, _("Spawn of child process failed! (%s)\n"),strerror(errno)); + _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;