Changeset 8482 for trunk/tools


Ignore:
Timestamp:
May 24, 2002, 4:41:30 AM (23 years ago)
Author:
bird
Message:

Last try. Now it should work!!!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/CmdQd/CmdQd.c

    r8481 r8482  
    1 /* $Id: CmdQd.c,v 1.16 2002-05-24 01:57:58 bird Exp $
     1/* $Id: CmdQd.c,v 1.17 2002-05-24 02:41:30 bird Exp $
    22 *
    33 * Command Queue Daemon / Client.
     
    119119#include <stdlib.h>
    120120#include <stdarg.h>
    121 #include <assert.h>
     121//#include <assert.h>
    122122#include <direct.h>
    123123#include <signal.h>
     
    127127#include <os2.h>
    128128
     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
    129146
    130147/*
     
    334351PSZ         pszSharedMem = SHARED_MEM_NAME; /* Default shared memname */
    335352                                        /* Could be overridden by env.var. CMDQD_MEM_NAME. */
     353BOOL        fDaemon = FALSE;            /* Set if we're the daemon. */
    336354
    337355/*******************************************************************************
     
    558576{
    559577    int     rc;
     578    fDaemon = TRUE;
    560579
    561580    /*
     
    14401459        if (pJob)
    14411460        {
     1461            static BOOL  fStdClosed = FALSE;
     1462            static HFILE hStdOutSaved = -1;
    14421463            int         rc;
    14431464            char        szArg[4096];
     
    14471468            RESULTCODES Res;
    14481469            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;
    14511474
    14521475            //printf("debug-%d: start %s\n", iWorkerId, pJob->JobInfo.szCommand);
     
    14671490            }
    14681491
     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
    14691509            rc = DosCreatePipe(&hPipeR, &hPipeW, sizeof(pJobOutput->szOutput) - 1);
    14701510            if (rc)
     
    14741514                return;
    14751515            }
     1516            assert(hPipeW != HF_STDOUT && hPipeR != HF_STDERR);
    14761517
    14771518            rc = DosSetDefaultDisk(  pJob->JobInfo.szCurrentDir[0] >= 'a'
     
    14811522            if (!rc)
    14821523            {
    1483                 static BOOL fStdClosed = FALSE;
    1484                 HFILE   hStdErr = HF_STDERR;
     1524                hStdErr = HF_STDERR;
     1525                hStdOut = HF_STDOUT;
    14851526                assert(   pJob->JobInfo.szzEnv[pJob->JobInfo.cchEnv-1] == '\0'
    14861527                       && 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);
    14941529                DosDupHandle(hPipeW, &hStdErr);
    1495                 DosSetFHState(hPipeR, OPEN_FLAGS_NOINHERIT);
     1530                DosClose(hPipeW);
     1531                DosSetFHState(hPipeR, OPEN_FLAGS_NOINHERIT); /* child shall not see this handle... */
    14961532                rc = DosExecPgm(szObj, sizeof(szObj), EXEC_ASYNCRESULT,
    14971533                                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);
    15001539                DosReleaseMutexSem(hmtxExec);
    15011540
     
    26272666    /* won't workin in daemon mode... */
    26282667    va_start(arg, pszFormat);
    2629     if (vfprintf(stdout, pszFormat, arg) <= 0)
     2668    if (!fDaemon)
     2669        vfprintf(stdout, pszFormat, arg);
     2670    else
    26302671    {
    26312672        FILE *phFile = fopen(".\\cmdqd.log", "a+");
Note: See TracChangeset for help on using the changeset viewer.