1 /*
2 * Copyright 2009, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 * Bruno Albuquerque, bga@bug-br.org.br
7 */
8
9 #include <OS.h>
10
11 #include <sys/resource.h>
12 #include <sys/wait.h>
13
14
15 extern pid_t _waitpid(pid_t pid, int* _status, int options,
16 team_usage_info *usage_info);
17
18 // prototypes for the compiler
19 pid_t _wait3_base(int *status, int options, struct rusage *rusage);
20 pid_t _wait4_base(pid_t pid, int *status, int options, struct rusage *rusage);
21 pid_t _wait3_current(int *status, int options, struct rusage *rusage);
22 pid_t _wait4_current(pid_t pid, int *status, int options,
23 struct rusage *rusage);
24
25
26 pid_t
_wait3_base(int * status,int options,struct rusage * rusage)27 _wait3_base(int *status, int options, struct rusage *rusage)
28 {
29 return _wait4_base(-1, status, options, rusage);
30 }
31
32
33 pid_t
_wait4_base(pid_t pid,int * status,int options,struct rusage * rusage)34 _wait4_base(pid_t pid, int *status, int options, struct rusage *rusage)
35 {
36 team_usage_info info;
37 pid_t waitPid = _waitpid(pid, status, options,
38 rusage != NULL ? &info : NULL);
39 if (waitPid != -1 && rusage != NULL) {
40 rusage->ru_utime.tv_sec = info.user_time / 1000000;
41 rusage->ru_utime.tv_usec = info.user_time % 1000000;
42
43 rusage->ru_stime.tv_sec = info.kernel_time / 1000000;
44 rusage->ru_stime.tv_usec = info.kernel_time % 1000000;
45 }
46
47 return waitPid;
48 }
49
50
51 pid_t
_wait3_current(int * status,int options,struct rusage * rusage)52 _wait3_current(int *status, int options, struct rusage *rusage)
53 {
54 return _wait4_current(-1, status, options, rusage);
55 }
56
57
58 pid_t
_wait4_current(pid_t pid,int * status,int options,struct rusage * rusage)59 _wait4_current(pid_t pid, int *status, int options, struct rusage *rusage)
60 {
61 pid_t waitPid = _wait4_base(pid, status, options, rusage);
62 if (waitPid != -1 && rusage != NULL) {
63 memset(&rusage->ru_maxrss, 0, sizeof(struct rusage) -
64 offsetof(struct rusage, ru_maxrss));
65 }
66
67 return waitPid;
68 }
69
70
71 #define DEFINE_LIBBSD_SYMBOL_VERSION(function, symbol, version) \
72 B_DEFINE_SYMBOL_VERSION(function, symbol "LIBBSD_" version)
73
74 DEFINE_LIBBSD_SYMBOL_VERSION("_wait3_base", "wait3@", "BASE");
75 DEFINE_LIBBSD_SYMBOL_VERSION("_wait4_base", "wait4@", "BASE");
76 DEFINE_LIBBSD_SYMBOL_VERSION("_wait3_current", "wait3@@", "1_BETA3");
77 DEFINE_LIBBSD_SYMBOL_VERSION("_wait4_current", "wait4@@", "1_BETA3");
78
79