222
223
wait_on_exec(struct extensible *ex)
225
#if defined(WIN32) && !defined (mingw32)
227
if (ex->tid != 0 && ex->pid != 0) {
228
HANDLE hThread = (HANDLE) ex->tid;
229
HANDLE hProcess = (HANDLE) ex->pid;
230
rc = WaitForSingleObject(hProcess, NETSNMP_TIMEOUT_WAITFORSINGLEOBJECT);
231
DEBUGMSGT(("exec:wait_on_exec","WaitForSingleObject rc=(%d)\n",rc ));
232
rc = CloseHandle( hThread );
233
DEBUGMSGT(("exec:wait_on_exec","CloseHandle hThread=(%d)\n",rc ));
234
rc = CloseHandle( hProcess );
235
DEBUGMSGT(("exec:wait_on_exec","CloseHandle hProcess=(%d)\n",rc ));
240
#ifndef NETSNMP_EXCACHETIME
225
241
if (ex->pid && waitpid(ex->pid, &ex->result, 0) < 0) {
226
242
setPerrorstatus("waitpid");
245
#endif /* NETSNMP_EXCACHETIME */
232
249
#define MAXARGS 30
248
265
DEBUGMSGTL(("exec:get_exec_output","calling %s\n", ex->command));
250
sprintf(cachefile, "%s/%s", get_persistent_directory(), CACHEFILE);
267
sprintf(cachefile, "%s/%s", get_persistent_directory(), NETSNMP_CACHEFILE);
268
#ifdef NETSNMP_EXCACHETIME
252
269
curtime = time(NULL);
253
if (curtime > (cachetime + EXCACHETIME) ||
270
if (curtime > (cachetime + NETSNMP_EXCACHETIME) ||
254
271
strcmp(ex->command, lastcmd) != 0) {
255
272
strcpy(lastcmd, ex->command);
256
273
cachetime = curtime;
259
cachebytes = MAXCACHESIZE;
276
cachebytes = NETSNMP_MAXCACHESIZE;
260
277
ex->result = run_exec_command( ex->command, NULL, cache, &cachebytes );
262
279
unlink(cachefile);
362
379
/* Set global child process handle */
363
380
ex->pid = (int)pi.hProcess;
381
ex->tid = (int)pi.hThread;
365
383
/* Close pipe handles to make sure that no handles to the write end of the
366
384
* output pipe are maintained in this process or else the pipe will
386
403
get_exec_pipes(char *cmd, int *fdIn, int *fdOut, int *pid)
405
/* Alexander Prömel, alexander@proemel.de 08/24/2006
406
The following code, is tested on picotux rev. 1.01.
407
I think, it will be better to put the named pipes, into /var/run or make it selectable via CONFIG file.
408
If the pipe file already exist, the creation will fail.
409
I put the pipes into /flash, the pipepath has to change in ucd-snmp/pass_persist.c too, if you change it here.
412
#ifdef __uClinux__ /* HAVE uClinux */
414
char fifo_in_path[256];
415
char fifo_out_path[256];
418
if ((tpid = vfork()) == 0) { /*temp child*/
419
execve(cmd, NULL,NULL);
424
/*initialize workspace*/
425
snprintf(fifo_in_path, 256, "/flash/cp_%d", tpid);
426
snprintf(fifo_out_path, 256, "/flash/pc_%d", tpid);
428
in = mkfifo(fifo_in_path, S_IRWXU); /*Create Input Pipe, 700*/
430
perror("parent: inpipe");
433
out = mkfifo(fifo_out_path, S_IRWXU); /*Create Output Pipe, 700*/
435
perror("parent: outpipe");
439
in = open(fifo_in_path,O_RDONLY); /*open the Input Pipe read Only*/
441
perror("parent: input");
444
out = open(fifo_out_path,O_WRONLY); /*open the Output Pipe write Only*/
446
perror("parent: output");
451
*fdOut = out; /*write*/
453
return (1); /* We are returning 0 for error... */
455
setPerrorstatus("vfork");
389
461
int fd[2][2], i, cnt;
390
462
char ctmp[STRMAX], *cptr1, *cptr2, argvs[STRMAX], **argv,
462
534
*fdOut = fd[0][1];
463
535
return (1); /* We are returning 0 for error... */
537
#endif /* uClinux or x86 */
465
538
#endif /* !HAVE_EXECV */
466
539
#if defined(WIN32) && !defined (mingw32) && !defined(HAVE_EXECV)
467
540
/* MSVC (MinGW not working but should use this code). Cygwin already works as it has execv and fork */
614
687
NETSNMP_DS_LIB_APPTYPE);
615
688
snmp_shutdown(name);
690
/* This signal handler may run with SIGALARM blocked.
691
* Since the signal mask is preserved accross execv(), we must
692
* make sure that SIGALARM is unblocked prior of execv'ing.
693
* Otherwise SIGALARM will be ignored in the next incarnation
694
* of snmpd, because the signal is blocked. And thus, the
695
* restart doesn't work anymore.