source: mainline/uspace/lib/posix/sys/wait.c@ 1e591c8

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1e591c8 was eb1edb0, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 14 years ago

Partial <wait.h> implementation.

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 * Copyright (c) 2011 Petr Koupy
3 * Copyright (c) 2011 Jiri Zarevucky
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup libposix
31 * @{
32 */
33/** @file Support for waiting.
34 */
35
36#define LIBPOSIX_INTERNAL
37
38#include "../internal/common.h"
39#include "wait.h"
40
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
68/**
69 *
70 * @param stat_ptr
71 * @return
72 */
73posix_pid_t posix_wait(int *stat_ptr)
74{
75 /* HelenOS does not support this. */
76 errno = ENOSYS;
77 return (posix_pid_t) -1;
78}
79
80/**
81 *
82 * @param pid
83 * @param stat_ptr
84 * @param options
85 * @return
86 */
87posix_pid_t posix_waitpid(posix_pid_t pid, int *stat_ptr, int options)
88{
89 assert(stat_ptr != NULL);
90 assert(options == 0 /* None of the options are supported. */);
91
92 task_exit_t texit;
93 int retval;
94
95 int rc = task_wait((task_id_t) pid, &texit, &retval);
96
97 if (rc < 0) {
98 /* Unable to retrieve status. */
99 errno = -rc;
100 return (posix_pid_t) -1;
101 }
102
103 if (texit == TASK_EXIT_NORMAL) {
104 // FIXME: relies on application not returning this value
105 assert(retval != INT_MIN);
106 *stat_ptr = retval;
107 } else {
108 /* Reserve the lowest value for unexpected termination. */
109 *stat_ptr = INT_MIN;
110 }
111
112 return pid;
113}
114
115/** @}
116 */
Note: See TracBrowser for help on using the repository browser.