32 #include <sys/types.h>
47 #define NOT_SUPPORTED(nm) \
48 nm ": not supported on this system"
54 return dup2 (old_fd, new_fd, msg);
64 #if defined (HAVE_DUP2)
68 msg = gnulib::strerror (errno);
80 return execvp (file, argv, msg);
91 #if defined (HAVE_EXECVP)
94 status =
::execvp (file.c_str (), argv);
99 msg = gnulib::strerror (errno);
112 #if defined (HAVE_FORK)
116 msg = gnulib::strerror (errno);
129 #if defined (HAVE_VFORK) || defined (HAVE_FORK)
130 #if defined (HAVE_VFORK)
137 msg = gnulib::strerror (errno);
150 #if defined (HAVE_GETPGRP)
154 msg = gnulib::strerror (errno);
165 #if defined (HAVE_GETPID)
175 #if defined (HAVE_GETPPID)
185 #if defined (HAVE_GETGID)
195 #if defined (HAVE_GETEGID)
205 #if defined (HAVE_GETUID)
215 #if defined (HAVE_GETEUID)
226 return pipe (fildes, msg);
232 msg = std::string ();
236 #if defined (HAVE_PIPE)
240 msg = gnulib::strerror (errno);
252 return waitpid (pid, status, options, msg);
260 msg = std::string ();
262 #if defined (HAVE_WAITPID)
266 msg = gnulib::strerror (errno);
278 return kill (pid, sig, msg);
284 msg = std::string ();
288 #if defined (HAVE_KILL)
289 status =
::kill (pid, sig);
292 msg = gnulib::strerror (errno);
302 bool sync_mode,
int *fildes)
306 return popen2 (cmd, args, sync_mode, fildes, msg, interactive);
311 bool sync_mode,
int *fildes, std::string& msg)
314 return popen2 (cmd, args, sync_mode, fildes, msg, interactive);
319 bool sync_mode,
int *fildes, std::string& msg,
322 #if defined (__WIN32__) && ! defined (__CYGWIN__)
323 return ::octave_popen2 (cmd, args, sync_mode, fildes, msg);
326 int child_stdin[2], child_stdout[2];
328 if (
pipe (child_stdin, msg) == 0)
330 if (
pipe (child_stdout, msg) == 0)
334 msg =
"popen2: process creation failed -- " + msg;
337 std::string child_msg;
342 gnulib::close (child_stdin[1]);
343 gnulib::close (child_stdout[0]);
347 gnulib::close (child_stdin[0]);
348 if (
dup2 (child_stdout[1], STDOUT_FILENO) >= 0)
350 gnulib::close (child_stdout[1]);
351 if (
execvp (cmd, args, child_msg) < 0)
352 child_msg =
"popen2 (child): unable to start process -- " + child_msg;
355 child_msg =
"popen2 (child): file handle duplication failed -- " + child_msg;
358 child_msg =
"popen2 (child): file handle duplication failed -- " + child_msg;
360 (*current_liboctave_error_handler)(child_msg.c_str ());
367 gnulib::close (child_stdin[0]);
368 gnulib::close (child_stdout[1]);
370 #if defined (F_SETFL) && defined (O_NONBLOCK)
371 if (! sync_mode &&
octave_fcntl (child_stdout[0], F_SETFL,
372 O_NONBLOCK, msg) < 0)
373 msg =
"popen2: error setting file mode -- " + msg;
377 fildes[0] = child_stdin[1];
378 fildes[1] = child_stdout[0];
382 gnulib::close (child_stdout[0]);
383 gnulib::close (child_stdout[1]);
386 msg =
"popen2: pipe creation failed -- " + msg;
388 gnulib::close (child_stdin[0]);
389 gnulib::close (child_stdin[1]);
392 msg =
"popen2: pipe creation failed -- " + msg;
408 msg = std::string ();
412 status = gnulib::fcntl (fd, cmd, arg);
415 msg = gnulib::strerror (errno);