From: short <> Date: Sun, 3 Mar 2002 02:08:41 +0000 (+0000) Subject: Implemented --gnokiid arguments for child spawning, not tested yet X-Git-Tag: uc_works1~21 X-Git-Url: https://git.jankratochvil.net/?p=gnokii.git;a=commitdiff_plain;h=e434e7467e6c831f5b00f166483764f6f7649828 Implemented --gnokiid arguments for child spawning, not tested yet --- diff --git a/common/data/virtmodem.c b/common/data/virtmodem.c index 6b6d61a..bcedc7e 100644 --- a/common/data/virtmodem.c +++ b/common/data/virtmodem.c @@ -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; 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; diff --git a/include/data/virtmodem.h b/include/data/virtmodem.h index a619e54..1d80fc6 100644 --- a/include/data/virtmodem.h +++ b/include/data/virtmodem.h @@ -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 */ diff --git a/include/uccompat.h b/include/uccompat.h index 2dab590..fa3a2b7 100644 --- a/include/uccompat.h +++ b/include/uccompat.h @@ -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 */