1 /* @(#)wait.h 1.31 19/12/09 Copyright 1995-2019 J. Schilling */ 2 /* 3 * Definitions to deal with various kinds of wait flavour 4 * 5 * Copyright (c) 1995-2019 J. Schilling 6 */ 7 /* 8 * The contents of this file are subject to the terms of the 9 * Common Development and Distribution License, Version 1.0 only 10 * (the "License"). You may not use this file except in compliance 11 * with the License. 12 * 13 * See the file CDDL.Schily.txt in this distribution for details. 14 * A copy of the CDDL is also available via the Internet at 15 * http://www.opensource.org/licenses/cddl1.txt 16 * 17 * When distributing Covered Code, include this CDDL HEADER in each 18 * file and include the License file CDDL.Schily.txt from this distribution. 19 */ 20 21 #ifndef _SCHILY_WAIT_H 22 #define _SCHILY_WAIT_H 23 24 #ifndef _SCHILY_MCONFIG_H 25 #include <schily/mconfig.h> 26 #endif 27 28 /* 29 * Needed for SysVr4 30 */ 31 #ifndef _SCHILY_TYPES_H 32 #include <schily/types.h> 33 #endif 34 35 #if defined(HAVE_WAIT_H) 36 # ifndef _INCL_WAIT_H 37 # include <wait.h> 38 # define _INCL_WAIT_H 39 # endif 40 #else 41 /* 42 * K&R Compiler doesn't like #elif 43 */ 44 # if defined(HAVE_SYS_WAIT_H) /* POSIX.1 compl. sys/wait.h */ 45 # undef HAVE_UNION_WAIT /* POSIX.1 doesn't use U_W */ 46 # ifndef _INCL_SYS_WAIT_H 47 # include <sys/wait.h> 48 # define _INCL_SYS_WAIT_H 49 # endif 50 # else 51 # if defined(HAVE_UNION_WAIT) /* Pure BSD U_W / sys/wait.h */ 52 # ifndef _INCL_SYS_WAIT_H 53 # include <sys/wait.h> 54 # define _INCL_SYS_WAIT_H 55 # endif 56 # endif 57 # endif 58 #endif 59 #ifdef JOS 60 # ifndef _INCL_SYS_EXIT_H 61 # include <sys/exit.h> 62 # define _INCL_SYS_EXIT_H 63 # endif 64 #endif 65 #if defined(__EMX__) || defined(__DJGPP__) 66 # ifndef _INCL_PROCESS_H 67 # include <process.h> 68 # define _INCL_PROCESS_H 69 # endif 70 #endif 71 72 /* 73 * Since some platforms need to include <signal.h> in order to make 74 * <wait.h> usable, we now always include <schily/signal.h> in special 75 * since this way supply a siginfo_t emulation. 76 * 77 * In former times, we had: 78 * #if !defined(HAVE_TYPE_SIGINFO_T) && defined(HAVE_SIGINFO_T) 79 */ 80 #ifndef _SCHILY_SIGNAL_H 81 #include <schily/signal.h> 82 #endif 83 84 #ifdef __cplusplus 85 extern "C" { 86 #endif 87 88 /* 89 * waitid() idtype_t definition, define when missing or broken. 90 * NetBSD-5 has an idtype_t that is in conflict with POSIX. 91 */ 92 #ifndef HAVE_TYPE_IDTYPE_T 93 94 #undef HAVE_WAITID /* Can't have waitid() with broken idtype_t */ 95 96 #undef P_PID 97 #undef P_PPID 98 #undef P_PGID 99 #undef P_SID 100 #undef P_CID 101 #undef P_UID 102 #undef P_GID 103 #undef P_ALL 104 105 #define P_PID MY_P_PID 106 #define P_PPID MY_P_PPID 107 #define P_PGID MY_P_PGID 108 #define P_SID MY_P_SID 109 #define P_CID MY_P_CID 110 #define P_UID MY_P_UID 111 #define P_GID MY_P_GID 112 #define P_ALL MY_P_ALL 113 114 typedef enum { 115 P_PID, /* A process identifier. */ 116 P_PPID, /* A parent process identifier. */ 117 P_PGID, /* A process group (job control group) */ 118 /* identifier. */ 119 P_SID, /* A session identifier. */ 120 P_CID, /* A scheduling class identifier. */ 121 P_UID, /* A user identifier. */ 122 P_GID, /* A group identifier. */ 123 P_ALL, /* All processes. */ 124 } js_idtype_t; 125 126 #undef idtype_t 127 #define idtype_t js_idtype_t 128 129 #endif /* HAVE_TYPE_IDTYPE_T */ 130 131 #ifndef WCOREFLG 132 #ifdef WCOREFLAG 133 #define WCOREFLG WCOREFLAG 134 #else 135 #define WCOREFLG 0x80 136 #endif 137 #define NO_WCOREFLG 138 #endif 139 140 #ifndef WSTOPFLG 141 #ifdef _WSTOPPED 142 #define WSTOPFLG _WSTOPPED 143 #else 144 #define WSTOPFLG 0x7F 145 #endif 146 #define NO_WSTOPFLG 147 #endif 148 149 #ifndef WCONTFLG 150 #define WCONTFLG 0xFFFF 151 #define NO_WCONTFLG 152 #endif 153 154 /* 155 * Work around a NetBSD bug that has been imported from BSD. 156 * There is a #define WSTOPPED _WSTOPPED that is in conflict with the 157 * AT&T waitid() flags definition that is part of the POSIX standard. 158 */ 159 #if defined(WSTOPPED) && defined(_WSTOPPED) && WSTOPPED == _WSTOPPED 160 #undef WSTOPPED 161 #define WSTOPPED WUNTRACED 162 #endif 163 164 /* 165 * waitid() option flags: 166 */ 167 #ifndef WCONTINUED 168 #define WCONTINUED 0 169 #define NO_WCONTINUED 170 #endif 171 #ifndef WEXITED 172 #define WEXITED 0 173 #define NO_WEXITED 174 #endif 175 #ifndef WNOHANG 176 #define WNOHANG 0 177 #define NO_WNOHANG 178 #endif 179 #ifndef WNOWAIT 180 #define WNOWAIT 0 181 #define NO_WNOWAIT 182 #endif 183 #ifndef WSTOPPED 184 #ifdef WUNTRACED 185 #define WSTOPPED WUNTRACED 186 #else 187 #define WSTOPPED 0 188 #endif 189 #define NO_WSTOPPED 190 #endif 191 #ifndef WTRAPPED 192 #define WTRAPPED 0 193 #define NO_WTRAPPED 194 #endif 195 196 /* 197 * waitid() code values, #define them when they are missing: 198 */ 199 #ifndef CLD_EXITED /* Assume all is missing then */ 200 #define CLD_EXITED 1 /* child has exited */ 201 #define CLD_KILLED 2 /* child was killed */ 202 #define CLD_DUMPED 3 /* child has coredumped */ 203 #define CLD_TRAPPED 4 /* traced child has stopped */ 204 #define CLD_STOPPED 5 /* child has stopped on signal */ 205 #define CLD_CONTINUED 6 /* stopped child has continued */ 206 #define NO_CLD_EXITED 207 #endif /* CLD_EXITED */ 208 209 #ifdef ultrix 210 /* 211 * The W*() macros on Ultrix do not work and this is a result of 212 * an incorrect definition for union wait. The kernel uses the 213 * right bits in the status, so we #undef USE_UNION_WAIT and all 214 * W*() macros. This results in #defining our working versions. 215 */ 216 #define WAIT_T union wait 217 #undef USE_UNION_WAIT 218 #undef WTERMSIG 219 #undef WCOREDUMP 220 #undef WEXITSTATUS 221 #undef WSTOPSIG 222 #undef WIFCONTINUED 223 #undef WIFSTOPPED 224 #undef WIFSIGNALED 225 #undef WIFEXITED 226 #endif /* ultrix */ 227 228 #if defined(HAVE_UNION_WAIT) && defined(USE_UNION_WAIT) 229 # define WAIT_T union wait 230 # define _W_U(w) ((union wait *)&(w)) 231 # ifndef WTERMSIG 232 # define WTERMSIG(status) (_W_U(status)->w_termsig) 233 # endif 234 # ifndef WCOREDUMP 235 # define WCOREDUMP(status) (_W_U(status)->w_coredump) 236 # endif 237 # ifndef WEXITSTATUS 238 # define WEXITSTATUS(status) (_W_U(status)->w_retcode) 239 # endif 240 # ifndef WSTOPSIG 241 # define WSTOPSIG(status) (_W_U(status)->w_stopsig) 242 # endif 243 # ifndef WIFCONTINUED 244 # define WIFCONTINUED(status) (0) 245 # endif 246 # ifndef WIFSTOPPED 247 # define WIFSTOPPED(status) (_W_U(status)->w_stopval == \ 248 WSTOPFLG) 249 # endif 250 # ifndef WIFSIGNALED 251 # define WIFSIGNALED(status) (_W_U(status)->w_stopval != \ 252 WSTOPFLG && \ 253 _W_U(status)->w_termsig != 0) 254 # endif 255 # ifndef WIFEXITED 256 # define WIFEXITED(status) (_W_U(status)->w_stopval != \ 257 WSTOPFLG && \ 258 _W_U(status)->w_termsig == 0) 259 # endif 260 #else 261 # ifndef WAIT_T 262 # define WAIT_T int 263 # endif 264 # define _W_I(w) (*(int *)&(w)) 265 # ifndef WTERMSIG 266 # define WTERMSIG(status) (_W_I(status) & 0x7F) 267 # endif 268 # ifndef WCOREDUMP 269 # ifdef WIFCORED /* Haiku */ 270 # define WCOREDUMP(status) (WIFCORED(_W_I(status))) 271 # else 272 # define WCOREDUMP(status) (_W_I(status) & 0x80) 273 # endif 274 # endif 275 # ifndef WEXITSTATUS 276 # define WEXITSTATUS(status) ((_W_I(status) >> 8) & 0xFF) 277 # endif 278 # ifndef WSTOPSIG 279 # define WSTOPSIG(status) ((_W_I(status) >> 8) & 0xFF) 280 # endif 281 /* 282 * WIFSTOPPED and WIFSIGNALED match the definitions on older UNIX versions 283 * e.g. SunOS-4.x or HP-UX 284 */ 285 # ifndef WIFCONTINUED 286 # ifdef NO_WCONTINUED 287 # define WIFCONTINUED(status) (0) 288 # else 289 # define WIFCONTINUED(status) ((_W_I(status) & 0xFFFF) == \ 290 WCONTFLG) 291 # endif 292 # endif 293 # ifndef WIFSTOPPED 294 # define WIFSTOPPED(status) ((_W_I(status) & 0xFF) == 0x7F) 295 # endif 296 # ifndef WIFSIGNALED 297 # define WIFSIGNALED(status) ((_W_I(status) & 0xFF) != 0x7F && \ 298 WTERMSIG(status) != 0) 299 # endif 300 # ifndef WIFEXITED 301 # define WIFEXITED(status) ((_W_I(status) & 0xFF) == 0) 302 # endif 303 #endif 304 305 306 #ifdef __cplusplus 307 } 308 #endif 309 310 #endif /* _SCHILY_WAIT_H */ 311