Changeset 1627


Ignore:
Timestamp:
Nov 8, 2004, 10:57:37 AM (21 years ago)
Author:
bird
Message:

Having a go at waitid (and waitpid()/wait()).

Location:
trunk/src/emx
Files:
2 added
6 edited

Legend:

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

    • Property cvs2svn:cvs-rev changed from 1.11 to 1.12
    r1626 r1627  
    3030#include <sys/cdefs.h>
    3131#include <sys/types.h>
     32#include <sys/_timeval.h>
     33#include <sys/resource.h>
     34#include <sys/wait.h>
    3235#include <signal.h>
    3336#include <emx/io.h>
     
    657660/** @} */
    658661
     662
     663
     664/** @defgroup grp_Back_process  LIBC Backend - Process Management
     665 * @{ */
     666
     667/**
     668 * Waits/polls for on one or more processes to change it's running status.
     669 *
     670 * @returns 0 on success, pSigInfo containing status info.
     671 * @returns -1 and errno on failure.
     672 * @param   enmIdType   What kind of process specification Id contains.
     673 * @param   Id          Process specification of the enmIdType sort.
     674 * @param   pSigInfo    Where to store the result.
     675 * @param   fOptions    The WEXITED, WUNTRACED, WSTOPPED and WCONTINUED flags are used to
     676 *                      select the events to report. WNOHANG is used for preventing the api
     677 *                      from blocking. And WNOWAIT is used for peeking.
     678 * @param   pResUsage   Where to store the reported resources usage for the child.
     679 *                      Optional and not implemented on OS/2.
     680 */
     681int __libc_Back_processWait(idtype_t enmIdType, id_t Id, siginfo_t *pSigInfo, unsigned fOptions, struct rusage *pUsage);
     682
     683/** @} */
     684
    659685__END_DECLS
    660686
  • trunk/src/emx/include/InnoTekLIBC/sharedpm.h

    • Property cvs2svn:cvs-rev changed from 1.14 to 1.15
    r1626 r1627  
    550550
    551551/**
     552 * Gets the exit code and reason of death for a specific child process
     553 * which is believed to have died.
     554 *
     555 * @returns 0 on success.
     556 * @returns Negative error code (errno.h) on failure.
     557 * @param   pid                 Process id.
     558 * @param   pendDeathReason     Where to store the death reason.
     559 * @param   piExitCode          Where to store the exit code.
     560 */
     561int __libc_spmReapChild(pid_t pid, __LIBC_EXIT_REASON *penmDeathReason, int *piExitCode);
     562
     563/**
    552564 * Locks the LIBC shared memory for short exclusive access.
    553565 * The call must call __libc_spmUnlock() as fast as possible and make
  • trunk/src/emx/include/InnoTekLIBC/thread.h

    • Property cvs2svn:cvs-rev changed from 1.9 to 1.10
    r1626 r1627  
    545545void (*__libc_TLSGetDestructor(int iTLSIndex, unsigned *pfFlags))(void *, int, unsigned);
    546546
     547/* fix later */
     548int __libc_back_threadCreate(void (*pfnStart)(void *), unsigned cbStack, void *pvArg, int fInternal);
     549
    547550/** @} */
    548551
  • trunk/src/emx/include/sys/wait.h

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1626 r1627  
    1 /* sys/wait.h (emx+gcc) */
     1/*-
     2 * Copyright (c) 1982, 1986, 1989, 1993, 1994
     3 *      The Regents of the University of California.  All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 * 1. Redistributions of source code must retain the above copyright
     9 *    notice, this list of conditions and the following disclaimer.
     10 * 2. Redistributions in binary form must reproduce the above copyright
     11 *    notice, this list of conditions and the following disclaimer in the
     12 *    documentation and/or other materials provided with the distribution.
     13 * 4. Neither the name of the University nor the names of its contributors
     14 *    may be used to endorse or promote products derived from this software
     15 *    without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     27 * SUCH DAMAGE.
     28 *
     29 *      @(#)wait.h      8.2 (Berkeley) 7/10/94
     30 * $FreeBSD: src/sys/sys/wait.h,v 1.20 2004/04/09 13:14:32 bde Exp $
     31 */
    232
    3 #ifndef _SYS_WAIT_H
    4 #define _SYS_WAIT_H
     33#ifndef _SYS_WAIT_H_
     34#define _SYS_WAIT_H_
    535
    6 #if defined (__cplusplus)
    7 extern "C" {
     36#include <sys/cdefs.h>
     37
     38/*
     39 * This file holds definitions relevant to the wait4 system call and the
     40 * alternate interfaces that use it (wait, wait3, waitpid).
     41 */
     42
     43/*
     44 * Macros to test the exit status returned by wait and extract the relevant
     45 * values.
     46 */
     47#if __BSD_VISIBLE
     48#define _W_INT(w)       (*(int *)&(w))  /* Convert union wait to int. */
     49#define WCOREFLAG       0200
     50#else
     51#define _W_INT(i)       (i)
    852#endif
    953
    10 #define WNOHANG         1
    11 #define WUNTRACED       2
     54#define _WSTATUS(x)     (_W_INT(x) & 0177)
     55#define _WSTOPPED       0177            /* _WSTATUS if process is stopped */
     56#define WIFSTOPPED(x)   (_WSTATUS(x) == _WSTOPPED)
     57#define WSTOPSIG(x)     (_W_INT(x) >> 8)
     58#define WIFSIGNALED(x)  (_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0)
     59#define WTERMSIG(x)     (_WSTATUS(x))
     60#define WIFEXITED(x)    (_WSTATUS(x) == 0)
     61#define WEXITSTATUS(x)  (_W_INT(x) >> 8)
     62#define WIFCONTINUED(x) (x == 0x13)     /* 0x13 == SIGCONT */
     63#if __BSD_VISIBLE
     64#define WCOREDUMP(x)    (_W_INT(x) & WCOREFLAG)
    1265
    13 #define WIFEXITED(st)   (((st) & 0x7f) == 0)
    14 #define WIFSIGNALED(st) (((st) & 0x7f) != 0x7f && ((st) & 0x7f) != 0)
    15 #define WIFSTOPPED(st)  (((st) & 0x7f) == 0x7f)
    16 
    17 #define WEXITSTATUS(st) ((st) >> 8)
    18 #define WTERMSIG(st)    ((st) & 0x7f)
    19 #define WSTOPSIG(st)    ((st) >> 8)
    20 
    21 int wait (int *);
    22 int waitpid (int, int *, int);
    23 
    24 #if !defined (_POSIX_SOURCE) || defined (_WITH_UNDERSCORE) || defined(__USE_EMX)
    25 
    26 int _wait (int *);
    27 int _waitpid (int, int *, int);
    28 
     66#define W_EXITCODE(ret, sig)    ((ret) << 8 | (sig))
     67#define W_STOPCODE(sig)         ((sig) << 8 | _WSTOPPED)
    2968#endif
    3069
    31 #if defined (__cplusplus)
    32 }
     70/*
     71 * Option bits for the third argument of wait4.  WNOHANG causes the
     72 * wait to not hang if there are no stopped or terminated processes, rather
     73 * returning an error indication in this case (pid==0).  WUNTRACED
     74 * indicates that the caller should receive status about untraced children
     75 * which stop due to signals.  If children are stopped and a wait without
     76 * this option is done, it is as though they were still running... nothing
     77 * about them is returned.
     78 */
     79#define WNOHANG         1       /* Don't hang in wait. */
     80#define WUNTRACED       2       /* Tell about stopped, untraced children. */
     81#define WCONTINUED      4       /* Report a job control continued process. */
     82
     83#if 0 /* bird: old __BSD_VISIBLE */
     84#define WLINUXCLONE 0x80000000  /* Wait for kthread spawned from linux_clone. */
    3385#endif
    3486
    35 #endif /* not SYS_WAIT_H */
     87/*
     88 * Tokens for special values of the "pid" parameter to wait4.
     89 */
     90#if __BSD_VISIBLE
     91#define WAIT_ANY        (-1)    /* any process */
     92#define WAIT_MYPGRP     0       /* any process in my process group */
     93#endif /* __BSD_VISIBLE */
     94
     95#ifdef _KERNEL
     96struct rusage;
     97int     kern_wait(struct thread *td, pid_t pid, int *status, int options,
     98            struct rusage *rup);
     99#else /* !_KERNEL */
     100#include <sys/types.h>
     101
     102__BEGIN_DECLS
     103pid_t   wait(int *);
     104pid_t   waitpid(pid_t, int *, int);
     105#if 0 /* bird: old __BSD_VISIBLE */
     106struct rusage;
     107pid_t   wait3(int *, int, struct rusage *);
     108pid_t   wait4(pid_t, int *, int, struct rusage *);
     109#endif
     110
     111
     112/*
     113 * bird: LIBC additions - start.
     114 */
     115#if __XSI_VISIBLE
     116#include <signal.h>
     117
     118/** Wait for processes that have exited. */
     119#define WEXITED         8
     120/** Wait for processes that have stopped. */
     121#define WSTOPPED       16
     122/** Keep the wait state around for later wait calls, i.e. just peek at the stuff. */
     123#define WNOWAIT        32
     124
     125/* The following values are used by the `waitid' function.  */
     126typedef enum
     127{
     128    /** Wait for any child process. */
     129    P_ALL,
     130    /** Wait for a specific process. */
     131    P_PID,
     132    /** Wait for processes of a process group. */
     133    P_PGID
     134} idtype_t;
     135
     136int     waitid(idtype_t, id_t, siginfo_t *, int);
     137#endif /* __XSI_VISIBLE */
     138
     139/*
     140 * bird: LIBC additions - end.
     141 */
     142
     143__END_DECLS
     144#endif /* _KERNEL */
     145
     146#endif /* !_SYS_WAIT_H_ */
  • trunk/src/emx/src/lib/process/beginthr.c

    • Property cvs2svn:cvs-rev changed from 1.11 to 1.12
    r1626 r1627  
    4747
    4848
    49 int _beginthread(void (*pfnStart)(void *), void *pvStack, unsigned cbStack, void *pvArg)
     49/* move me !! */
     50int __libc_back_threadCreate(void (*pfnStart)(void *), unsigned cbStack, void *pvArg, int fInternal)
    5051{
    51     LIBCLOG_ENTER("pfnStart=%p pvStart=%p cbStack=%d pvArg=%p\n", (void *)pfnStart, pvStack, cbStack, pvArg);
     52    LIBCLOG_ENTER("pfnStart=%p cbStack=%d pvArg=%p fInternal=%d\n", (void *)pfnStart, cbStack, pvArg, fInternal);
    5253    int             rc;
    5354    TID             tid;
     
    6869     * Set the startup thread info and create a new thread.
    6970     */
     71    pThrd->fInternalThread    = fInternal;
    7072    pThrd->u.startup.pfnStart = pfnStart;
    7173    pThrd->u.startup.pvArg    = pvArg;
     
    9496}
    9597
     98int _beginthread(void (*pfnStart)(void *), void *pvStack, unsigned cbStack, void *pvArg)
     99{
     100    LIBCLOG_ENTER("pfnStart=%p pvStack=%p cbStack=%d pvArg=%p\n", (void *)pfnStart, pvStack, cbStack, pvArg);
     101    int rc = __libc_back_threadCreate(pfnStart, cbStack, pvArg, 0);
     102    if (rc >= 0)
     103        LIBCLOG_RETURN_INT(-1);
     104    errno = -rc;
     105    LIBCLOG_RETURN_INT(-1);
     106}
     107
    96108
    97109void _endthread(void)
  • trunk/src/emx/src/lib/sys/sharedpm.c

    • Property cvs2svn:cvs-rev changed from 1.17 to 1.18
    r1626 r1627  
    188188    LIBCLOG_RETURN_VOID();
    189189}
     190
     191
     192/**
     193 * Gets the exit code and reason of death for a specific child process
     194 * which is believed to have died.
     195 *
     196 * @returns 0 on success.
     197 * @returns Negative error code (errno.h) on failure.
     198 * @param   pid                 Process id.
     199 * @param   pendDeathReason     Where to store the death reason.
     200 * @param   piExitCode          Where to store the exit code.
     201 */
     202int __libc_spmReapChild(pid_t pid, __LIBC_EXIT_REASON *penmDeathReason, int *piExitCode)
     203{
     204    LIBCLOG_ENTER("pid=%#x (%d) penmDeathReason=%p piExitCode=%p\n", pid, pid, (void *)penmDeathReason, (void *)piExitCode);
     205    __LIBC_SPMXCPTREGREC    RegRec;
     206    int                     iExitCode = 0;
     207    __LIBC_EXIT_REASON      enmDeathReason = 0;
     208
     209    /*
     210     * Set return code and reason.
     211     */
     212    int rc = spmRequestMutexErrno(&RegRec);
     213    if (!rc)
     214    {
     215        /*
     216         * Try find the process, it gotta be a zombie.
     217         */
     218        __LIBC_PSPMPROCESS pProcess = spmQueryProcessInState(pid, __LIBC_PROCSTATE_ZOMBIE);
     219        if (pProcess)
     220        {
     221            iExitCode = pProcess->iExitCode;
     222            enmDeathReason = pProcess->enmDeathReason;
     223
     224            /* reap it */
     225            if (pProcess->cReferences > 0)
     226                pProcess->cReferences--;
     227            if (pProcess->cReferences <= 0)
     228                spmFreeProcess(pProcess);
     229        }
     230        else
     231            rc = -ESRCH;
     232
     233        /*
     234         * We're done, free the mutex and store the results.
     235         */
     236        spmReleaseMutex(&RegRec);
     237        *penmDeathReason = enmDeathReason;
     238        *piExitCode = iExitCode;
     239    }
     240
     241    LIBCLOG_RETURN_INT(rc);
     242}
     243
    190244
    191245#ifdef TIMEBOMB
Note: See TracChangeset for help on using the changeset viewer.