Changeset 8482 for trunk/tools
- Timestamp:
- May 24, 2002, 4:41:30 AM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/CmdQd/CmdQd.c
r8481 r8482 1 /* $Id: CmdQd.c,v 1.1 6 2002-05-24 01:57:58bird Exp $1 /* $Id: CmdQd.c,v 1.17 2002-05-24 02:41:30 bird Exp $ 2 2 * 3 3 * Command Queue Daemon / Client. … … 119 119 #include <stdlib.h> 120 120 #include <stdarg.h> 121 #include <assert.h>121 //#include <assert.h> 122 122 #include <direct.h> 123 123 #include <signal.h> … … 127 127 #include <os2.h> 128 128 129 130 /******************************************************************************* 131 * Defined Constants And Macros * 132 *******************************************************************************/ 133 #undef assert 134 //#define assert(expr) ((expr) ? (void)0, (void)0 \ 135 // : Error("assert: %s\n CmdQd.c line %d function %s\n",\ 136 // #expr, __FUNCTION__, __LINE__), __interrupt(3)) 137 #ifdef DEBUG 138 #define assert(expr) \ 139 do { if (!(expr)) { Error("assert: %s\n CmdQd.c line %d function %s\n", \ 140 #expr, __LINE__, __FUNCTION__); \ 141 __interrupt(3); } \ 142 } while (0) 143 #else 144 #define assert(expr) do { } while(0) 145 #endif 129 146 130 147 /* … … 334 351 PSZ pszSharedMem = SHARED_MEM_NAME; /* Default shared memname */ 335 352 /* Could be overridden by env.var. CMDQD_MEM_NAME. */ 353 BOOL fDaemon = FALSE; /* Set if we're the daemon. */ 336 354 337 355 /******************************************************************************* … … 558 576 { 559 577 int rc; 578 fDaemon = TRUE; 560 579 561 580 /* … … 1440 1459 if (pJob) 1441 1460 { 1461 static BOOL fStdClosed = FALSE; 1462 static HFILE hStdOutSaved = -1; 1442 1463 int rc; 1443 1464 char szArg[4096]; … … 1447 1468 RESULTCODES Res; 1448 1469 PID pid; 1449 HPIPE hPipeR = NULLHANDLE; 1450 HPIPE hPipeW = HF_STDOUT; 1470 HPIPE hPipeR = -1; 1471 HPIPE hPipeW = -1; 1472 HFILE hStdErr; 1473 HFILE hStdOut; 1451 1474 1452 1475 //printf("debug-%d: start %s\n", iWorkerId, pJob->JobInfo.szCommand); … … 1467 1490 } 1468 1491 1492 if (!fStdClosed) 1493 { /* only do this once! */ 1494 DosDupHandle(HF_STDOUT, &hStdOutSaved); 1495 DosSetFHState(hStdOutSaved, OPEN_FLAGS_NOINHERIT); /* child shall not see this handle! */ 1496 fclose(stdin); 1497 DosClose(HF_STDIN); 1498 fclose(stdout); 1499 DosClose(HF_STDOUT); 1500 fclose(stderr); 1501 DosClose(HF_STDERR); 1502 hStdOut = HF_STDOUT; 1503 DosDupHandle(hStdOutSaved, &hStdOut); 1504 hStdErr = HF_STDERR; 1505 DosDupHandle(hStdOutSaved, &hStdErr); 1506 fStdClosed = TRUE; 1507 } 1508 1469 1509 rc = DosCreatePipe(&hPipeR, &hPipeW, sizeof(pJobOutput->szOutput) - 1); 1470 1510 if (rc) … … 1474 1514 return; 1475 1515 } 1516 assert(hPipeW != HF_STDOUT && hPipeR != HF_STDERR); 1476 1517 1477 1518 rc = DosSetDefaultDisk( pJob->JobInfo.szCurrentDir[0] >= 'a' … … 1481 1522 if (!rc) 1482 1523 { 1483 static BOOL fStdClosed = FALSE;1484 HFILE hStdErr = HF_STDERR;1524 hStdErr = HF_STDERR; 1525 hStdOut = HF_STDOUT; 1485 1526 assert( pJob->JobInfo.szzEnv[pJob->JobInfo.cchEnv-1] == '\0' 1486 1527 && pJob->JobInfo.szzEnv[pJob->JobInfo.cchEnv-2] == '\0'); 1487 if (!fStdClosed) 1488 { /* only do this once! */ 1489 DosClose(HF_STDIN); 1490 DosClose(HF_STDOUT); 1491 DosClose(HF_STDERR); 1492 fStdClosed = TRUE; 1493 } 1528 DosDupHandle(hPipeW, &hStdOut); 1494 1529 DosDupHandle(hPipeW, &hStdErr); 1495 DosSetFHState(hPipeR, OPEN_FLAGS_NOINHERIT); 1530 DosClose(hPipeW); 1531 DosSetFHState(hPipeR, OPEN_FLAGS_NOINHERIT); /* child shall not see this handle... */ 1496 1532 rc = DosExecPgm(szObj, sizeof(szObj), EXEC_ASYNCRESULT, 1497 1533 szArg, pJob->JobInfo.szzEnv, &Res, szArg); 1498 DosClose(hPipeW); 1499 DosClose(hStdErr); 1534 /* Placeholders, prevents clashes... */ 1535 hStdOut = HF_STDOUT; 1536 DosDupHandle(hStdOutSaved, &hStdOut); 1537 hStdErr = HF_STDERR; 1538 DosDupHandle(hStdOutSaved, &hStdErr); 1500 1539 DosReleaseMutexSem(hmtxExec); 1501 1540 … … 2627 2666 /* won't workin in daemon mode... */ 2628 2667 va_start(arg, pszFormat); 2629 if (vfprintf(stdout, pszFormat, arg) <= 0) 2668 if (!fDaemon) 2669 vfprintf(stdout, pszFormat, arg); 2670 else 2630 2671 { 2631 2672 FILE *phFile = fopen(".\\cmdqd.log", "a+");
Note:
See TracChangeset
for help on using the changeset viewer.