Changeset 8481 for trunk/tools


Ignore:
Timestamp:
May 24, 2002, 3:57:58 AM (23 years ago)
Author:
bird
Message:

Another try..

File:
1 edited

Legend:

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

    r8480 r8481  
    1 /* $Id: CmdQd.c,v 1.15 2002-05-24 01:11:35 bird Exp $
     1/* $Id: CmdQd.c,v 1.16 2002-05-24 01:57:58 bird Exp $
    22 *
    33 * Command Queue Daemon / Client.
     
    14471447            RESULTCODES Res;
    14481448            PID         pid;
    1449             HFILE       hStdIn = HF_STDIN;
    1450             HFILE       hStdOut = HF_STDOUT;
    1451             HFILE       hStdErr = HF_STDERR;
    1452             HFILE       hStdInSave = -1;
    1453             HFILE       hStdOutSave = -1;
    1454             HFILE       hStdErrSave = -1;
    14551449            HPIPE       hPipeR = NULLHANDLE;
    1456             HPIPE       hPipeW = NULLHANDLE;
     1450            HPIPE       hPipeW = HF_STDOUT;
    14571451
    14581452            //printf("debug-%d: start %s\n", iWorkerId, pJob->JobInfo.szCommand);
     
    14631457            WorkerArguments(&szArg[0], &pJob->JobInfo.szzEnv[0], &pJob->JobInfo.szCommand[0],
    14641458                            &pJob->JobInfo.szCurrentDir[0], &PathCache);
    1465             rc = DosCreatePipe(&hPipeR, &hPipeW, sizeof(pJobOutput->szOutput) - 1);
    1466             if (rc)
    1467             {
    1468                 Error("Internal Error: Failed to create pipe! rc=%d\n", rc);
    1469                 return;
    1470             }
    1471 
    1472             if (DosRequestMutexSem(hmtxExec, SEM_INDEFINITE_WAIT))
    1473             {
    1474                 DosClose(hPipeR);
    1475                 DosClose(hPipeW);
    1476                 return;
    1477             }
    1478 
    14791459            pJob->pJobOutput = pJobOutput = pJobOutputLast = malloc(sizeof(JOBOUTPUT));
    14801460            pJobOutput->pNext = NULL;
    14811461            pJobOutput->cchOutput = sprintf(pJobOutput->szOutput, "Job: %s\n", pJob->JobInfo.szCommand);
     1462
     1463            if (DosRequestMutexSem(hmtxExec, SEM_INDEFINITE_WAIT))
     1464            {
     1465                Error("Internal Error: Failed to take exec mutex! rc=%d\n", rc);
     1466                return;
     1467            }
     1468
     1469            rc = DosCreatePipe(&hPipeR, &hPipeW, sizeof(pJobOutput->szOutput) - 1);
     1470            if (rc)
     1471            {
     1472                DosReleaseMutexSem(hmtxExec);
     1473                Error("Internal Error: Failed to create pipe! rc=%d\n", rc);
     1474                return;
     1475            }
    14821476
    14831477            rc = DosSetDefaultDisk(  pJob->JobInfo.szCurrentDir[0] >= 'a'
     
    14871481            if (!rc)
    14881482            {
     1483                static BOOL fStdClosed = FALSE;
     1484                HFILE   hStdErr = HF_STDERR;
    14891485                assert(   pJob->JobInfo.szzEnv[pJob->JobInfo.cchEnv-1] == '\0'
    14901486                       && pJob->JobInfo.szzEnv[pJob->JobInfo.cchEnv-2] == '\0');
    1491                 DosDupHandle(HF_STDIN, &hStdInSave);
    1492                 DosDupHandle(HF_STDOUT, &hStdOutSave);
    1493                 DosDupHandle(HF_STDERR, &hStdErrSave);
    1494                 DosDupHandle(hPipeW, &hStdOut);
     1487                if (!fStdClosed)
     1488                {   /* only do this once! */
     1489                    DosClose(HF_STDIN);
     1490                    DosClose(HF_STDOUT);
     1491                    DosClose(HF_STDERR);
     1492                    fStdClosed = TRUE;
     1493                }
    14951494                DosDupHandle(hPipeW, &hStdErr);
    1496                 DosClose(HF_STDIN);
    14971495                DosSetFHState(hPipeR, OPEN_FLAGS_NOINHERIT);
    1498                 DosSetFHState(hPipeW, OPEN_FLAGS_NOINHERIT);
    1499                 DosSetFHState(hStdInSave, OPEN_FLAGS_NOINHERIT);
    1500                 DosSetFHState(hStdOutSave, OPEN_FLAGS_NOINHERIT);
    1501                 DosSetFHState(hStdErrSave, OPEN_FLAGS_NOINHERIT);
    15021496                rc = DosExecPgm(szObj, sizeof(szObj), EXEC_ASYNCRESULT,
    15031497                                szArg, pJob->JobInfo.szzEnv, &Res, szArg);
    1504                 hStdIn = HF_STDIN;
    1505                 DosClose(hStdOut); hStdOut = HF_STDOUT;
    1506                 DosClose(hStdErr); hStdErr = HF_STDERR;
    1507                 DosDupHandle(hStdInSave, &hStdIn);
    1508                 DosDupHandle(hStdOutSave, &hStdOut);
    1509                 DosDupHandle(hStdErrSave, &hStdErr);
    1510                 DosClose(hStdInSave);
    1511                 DosClose(hStdOutSave);
    1512                 DosClose(hStdErrSave);
     1498                DosClose(hPipeW);
     1499                DosClose(hStdErr);
    15131500                DosReleaseMutexSem(hmtxExec);
    1514                 DosClose(hPipeW);
    15151501
    15161502
     
    26392625{
    26402626    va_list arg;
    2641 
     2627    /* won't workin in daemon mode... */
    26422628    va_start(arg, pszFormat);
    2643     vfprintf(stdout, pszFormat, arg);
     2629    if (vfprintf(stdout, pszFormat, arg) <= 0)
     2630    {
     2631        FILE *phFile = fopen(".\\cmdqd.log", "a+");
     2632        if (phFile)
     2633        {
     2634            fprintf(phFile, "%d:", getpid());
     2635            vfprintf(phFile, pszFormat, arg);
     2636            fclose(phFile);
     2637        }
     2638    }
    26442639    va_end(arg);
    26452640}
Note: See TracChangeset for help on using the changeset viewer.