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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since fdf97f6 was fdf97f6, checked in by Vojtech Horky <vojtechhorky@…>, 12 years ago

Libposix functions are without posix_ prefix

Prior this commit, libposix headers declared all functions as posix_*
and used macros to rename e.g. strncpy to posix_strncpy in all (ported)
sources.

After this change, libposix headers look as normal POSIX compliant headers
(well, almost) and no renaming is done in the source codei (of the ported
applications). Instead, the renaming is done at object files level to
bypass weird problems that are bound to happen if you use macros.

The scheme is following. libposix headers use special macro to declare
the names. When included from outside, the functions have their normal
(standard) names. When included from the libposix sources, posix_ prefix
is added. Thus, when libposix is compiled and linked, it contains the
posix_* naming while compiling of ported software uses the normal
non-prefixed versions. This way the posix_* can use HelenOS libc without
any problem. Before linking, the posix_* prefix is removed from all
symbols and special prefix helenos_libc_ is added to all functions
that exists in our (HelenOS) libc and its name clashes with the POSIX
one.

The following happens, for example, to the open() function that exists in
both libposix and in libc.

  • Headers and sources of libc are left intact.
  • Copy of libc.a is made and to all clashing functions is added the helenos_libc prefix. This library is called libc4posix.a.
  • POSIX_DEF(open)(const char *) is used in libposix headers. This macro expands to plain open when included from the "outside world". But it expands to posix_open when included from libposix sources.
  • Libposix is compiled and linked, containing posix_open() that internally calls open() [the original one from libc].
  • Libposix is transformed - all open() are replaced with prefix variant: helenos_libc_open() and all posix_open() are replaced with open(). The transformed library is stored as libposixaslibc.a

Binutils and PCC are then linked with libc4posix and libposixaslibc
libraries instead of libc and libposix as was done previously.

WARNING: it looks that binutils, PCC and MSIM still works but not all
architectures were tested.

  • Property mode set to 100644
File size: 3.7 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#define __POSIX_DEF__(x) posix_##x
38
39#include "../internal/common.h"
40#include "posix/sys/wait.h"
41
42#include "libc/task.h"
43#include "posix/assert.h"
44#include "posix/errno.h"
45#include "posix/limits.h"
46#include "posix/signal.h"
47
48int __posix_wifexited(int status) {
49 return status != INT_MIN;
50}
51
52int __posix_wexitstatus(int status) {
53 assert(__posix_wifexited(status));
54 return status;
55}
56
57int __posix_wifsignaled(int status) {
58 return status == INT_MIN;
59}
60
61int __posix_wtermsig(int status) {
62 assert(__posix_wifsignaled(status));
63 /* There is no way to distinguish reason
64 * for unexpected termination at the moment.
65 */
66 return SIGABRT;
67}
68
69/**
70 * Wait for any child process to stop or terminate.
71 *
72 * @param stat_ptr Location of the final status code of the child process.
73 * @return ID of the child process for which status is reported,
74 * -1 on signal interrupt, (pid_t)-1 otherwise.
75 */
76posix_pid_t posix_wait(int *stat_ptr)
77{
78 /* HelenOS does not support this. */
79 errno = ENOSYS;
80 return (posix_pid_t) -1;
81}
82
83/**
84 * Wait for a child process to stop or terminate.
85 *
86 * @param pid What child process shall the caller wait for. See POSIX manual
87 * for details.
88 * @param stat_ptr Location of the final status code of the child process.
89 * @param options Constraints of the waiting. See POSIX manual for details.
90 * @return ID of the child process for which status is reported,
91 * -1 on signal interrupt, 0 if non-blocking wait is requested but there is
92 * no child process whose status can be reported, (pid_t)-1 otherwise.
93 */
94posix_pid_t posix_waitpid(posix_pid_t pid, int *stat_ptr, int options)
95{
96 assert(stat_ptr != NULL);
97 assert(options == 0 /* None of the options are supported. */);
98
99 task_exit_t texit;
100 int retval;
101
102 int rc = task_wait((task_id_t) pid, &texit, &retval);
103
104 if (rc < 0) {
105 /* Unable to retrieve status. */
106 errno = -rc;
107 return (posix_pid_t) -1;
108 }
109
110 if (texit == TASK_EXIT_NORMAL) {
111 // FIXME: relies on application not returning this value
112 assert(retval != INT_MIN);
113 *stat_ptr = retval;
114 } else {
115 /* Reserve the lowest value for unexpected termination. */
116 *stat_ptr = INT_MIN;
117 }
118
119 return pid;
120}
121
122/** @}
123 */
Note: See TracBrowser for help on using the repository browser.