1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2016-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING.  If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 // These functions may be provided by gnulib.  We don't include gnulib
27 // headers directly in Octave's C++ source files to avoid problems that
28 // may be caused by the way that gnulib overrides standard library
29 // functions.
30 
31 #if defined (HAVE_CONFIG_H)
32 #  include "config.h"
33 #endif
34 
35 #include <sys/types.h>
36 #include <sys/wait.h>
37 
38 #include "wait-wrappers.h"
39 
40 #if ! defined (WCONTINUE)
41 #  define WCONTINUE 0
42 #endif
43 
44 #if ! defined (WNOHANG)
45 #  define WNOHANG 0
46 #endif
47 
48 #if ! defined (WUNTRACED)
49 #  define WUNTRACED 0
50 #endif
51 
52 #if ! defined (WIFCONTINUED)
53 #  define WIFCONTINUED(x) false
54 #endif
55 
56 pid_t
octave_waitpid_wrapper(pid_t pid,int * statusp,int options)57 octave_waitpid_wrapper (pid_t pid, int *statusp, int options)
58 {
59 #if defined (__WIN32__) && ! defined (__CYGWIN__)
60 
61   octave_unused_parameter (pid);
62   octave_unused_parameter (options);
63 
64   // gnulib's waitpid replacement currently uses _cwait, which
65   // apparently only works with console applications.
66   *statusp = 0;
67   return -1;
68 #else
69   return waitpid (pid, statusp, options);
70 #endif
71 }
72 
73 int
octave_wcontinue_wrapper(void)74 octave_wcontinue_wrapper (void)
75 {
76   return WCONTINUE;
77 }
78 
79 int
octave_wnohang_wrapper(void)80 octave_wnohang_wrapper (void)
81 {
82   return WNOHANG;
83 }
84 
85 int
octave_wuntraced_wrapper(void)86 octave_wuntraced_wrapper (void)
87 {
88   return WUNTRACED;
89 }
90 
91 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
92 // Disable the unused parameter warning for the following wrapper functions.
93 // The <sys/wait.h> header provided by gnulib may define some of the W*
94 // macros to expand to a constant and ignore the parameter.
95 #pragma GCC diagnostic push
96 #pragma GCC diagnostic ignored "-Wunused-parameter"
97 #endif
98 
99 int
octave_wcoredump_wrapper(int status)100 octave_wcoredump_wrapper (int status)
101 {
102   return WCOREDUMP (status);
103 }
104 
105 int
octave_wexitstatus_wrapper(int status)106 octave_wexitstatus_wrapper (int status)
107 {
108   return WEXITSTATUS (status);
109 }
110 
111 bool
octave_wifcontinued_wrapper(int status)112 octave_wifcontinued_wrapper (int status)
113 {
114   return WIFCONTINUED (status);
115 }
116 
117 bool
octave_wifexited_wrapper(int status)118 octave_wifexited_wrapper (int status)
119 {
120   return WIFEXITED (status);
121 }
122 
123 bool
octave_wifsignaled_wrapper(int status)124 octave_wifsignaled_wrapper (int status)
125 {
126   return WIFSIGNALED (status);
127 }
128 
129 bool
octave_wifstopped_wrapper(int status)130 octave_wifstopped_wrapper (int status)
131 {
132   return WIFSTOPPED (status);
133 }
134 
135 int
octave_wstopsig_wrapper(int status)136 octave_wstopsig_wrapper (int status)
137 {
138   return WSTOPSIG (status);
139 }
140 
141 int
octave_wtermsig_wrapper(int status)142 octave_wtermsig_wrapper (int status)
143 {
144   return WTERMSIG (status);
145 }
146 
147 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
148 // Restore prevailing warning state for remainder of the file.
149 #pragma GCC diagnostic pop
150 #endif
151