Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/posix/sys/wait.c

    r4cf8ca6 r2a53f71  
    3939#include "wait.h"
    4040
     41#include "../libc/task.h"
     42#include "../assert.h"
     43#include "../errno.h"
     44#include "../limits.h"
     45#include "../signal.h"
     46
     47int __posix_wifexited(int status) {
     48        return status != INT_MIN;
     49}
     50
     51int __posix_wexitstatus(int status) {
     52        assert(__posix_wifexited(status));
     53        return status;
     54}
     55
     56int __posix_wifsignaled(int status) {
     57        return status == INT_MIN;
     58}
     59
     60int __posix_wtermsig(int status) {
     61        assert(__posix_wifsignaled(status));
     62        /* There is no way to distinguish reason
     63         * for unexpected termination at the moment.
     64         */
     65        return SIGABRT;
     66}
     67
    4168/**
     69 * Wait for any child process to stop or terminate.
    4270 *
    43  * @param stat_ptr
    44  * @return
     71 * @param stat_ptr Location of the final status code of the child process.
     72 * @return ID of the child process for which status is reported,
     73 *     -1 on signal interrupt, (pid_t)-1 otherwise.
    4574 */
    4675posix_pid_t posix_wait(int *stat_ptr)
    4776{
    48         // TODO: low priority, just a compile-time dependency of binutils
    49         not_implemented();
     77        /* HelenOS does not support this. */
     78        errno = ENOSYS;
     79        return (posix_pid_t) -1;
    5080}
    5181
    5282/**
     83 * Wait for a child process to stop or terminate.
    5384 *
    54  * @param pid
    55  * @param stat_ptr
    56  * @param options
    57  * @return
     85 * @param pid What child process shall the caller wait for. See POSIX manual
     86 *     for details.
     87 * @param stat_ptr Location of the final status code of the child process.
     88 * @param options Constraints of the waiting. See POSIX manual for details.
     89 * @return ID of the child process for which status is reported,
     90 *     -1 on signal interrupt, 0 if non-blocking wait is requested but there is
     91 *     no child process whose status can be reported, (pid_t)-1 otherwise.
    5892 */
    5993posix_pid_t posix_waitpid(posix_pid_t pid, int *stat_ptr, int options)
    6094{
    61         // TODO: low priority, just a compile-time dependency of binutils
    62         not_implemented();
     95        assert(stat_ptr != NULL);
     96        assert(options == 0 /* None of the options are supported. */);
     97       
     98        task_exit_t texit;
     99        int retval;
     100       
     101        int rc = task_wait((task_id_t) pid, &texit, &retval);
     102       
     103        if (rc < 0) {
     104                /* Unable to retrieve status. */
     105                errno = -rc;
     106                return (posix_pid_t) -1;
     107        }
     108       
     109        if (texit == TASK_EXIT_NORMAL) {
     110                // FIXME: relies on application not returning this value
     111                assert(retval != INT_MIN);
     112                *stat_ptr = retval;
     113        } else {
     114                /* Reserve the lowest value for unexpected termination. */
     115                *stat_ptr = INT_MIN;
     116        }
     117       
     118        return pid;
    63119}
    64120
Note: See TracChangeset for help on using the changeset viewer.