On March 31, 2003 07:12 pm, Alexandre Julliard wrote:
Log message: Use _spawnvp to replace fork for non-Unix platforms.
What about adding it to the portability lib? I can do the patch if you want...
"Dimitrie O. Paun" dpaun@rogers.com writes:
What about adding it to the portability lib? I can do the patch if you want...
I'm not sure about that; it would be somewhat cleaner, but OTOH I'm not sure I like the idea of adding DOS functions in the portability layer...
On March 31, 2003 10:20 pm, Alexandre Julliard wrote:
I'm not sure about that; it would be somewhat cleaner, but OTOH I'm not sure I like the idea of adding DOS functions in the portability layer...
However, if we are to depend on winegcc/winewrap, we need to be able to compile it anyway, no? And since it has a well defined semantics (that's much more commonly available than the fork/exec), it's not necessarily a bad addition.
I mean, there's nothing conceptually wrong with spawn/CreateProcess/etc. vs. fork+exec. However, on system that are spawn-based, it's *so* difficult to simulate fork+exec, and for no good reason, if all you need is to spawn another program. So it seems to me having spawn in a portability layer may actually be a good thing, since it's more semantically loaded than fork, and thus easier to simulate on a large range of systems.
"Dimitrie O. Paun" dpaun@rogers.com writes:
However, if we are to depend on winegcc/winewrap, we need to be able to compile it anyway, no? And since it has a well defined semantics (that's much more commonly available than the fork/exec), it's not necessarily a bad addition.
Yes, it's just that I don't like to add non-Unix APIs to the portability layer, but I guess there are good reasons for making an exception here.
On March 31, 2003 11:31 pm, Alexandre Julliard wrote:
Yes, it's just that I don't like to add non-Unix APIs to the portability layer, but I guess there are good reasons for making an exception here.
I agree -- adding non-Unix APIs is not a good idea. 100% with you. But this one is one particular case of a common operation that is hard to emulate with other APIs, and when emulated, it's slow and/or buggy :).
OK, here's a patch to add _spawnvp to the portability lib. There are still a few questions: -- Should we provide the entire family (I wouldn't, unless we really need them, but that can wait for that need :))? -- What about conflicts with stuff in dlls/msvcrt/process.c? What if we need wine/port. in process.c in the future (not a big deal, we can fudge it then)? What about winelib apps that link with msvcrt?
ChangeLog Add _spawnvp to the portability lib.
Index: include/wine/port.h =================================================================== RCS file: /var/cvs/wine/include/wine/port.h,v retrieving revision 1.36 diff -u -r1.36 port.h --- include/wine/port.h 28 Mar 2003 00:36:13 -0000 1.36 +++ include/wine/port.h 1 Apr 2003 05:32:12 -0000 @@ -211,6 +211,16 @@ ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset ); #endif /* HAVE_PWRITE */
+#ifndef HAVE__SPAWNVP +/* Process creation flags */ +#define _P_WAIT 0 +#define _P_NOWAIT 1 +#define _P_OVERLAY 2 +#define _P_NOWAITO 3 +#define _P_DETACH 4 +int _spawnvp(int mode, const char *cmdname, char *const argv[]); +#endif /* HAVE__SPAWNVP */ + #ifndef HAVE_STATFS int statfs(const char *name, struct statfs *info); #endif /* !defined(HAVE_STATFS) */ Index: libs/port/Makefile.in =================================================================== RCS file: /var/cvs/wine/libs/port/Makefile.in,v retrieving revision 1.5 diff -u -r1.5 Makefile.in --- libs/port/Makefile.in 20 Mar 2003 23:44:36 -0000 1.5 +++ libs/port/Makefile.in 1 Apr 2003 05:20:57 -0000 @@ -16,6 +16,7 @@ mkstemps.c \ pread.c \ pwrite.c \ + spawn.c \ statfs.c \ strcasecmp.c \ strerror.c \ --- /dev/null 2002-08-30 19:31:37.000000000 -0400 +++ libs/port/spawn.c 2003-04-01 00:31:40.000000000 -0500 @@ -0,0 +1,51 @@ +/* + * _spawnvp function + * + * Copyright 2003 Dimitrie O. Paun + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "config.h" +#include "wine/port.h" + +#include <errno.h> +#ifdef HAVE_SYS_WAIT_H +#include <sys/wait.h> +#endif +#include <sys/stat.h> +#ifdef HAVE_UNISTD_H +# include <unistd.h> +#endif + +#ifndef HAVE__SPAWNVP +int _spawnvp(int mode, const char *cmdname, char *const argv[]) +{ + int pid = 0, status, wret; + + if (mode != _P_OVERLAY) pid = fork(); + if (pid == 0) pid = execvp(argv[0], argv); + if (pid < 0) return -1; + + if (mode != _P_WAIT) return pid; + + while (pid != (wret = waitpid(pid, &status, 0))) + if (wret == -1 && errno != EINTR) break; + + if (pid == wret && WIFEXITED(status)) return WEXITSTATUS(status); + + return 255; /* abnormal exit with an abort or an interrupt */ +} +#endif /* HAVE__SPAWNVP */
"Dimitrie O. Paun" dpaun@rogers.com writes:
OK, here's a patch to add _spawnvp to the portability lib. There are still a few questions: -- Should we provide the entire family (I wouldn't, unless we really need them, but that can wait for that need :))?
Yep that can wait.
-- What about conflicts with stuff in dlls/msvcrt/process.c? What if we need wine/port. in process.c in the future (not a big deal, we can fudge it then)? What about winelib apps that link with msvcrt?
If they link with msvcrt then they are not supposed to use wine/port.h. To avoid trouble with process.c I'd suggest naming the function spawnvp, without the underscore prefix, and making it call the real _spawnvp on Windows.
On 1 Apr 2003, Alexandre Julliard wrote:
If they link with msvcrt then they are not supposed to use wine/port.h. To avoid trouble with process.c I'd suggest naming the function spawnvp, without the underscore prefix, and making it call the real _spawnvp on Windows.
Cool. Here it is again. I'll make use of it as soon as it gets into the tree.
ChangeLog Add spawnvp to the portability lib.
Index: include/wine/port.h =================================================================== RCS file: /var/cvs/wine/include/wine/port.h,v retrieving revision 1.36 diff -u -r1.36 port.h --- include/wine/port.h 28 Mar 2003 00:36:13 -0000 1.36 +++ include/wine/port.h 1 Apr 2003 17:24:48 -0000 @@ -211,6 +211,16 @@ ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset ); #endif /* HAVE_PWRITE */
+#ifndef HAVE__SPAWNVP +/* Process creation flags */ +#define _P_WAIT 0 +#define _P_NOWAIT 1 +#define _P_OVERLAY 2 +#define _P_NOWAITO 3 +#define _P_DETACH 4 +int spawnvp(int mode, const char *cmdname, char *const argv[]); +#endif /* HAVE__SPAWNVP */ + #ifndef HAVE_STATFS int statfs(const char *name, struct statfs *info); #endif /* !defined(HAVE_STATFS) */ Index: libs/port/Makefile.in =================================================================== RCS file: /var/cvs/wine/libs/port/Makefile.in,v retrieving revision 1.5 diff -u -r1.5 Makefile.in --- libs/port/Makefile.in 20 Mar 2003 23:44:36 -0000 1.5 +++ libs/port/Makefile.in 1 Apr 2003 05:20:57 -0000 @@ -16,6 +16,7 @@ mkstemps.c \ pread.c \ pwrite.c \ + spawn.c \ statfs.c \ strcasecmp.c \ strerror.c \ --- /dev/null 2002-08-30 19:31:37.000000000 -0400 +++ libs/port/spawn.c 2003-04-01 12:26:51.000000000 -0500 @@ -0,0 +1,53 @@ +/* + * spawnvp function + * + * Copyright 2003 Dimitrie O. Paun + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "config.h" +#include "wine/port.h" + +#include <errno.h> +#ifdef HAVE_SYS_WAIT_H +#include <sys/wait.h> +#endif +#include <sys/stat.h> +#ifdef HAVE_UNISTD_H +# include <unistd.h> +#endif + +int spawnvp(int mode, const char *cmdname, char *const argv[]) +{ +#ifndef HAVE__SPAWNVP + int pid = 0, status, wret; + + if (mode != _P_OVERLAY) pid = fork(); + if (pid == 0) pid = execvp(argv[0], argv); + if (pid < 0) return -1; + + if (mode != _P_WAIT) return pid; + + while (pid != (wret = waitpid(pid, &status, 0))) + if (wret == -1 && errno != EINTR) break; + + if (pid == wret && WIFEXITED(status)) return WEXITSTATUS(status); + + return 255; /* abnormal exit with an abort or an interrupt */ +#else /* HAVE__SPAWNVP */ + return _spawnvp(mode, cmdname, argv); +#endif /* HAVE__SPAWNVP */ +}