-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement posix_spawn*() with spawn2()
This implementation improved the following things over LIBC: 1. Support chdir and fchdir file action. 2. Copy contents of a path of a file action not a value of a pointer. This is a requirement of POSIX. 3. Correct behaviors of posix_spawn() and posix_spawnp() which they are swapped. modified: Makefile modified: check.cmd new file: include/os2compat/spawn.h new file: process/posix_spawn/posix_spawn.h new file: process/posix_spawn/spawn_faction_addchdir.c new file: process/posix_spawn/spawn_faction_addclose.c new file: process/posix_spawn/spawn_faction_adddup2.c new file: process/posix_spawn/spawn_faction_addfchdir.c new file: process/posix_spawn/spawn_faction_addopen.c new file: process/posix_spawn/spawn_faction_destroy.c new file: process/posix_spawn/spawn_faction_init.c new file: process/posix_spawn/spawn_int.h new file: process/posix_spawn/spawnattr_destroy.c new file: process/posix_spawn/spawnattr_getdefault.c new file: process/posix_spawn/spawnattr_getflags.c new file: process/posix_spawn/spawnattr_getpgroup.c new file: process/posix_spawn/spawnattr_getschedparam.c new file: process/posix_spawn/spawnattr_getschedpolicy.c new file: process/posix_spawn/spawnattr_getsigmask.c new file: process/posix_spawn/spawnattr_init.c new file: process/posix_spawn/spawnattr_setdefault.c new file: process/posix_spawn/spawnattr_setflags.c new file: process/posix_spawn/spawnattr_setpgroup.c new file: process/posix_spawn/spawnattr_setschedparam.c new file: process/posix_spawn/spawnattr_setschedpolicy.c new file: process/posix_spawn/spawnattr_setsigmask.c new file: process/posix_spawn/spawne.c new file: process/posix_spawn/spawni.c new file: process/posix_spawn/spawnpe.c modified: testcase/Makefile new file: testcase/gltests/executable-script new file: testcase/gltests/executable-script.sh new file: testcase/gltests/executable-shell-script new file: testcase/gltests/macros.h new file: testcase/gltests/test-posix_spawn-chdir.c new file: testcase/gltests/test-posix_spawn-dup2-stdin.c new file: testcase/gltests/test-posix_spawn-dup2-stdin.sh new file: testcase/gltests/test-posix_spawn-dup2-stdout.c new file: testcase/gltests/test-posix_spawn-dup2-stdout.sh new file: testcase/gltests/test-posix_spawn-fchdir.c new file: testcase/gltests/test-posix_spawn-inherit0.c new file: testcase/gltests/test-posix_spawn-inherit1.c new file: testcase/gltests/test-posix_spawn-open1.c new file: testcase/gltests/test-posix_spawn-open2.c new file: testcase/gltests/test-posix_spawn-script.c new file: testcase/gltests/test-posix_spawn_file_actions_addchdir.c new file: testcase/gltests/test-posix_spawn_file_actions_addclose.c new file: testcase/gltests/test-posix_spawn_file_actions_adddup2.c new file: testcase/gltests/test-posix_spawn_file_actions_addfchdir.c new file: testcase/gltests/test-posix_spawn_file_actions_addopen.c new file: testcase/gltests/test-posix_spawnp-script.c
- Loading branch information
Showing
51 changed files
with
3,678 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* spawn.h for os2compat | ||
* | ||
* Copyright (C) 2024 KO Myung-Hun <[email protected]> | ||
* | ||
* This program is free software. It comes without any warranty, to | ||
* the extent permitted by applicable law. You can redistribute it | ||
* and/or modify it under the terms of the Do What The Fuck You Want | ||
* To Public License, Version 2, as published by Sam Hocevar. See | ||
* http://www.wtfpl.net/ for more details. | ||
*/ | ||
|
||
#ifndef OS2COMPAT_INCLUDE_SPAWN_H | ||
#define OS2COMPAT_INCLUDE_SPAWN_H | ||
|
||
#include "priv/process/posix_spawn/posix_spawn.h" | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* posix_spawn_file_actions_addchdir() and posix_spawn_file_actions_addfchdir() | ||
* implementation for OS/2 kLIBC | ||
* | ||
* Copyright (C) 2024 KO Myung-Hun <[email protected]> | ||
* | ||
* This program is free software. It comes without any warranty, to | ||
* the extent permitted by applicable law. You can redistribute it | ||
* and/or modify it under the terms of the Do What The Fuck You Want | ||
* To Public License, Version 2, as published by Sam Hocevar. See | ||
* http://www.wtfpl.net/ for more details. | ||
*/ | ||
|
||
#ifndef OS2COMPAT_POSIX_SPAWN_H | ||
#define OS2COMPAT_POSIX_SPAWN_H | ||
|
||
#include <spawn.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
int os2compat_posix_spawn_file_actions_addchdir(posix_spawn_file_actions_t | ||
*restrict file_actions, const char *restrict path); | ||
|
||
int os2compat_posix_spawn_file_actions_addfchdir(posix_spawn_file_actions_t | ||
*file_actions, int fildes); | ||
|
||
#define posix_spawn_file_actions_addchdir \ | ||
os2compat_posix_spawn_file_actions_addchdir | ||
|
||
#define posix_spawn_file_actions_addfchdir \ | ||
os2compat_posix_spawn_file_actions_addfchdir | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* Copyright (C) 2018-2024 Free Software Foundation, Inc. | ||
This file 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 file 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 program. If not, see <https://www.gnu.org/licenses/>. */ | ||
|
||
/* Specification. */ | ||
#include <spawn.h> | ||
|
||
#include <errno.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include <emx/umalloc.h> | ||
|
||
#include "spawn_int.h" | ||
|
||
#include "posix_spawn.h" | ||
|
||
/* Add an action to FILE-ACTIONS which tells the implementation to call | ||
'chdir' to the given directory during the 'spawn' call. */ | ||
int | ||
posix_spawn_file_actions_addchdir (posix_spawn_file_actions_t *file_actions, | ||
const char *path) | ||
{ | ||
/* Copy PATH, because the caller may free it before calling posix_spawn() | ||
or posix_spawnp(). */ | ||
char *path_copy = _hstrdup (path); | ||
if (path_copy == NULL) | ||
return ENOMEM; | ||
|
||
/* Allocate more memory if needed. */ | ||
if (file_actions->__used == file_actions->__allocated | ||
&& __posix_spawn_file_actions_realloc (file_actions) != 0) | ||
{ | ||
/* This can only mean we ran out of memory. */ | ||
free (path_copy); | ||
return ENOMEM; | ||
} | ||
|
||
{ | ||
struct __spawn_action *rec; | ||
|
||
/* Add the new value. */ | ||
rec = &file_actions->__actions[file_actions->__used]; | ||
rec->tag = spawn_do_chdir; | ||
rec->action.chdir_action.path = path_copy; | ||
|
||
/* Account for the new entry. */ | ||
++file_actions->__used; | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* Copyright (C) 2000, 2009-2024 Free Software Foundation, Inc. | ||
This file is part of the GNU C Library. | ||
This file 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 file 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 program. If not, see <https://www.gnu.org/licenses/>. */ | ||
|
||
/* Specification. */ | ||
#include <spawn.h> | ||
|
||
#include <errno.h> | ||
#include <unistd.h> | ||
|
||
#define __sysconf(open_max) getdtablesize () | ||
|
||
#include "spawn_int.h" | ||
|
||
/* Add an action to FILE-ACTIONS which tells the implementation to call | ||
'close' for the given file descriptor during the 'spawn' call. */ | ||
int | ||
posix_spawn_file_actions_addclose (posix_spawn_file_actions_t *file_actions, | ||
int fd) | ||
{ | ||
int maxfd = __sysconf (_SC_OPEN_MAX); | ||
|
||
/* Test for the validity of the file descriptor. */ | ||
if (fd < 0 || fd >= maxfd) | ||
return EBADF; | ||
|
||
/* Allocate more memory if needed. */ | ||
if (file_actions->__used == file_actions->__allocated | ||
&& __posix_spawn_file_actions_realloc (file_actions) != 0) | ||
/* This can only mean we ran out of memory. */ | ||
return ENOMEM; | ||
|
||
{ | ||
struct __spawn_action *rec; | ||
|
||
/* Add the new value. */ | ||
rec = &file_actions->__actions[file_actions->__used]; | ||
rec->tag = spawn_do_close; | ||
rec->action.open_action.fd = fd; | ||
|
||
/* Account for the new entry. */ | ||
++file_actions->__used; | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* Copyright (C) 2000, 2009-2024 Free Software Foundation, Inc. | ||
This file is part of the GNU C Library. | ||
This file 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 file 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 program. If not, see <https://www.gnu.org/licenses/>. */ | ||
|
||
/* Specification. */ | ||
#include <spawn.h> | ||
|
||
#include <errno.h> | ||
#include <unistd.h> | ||
|
||
#define __sysconf(open_max) getdtablesize () | ||
|
||
#include "spawn_int.h" | ||
|
||
/* Add an action to FILE-ACTIONS which tells the implementation to call | ||
'dup2' for the given file descriptors during the 'spawn' call. */ | ||
int | ||
posix_spawn_file_actions_adddup2 (posix_spawn_file_actions_t *file_actions, | ||
int fd, int newfd) | ||
{ | ||
int maxfd = __sysconf (_SC_OPEN_MAX); | ||
|
||
/* Test for the validity of the file descriptor. */ | ||
if (fd < 0 || newfd < 0 || fd >= maxfd || newfd >= maxfd) | ||
return EBADF; | ||
|
||
/* Allocate more memory if needed. */ | ||
if (file_actions->__used == file_actions->__allocated | ||
&& __posix_spawn_file_actions_realloc (file_actions) != 0) | ||
/* This can only mean we ran out of memory. */ | ||
return ENOMEM; | ||
|
||
{ | ||
struct __spawn_action *rec; | ||
|
||
/* Add the new value. */ | ||
rec = &file_actions->__actions[file_actions->__used]; | ||
rec->tag = spawn_do_dup2; | ||
rec->action.dup2_action.fd = fd; | ||
rec->action.dup2_action.newfd = newfd; | ||
|
||
/* Account for the new entry. */ | ||
++file_actions->__used; | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* Copyright (C) 2018-2024 Free Software Foundation, Inc. | ||
This file 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 file 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 program. If not, see <https://www.gnu.org/licenses/>. */ | ||
|
||
/* Specification. */ | ||
#include <spawn.h> | ||
|
||
#include <errno.h> | ||
#include <unistd.h> | ||
|
||
#define __sysconf(open_max) getdtablesize () | ||
|
||
#include "spawn_int.h" | ||
|
||
#include "posix_spawn.h" | ||
|
||
/* Add an action to FILE-ACTIONS which tells the implementation to call | ||
'fchdir' to the given directory during the 'spawn' call. */ | ||
int | ||
posix_spawn_file_actions_addfchdir (posix_spawn_file_actions_t *file_actions, | ||
int fd) | ||
{ | ||
int maxfd = __sysconf (_SC_OPEN_MAX); | ||
|
||
/* Test for the validity of the file descriptor. */ | ||
if (fd < 0 || fd >= maxfd) | ||
return EBADF; | ||
|
||
/* Allocate more memory if needed. */ | ||
if (file_actions->__used == file_actions->__allocated | ||
&& __posix_spawn_file_actions_realloc (file_actions) != 0) | ||
/* This can only mean we ran out of memory. */ | ||
return ENOMEM; | ||
|
||
{ | ||
struct __spawn_action *rec; | ||
|
||
/* Add the new value. */ | ||
rec = &file_actions->__actions[file_actions->__used]; | ||
rec->tag = spawn_do_fchdir; | ||
rec->action.fchdir_action.fd = fd; | ||
|
||
/* Account for the new entry. */ | ||
++file_actions->__used; | ||
|
||
return 0; | ||
} | ||
} |
Oops, something went wrong.