summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2023-01-19 00:32:12 +0100
committerLudovic Courtès <ludo@gnu.org>2023-01-19 00:32:12 +0100
commit3bb08542d297980ea8ca9403e71d2fcd640c4877 (patch)
tree9d844e98ae86f2a14210a6d6775a9636032a044e
parentd98888290b243e1c98ac7afb085a0925a33c8615 (diff)
downloadguile-3bb08542d297980ea8ca9403e71d2fcd640c4877.tar.gz
Add Gnulib modules for 'posix_spawn' file operations.
This is again from Gnulib v0.1-5703-g356a414e8c. * m4/gnulib-cache.m4: Add 'posix_spawn_file_actions_addclose', 'posix_spawn_file_actions_adddup2', 'posix_spawn_file_actions_addopen', and 'posix_spawn_file_actions_init'.
-rw-r--r--lib/Makefile.am44
-rw-r--r--lib/spawn_faction_addclose.c69
-rw-r--r--lib/spawn_faction_adddup2.c70
-rw-r--r--lib/spawn_faction_addopen.c86
-rw-r--r--lib/spawn_faction_init.c56
-rw-r--r--m4/gnulib-cache.m48
-rw-r--r--m4/gnulib-comp.m433
7 files changed, 366 insertions, 0 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index c3223052f..eddfa7282 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -111,6 +111,10 @@
# pipe2 \
# poll \
# posix_spawn \
+# posix_spawn_file_actions_addclose \
+# posix_spawn_file_actions_adddup2 \
+# posix_spawn_file_actions_addopen \
+# posix_spawn_file_actions_init \
# posix_spawnp \
# putenv \
# readlink \
@@ -2068,6 +2072,46 @@ EXTRA_DIST += spawn_int.h
## end gnulib module posix_spawn-internal
+## begin gnulib module posix_spawn_file_actions_addclose
+
+if GL_COND_OBJ_SPAWN_FACTION_ADDCLOSE
+libgnu_la_SOURCES += spawn_faction_addclose.c
+endif
+
+EXTRA_DIST += spawn_int.h
+
+## end gnulib module posix_spawn_file_actions_addclose
+
+## begin gnulib module posix_spawn_file_actions_adddup2
+
+if GL_COND_OBJ_SPAWN_FACTION_ADDDUP2
+libgnu_la_SOURCES += spawn_faction_adddup2.c
+endif
+
+EXTRA_DIST += spawn_int.h
+
+## end gnulib module posix_spawn_file_actions_adddup2
+
+## begin gnulib module posix_spawn_file_actions_addopen
+
+if GL_COND_OBJ_SPAWN_FACTION_ADDOPEN
+libgnu_la_SOURCES += spawn_faction_addopen.c
+endif
+
+EXTRA_DIST += spawn_int.h
+
+## end gnulib module posix_spawn_file_actions_addopen
+
+## begin gnulib module posix_spawn_file_actions_init
+
+if GL_COND_OBJ_SPAWN_FACTION_INIT
+libgnu_la_SOURCES += spawn_faction_init.c
+endif
+
+EXTRA_DIST += spawn_int.h
+
+## end gnulib module posix_spawn_file_actions_init
+
## begin gnulib module posix_spawnp
if GL_COND_OBJ_SPAWNP
diff --git a/lib/spawn_faction_addclose.c b/lib/spawn_faction_addclose.c
new file mode 100644
index 000000000..c87a23794
--- /dev/null
+++ b/lib/spawn_faction_addclose.c
@@ -0,0 +1,69 @@
+/* Copyright (C) 2000, 2009-2023 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/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <spawn.h>
+
+#include <errno.h>
+#include <unistd.h>
+
+#if !_LIBC
+# define __sysconf(open_max) getdtablesize ()
+#endif
+
+#if REPLACE_POSIX_SPAWN
+# include "spawn_int.h"
+#endif
+
+/* 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)
+#undef posix_spawn_file_actions_addclose
+{
+ int maxfd = __sysconf (_SC_OPEN_MAX);
+
+ /* Test for the validity of the file descriptor. */
+ if (fd < 0 || fd >= maxfd)
+ return EBADF;
+
+#if !REPLACE_POSIX_SPAWN
+ return posix_spawn_file_actions_addclose (file_actions, fd);
+#else
+ /* 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;
+ }
+#endif
+}
diff --git a/lib/spawn_faction_adddup2.c b/lib/spawn_faction_adddup2.c
new file mode 100644
index 000000000..27f4aa314
--- /dev/null
+++ b/lib/spawn_faction_adddup2.c
@@ -0,0 +1,70 @@
+/* Copyright (C) 2000, 2009-2023 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/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <spawn.h>
+
+#include <errno.h>
+#include <unistd.h>
+
+#if !_LIBC
+# define __sysconf(open_max) getdtablesize ()
+#endif
+
+#if REPLACE_POSIX_SPAWN
+# include "spawn_int.h"
+#endif
+
+/* 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)
+#undef posix_spawn_file_actions_adddup2
+{
+ 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;
+
+#if !REPLACE_POSIX_SPAWN
+ return posix_spawn_file_actions_adddup2 (file_actions, fd, newfd);
+#else
+ /* 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;
+ }
+#endif
+}
diff --git a/lib/spawn_faction_addopen.c b/lib/spawn_faction_addopen.c
new file mode 100644
index 000000000..fa3e1cb49
--- /dev/null
+++ b/lib/spawn_faction_addopen.c
@@ -0,0 +1,86 @@
+/* Copyright (C) 2000, 2009-2023 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/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <spawn.h>
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#if !_LIBC
+# define __sysconf(open_max) getdtablesize ()
+#endif
+
+#if REPLACE_POSIX_SPAWN
+# include "spawn_int.h"
+#endif
+
+/* Add an action to FILE-ACTIONS which tells the implementation to call
+ 'open' for the given file during the 'spawn' call. */
+int
+posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *file_actions,
+ int fd, const char *path, int oflag,
+ mode_t mode)
+#undef posix_spawn_file_actions_addopen
+{
+ int maxfd = __sysconf (_SC_OPEN_MAX);
+
+ /* Test for the validity of the file descriptor. */
+ if (fd < 0 || fd >= maxfd)
+ return EBADF;
+
+#if !REPLACE_POSIX_SPAWN
+ return posix_spawn_file_actions_addopen (file_actions, fd, path, oflag, mode);
+#else
+ {
+ /* Copy PATH, because the caller may free it before calling posix_spawn()
+ or posix_spawnp(). */
+ char *path_copy = strdup (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_open;
+ rec->action.open_action.fd = fd;
+ rec->action.open_action.path = path_copy;
+ rec->action.open_action.oflag = oflag;
+ rec->action.open_action.mode = mode;
+
+ /* Account for the new entry. */
+ ++file_actions->_used;
+
+ return 0;
+ }
+ }
+#endif
+}
diff --git a/lib/spawn_faction_init.c b/lib/spawn_faction_init.c
new file mode 100644
index 000000000..12089d9de
--- /dev/null
+++ b/lib/spawn_faction_init.c
@@ -0,0 +1,56 @@
+/* Copyright (C) 2000, 2009-2023 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/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <spawn.h>
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "spawn_int.h"
+
+
+/* Function used to increase the size of the allocated array. This
+ function is called from the 'add'-functions. */
+int
+__posix_spawn_file_actions_realloc (posix_spawn_file_actions_t *file_actions)
+{
+ int newalloc = file_actions->_allocated + 8;
+ void *newmem = realloc (file_actions->_actions,
+ newalloc * sizeof (struct __spawn_action));
+
+ if (newmem == NULL)
+ /* Not enough memory. */
+ return ENOMEM;
+
+ file_actions->_actions = (struct __spawn_action *) newmem;
+ file_actions->_allocated = newalloc;
+
+ return 0;
+}
+
+
+/* Initialize data structure for file attribute for 'spawn' call. */
+int
+posix_spawn_file_actions_init (posix_spawn_file_actions_t *file_actions)
+{
+ /* Simply clear all the elements. */
+ memset (file_actions, '\0', sizeof (*file_actions));
+ return 0;
+}
diff --git a/m4/gnulib-cache.m4 b/m4/gnulib-cache.m4
index d9c27f935..cb3a403df 100644
--- a/m4/gnulib-cache.m4
+++ b/m4/gnulib-cache.m4
@@ -116,6 +116,10 @@
# pipe2 \
# poll \
# posix_spawn \
+# posix_spawn_file_actions_addclose \
+# posix_spawn_file_actions_adddup2 \
+# posix_spawn_file_actions_addopen \
+# posix_spawn_file_actions_init \
# posix_spawnp \
# putenv \
# readlink \
@@ -217,6 +221,10 @@ gl_MODULES([
pipe2
poll
posix_spawn
+ posix_spawn_file_actions_addclose
+ posix_spawn_file_actions_adddup2
+ posix_spawn_file_actions_addopen
+ posix_spawn_file_actions_init
posix_spawnp
putenv
readlink
diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4
index 1187c1a6a..215acc1e7 100644
--- a/m4/gnulib-comp.m4
+++ b/m4/gnulib-comp.m4
@@ -194,6 +194,10 @@ AC_DEFUN([gl_EARLY],
# Code from module poll-h:
# Code from module posix_spawn:
# Code from module posix_spawn-internal:
+ # Code from module posix_spawn_file_actions_addclose:
+ # Code from module posix_spawn_file_actions_adddup2:
+ # Code from module posix_spawn_file_actions_addopen:
+ # Code from module posix_spawn_file_actions_init:
# Code from module posix_spawnp:
# Code from module putenv:
# Code from module raise:
@@ -622,6 +626,22 @@ AC_DEFUN([gl_INIT],
gl_CONDITIONAL([GL_COND_OBJ_SPAWN],
[test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1])
gl_SPAWN_MODULE_INDICATOR([posix_spawn])
+ gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE
+ gl_CONDITIONAL([GL_COND_OBJ_SPAWN_FACTION_ADDCLOSE],
+ [test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE = 1])
+ gl_SPAWN_MODULE_INDICATOR([posix_spawn_file_actions_addclose])
+ gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2
+ gl_CONDITIONAL([GL_COND_OBJ_SPAWN_FACTION_ADDDUP2],
+ [test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 = 1])
+ gl_SPAWN_MODULE_INDICATOR([posix_spawn_file_actions_adddup2])
+ gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN
+ gl_CONDITIONAL([GL_COND_OBJ_SPAWN_FACTION_ADDOPEN],
+ [test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN = 1])
+ gl_SPAWN_MODULE_INDICATOR([posix_spawn_file_actions_addopen])
+ gl_POSIX_SPAWN
+ gl_CONDITIONAL([GL_COND_OBJ_SPAWN_FACTION_INIT],
+ [test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1])
+ gl_SPAWN_MODULE_INDICATOR([posix_spawn_file_actions_init])
gl_POSIX_SPAWN
gl_CONDITIONAL([GL_COND_OBJ_SPAWNP],
[test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1])
@@ -1704,6 +1724,15 @@ AC_SUBST([LTALLOCA])
if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1; then
func_gl_gnulib_m4code_332607f759618fb73dfc3076748afea7
fi
+ if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE = 1; then
+ func_gl_gnulib_m4code_getdtablesize
+ fi
+ if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 = 1; then
+ func_gl_gnulib_m4code_getdtablesize
+ fi
+ if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN = 1; then
+ func_gl_gnulib_m4code_getdtablesize
+ fi
if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1; then
func_gl_gnulib_m4code_332607f759618fb73dfc3076748afea7
fi
@@ -2232,6 +2261,10 @@ AC_DEFUN([gl_FILE_LIST], [
lib/sockets.h
lib/spawn.c
lib/spawn.in.h
+ lib/spawn_faction_addclose.c
+ lib/spawn_faction_adddup2.c
+ lib/spawn_faction_addopen.c
+ lib/spawn_faction_init.c
lib/spawn_int.h
lib/spawni.c
lib/spawnp.c