Changeset 1723 for trunk/src


Ignore:
Timestamp:
Dec 9, 2004, 9:19:34 AM (21 years ago)
Author:
bird
Message:

Fixed wait*() WNOHANG bug and cleanedup some errorcode stuff. Switched wait4 and waitpid - wait4 is the master now.

Location:
trunk/src/emx/src/lib
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/src/lib/process/wait.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1722 r1723  
    5050     * Just pass it along to waitpid.
    5151     */
    52     pid_t pid = waitpid(-1, piStatus, 0);
     52    pid_t pid = wait4(-1, piStatus, 0, NULL);
    5353    if (pid > 0)
    5454        LIBCLOG_RETURN_MSG(pid, "ret %d (%#x) iStatus=%#x\n", pid, pid, piStatus ? *piStatus : -1);
  • trunk/src/emx/src/lib/process/wait4.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1722 r1723  
    22/** @file
    33 *
    4  * LIBC - wait3().
     4 * LIBC - wait4().
    55 *
    66 * Copyright (c) 2004 knut st. osmundsen <bird@innotek.de>
     
    6262    {
    6363        LIBC_ASSERTM_FAILED("pRUsage=%p - not implemented\n", (void *)pRUsage);
    64         errno = ENOSYS;
     64        /* errno = ENOSYS;
     65        LIBCLOG_RETURN_INT(-1); */
     66    }
     67    if (fOptions & ~(WEXITED | WUNTRACED | WSTOPPED | WCONTINUED | WNOHANG | WNOWAIT))
     68    {
     69        LIBC_ASSERTM_FAILED("Unknown options %#x. (fOptions=%#x)\n",
     70                            fOptions & ~(WEXITED | WUNTRACED | WSTOPPED | WCONTINUED | WNOHANG | WNOWAIT), fOptions);
     71        errno = EINVAL;
    6572        LIBCLOG_RETURN_INT(-1);
    6673    }
    6774
    6875    /*
    69      * Let waitpid do the job.
     76     * Call waitid to do the actual waiting.
    7077     */
    71     pid = waitpid(pid, piStatus, fOptions);
     78    /* convert pid to enmIdType and Id. */
     79    id_t     Id;
     80    idtype_t enmIdType;
    7281    if (pid > 0)
    73         LIBCLOG_RETURN_MSG(pid, "ret %d (%#x) iStatus=%#x\n", pid, pid, piStatus ? *piStatus : -1);
    74     LIBCLOG_RETURN_INT(pid);
     82    {
     83        enmIdType = P_PID;
     84        Id = pid;
     85    }
     86    else if (pid == 0)
     87    {
     88        enmIdType = P_PGID;
     89        Id = 0;
     90    }
     91    else if (pid == -1)
     92    {
     93        enmIdType = P_ALL;
     94        Id = 0;
     95    }
     96    else
     97    {
     98        Id = -pid;
     99        enmIdType = P_PGID;
     100    }
     101
     102    /* do the call */
     103    siginfo_t SigInfo = {0};
     104    int rc = __libc_Back_processWait(enmIdType, Id, &SigInfo, fOptions | WEXITED, pRUsage);
     105    if (!rc)
     106    {
     107        /*
     108         * Convert signal info to status code.
     109         */
     110        int iStatus;
     111        switch (SigInfo.si_code)
     112        {
     113            default:
     114                LIBC_ASSERTM_FAILED("Invalid si_code=%d\n", SigInfo.si_code);
     115            case CLD_EXITED:    iStatus = W_EXITCODE(SigInfo.si_status, 0); break;
     116            case CLD_KILLED:    iStatus = W_EXITCODE(0, SigInfo.si_status); break;
     117            case CLD_DUMPED:    iStatus = W_EXITCODE(0, SigInfo.si_status) | WCOREFLAG; break;
     118            case CLD_TRAPPED:   iStatus = W_STOPCODE(SigInfo.si_status); break;
     119            case CLD_STOPPED:   iStatus = W_STOPCODE(SigInfo.si_status); break;
     120            case CLD_CONTINUED: iStatus = W_STOPCODE(SigInfo.si_status); break;
     121
     122        }
     123        if (piStatus)
     124            *piStatus = iStatus;
     125        LIBCLOG_RETURN_MSG(SigInfo.si_pid, "ret %d (%#x) iStatus=%#x\n",
     126                           SigInfo.si_pid, SigInfo.si_pid, iStatus);
     127    }
     128
     129    /*
     130     * wait4() doesn't return EINVAL for anything but invalid fOptions
     131     * and since we've already validated those, they cannot be the cause
     132     * of EINVAL.
     133     */
     134    if (rc == -EINVAL)
     135        rc = -ECHILD;
     136    errno = -rc;
     137    LIBCLOG_RETURN_INT((pid_t)-1);
    75138}
    76139
  • trunk/src/emx/src/lib/process/waitid.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1722 r1723  
    4242 * @returns 0 on success, pSigInfo containing status info.
    4343 * @returns -1 and errno on failure.
     44 *          ECHILD is returned as specfied for waitpid() in SuS. The waitid() errno specs
     45 *          are very short and doesn't explain what they mean by "idtype and id specify an
     46 *          invalid set of processes".
    4447 * @param   enmIdType   What kind of process specification Id contains.
    4548 * @param   Id          Process specification of the enmIdType sort.
  • trunk/src/emx/src/lib/process/waitpid.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1722 r1723  
    5454{
    5555    LIBCLOG_ENTER("pid=%#x (%d) piStatus=%p fOptions=%#x\n", pid, pid, (void *)piStatus, fOptions);
    56 
    5756    /*
    58      * Call waitid to do the actual waiting.
     57     * Let wait4 do the job.
    5958     */
    60     /* convert pid to enmIdType and Id. */
    61     id_t     Id;
    62     idtype_t enmIdType;
     59    pid = wait4(pid, piStatus, fOptions, NULL);
    6360    if (pid > 0)
    64     {
    65         enmIdType = P_PID;
    66         Id = pid;
    67     }
    68     else if (pid == 0)
    69     {
    70         enmIdType = P_PGID;
    71         Id = 0;
    72     }
    73     else if (pid == -1)
    74     {
    75         enmIdType = P_ALL;
    76         Id = 0;
    77     }
    78     else
    79     {
    80         Id = -pid;
    81         enmIdType = P_PGID;
    82     }
    83 
    84     /* do the call */
    85     siginfo_t SigInfo = {0};
    86     int rc = waitid(P_ALL, 0, &SigInfo, fOptions | WEXITED);
    87     if (!rc)
    88     {
    89         /*
    90          * Convert signal info to status code.
    91          */
    92         int iStatus;
    93         switch (SigInfo.si_code)
    94         {
    95             default:
    96                 LIBC_ASSERTM_FAILED("Invalid si_code=%d\n", SigInfo.si_code);
    97             case CLD_EXITED:    iStatus = W_EXITCODE(SigInfo.si_status, 0); break;
    98             case CLD_KILLED:    iStatus = W_EXITCODE(0, SigInfo.si_status); break;
    99             case CLD_DUMPED:    iStatus = W_EXITCODE(0, SigInfo.si_status) | WCOREFLAG; break;
    100             case CLD_TRAPPED:   iStatus = W_STOPCODE(SigInfo.si_status); break;
    101             case CLD_STOPPED:   iStatus = W_STOPCODE(SigInfo.si_status); break;
    102             case CLD_CONTINUED: iStatus = W_STOPCODE(SigInfo.si_status); break;
    103 
    104         }
    105         if (piStatus)
    106             *piStatus = iStatus;
    107         LIBCLOG_RETURN_MSG(SigInfo.si_pid, "ret %d (%#x) iStatus=%#x\n",
    108                            SigInfo.si_pid, SigInfo.si_pid, iStatus);
    109     }
    110     LIBCLOG_RETURN_INT(rc);
     61        LIBCLOG_RETURN_MSG(pid, "ret %d (%#x) iStatus=%#x\n", pid, pid, piStatus ? *piStatus : -1);
     62    LIBCLOG_RETURN_INT(-1);
    11163}
    11264
  • trunk/src/emx/src/lib/sys/b_processWait.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1722 r1723  
    736736    {
    737737        case P_ALL:
     738            break;
    738739        case P_PID:
     740            if (Id <= 0 || Id >= 0x7fffffff)
     741            {
     742                LIBC_ASSERTM_FAILED("Invalid P_PID Id %lld\n", Id);
     743                LIBCLOG_RETURN_INT(-EINVAL);
     744            }
     745            break;
    739746        case P_PGID:
     747            if (Id < 0 || Id >= 0x7fffffff)
     748            {
     749                LIBC_ASSERTM_FAILED("Invalid P_PGID Id %lld\n", Id);
     750                LIBCLOG_RETURN_INT(-EINVAL);
     751            }
    740752            break;
    741753        default:
     
    803815            if (fFlag && (fFlag & fOptions))
    804816            {
    805                 if (    enmIdType == P_ALL
    806                     ||  (enmIdType == P_PID  && pInfo->pid  == pid)
    807                     ||  (enmIdType == P_PGID && pInfo->pgrp == pid))
     817                if (enmIdType == P_ALL)
     818                    break;
     819                else if (enmIdType == P_PID)
     820                {
     821                    if (pInfo->pid == pid)
     822                        break;
     823                }
     824                else if (enmIdType == P_PGID && pInfo->pgrp == pid)
    808825                    break;
    809826            }
     
    885902                 * Should call DosVerifyPidTid and DosGetPPid(). */
    886903                waitSemRelease();
    887                 rc = -ECHILD;           /* this ain't correct! */
     904                rc = -ECHILD; /* See discussion in this function description and in waitid(). */
    888905                break;
    889906            }
     
    894911            if (rc)
    895912            {
     913                rc = __libc_spmValidPGrp((pid_t)Id, 0 /* check for group existance */);
    896914                waitSemRelease();
    897                 rc = -ECHILD;
     915                rc = -ECHILD; /* See discussion in this function description and in waitid(). */
    898916                break;
    899917            }
    900918        }
    901919        waitSemRelease();
     920
     921        /*
     922         * If non-blocking we must return now.
     923         */
     924        if (fOptions & WNOHANG)
     925        {
     926            rc = 0;
     927            break;
     928        }
    902929
    903930        /*
Note: See TracChangeset for help on using the changeset viewer.