Changeset 1631


Ignore:
Timestamp:
Nov 14, 2004, 8:03:24 PM (21 years ago)
Author:
bird
Message:

Bugfixing signals and stuff.

Location:
trunk/src/emx
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/include/InnoTekLIBC/sharedpm.h

    • Property cvs2svn:cvs-rev changed from 1.17 to 1.18
    r1630 r1631  
    675675
    676676/**
     677 * Validates a process group id.
     678 *
     679 * @returns 0 if valid.
     680 * @returns -ESRCH if not valid.
     681 * @param   pgrp            Process group id to validate. 0 if the same as
     682 *                          the same as the current process.
     683 * @param   fOnlyChildren   Restrict the search to immediate children.
     684 */
     685int __libc_spmValidPGrp(pid_t pgrp, int fOnlyChildren);
     686
     687
     688/**
    677689 * Identificators which can be obtained using __libc_spmGetId().
    678690 */
  • trunk/src/emx/src/lib/process/beginthr.c

    • Property cvs2svn:cvs-rev changed from 1.12 to 1.13
    r1630 r1631  
    101101    int rc = __libc_back_threadCreate(pfnStart, cbStack, pvArg, 0);
    102102    if (rc >= 0)
    103         LIBCLOG_RETURN_INT(-1);
     103        LIBCLOG_RETURN_INT(rc);
    104104    errno = -rc;
    105105    LIBCLOG_RETURN_INT(-1);
  • trunk/src/emx/src/lib/process/waitpid.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1630 r1631  
    8484    /* do the call */
    8585    siginfo_t SigInfo = {0};
    86     int rc = waitid(P_ALL, 0, &SigInfo, WEXITED);
     86    int rc = waitid(P_ALL, 0, &SigInfo, fOptions | WEXITED);
    8787    if (!rc)
    8888    {
     
    108108                           SigInfo.si_pid, SigInfo.si_pid, iStatus);
    109109    }
    110     errno = -rc;
    111     LIBCLOG_RETURN_INT(-1);
     110    LIBCLOG_RETURN_INT(rc);
    112111}
    113112
  • trunk/src/emx/src/lib/sys/__select.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1630 r1631  
    2727#include "libc-alias.h"
    2828#define INCL_FSMACROS
    29 #define INCL_DOSPROCESS
     29#define INCL_DOSSEMAPHORES
     30#define INCL_ERRORS
    3031#include <os2emx.h>
    3132#include <stdlib.h>
     
    3738#include <emx/syscalls.h>
    3839#include "syscalls.h"
     40#include "backend.h"
    3941
    4042
     
    4850    int rc;
    4951    if (!tv)
    50         rc = DosSleep(~0);
     52        rc = DosWaitEventSem(__libc_back_ghevWait, SEM_INDEFINITE_WAIT);
    5153    else
    5254    {
     
    5456        if (!cMillies && tv->tv_usec)
    5557            cMillies = 1;
    56         rc = DosSleep(cMillies);
     58        rc = DosWaitEventSem(__libc_back_ghevWait, cMillies);
    5759    }
    5860    FS_RESTORE();
     
    6163     * Return.
    6264     */
    63     if (!rc)
     65    if (!rc || rc == ERROR_TIMEOUT || rc == ERROR_SEM_TIMEOUT)
    6466        return 0;
    6567    errno = __libc_native2errno(rc);
     
    174176        rc = pfnSelect(nfds, readfds, writefds, exceptfds, tv, &rc2);
    175177    }
    176     else if (tv)
    177     {
    178         FS_VAR();
    179         /* wait for the given amount of time. */
    180         rc2 = rc = 0;
    181         FS_SAVE_LOAD();
    182         DosSleep(tv->tv_sec * 1000 + tv->tv_usec / 1000);
    183         FS_RESTORE();
    184     }
    185178    else
    186179    {
  • trunk/src/emx/src/lib/sys/__spawnve.c

    • Property cvs2svn:cvs-rev changed from 1.12 to 1.13
    r1630 r1631  
    275275
    276276            /*
    277              * Notify the process waiter system.
    278              */
    279             __libc_back_processWaitNotifyExec();
    280 
    281             /*
    282277             * Create the process.
    283278             */
     
    290285                __atomic_cmpxchg32((volatile uint32_t *)(void *)&pEmbryo->pid, (uint32_t)resc.codeTerminate, 0);
    291286                LIBCLOG_MSG("Spawned pid=%04lx (%ld)\n", resc.codeTerminate, resc.codeTerminate);
     287                __libc_back_processWaitNotifyExec(resc.codeTerminate);
    292288
    293289                /* cleanup embryo and other stuff. */
  • trunk/src/emx/src/lib/sys/b_process.h

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1630 r1631  
    3737
    3838void __libc_back_processWaitNotifyTerm(void);
    39 void __libc_back_processWaitNotifyExec(void);
     39void __libc_back_processWaitNotifyExec(pid_t pid);
    4040void __libc_back_processWaitNotifyChild(siginfo_t *pSigInfo);
    4141void __libc_back_processWaitNotifyNoWait(int fNoWaitStatus);
  • trunk/src/emx/src/lib/sys/b_processWait.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1630 r1631  
    8484
    8585
     86/** Pointer to child process info node. */
     87typedef struct WAITCHILD *PWAITCHILD;
     88/**
     89 * Child Process info node.
     90 */
     91typedef struct WAITCHILD
     92{
     93    /** Pointer to the next one. */
     94    volatile PWAITCHILD pNext;
     95    /** Process Id. */
     96    pid_t               pid;
     97} WAITCHILD;
     98
    8699
    87100/*******************************************************************************
     
    102115/** Index into the preallocated nodes. */
    103116static volatile unsigned    giWaitPreAlloced;
     117/** List of known children. */
     118static volatile PWAITCHILD  gpChildrenHead;
     119/** Number of known child processes. */
     120static volatile unsigned    gcChildren;
     121/** Total number of born child processes. */
     122static volatile unsigned    gcBirths;
     123/** Total number of died child processes. */
     124static volatile unsigned    gcDeaths;
    104125
    105126/** If this flag is set we don't care for wait status info.
     
    110131/** The event semaphore the callers are sleeping on. */
    111132static volatile HEV         ghevWait;
     133/** The event semaphore the wait thread are sleeping on. */
     134static volatile HEV         ghevBirth;
    112135
    113136/** Thread ID of the wait thread. */
    114137static volatile TID         gtidThread;
    115138/** Termination indicator. Used to help the wait thread terminate fast. */
    116 static volatile int         gfTerminate;
     139static volatile unsigned    gfTerminate;
    117140
    118141
     
    146169        if (rc)
    147170            abort();
     171        rc = DosCreateEventSemEx(NULL, (PHEV)&ghevBirth, 0, FALSE);
     172        if (rc)
     173            abort();
     174
    148175
    149176        /* done */
     
    164191    {
    165192        /* kill the thread */
    166         gfTerminate = TRUE;
     193        __atomic_xchg(&gfTerminate, 1);
     194        DosKillThread(gtidThread);
    167195        gtidThread = 0;
    168         DosKillThread(gtidThread);
    169 
    170         /* destroy the event semaphore. */
    171         HEV hev = ghevWait;
    172         ghevWait = NULLHANDLE;
    173         if (hev)
    174             DosPostEventSem(hev);
     196    }
     197
     198    /* destroy the birth event semaphore. */
     199    HEV hev = ghevBirth;
     200    ghevBirth = NULLHANDLE;
     201    if (hev)
     202    {
     203        DosPostEventSem(hev);
     204        DosCloseEventSem(hev);
     205    }
     206
     207    /* destroy the wait event semaphore. */
     208    hev = ghevWait;
     209    ghevWait = NULLHANDLE;
     210    if (hev)
     211    {
     212        DosPostEventSem(hev);
     213        DosCloseEventSem(hev);
    175214    }
    176215}
     
    218257    pWait->pNext = NULL;
    219258    pWait->pPrev = gpWaitTail;
    220     if (!pWait->pPrev)
     259    if (pWait->pPrev)
     260        pWait->pPrev->pNext = pWait;
     261    else
    221262        gpWaitHead = pWait;
    222263    gpWaitTail = pWait;
     
    233274    PTIB        pTib;
    234275    DosGetInfoBlocks(&pTib, &pPib);
     276    DosSetPriority(PRTYS_THREAD, PRTYC_REGULAR, 1, 0);
    235277
    236278    /*
     
    240282    for (;!gfTerminate;)
    241283    {
    242         for (;!gfTerminate;)
    243         {
     284        /*
     285         * Check for exit condition.
     286         */
     287        fInternalTerm = gfTerminate;
     288        if (pPib->pib_flstatus & (0x40/*dying*/ | 0x04/*exiting all*/ | 0x02/*Exiting Thread 1*/ | 0x01/*ExitList */))
     289        {
     290            LIBCLOG_MSG("Terminating thread, exit conditions detected. pib_flstatus=%#lx\n",  pPib->pib_flstatus);
     291            fInternalTerm = 1;
     292        }
     293
     294        /*
     295         * Wait for children.
     296         */
     297        WAITINFO Wait;
     298        int rc = waitChild(&Wait, fInternalTerm, 0 /* any child */);
     299        if (!rc)
     300        {
     301            /* enter semaphore protection. */
     302            rc = waitSemRequest(1);
     303
    244304            /*
    245              * Check for exit condition.
     305             * Need we bother inserting it?
    246306             */
    247             fInternalTerm = gfTerminate;
    248             if (pPib->pib_flstatus & (0x40/*dying*/ | 0x04/*exiting all*/ | 0x02/*Exiting Thread 1*/ | 0x01/*ExitList */))
     307            if (!gfNoWaitStatus)
     308                waitAllocInsert(&Wait);
     309
     310            /*
     311             * Increment death number and decrement number of (known) children.
     312             */
     313            __atomic_increment(&gcDeaths);
     314
     315            /*
     316             * Remove the child from the list.
     317             */
     318            PWAITCHILD pPrev = NULL;
     319            PWAITCHILD pChild = gpChildrenHead;
     320            while (pChild)
    249321            {
    250                 LIBCLOG_MSG("Terminating thread, exit conditions detected. pib_flstatus=%#lx\n",  pPib->pib_flstatus);
    251                 fInternalTerm = TRUE;
     322                if (pChild->pid == Wait.pid)
     323                {
     324                    if (pPrev)
     325                        pPrev->pNext = pChild->pNext;
     326                    else
     327                        gpChildrenHead = pChild->pNext;
     328                    __atomic_decrement_min(&gcChildren, 0);
     329                    break;
     330                }
     331
     332                /* next */
     333                pPrev = pChild;
     334                pChild = pChild->pNext;
    252335            }
    253336
    254337            /*
    255              * Wait for children.
     338             * Wake up any waiters.
    256339             */
    257             WAITINFO Wait;
    258             int rc = waitChild(&Wait, fInternalTerm, 0 /* any child */);
     340            if (DosPostEventSem(ghevWait) == ERROR_INVALID_HANDLE)
     341                fInternalTerm = 1;
     342
     343            /*
     344             * Leave semaphore protection and wait again unless someone's hinting it's time to quit...
     345             */
    259346            if (!rc)
    260             {
    261                 /*
    262                  * Need we bother inserting it?
    263                  */
    264                 rc = waitSemRequest(1);
    265                 if (!rc && !gfNoWaitStatus)
    266                     rc = waitAllocInsert(&Wait);
    267 
    268                 /*
    269                  * Wake up any waiters.
    270                  */
    271                 int rcOS2 = DosPostEventSem(ghevWait);
    272                 if (!rc)
    273                     waitSemRelease();
    274                 if (rc || (rcOS2 && rcOS2 != ERROR_TOO_MANY_POSTS && rcOS2 != ERROR_ALREADY_POSTED))
    275                     fInternalTerm = 1;
    276                 rc = 0;
    277             }
    278             if (rc || fInternalTerm)
     347                waitSemRelease();
     348            if (fInternalTerm)
    279349                break;
    280         }
    281 
    282         /*
    283          * Check if we're encouraged to quit.
    284          */
    285         if (fInternalTerm || gfTerminate)
    286             break;
     350            continue;
     351        }
    287352
    288353        /*
     
    293358         * using the nowait option on the API call.
    294359         */
     360        if (fInternalTerm || gfTerminate)
     361            break;
    295362        if (pPib->pib_flstatus & (0x40/*dying*/ | 0x04/*exiting all*/ | 0x02/*Exiting Thread 1*/ | 0x01/*ExitList */))
    296363        {
    297364            LIBCLOG_MSG("Terminating thread, exit conditions detected. pib_flstatus=%#lx\n",  pPib->pib_flstatus);
    298             fInternalTerm = TRUE;
     365            fInternalTerm = 1;
    299366            continue;
    300367        }
    301368
    302         DosWaitEventSem(ghevWait, 30*1000);
     369        if (rc == ERROR_WAIT_NO_CHILDREN)
     370        {
     371            DosWaitEventSem(ghevBirth, 5*1000);
     372            ULONG cIgnore;
     373            if (DosResetEventSem(ghevBirth, &cIgnore) == ERROR_INVALID_HANDLE)
     374                fInternalTerm = 1;
     375        }
     376        else
     377            LIBC_ASSERTM_FAILED("waitChild -> rc=%d expected ERROR_WAIT_NO_CHILDREN!\n", rc);
    303378    }
    304379
     
    485560 * it's time to start collect child status codes.
    486561 */
    487 void __libc_back_processWaitNotifyExec(void)
    488 {
    489     if (gtidThread)
    490         return;
    491 
     562void __libc_back_processWaitNotifyExec(pid_t pid)
     563{
     564    PWAITCHILD pChild = _hmalloc(sizeof(*pChild));
    492565    waitSemRequest(0);
     566
     567    /*
     568     * Tell wait thread that there is a child waiting.
     569     */
     570    if (pChild)
     571    {
     572        pChild->pid = pid;
     573        pChild->pNext = gpChildrenHead;
     574        gpChildrenHead = pChild;
     575    }
     576    __atomic_increment(&gcChildren);
     577    __atomic_increment(&gcBirths);
     578    int rc = DosPostEventSem(ghevBirth);
     579    LIBC_ASSERTM(!rc, "DosPostEventSem(%#lx (birth)) -> %d\n", ghevBirth, rc);
     580    rc = rc;
     581
     582    /*
     583     * No wait thread? Create one.
     584     */
    493585    if (!gtidThread)
    494586    {
     
    500592        {
    501593            gtidThread = tid;
    502             LIBCLOG_MSG2("Create waitThread! tid=%#x (%d)\n", tid, tid);
     594            LIBCLOG_MSG2("Created waitThread! tid=%#x (%d)\n", tid, tid);
    503595        }
    504596        else
     
    509601        }
    510602    }
     603
    511604    waitSemRelease();
    512605}
     
    530623    __atomic_xchg(&gfNoWaitStatus, fNoWaitStatus);
    531624}
     625
    532626
    533627/**
     
    571665            /* insert it */
    572666            waitInsertFIFO(pWait);
     667            DosPostEventSem(ghevWait);
    573668        }
    574669        else
     
    619714
    620715    /*
    621      * Make sure there is a worker around.
    622      */
    623     if (!gtidThread)
    624         __libc_back_processWaitNotifyExec();
    625 
    626     /*
    627716     * Validate options.
    628717     */
     
    676765        LIBCLOG_RETURN_MSG(rc, "%d mutex\n", rc);
    677766    unsigned    cIterations = 0;
     767    int         fInterrupted = 0;
    678768    for (;; cIterations++)
    679769    {
     
    682772         */
    683773        WAITINFO    Wait;
     774        pid_t       pid = (pid_t)Id;
     775        if (!pid && enmIdType == P_PGID)
     776            pid = (pid_t)__libc_spmGetId(__LIBC_SPMID_PGRP);
    684777        PWAITINFO   pInfo = gpWaitHead;
    685778        while (pInfo)
     
    712805            if (fFlag && (fFlag & fOptions))
    713806            {
    714                 if (enmIdType == P_ALL)
    715                     break;
    716                 if (    (enmIdType == P_PID  && pInfo->pid  == (pid_t)Id)
    717                     ||  (enmIdType == P_PGID && pInfo->pgrp == (pid_t)Id))
     807                if (    enmIdType == P_ALL
     808                    ||  (enmIdType == P_PID  && pInfo->pid  == pid)
     809                    ||  (enmIdType == P_PGID && pInfo->pgrp == pid))
    718810                    break;
    719811            }
     
    755847                waitInfoToSigInfo(&Wait, pSigInfo);
    756848            /* return */
     849            rc = 0;
    757850            break;
    758851        }
     
    760853        /*
    761854         * Verify the wait id (again).
    762          */
     855         *
     856         * Because of the design we cannot use DosWaitChild to check if
     857         * the process actually have any children. Which means we'll
     858         * have to use some child counting and thread states to check this.
     859         */
     860        if (enmIdType == P_ALL)
     861        {
     862            /*
     863             * It's enough to know that there are children around.
     864             */
     865            if (!gcChildren && !gpChildrenHead)
     866            {
     867                /** @todo Later we'll add support for waiting on processes spawned by direct calls to DosExecPgm.
     868                 * Should call DosWaitChild to be 99% sure. */
     869                waitSemRelease();
     870                rc = -ECHILD;
     871                break;
     872            }
     873        }
     874        else if (enmIdType == P_PID)
     875        {
     876            /*
     877             * In this case we'll have to make sure this PID exists
     878             * AND that it's a child of ours.
     879             */
     880            PWAITCHILD pChild = gpChildrenHead;
     881            for (;pChild; pChild = pChild->pNext)
     882                if (pChild->pid == (pid_t)Id)
     883                    break;
     884            if (!pChild)
     885            {
     886                /** @todo Later we'll add support for waiting on processes spawned by direct calls to DosExecPgm.
     887                 * Should call DosVerifyPidTid and DosGetPPid(). */
     888                waitSemRelease();
     889                rc = -ECHILD;           /* this ain't correct! */
     890                break;
     891            }
     892        }
     893        else
     894        {
     895            rc = __libc_spmValidPGrp((pid_t)Id, 1 /* only children */);
     896            if (rc)
     897            {
     898                waitSemRelease();
     899                rc = -ECHILD;
     900                break;
     901            }
     902        }
    763903        waitSemRelease();
    764         if (    enmIdType == P_ALL
    765             ||  enmIdType == P_PID)
    766         {
    767             /*
    768              * All, or one specific, child process.
    769              */
    770             rc = waitChild(&Wait, 1 /* no wait */, enmIdType == P_PID ? (pid_t)Id : 0);
    771             if (!rc)
    772             {
    773                 /*
    774                  * Need we bother inserting it?
    775                  * Anyway we'll have to wake the other waiters so they can recheck
    776                  * their stuff, like we're gonna do now.
    777                  */
    778                 rc = waitSemRequest(1);
    779                 if (!rc && !gfNoWaitStatus)
    780                     rc = waitAllocInsert(&Wait);
    781                 DosPostEventSem(ghevWait);
    782                 if (rc)
    783                     break;
    784                 continue;
    785             }
    786         }
    787         else
    788         {
    789             rc = __libc_Back_signalSendPGrp((pid_t)Id, 0);
    790             if (rc)
    791                 LIBCLOG_RETURN_INT(rc);
    792         }
    793 
    794         /*
    795          * Interpret OS/2 error codes.
    796          */
    797         if (rc == ERROR_NO_CHILDREN)
    798             LIBCLOG_RETURN_INT(-ECHILD);
    799         if (rc == ERROR_INVALID_PROCID)
    800             LIBCLOG_RETURN_INT(-ESRCH);     /* waitid() -> EINVAL, wait[pid|3|4]() -> ECHILD */
    801         if (rc == ERROR_NO_CHILD_PROCESS)
    802             LIBCLOG_RETURN_INT(-EPERM);     /* waitid() -> EINVAL, wait[pid|3|4]() -> ECHILD */
    803         if (rc != ERROR_CHILD_NOT_COMPLETE)
    804             LIBCLOG_RETURN_MSG(-EINVAL, "%d (-EINVAL) OS/2 rc=%d\n", -EINVAL, rc);
    805         if ((fOptions & WNOHANG))
    806             LIBCLOG_RETURN_INT(-ECHILD);
     904
     905        /*
     906         * Delayed interrupted condition.
     907         */
     908        if (fInterrupted)
     909        {
     910            rc = -EINTR;
     911            break;
     912        }
    807913
    808914        /*
     
    812918         * if it is we'll not gonna hang along here anylonger. Only 2nd and
    813919         * subsequent iterations => 30 second timeout before deadlock is fixed.
    814         */
     920         */
    815921        if (    cIterations >= 1
    816922            &&  (pPib->pib_flstatus & (0x40/*dying*/ | 0x04/*exiting all*/ | 0x02/*Exiting Thread 1*/ | 0x01/*ExitList */))
     
    819925        rc = DosWaitEventSem(ghevWait, 30*1000);
    820926        if (rc == ERROR_INTERRUPT)
    821             LIBCLOG_RETURN_INT(-EINTR);
    822         if (!rc && rc != ERROR_TIMEOUT && rc != ERROR_SEM_TIMEOUT)
     927            fInterrupted = 1;
     928        else if (rc && rc != ERROR_TIMEOUT && rc != ERROR_SEM_TIMEOUT)
    823929            LIBCLOG_RETURN_MSG(-EDEADLK, "%d (-DEADLK) waitsem -> rc=%d\n", -EDEADLK, rc);
    824930
  • trunk/src/emx/src/lib/sys/b_signalStack.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1630 r1631  
    7676            {
    7777                LIBC_ASSERTM_FAILED("ss_size=%d is too small. minimum size is %d\n", pStack->ss_size, MINSIGSTKSZ);
    78                 LIBCLOG_RETURN_INT(-EINVAL);
     78                LIBCLOG_RETURN_INT(-ENOMEM);
    7979            }
    8080
  • trunk/src/emx/src/lib/sys/backend.h

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1630 r1631  
    3232__BEGIN_DECLS
    3333
     34/** Wait Event Semaphore.
     35 * This is an event semaphore which will never be posted (unless we wanna resolve
     36 * some nasty deadlock in the future) but is used to wait for a signal to arrive.
     37 * When a signal arrives the wait will be interrupted to allow for execution of
     38 * the exception and signal processing. DosWaitEventSem will return ERROR_INTERRUPT.
     39 */
     40extern unsigned long __libc_back_ghevWait;
     41
    3442/**
    3543 * Converts native error code to errno error code.
  • trunk/src/emx/src/lib/sys/libcfork.c

    • Property cvs2svn:cvs-rev changed from 1.8 to 1.9
    r1630 r1631  
    5151#include "syscalls.h"
    5252#include "DosEx.h"
     53#include "b_process.h"
    5354
    5455
     
    403404                    forkParCompletionChild(pForkHandle, rc);
    404405                }
     406
     407                /*
     408                 * Try reap the child in case of failure.
     409                 */
     410                if (rc < 0)
     411                {
     412                    FS_VAR();
     413                    FS_SAVE_LOAD();
     414                    RESULTCODES resc;
     415                    PID         pibReaped;
     416                    DosWaitChild(DCWA_PROCESS,DCWW_NOWAIT, &resc, &pibReaped, pid);
     417                    FS_RESTORE();
     418                }
    405419            }
    406420        }
     
    417431     * Return.
    418432     */
     433    if (rc >= 0)
     434        __libc_back_processWaitNotifyExec(pid);
     435
    419436    _fmutex_release(&__libc_gmtxExec);
    420437    if (rc >= 0)
  • trunk/src/emx/src/lib/sys/sharedpm.c

    • Property cvs2svn:cvs-rev changed from 1.20 to 1.21
    r1630 r1631  
    7373#define __LIBC_LOG_GROUP    __LIBC_LOG_GRP_BACK_SPM
    7474#include <InnoTekLIBC/logstrict.h>
     75#include "b_process.h"
    7576#include "syscalls.h"
    7677
     
    268269         */
    269270        spmReleaseMutex(&RegRec);
    270         *pNotify = NotifyTmp;
    271     }
    272 
     271        *pNotifyOut = NotifyTmp;
     272    }
     273
     274    LIBCLOG_RETURN_INT(rc);
     275}
     276
     277/**
     278 * Validates a process group id.
     279 *
     280 * @returns 0 if valid.
     281 * @returns -ESRCH if not valid.
     282 * @param   pgrp            Process group id to validate. 0 if the same as
     283 *                          the same as the current process.
     284 * @param   fOnlyChildren   Restrict the search to immediate children.
     285 */
     286int __libc_spmValidPGrp(pid_t pgrp, int fOnlyChildren)
     287{
     288    LIBCLOG_ENTER("pgrp=%#x (%d) fOnlyChildren=%d\n", pgrp, pgrp, fOnlyChildren);
     289
     290    /*
     291     * Set return code and reason.
     292     */
     293    __LIBC_SPMXCPTREGREC    RegRec;
     294    int rc = spmRequestMutex(&RegRec);
     295    if (!rc)
     296    {
     297        /*
     298         * Iterate all living processes looking for matching pgrps.
     299         * Quit when we've found a match.
     300         */
     301        rc = -ESRCH;
     302        pid_t pid = fOnlyChildren ? gpSPMSelf->pid : 0;
     303        if (!pgrp)
     304            pgrp = gpSPMSelf->pgrp;
     305        __LIBC_PSPMPROCESS pProcess = gpSPMHdr->apHeads[__LIBC_PROCSTATE_ALIVE];
     306        for (; pProcess; pProcess = pProcess->pNext)
     307            if (    pProcess->pgrp == pgrp
     308                &&  (!pid || pProcess->pidParent == pid))
     309            {
     310                rc = 0;
     311                break;
     312            }
     313
     314        spmReleaseMutex(&RegRec);
     315    }
    273316    LIBCLOG_RETURN_INT(rc);
    274317}
     
    20092052{
    20102053    /*
     2054     * Notify the wait facilities.
     2055     */
     2056    __libc_back_processWaitNotifyTerm();
     2057
     2058    /*
    20112059     * Check if the memory is accessible, if it ain't we'll crash or do other
    20122060     * nasty things is the code below.
     
    22652313     */
    22662314    for (pProcess = gpSPMHdr->apHeads[enmState]; pProcess ; pProcess = pProcess->pNext)
    2267         if (pProcess->pid == pid && pProcess->enmState == enmState)
     2315        if (pProcess->pid == pid)
    22682316            LIBCLOG_RETURN_P(pProcess);
    22692317
     
    24282476        pProcess->uVersion          = SPM_VERSION;
    24292477        pProcess->cReferences       = 1;
    2430         pProcess->enmState          = __LIBC_PROCSTATE_EMBRYO;
     2478        pProcess->enmState          = __LIBC_PROCSTATE_ALIVE;
    24312479        pProcess->pid               = pid;
    24322480        pProcess->pidParent         = pidParent;
  • trunk/src/emx/src/lib/sys/signals.c

    • Property cvs2svn:cvs-rev changed from 1.11 to 1.12
    r1630 r1631  
    8585#include <InnoTekLIBC/logstrict.h>
    8686#include "syscalls.h"
     87#include "backend.h"
    8788#include "b_signal.h"
    8889#include "b_process.h"
     
    220221static HMTX             ghmtxSignals;
    221222
    222 /** Signal Wait Event Semaphore.
     223/** Wait Event Semaphore.
    223224 * This is an event semaphore which will never be posted (unless we wanna resolve
    224225 * some nasty deadlock in the future) but is used to wait for a signal to arrive.
     
    226227 * the exception and signal processing. DosWaitEventSem will return ERROR_INTERRUPT.
    227228 */
    228 static HEV              ghevWait;
     229HEV              __libc_back_ghevWait;
    229230
    230231static const char gaszSignalNames[__SIGSET_MAXSIGNALS][12] =
     
    587588         * Create the wait semaphore.
    588589         */
    589         rc = DosCreateEventSemEx(NULL, &ghevWait, 0, 0);
     590        rc = DosCreateEventSemEx(NULL, &__libc_back_ghevWait, 0, 0);
    590591        if (!rc)
    591592        {
     
    13161317        {
    13171318            /*
    1318              * Let's see if we can ignore it or successfully schedule it to a thread.
     1319             * Let's see if we can ignore it or successfully schedule it to a thread,
     1320             * or if it's SIGCHLD which might be required to get wait*() working right.
    13191321             */
    13201322            __LIBC_PTHREAD pThrdSig = NULL;
     
    13221324                ||  (   gaSignalActions[iSignalNo].__sigaction_u.__sa_handler == SIG_DFL
    13231325                     && (gafSignalProperties[iSignalNo] & SPA_MASK) == SPA_IGNORE)
     1326                || iSignalNo == SIGCHLD
    13241327                || (pThrdSig = signalScheduleThread(iSignalNo, pThrd)))
    13251328            {
     
    19671970    LIBCLOG_MSG("Calling DosExit(,127)\n");
    19681971    for (;;)
     1972    {
     1973        DosKillProcess(DKP_PROCESS, 0);
    19691974        DosExit(EXIT_THREAD, 127);
     1975    }
    19701976}
    19711977
     
    20592065    LIBCLOG_MSG("Calling DosExit(,127)\n");
    20602066    for (;;)
     2067    {
     2068        DosKillProcess(DKP_PROCESS, 0);
    20612069        DosExit(EXIT_THREAD, 127);
     2070    }
    20622071}
    20632072
     
    21262135     */
    21272136    __libc_back_signalSemRelease();
    2128     DosWaitEventSem(ghevWait, SEM_INDEFINITE_WAIT);
     2137    DosWaitEventSem(__libc_back_ghevWait, SEM_INDEFINITE_WAIT);
    21292138    return __libc_back_signalSemRequest();
    21302139}
     
    21792188        SigInfo = *pSigInfo;
    21802189    SigInfo.si_signo        = iSignalNo;
    2181     if (pSigInfo)
     2190    if (!pSigInfo)
    21822191        SigInfo.si_code     = SI_USER;
    21832192    if (SigInfo.si_pid)
     
    29822991    for (;;)
    29832992    {
    2984         int rc = DosWaitEventSem(ghevWait, cMillies);
     2993        int rc = DosWaitEventSem(__libc_back_ghevWait, cMillies);
    29852994
    29862995        /*
Note: See TracChangeset for help on using the changeset viewer.