Mercurial > octave
changeset 22264:9b78fda78300
fix build failure for --without-z (bug #48757)
* liboctave/wrappers/async-system-wrapper.h,
liboctave/wrappers/async-system-wrapper.c: New files for function
extracted from Fsystem.
* liboctave/wrappers/module.mk: Update.
* toplev.cc: Include async-system-wrapper.h.
(Fsystem): Use new octave_async_system_wrapper for async case.
* oct-procbuf.cc: Include unistd.h, reluctantly. Use HAVE_UNISTD_H
instead of HAVE_SYS_WAIT_H for conditional code.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 11 Aug 2016 12:33:26 -0400 |
parents | 05a8be08368e |
children | 15b9d7cb3098 |
files | libinterp/corefcn/oct-procbuf.cc libinterp/corefcn/toplev.cc liboctave/wrappers/async-system-wrapper.c liboctave/wrappers/async-system-wrapper.h liboctave/wrappers/module.mk |
diffstat | 5 files changed, 143 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/oct-procbuf.cc Thu Aug 11 08:16:52 2016 -0400 +++ b/libinterp/corefcn/oct-procbuf.cc Thu Aug 11 12:33:26 2016 -0400 @@ -28,6 +28,18 @@ #include <iostream> +// FIXME: we would prefer to avoid including these directly in Octave +// sources, but eliminating them is complicated by the mingling of +// octave_procbuf_list and the calls to system library functions like +// execl. + +#if defined (HAVE_UNISTD_H) +# if defined (HAVE_SYS_TYPES_H) +# include <sys/types.h> +# endif +# include <unistd.h> +#endif + #include "lo-mappers.h" #include "lo-utils.h" #include "oct-procbuf.h" @@ -77,7 +89,7 @@ return this; -#elif defined (HAVE_SYS_WAIT_H) +#elif defined (HAVE_UNISTD_H) int pipe_fds[2]; @@ -174,7 +186,7 @@ return this; -#elif defined (HAVE_SYS_WAIT_H) +#elif defined (HAVE_UNISTD_H) if (f) {
--- a/libinterp/corefcn/toplev.cc Thu Aug 11 08:16:52 2016 -0400 +++ b/libinterp/corefcn/toplev.cc Thu Aug 11 12:33:26 2016 -0400 @@ -36,6 +36,7 @@ # include <windows.h> #endif +#include "async-system-wrapper.h" #include "child-list.h" #include "lo-error.h" #include "oct-fftw.h" @@ -246,41 +247,7 @@ #endif if (type == et_async) - { - // FIXME: maybe this should go in sysdep.cc? -#if defined (HAVE_FORK) - pid_t pid = fork (); - - if (pid < 0) - error ("system: fork failed -- can't create child process"); - else if (pid == 0) - { - // FIXME: should probably replace this call with something portable. - execl (SHELL_PATH, "sh", "-c", cmd_str.c_str (), - static_cast<char *> (0)); - - panic_impossible (); - } - else - retval(0) = pid; -#elif defined (OCTAVE_USE_WINDOWS_API) - STARTUPINFO si; - PROCESS_INFORMATION pi; - ZeroMemory (&si, sizeof (si)); - ZeroMemory (&pi, sizeof (pi)); - OCTAVE_LOCAL_BUFFER (char, xcmd_str, cmd_str.length ()+1); - strcpy (xcmd_str, cmd_str.c_str ()); - - if (! CreateProcess (0, xcmd_str, 0, 0, FALSE, 0, 0, 0, &si, &pi)) - error ("system: CreateProcess failed -- can't create child process"); - - retval(0) = pi.dwProcessId; - CloseHandle (pi.hProcess); - CloseHandle (pi.hThread); -#else - err_disabled_feature ("system", "asynchronous system calls"); -#endif - } + retval(0) = octave_async_system_wrapper (cmd_str.c_str ()); else if (return_output) retval = run_command_and_return_output (cmd_str); else
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/wrappers/async-system-wrapper.c Thu Aug 11 12:33:26 2016 -0400 @@ -0,0 +1,87 @@ +/* + +Copyright (C) 2016 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +<http://www.gnu.org/licenses/>. + +*/ + +// areadlink is provided by gnulib. We don't include gnulib headers +// directly in Octave's C++ source files to avoid problems that may be +// caused by the way that gnulib overrides standard library functions. + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#if defined (__WIN32__) && ! defined (__CYGWIN__) +# include <stdlib.h> +# include <string.h> +# define WIN32_LEAN_AND_MEAN 1 +# include <windows.h> +#else +# include <sys/types.h> +# include <unistd.h> +#endif + +#include "async-system-wrapper.h" + +pid_t +octave_async_system_wrapper (const char *cmd) +{ + int retval = -1; + + if (! cmd) + return retval; + +#if defined (OCTAVE_USE_WINDOWS_API) + + STARTUPINFO si; + PROCESS_INFORMATION pi; + + ZeroMemory (&si, sizeof (si)); + ZeroMemory (&pi, sizeof (pi)); + + char *xcmd = (char *) malloc (strlen (cmd) + 1); + + strcpy (xcmd, cmd); + + if (! CreateProcess (0, xcmd, 0, 0, FALSE, 0, 0, 0, &si, &pi)) + retval = -1; + else + { + retval = pi.dwProcessId; + + CloseHandle (pi.hProcess); + CloseHandle (pi.hThread); + } + + free (xcmd); + +#else + + pid_t pid = fork (); + + if (pid == 0) + execl (SHELL_PATH, "sh", "-c", cmd, (char *) (0)); + else + retval = pid; + +#endif + + return retval; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/wrappers/async-system-wrapper.h Thu Aug 11 12:33:26 2016 -0400 @@ -0,0 +1,38 @@ +/* + +Copyright (C) 2016 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +<http://www.gnu.org/licenses/>. + +*/ + +#if ! defined (octave_async_system_wrapper_h) +#define octave_async_system_wrapper_h 1 + +#include <sys/types.h> + +#if defined __cplusplus +extern "C" { +#endif + +extern pid_t octave_async_system_wrapper (const char *cmd); + +#if defined __cplusplus +} +#endif + +#endif
--- a/liboctave/wrappers/module.mk Thu Aug 11 08:16:52 2016 -0400 +++ b/liboctave/wrappers/module.mk Thu Aug 11 12:33:26 2016 -0400 @@ -1,5 +1,6 @@ NOINSTALL_WRAPPERS_INC = \ liboctave/wrappers/areadlink-wrapper.h \ + liboctave/wrappers/async-system-wrapper.h \ liboctave/wrappers/base64-wrappers.h \ liboctave/wrappers/canonicalize-file-name-wrapper.h \ liboctave/wrappers/dirent-wrappers.h \ @@ -34,6 +35,7 @@ WRAPPERS_SRC = \ liboctave/wrappers/areadlink-wrapper.c \ + liboctave/wrappers/async-system-wrapper.c \ liboctave/wrappers/base64-wrappers.c \ liboctave/wrappers/canonicalize-file-name-wrapper.c \ liboctave/wrappers/dirent-wrappers.c \