GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
oct-syscalls.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2017 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include <ctime>
28 #include <cerrno>
29 #include <cstdlib>
30 #include <cstring>
31 
32 #include "fcntl-wrappers.h"
33 #include "lo-utils.h"
34 #include "lo-sysdep.h"
35 #include "oct-syscalls.h"
36 #include "octave-popen2.h"
37 #include "signal-wrappers.h"
38 #include "str-vec.h"
39 #include "unistd-wrappers.h"
40 #include "wait-wrappers.h"
41 
42 #define NOT_SUPPORTED(nm) \
43  nm ": not supported on this system"
44 
45 namespace octave
46 {
47  namespace sys
48  {
49  int
50  dup2 (int old_fd, int new_fd)
51  {
52  std::string msg;
53  return octave::sys::dup2 (old_fd, new_fd, msg);
54  }
55 
56  int
57  dup2 (int old_fd, int new_fd, std::string& msg)
58  {
59  msg = "";
60 
61  int status = -1;
62 
63  status = octave_dup2_wrapper (old_fd, new_fd);
64 
65  if (status < 0)
66  msg = std::strerror (errno);
67 
68  return status;
69  }
70 
71  int
73  {
74  std::string msg;
75  return octave::sys::execvp (file, argv, msg);
76  }
77 
78  int
80  std::string& msg)
81  {
82  msg = "";
83 
84  char **argv = args.c_str_vec ();
85 
86  int status = octave_execvp_wrapper (file.c_str (), argv);
87 
89 
90  if (status < 0)
91  msg = std::strerror (errno);
92 
93  return status;
94  }
95 
96  pid_t
98  {
99  pid_t status = -1;
100 
101  if (octave_have_fork ())
102  {
103  status = octave_fork_wrapper ();
104 
105  if (status < 0)
106  msg = std::strerror (errno);
107  }
108  else
109  msg = NOT_SUPPORTED ("fork");
110 
111  return status;
112  }
113 
114  pid_t
116  {
117  pid_t status = -1;
118 
119  if (octave_have_vfork () || octave_have_fork ())
120  {
121  if (octave_have_vfork ())
122  status = octave_vfork_wrapper ();
123  else
124  status = octave_fork_wrapper ();
125 
126  if (status < 0)
127  msg = std::strerror (errno);
128  }
129  else
130  msg = NOT_SUPPORTED ("vfork");
131 
132  return status;
133  }
134 
135  pid_t
137  {
138  pid_t status = octave_getpgrp_wrapper ();
139 
140  if (status < 0)
141  msg = std::strerror (errno);
142 
143  return status;
144  }
145 
146  pid_t
147  getpid (void)
148  {
149  return octave_getpid_wrapper ();
150  }
151 
152  pid_t
153  getppid (void)
154  {
155  return octave_getppid_wrapper ();
156  }
157 
158  gid_t
159  getgid (void)
160  {
161  return octave_getgid_wrapper ();
162  }
163 
164  gid_t
165  getegid (void)
166  {
167  return octave_getegid_wrapper ();
168  }
169 
170  uid_t
171  getuid (void)
172  {
173  return octave_getuid_wrapper ();
174  }
175 
176  uid_t
177  geteuid (void)
178  {
179  return octave_geteuid_wrapper ();
180  }
181 
182  int
183  pipe (int *fildes)
184  {
185  std::string msg;
186  return octave::sys::pipe (fildes, msg);
187  }
188 
189  int
190  pipe (int *fildes, std::string& msg)
191  {
192  msg = "";
193 
194  int status = -1;
195 
196  status = octave_pipe_wrapper (fildes);
197 
198  if (status < 0)
199  msg = std::strerror (errno);
200 
201  return status;
202  }
203 
204  pid_t
205  waitpid (pid_t pid, int *status, int options)
206  {
207  std::string msg;
208  return octave::sys::waitpid (pid, status, options, msg);
209  }
210 
211  pid_t
212  waitpid (pid_t pid, int *status, int options,
213  std::string& msg)
214  {
215  pid_t retval = -1;
216  msg = "";
217 
218  retval = octave_waitpid_wrapper (pid, status, options);
219 
220  if (retval < 0)
221  msg = std::strerror (errno);
222 
223  return retval;
224  }
225 
226  int
227  wcontinue (void)
228  {
229  return octave_wcontinue_wrapper ();
230  }
231 
232  int
233  wcoredump (int status)
234  {
235  return octave_wcoredump_wrapper (status);
236  }
237 
238  bool
239  wifcontinued (int status)
240  {
241  return octave_wifcontinued_wrapper (status);
242  }
243 
244  bool
245  wifexited (int status)
246  {
247  return octave_wifexited_wrapper (status);
248  }
249 
250  bool
251  wifsignaled (int status)
252  {
253  return octave_wifsignaled_wrapper (status);
254  }
255 
256  bool
257  wifstopped (int status)
258  {
259  return octave_wifstopped_wrapper (status);
260  }
261 
262  int
263  wexitstatus (int status)
264  {
265  return octave_wexitstatus_wrapper (status);
266  }
267 
268  int
269  wnohang (void)
270  {
271  return octave_wnohang_wrapper ();
272  }
273 
274  int
275  wstopsig (int status)
276  {
277  return octave_wstopsig_wrapper (status);
278  }
279 
280  int
281  wtermsig (int status)
282  {
283  return octave_wtermsig_wrapper (status);
284  }
285 
286  int
287  wuntraced (void)
288  {
289  return octave_wuntraced_wrapper ();
290  }
291 
292  int
293  kill (pid_t pid, int sig)
294  {
295  std::string msg;
296  return octave::sys::kill (pid, sig, msg);
297  }
298 
299  int
300  kill (pid_t pid, int sig, std::string& msg)
301  {
302  msg = "";
303 
304  int status = -1;
305 
306  if (octave_have_kill ())
307  {
308  status = octave_kill_wrapper (pid, sig);
309 
310  if (status < 0)
311  msg = std::strerror (errno);
312  }
313  else
314  msg = NOT_SUPPORTED ("kill");
315 
316  return status;
317  }
318 
319  pid_t
320  popen2 (const std::string& cmd, const string_vector& args,
321  bool sync_mode, int *fildes)
322  {
323  std::string msg;
324  return octave::sys::popen2 (cmd, args, sync_mode, fildes, msg);
325  }
326 
327  pid_t
328  popen2 (const std::string& cmd, const string_vector& args,
329  bool sync_mode, int *fildes, std::string& msg)
330  {
331  char **argv = args.c_str_vec ();
332  const char *errmsg;
333 
334  pid_t pid = octave_popen2 (cmd.c_str (), argv, sync_mode, fildes,
335  &errmsg);
336 
338 
339  if (pid < 0)
340  msg = errmsg;
341 
342  return pid;
343  }
344 
345  int
346  fcntl (int fd, int cmd, long arg)
347  {
348  std::string msg;
349  return octave::sys::fcntl (fd, cmd, arg, msg);
350  }
351 
352  int
353  fcntl (int fd, int cmd, long arg, std::string& msg)
354  {
355  msg = "";
356 
357  int status = -1;
358 
359  status = octave_fcntl_wrapper (fd, cmd, arg);
360 
361  if (status < 0)
362  msg = std::strerror (errno);
363 
364  return status;
365  }
366  }
367 }
int dup2(int old_fd, int new_fd)
Definition: oct-syscalls.cc:50
uid_t octave_geteuid_wrapper(void)
bool octave_wifsignaled_wrapper(int status)
Definition: wait-wrappers.c:91
Octave interface to the compression and uncompression libraries.
Definition: aepbalance.cc:47
For example cd octave end example noindent changes the current working directory to file
Definition: dirfns.cc:120
pid_t octave_vfork_wrapper(void)
int fcntl(int fd, int cmd, long arg)
bool octave_wifexited_wrapper(int status)
Definition: wait-wrappers.c:85
int kill(pid_t pid, int sig)
int octave_kill_wrapper(pid_t pid, int signum)
pid_t octave_getpid_wrapper(void)
int wcontinue(void)
uid_t octave_getuid_wrapper(void)
int octave_wcontinue_wrapper(void)
Definition: wait-wrappers.c:63
pid_t getpid(void)
char ** c_str_vec(void) const
Definition: str-vec.cc:154
gid_t getgid(void)
pid_t getppid(void)
static void delete_c_str_vec(const char *const *)
Definition: str-vec.cc:182
int octave_pipe_wrapper(int *fd)
int octave_fcntl_wrapper(int fd, int cmd, int arg)
octave_value arg
Definition: pr-output.cc:3440
bool octave_wifcontinued_wrapper(int status)
Definition: wait-wrappers.c:79
string_vector argv
Definition: load-save.cc:635
bool wifstopped(int status)
JNIEnv void * args
Definition: ov-java.cc:67
pid_t octave_popen2(const char *cmd, char *const *args, bool sync_mode, int *fildes, const char **errmsg)
int octave_wtermsig_wrapper(int status)
bool wifsignaled(int status)
pid_t waitpid(pid_t pid, int *status, int options)
gid_t octave_getgid_wrapper(void)
int wexitstatus(int status)
int octave_wstopsig_wrapper(int status)
octave_value retval
Definition: data.cc:6294
gid_t octave_getegid_wrapper(void)
int wcoredump(int status)
bool octave_have_vfork(void)
int wuntraced(void)
uid_t geteuid(void)
pid_t octave_fork_wrapper(void)
bool octave_have_kill(void)
int octave_wexitstatus_wrapper(int status)
bool wifexited(int status)
int octave_execvp_wrapper(const char *file, char *const *argv)
bool octave_have_fork(void)
int wnohang(void)
#define NOT_SUPPORTED(nm)
Definition: oct-syscalls.cc:42
bool wifcontinued(int status)
int execvp(const std::string &file, const string_vector &argv)
Definition: oct-syscalls.cc:72
OCTAVE_EXPORT octave_value_list only variables visible in the local scope are displayed The following are valid options
Definition: variables.cc:1859
pid_t octave_getppid_wrapper(void)
int wtermsig(int status)
gid_t getegid(void)
pid_t octave_waitpid_wrapper(pid_t pid, int *statusp, int options)
Definition: wait-wrappers.c:50
int wstopsig(int status)
pid_t fork(std::string &msg)
Definition: oct-syscalls.cc:97
int octave_wcoredump_wrapper(int status)
Definition: wait-wrappers.c:69
uid_t getuid(void)
int pipe(int *fildes)
int octave_wuntraced_wrapper(void)
int octave_wnohang_wrapper(void)
pid_t octave_getpgrp_wrapper(void)
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
bool octave_wifstopped_wrapper(int status)
Definition: wait-wrappers.c:97
int octave_dup2_wrapper(int fd1, int fd2)
pid_t getpgrp(std::string &msg)
pid_t vfork(std::string &msg)
pid_t popen2(const std::string &cmd, const string_vector &args, bool sync_mode, int *fildes)