Ignore:
Timestamp:
Nov 7, 2004, 3:19:42 PM (21 years ago)
Author:
bird
Message:

More signal debugging and cleanup.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/src/lib/sys/signals.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1617 r1618  
    10271027         */
    10281028        if (   pThrdSig->enmStatus == enmLIBCThreadStatus_sigwait
    1029             && __SIGSET_ISSET(&pThrdSig->u.SigWait.SigSetWait, iSignalNo))
     1029            && __SIGSET_ISSET(&pThrdSig->u.SigSetWait, iSignalNo))
    10301030        {
    10311031            /*
    10321032             * Wake up a sigwait call.
    10331033             */
    1034             /** @todo install extra exception handler while accessing this. */
    10351034            if (pSigInfo)
    1036                 *pThrdSig->u.SigWait.pSigInfo = *pSigInfo;
     1035                SigInfo = *pSigInfo;
    10371036            else
    1038             {
    1039                 bzero(pThrdSig->u.SigWait.pSigInfo, sizeof(*pThrdSig->u.SigWait.pSigInfo));
    1040                 pThrdSig->u.SigWait.pSigInfo->si_signo = iSignalNo;
    1041             }
     1037                bzero((void *)&pThrdSig->u.pSigWait->SigInfo, sizeof(pThrdSig->u.pSigWait->SigInfo));
     1038            pThrdSig->u.pSigWait->SigInfo.si_signo = iSignalNo;
     1039            pThrdSig->u.pSigWait->fDone = 1;
    10421040            pThrdSig->enmStatus = enmLIBCThreadStatus_unknown;
     1041
     1042
     1043
     1044
     1045
     1046
     1047
     1048
     1049
     1050
     1051
     1052
     1053
     1054
     1055
    10431056            if (pThrdSig != pThrd)
    10441057                __libc_back_signalPokeThread(pThrdSig);
    1045             LIBCLOG_MSG("wokeup sigwait in thread %d on signal %d.\n", pThrdSig->tid, iSignalNo);
     1058            LIBCLOG_MSG("wokeup sigwait in thread % on signal %d.\n", pThrdSig->tid, iSignalNo);
    10461059        }
    10471060        else
     
    11161129                if (pThrdSig != pThrd)
    11171130                    __libc_back_signalPokeThread(pThrdSig);
    1118                 LIBCLOG_MSG("setting %d pending on thread %d's and poking it.\n", pThrdSig->tid, iSignalNo);
     1131                LIBCLOG_MSG("setting %d pending on thread %'s and poking it.\n", pThrdSig->tid, iSignalNo);
    11191132            }
    11201133        }
     
    13511364
    13521365    /*
    1353      * If we've got a queue node, queue it.
    1354      */
    1355     if (pSig)
    1356     {
    1357         pSig->pNext = NULL;
    1358         pSig->pPrev = pThrdSig->SigQueue.pTail;
    1359         if (pThrdSig->SigQueue.pTail)
    1360             pThrdSig->SigQueue.pTail->pNext = pSig;
     1366     * Check if this was a sig*wait* case.
     1367     */
     1368    if (   pThrdSig->enmStatus == enmLIBCThreadStatus_sigwait
     1369        && __SIGSET_ISSET(&pThrdSig->u.pSigWait->SigSetWait, iSignalNo))
     1370    {
     1371        /*
     1372         * Store result with the thread.
     1373         */
     1374        if (pSig)
     1375            pThrdSig->u.pSigWait->SigInfo = pSig->SigInfo;
    13611376        else
    1362             pThrdSig->SigQueue.pHead = pSig;
    1363         pThrdSig->SigQueue.pTail = pSig;
    1364     }
    1365 
    1366     /*
    1367      * In any case, we set the signal pending and poke the thread.
    1368      */
    1369     __SIGSET_SET(&pThrd->SigSetPending, iSignalNo);
    1370     if (pThrdSig != pThrd)
    1371         __libc_back_signalPokeThread(pThrdSig);
    1372     LIBCLOG_MSG("setting %d pending on thread %d's and poking it.\n", pThrdSig->tid, iSignalNo);
     1377            bzero((void *)&pThrdSig->u.pSigWait->SigInfo, sizeof(pThrdSig->u.pSigWait->SigInfo));
     1378        pThrdSig->u.pSigWait->SigInfo.si_signo = iSignalNo;
     1379        pThrdSig->u.pSigWait->fDone = 1;
     1380        pThrdSig->enmStatus = enmLIBCThreadStatus_unknown;
     1381
     1382        /*
     1383         * Free the signal node.
     1384         */
     1385        pSig->pNext = gpSigQueuedFree;
     1386        gpSigQueuedFree = pSig->pNext;
     1387        gcSigQueuedFree++;
     1388
     1389        /*
     1390         * Check if there is an unqueued pending signal which we should clear.
     1391         */
     1392        pSig = pThrdSig->SigQueue.pHead;
     1393        while (pSig && pSig->SigInfo.si_signo != iSignalNo)
     1394            pSig = pSig->pNext;
     1395        if (!pSig)
     1396            __SIGSET_CLEAR(&pThrdSig->SigSetPending, iSignalNo);
     1397        else
     1398            __SIGSET_SET(&pThrdSig->SigSetPending, iSignalNo);
     1399
     1400        /*
     1401         * Poke the thread.
     1402         */
     1403        if (pThrdSig != pThrd)
     1404            __libc_back_signalPokeThread(pThrdSig);
     1405        LIBCLOG_MSG("wokeup sigwait in thread %#x on signal %d.\n", pThrdSig->tid, iSignalNo);
     1406    }
     1407    else
     1408    {
     1409        /*
     1410         * If we've got a queue node, queue it.
     1411         */
     1412        if (pSig)
     1413        {
     1414            pSig->pNext = NULL;
     1415            pSig->pPrev = pThrdSig->SigQueue.pTail;
     1416            if (pThrdSig->SigQueue.pTail)
     1417                pThrdSig->SigQueue.pTail->pNext = pSig;
     1418            else
     1419                pThrdSig->SigQueue.pHead = pSig;
     1420            pThrdSig->SigQueue.pTail = pSig;
     1421        }
     1422
     1423        /*
     1424         * And in any case set it pending.
     1425         */
     1426        __SIGSET_SET(&pThrd->SigSetPending, iSignalNo);
     1427
     1428        /*
     1429         * Poke the thread.
     1430         */
     1431        if (pThrdSig != pThrd)
     1432            __libc_back_signalPokeThread(pThrdSig);
     1433        LIBCLOG_MSG("setting %d pending on thread %#x's and poking it.\n", pThrdSig->tid, iSignalNo);
     1434    }
     1435
    13731436    LIBCLOG_RETURN_VOID();
    13741437}
     
    13861449{
    13871450    LIBC_ASSERTM(__libc_back_signalSemIsOwner(), "Thread does not own the signal semaphore!!!\n");
     1451
     1452
     1453
     1454
     1455
     1456
     1457
     1458
     1459
     1460
    13881461
    13891462    /*
     
    14231496     */
    14241497    if (   pCur->enmStatus == enmLIBCThreadStatus_sigwait
    1425         && __SIGSET_ISSET(&pCur->u.SigWait.SigSetWait, pParam->iSignalNo))
     1498        && __SIGSET_ISSET(&pCur->u.SigSetWait, pParam->iSignalNo))
    14261499    {
    14271500        if (pCur == pParam->pThrd)
     
    14431516        ||  (   pBest
    14441517             && pBest->enmStatus == enmLIBCThreadStatus_sigwait
    1445              && __SIGSET_ISSET(&pCur->u.SigWait.SigSetWait, pParam->iSignalNo)))
     1518             && __SIGSET_ISSET(&pSigSetWait, pParam->iSignalNo)))
    14461519        return 0;
    14471520    /* ok, it's not blocking it so it's ok to use it. */
     
    15521625
    15531626        /*
    1554          * Deliver signals /execute signal default actions in this order:
    1555          *   0. Passed in signal (ignores blocking).
    1556          *   1. SIGKILL
    1557          *   2. Realtime signals. (queued)
    1558          *   3. SIGTERM
    1559          *   4. SIGABRT
    1560          *   5. SIGCHLD
    1561          *   6. SIGCONT
    1562          *   7. Ascending from pending mask.
    1563          *
    1564          * Note that 0 and 1 may be violating the POSIX specs.
    1565          */
    1566         if (!iSignalNo || !__SIGSET_ISSET(&pThrd->SigSetPending, iSignalNo))
    1567         {
    1568             iSignalNo = SIGKILL;
    1569             if (!__SIGSET_ISSET(&SigDeliver, SIGKILL))
    1570             {
    1571                 iSignalNo = SIGRTMIN;
    1572                 while (iSignalNo <= SIGRTMAX && !__SIGSET_ISSET(&SigDeliver, iSignalNo))
    1573                     iSignalNo++;
    1574                 if (iSignalNo > SIGRTMAX)
    1575                 {
    1576                     iSignalNo = SIGTERM;
    1577                     if (!__SIGSET_ISSET(&SigDeliver, SIGTERM))
    1578                     {
    1579                         iSignalNo = SIGABRT;
    1580                         if (!__SIGSET_ISSET(&SigDeliver, SIGABRT))
    1581                         {
    1582                             iSignalNo = SIGCHLD;
    1583                             if (!__SIGSET_ISSET(&SigDeliver, SIGCHLD))
    1584                             {
    1585                                 iSignalNo = SIGCONT;
    1586                                 if (!__SIGSET_ISSET(&SigDeliver, SIGCONT))
    1587                                 {
    1588                                     iSignalNo = 1;
    1589                                     while (iSignalNo < SIGRTMIN && !__SIGSET_ISSET(&SigDeliver, iSignalNo))
    1590                                         iSignalNo++;
    1591                                     if (iSignalNo >= SIGRTMIN)
    1592                                     {
    1593                                         LIBC_ASSERTM_FAILED("Internal error!!!\n");
    1594                                         LIBCLOG_RETURN_INT(__LIBC_BSRR_CONTINUE);
    1595                                     }
    1596                                 }
    1597                             }
    1598                         }
    1599                     }
    1600                 }
    1601             }
    1602         }
    1603 
    1604         /*
    1605          * Check if there is a queue element for the signal.
    1606          */
    1607         siginfo_t   SigInfo = {0};
    1608         PSIGQUEUED pSig = pThrd->SigQueue.pHead;
    1609         while (pSig)
    1610         {
    1611             if (pSig->SigInfo.si_signo == iSignalNo)
    1612             {
    1613                 /* unlink */
    1614                 if (pSig->pPrev)
    1615                     pSig->pPrev->pNext    = pSig->pNext;
    1616                 else
    1617                     pThrd->SigQueue.pHead = pSig->pNext;
    1618                 if (pSig->pNext)
    1619                     pSig->pNext->pPrev    = pSig->pPrev;
    1620                 else
    1621                     pThrd->SigQueue.pTail = pSig->pPrev;
    1622 
    1623                 /*
    1624                  * Check if more signals of this type so we can update the
    1625                  * pending mask correctly.
    1626                  */
    1627                 PSIGQUEUED pSigMore = pSig->pNext;
    1628                 while (pSigMore && pSigMore->SigInfo.si_signo != iSignalNo)
    1629                     pSigMore = pSigMore->pNext;
    1630                 if (!pSigMore)
    1631                     __SIGSET_CLEAR(&pThrd->SigSetPending, iSignalNo);
    1632 
    1633                 /*
    1634                  * Copy the signal to the SigInfo structure on the stack
    1635                  * and then release the signal queue structure.
    1636                  */
    1637                 SigInfo = pSig->SigInfo;
    1638                 break;
    1639             }
    1640             /* next */
    1641             pSig = pSig->pNext;
    1642         }
    1643 
    1644         /*
    1645          * If no queued signal data, then we can simply clear it in the pending mask.
    1646          */
    1647         if (!pSig)
    1648         {
    1649             SigInfo.si_signo = iSignalNo;
    1650             __SIGSET_CLEAR(&pThrd->SigSetPending, iSignalNo);
    1651         }
    1652 
    1653 
    1654         /*
    1655          * What to do for this signal?
    1656          */
     1627         * Accept the signal.
     1628         */
     1629        siginfo_t SigInfo;
     1630        if (iSignalNo && __SIGSET_ISSET(&pThrd->SigSetPending, iSignalNo))
     1631            iSignalNo = __libc_back_signalAccept(pThrd, iSignalNo, &SigDeliver, &SigInfo);
     1632        LIBC_ASSERTM(__SIGSET_SIG_VALID(iSignalNo), "iSignalNo=%d\n", iSignalNo);
    16571633        struct sigaction SigAction = gaSignalActions[iSignalNo];
     1634
     1635
     1636
     1637
     1638
     1639
     1640
     1641
     1642
     1643
     1644
     1645
     1646
     1647
     1648
     1649
     1650
     1651
     1652
     1653
     1654
     1655
     1656
     1657
     1658
     1659
     1660
     1661
     1662
     1663
     1664
     1665
     1666
    16581667        if (    SigAction.__sigaction_u.__sa_handler == SIG_IGN
    16591668            ||  (   SigAction.__sigaction_u.__sa_handler == SIG_DFL
     
    16661675        }
    16671676
     1677
     1678
     1679
    16681680        if (SigAction.__sigaction_u.__sa_handler == SIG_DFL)
    16691681        {
     
    17301742            if (gafSignalProperties[iSignalNo] & SPP_NOBLOCK)
    17311743                __SIGSET_CLEAR(&SigAction.sa_mask, iSignalNo);
    1732             sigset_t SigSetOld = pThrd->SigSetBlocked;
     1744            sigset_t SigSetOld = d;
    17331745            __SIGSET_OR(&pThrd->SigSetBlocked, &pThrd->SigSetBlocked, &SigAction.sa_mask);
    17341746
     
    19922004static int signalJobStop(int iSignalNo)
    19932005{
    1994     LIBC_ASSERTM(__libc_threadCurrent()->tid == 1, "Invalid thread %d\n", __libc_threadCurrent()->tid);
     2006    LIBC_ASSERTM(__libc_threadCurrent()->tid == 1, "Invalid thread %\n", __libc_threadCurrent()->tid);
    19952007
    19962008    /*
     
    20192031static int signalJobResume(void)
    20202032{
    2021     LIBC_ASSERTM(__libc_threadCurrent()->tid == 1, "Invalid thread %d\n", __libc_threadCurrent()->tid);
     2033    LIBC_ASSERTM(__libc_threadCurrent()->tid == 1, "Invalid thread %\n", __libc_threadCurrent()->tid);
    20222034
    20232035    /*
     
    23582370 *
    23592371 * @returns 0 on success.
    2360  * @returns -Negative errno on failure.
     2372 * @returns on failure.
    23612373 * @param   iSignalNo   Signal number.
    23622374 * @param   pSigAct     Pointer to new signal action.
     
    25572569
    25582570/**
     2571
     2572
     2573
     2574
     2575
     2576
     2577
     2578
     2579
     2580
     2581
     2582
     2583
     2584
     2585
     2586
     2587
     2588
     2589
     2590
     2591
     2592
     2593
     2594
     2595
     2596
     2597
     2598
     2599
     2600
     2601
     2602
     2603
     2604
     2605
     2606
     2607
     2608
     2609
     2610
     2611
     2612
     2613
     2614
     2615
     2616
     2617
     2618
     2619
     2620
     2621
     2622
     2623
     2624
     2625
     2626
     2627
     2628
     2629
     2630
     2631
     2632
     2633
     2634
     2635
     2636
     2637
     2638
     2639
     2640
     2641
     2642
     2643
     2644
     2645
     2646
     2647
     2648
     2649
     2650
     2651
     2652
     2653
     2654
     2655
     2656
     2657
     2658
     2659
     2660
     2661
     2662
     2663
     2664
     2665
     2666
     2667
     2668
     2669
     2670
     2671
     2672
     2673
     2674
     2675
     2676
     2677
     2678
     2679
     2680
     2681
     2682
     2683
     2684
     2685
     2686
     2687
     2688
     2689
     2690
     2691
     2692
     2693
     2694
     2695
     2696
     2697
     2698
     2699
     2700
     2701
     2702
     2703
     2704
     2705
     2706
     2707
     2708
     2709
     2710
     2711
     2712
     2713
     2714
     2715
     2716
     2717
     2718
     2719
     2720
     2721
     2722
     2723
     2724
     2725
     2726
     2727
     2728
     2729
     2730
     2731
     2732
     2733
     2734
     2735
     2736
     2737
     2738
     2739
     2740
     2741
     2742
     2743
     2744
     2745
     2746
     2747
     2748
     2749
     2750
     2751
     2752
     2753
     2754
     2755
     2756
     2757
     2758
     2759
     2760
     2761
     2762
     2763
     2764
     2765
     2766
     2767
     2768
     2769
     2770
     2771
     2772
     2773
     2774
     2775
     2776
     2777
     2778
     2779
     2780
     2781
     2782
     2783
     2784
     2785
     2786
     2787
     2788
     2789
     2790
     2791
     2792
     2793
     2794
     2795
     2796
     2797
     2798
    25592799 * Gets the current timestamp.
    25602800 *
Note: See TracChangeset for help on using the changeset viewer.