>From ba3aeabdd5317c3e21d1da54577235a054ce60f3 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 26 Dec 2020 14:09:29 +0100 Subject: [PATCH 01/15] execve, execvpe, execvp, execv, execl, execle, execlp: Prepare modules. * lib/unistd.in.h (execl, execle, execlp, execv, execve, execvp, execvpe): Add declarations for the new modules. * m4/unistd_h.m4 (gl_UNISTD_H): Test whether execl, execle, execlp, execv, execve, execvp, execvpe are declared. (gl_UNISTD_H_DEFAULTS): Initialize GNULIB_EXEC*, HAVE_EXECVPE, REPLACE_EXEC*. * modules/unistd (Makefile.am): Substitute GNULIB_EXEC*, HAVE_EXECVPE, REPLACE_EXEC*. * tests/test-unistd-c++.cc: Check the signature of execl, execle, execlp, execv, execve, execvp, execvpe. --- ChangeLog | 14 ++++ lib/unistd.in.h | 195 +++++++++++++++++++++++++++++++++++++++++------ m4/unistd_h.m4 | 18 ++++- modules/unistd | 15 ++++ tests/test-unistd-c++.cc | 35 +++++++++ 5 files changed, 253 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6752466..459df8e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 2020-12-26 Bruno Haible + execve, execvpe, execvp, execv, execl, execle, execlp: Prepare modules. + * lib/unistd.in.h (execl, execle, execlp, execv, execve, execvp, + execvpe): Add declarations for the new modules. + * m4/unistd_h.m4 (gl_UNISTD_H): Test whether execl, execle, execlp, + execv, execve, execvp, execvpe are declared. + (gl_UNISTD_H_DEFAULTS): Initialize GNULIB_EXEC*, HAVE_EXECVPE, + REPLACE_EXEC*. + * modules/unistd (Makefile.am): Substitute GNULIB_EXEC*, HAVE_EXECVPE, + REPLACE_EXEC*. + * tests/test-unistd-c++.cc: Check the signature of execl, execle, + execlp, execv, execve, execvp, execvpe. + +2020-12-26 Bruno Haible + stack: Fix typo in comments. * lib/stack.h: Fix typo in comments. diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 7517e3b..d43556a 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -615,7 +615,26 @@ _GL_WARN_ON_USE (euidaccess, "euidaccess is unportable - " #endif -#if @GNULIB_MDA_EXECL@ +#if @GNULIB_EXECL@ +# if @REPLACE_EXECL@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef execl +# define execl rpl_execl +# endif +_GL_FUNCDECL_RPL (execl, int, (const char *program, const char *arg, ...) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (execl, int, (const char *program, const char *arg, ...)); +# else +_GL_CXXALIAS_SYS (execl, int, (const char *program, const char *arg, ...)); +# endif +_GL_CXXALIASWARN (execl); +#elif defined GNULIB_POSIXCHECK +# undef execl +# if HAVE_RAW_DECL_EXECL +_GL_WARN_ON_USE (execl, "execl behaves very differently on mingw - " + "use gnulib module execl for portability"); +# endif +#elif @GNULIB_MDA_EXECL@ /* On native Windows, map 'execl' to '_execl', so that -loldnames is not required. In C++ with GNULIB_NAMESPACE, avoid differences between platforms by defining GNULIB_NAMESPACE::execl always. */ @@ -631,7 +650,26 @@ _GL_CXXALIAS_SYS (execl, int, (const char *program, const char *arg, ...)); _GL_CXXALIASWARN (execl); #endif -#if @GNULIB_MDA_EXECLE@ +#if @GNULIB_EXECLE@ +# if @REPLACE_EXECLE@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef execle +# define execle rpl_execle +# endif +_GL_FUNCDECL_RPL (execle, int, (const char *program, const char *arg, ...) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (execle, int, (const char *program, const char *arg, ...)); +# else +_GL_CXXALIAS_SYS (execle, int, (const char *program, const char *arg, ...)); +# endif +_GL_CXXALIASWARN (execle); +#elif defined GNULIB_POSIXCHECK +# undef execle +# if HAVE_RAW_DECL_EXECLE +_GL_WARN_ON_USE (execle, "execle behaves very differently on mingw - " + "use gnulib module execle for portability"); +# endif +#elif @GNULIB_MDA_EXECLE@ /* On native Windows, map 'execle' to '_execle', so that -loldnames is not required. In C++ with GNULIB_NAMESPACE, avoid differences between platforms by defining GNULIB_NAMESPACE::execle always. */ @@ -640,14 +678,34 @@ _GL_CXXALIASWARN (execl); # undef execle # define execle _execle # endif -_GL_CXXALIAS_MDA (execle, intptr_t, (const char *program, const char *arg, ...)); +_GL_CXXALIAS_MDA (execle, intptr_t, + (const char *program, const char *arg, ...)); # else _GL_CXXALIAS_SYS (execle, int, (const char *program, const char *arg, ...)); # endif _GL_CXXALIASWARN (execle); #endif -#if @GNULIB_MDA_EXECLP@ +#if @GNULIB_EXECLP@ +# if @REPLACE_EXECLP@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef execlp +# define execlp rpl_execlp +# endif +_GL_FUNCDECL_RPL (execlp, int, (const char *program, const char *arg, ...) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (execlp, int, (const char *program, const char *arg, ...)); +# else +_GL_CXXALIAS_SYS (execlp, int, (const char *program, const char *arg, ...)); +# endif +_GL_CXXALIASWARN (execlp); +#elif defined GNULIB_POSIXCHECK +# undef execlp +# if HAVE_RAW_DECL_EXECLP +_GL_WARN_ON_USE (execlp, "execlp behaves very differently on mingw - " + "use gnulib module execlp for portability"); +# endif +#elif @GNULIB_MDA_EXECLP@ /* On native Windows, map 'execlp' to '_execlp', so that -loldnames is not required. In C++ with GNULIB_NAMESPACE, avoid differences between platforms by defining GNULIB_NAMESPACE::execlp always. */ @@ -656,7 +714,8 @@ _GL_CXXALIASWARN (execle); # undef execlp # define execlp _execlp # endif -_GL_CXXALIAS_MDA (execlp, intptr_t, (const char *program, const char *arg, ...)); +_GL_CXXALIAS_MDA (execlp, intptr_t, + (const char *program, const char *arg, ...)); # else _GL_CXXALIAS_SYS (execlp, int, (const char *program, const char *arg, ...)); # endif @@ -664,7 +723,26 @@ _GL_CXXALIASWARN (execlp); #endif -#if @GNULIB_MDA_EXECV@ +#if @GNULIB_EXECV@ +# if @REPLACE_EXECV@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef execv +# define execv rpl_execv +# endif +_GL_FUNCDECL_RPL (execv, int, (const char *program, char * const *argv) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (execv, int, (const char *program, char * const *argv)); +# else +_GL_CXXALIAS_SYS (execv, int, (const char *program, char * const *argv)); +# endif +_GL_CXXALIASWARN (execv); +#elif defined GNULIB_POSIXCHECK +# undef execv +# if HAVE_RAW_DECL_EXECV +_GL_WARN_ON_USE (execv, "execv behaves very differently on mingw - " + "use gnulib module execv for portability"); +# endif +#elif @GNULIB_MDA_EXECV@ /* On native Windows, map 'execv' to '_execv', so that -loldnames is not required. In C++ with GNULIB_NAMESPACE, avoid differences between platforms by defining GNULIB_NAMESPACE::execv always. */ @@ -673,15 +751,37 @@ _GL_CXXALIASWARN (execlp); # undef execv # define execv _execv # endif -_GL_CXXALIAS_MDA (execv, intptr_t, - (const char *program, const char * const *argv)); +_GL_CXXALIAS_MDA_CAST (execv, intptr_t, + (const char *program, char * const *argv)); # else _GL_CXXALIAS_SYS (execv, int, (const char *program, char * const *argv)); # endif _GL_CXXALIASWARN (execv); #endif -#if @GNULIB_MDA_EXECVE@ +#if @GNULIB_EXECVE@ +# if @REPLACE_EXECVE@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef execve +# define execve rpl_execve +# endif +_GL_FUNCDECL_RPL (execve, int, + (const char *program, char * const *argv, char * const *env) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (execve, int, + (const char *program, char * const *argv, char * const *env)); +# else +_GL_CXXALIAS_SYS (execve, int, + (const char *program, char * const *argv, char * const *env)); +# endif +_GL_CXXALIASWARN (execve); +#elif defined GNULIB_POSIXCHECK +# undef execve +# if HAVE_RAW_DECL_EXECVE +_GL_WARN_ON_USE (execve, "execve behaves very differently on mingw - " + "use gnulib module execve for portability"); +# endif +#elif @GNULIB_MDA_EXECVE@ /* On native Windows, map 'execve' to '_execve', so that -loldnames is not required. In C++ with GNULIB_NAMESPACE, avoid differences between platforms by defining GNULIB_NAMESPACE::execve always. */ @@ -690,9 +790,9 @@ _GL_CXXALIASWARN (execv); # undef execve # define execve _execve # endif -_GL_CXXALIAS_MDA (execve, intptr_t, - (const char *program, const char * const *argv, - const char * const *env)); +_GL_CXXALIAS_MDA_CAST (execve, intptr_t, + (const char *program, char * const *argv, + char * const *env)); # else _GL_CXXALIAS_SYS (execve, int, (const char *program, char * const *argv, char * const *env)); @@ -700,7 +800,26 @@ _GL_CXXALIAS_SYS (execve, int, _GL_CXXALIASWARN (execve); #endif -#if @GNULIB_MDA_EXECVP@ +#if @GNULIB_EXECVP@ +# if @REPLACE_EXECVP@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef execvp +# define execvp rpl_execvp +# endif +_GL_FUNCDECL_RPL (execvp, int, (const char *program, char * const *argv) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (execvp, int, (const char *program, char * const *argv)); +# else +_GL_CXXALIAS_SYS (execvp, int, (const char *program, char * const *argv)); +# endif +_GL_CXXALIASWARN (execvp); +#elif defined GNULIB_POSIXCHECK +# undef execvp +# if HAVE_RAW_DECL_EXECVP +_GL_WARN_ON_USE (execvp, "execvp behaves very differently on mingw - " + "use gnulib module execvp for portability"); +# endif +#elif @GNULIB_MDA_EXECVP@ /* On native Windows, map 'execvp' to '_execvp', so that -loldnames is not required. In C++ with GNULIB_NAMESPACE, avoid differences between platforms by defining GNULIB_NAMESPACE::execvp always. */ @@ -709,15 +828,42 @@ _GL_CXXALIASWARN (execve); # undef execvp # define execvp _execvp # endif -_GL_CXXALIAS_MDA (execvp, intptr_t, - (const char *program, const char * const *argv)); +_GL_CXXALIAS_MDA_CAST (execvp, intptr_t, + (const char *program, char * const *argv)); # else _GL_CXXALIAS_SYS (execvp, int, (const char *program, char * const *argv)); # endif _GL_CXXALIASWARN (execvp); #endif -#if @GNULIB_MDA_EXECVPE@ +#if @GNULIB_EXECVPE@ +# if @REPLACE_EXECVPE@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef execvpe +# define execvpe rpl_execvpe +# endif +_GL_FUNCDECL_RPL (execvpe, int, + (const char *program, char * const *argv, char * const *env) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (execvpe, int, + (const char *program, char * const *argv, char * const *env)); +# else +# if !@HAVE_DECL_EXECVPE@ +_GL_FUNCDECL_SYS (execvpe, int, + (const char *program, char * const *argv, char * const *env) + _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (execvpe, int, + (const char *program, char * const *argv, char * const *env)); +# endif +_GL_CXXALIASWARN (execvpe); +#elif defined GNULIB_POSIXCHECK +# undef execvpe +# if HAVE_RAW_DECL_EXECVPE +_GL_WARN_ON_USE (execvpe, "execvpe behaves very differently on mingw - " + "use gnulib module execvpe for portability"); +# endif +#elif @GNULIB_MDA_EXECVPE@ /* On native Windows, map 'execvpe' to '_execvpe', so that -loldnames is not required. In C++ with GNULIB_NAMESPACE, avoid differences between platforms by defining GNULIB_NAMESPACE::execvpe on all platforms that have @@ -727,16 +873,19 @@ _GL_CXXALIASWARN (execvp); # undef execvpe # define execvpe _execvpe # endif -_GL_CXXALIAS_MDA (execvpe, intptr_t, - (const char *program, const char * const *argv, - const char * const *env)); -# else -# if @HAVE_DECL_EXECVPE@ +_GL_CXXALIAS_MDA_CAST (execvpe, intptr_t, + (const char *program, char * const *argv, + char * const *env)); +# elif @HAVE_EXECVPE@ +# if !@HAVE_DECL_EXECVPE@ +_GL_FUNCDECL_SYS (execvpe, int, + (const char *program, char * const *argv, char * const *env) + _GL_ARG_NONNULL ((1, 2))); +# endif _GL_CXXALIAS_SYS (execvpe, int, (const char *program, char * const *argv, char * const *env)); -# endif # endif -# if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_DECL_EXECVPE@ +# if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_EXECVPE@ _GL_CXXALIASWARN (execvpe); # endif #endif diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4 index db96e2b..f0db575 100644 --- a/m4/unistd_h.m4 +++ b/m4/unistd_h.m4 @@ -1,4 +1,4 @@ -# unistd_h.m4 serial 84 +# unistd_h.m4 serial 85 dnl Copyright (C) 2006-2020 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -42,6 +42,7 @@ AC_DEFUN([gl_UNISTD_H], # endif #endif ]], [access chdir chown copy_file_range dup dup2 dup3 environ euidaccess + execl execle execlp execv execve execvp execvpe faccessat fchdir fchownat fdatasync fsync ftruncate getcwd getdomainname getdtablesize getentropy getgroups gethostname getlogin getlogin_r getpagesize getpass @@ -79,6 +80,13 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], GNULIB_DUP3=0; AC_SUBST([GNULIB_DUP3]) GNULIB_ENVIRON=0; AC_SUBST([GNULIB_ENVIRON]) GNULIB_EUIDACCESS=0; AC_SUBST([GNULIB_EUIDACCESS]) + GNULIB_EXECL=0; AC_SUBST([GNULIB_EXECL]) + GNULIB_EXECLE=0; AC_SUBST([GNULIB_EXECLE]) + GNULIB_EXECLP=0; AC_SUBST([GNULIB_EXECLP]) + GNULIB_EXECV=0; AC_SUBST([GNULIB_EXECV]) + GNULIB_EXECVE=0; AC_SUBST([GNULIB_EXECVE]) + GNULIB_EXECVP=0; AC_SUBST([GNULIB_EXECVP]) + GNULIB_EXECVPE=0; AC_SUBST([GNULIB_EXECVPE]) GNULIB_FACCESSAT=0; AC_SUBST([GNULIB_FACCESSAT]) GNULIB_FCHDIR=0; AC_SUBST([GNULIB_FCHDIR]) GNULIB_FCHOWNAT=0; AC_SUBST([GNULIB_FCHOWNAT]) @@ -150,6 +158,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], HAVE_COPY_FILE_RANGE=1; AC_SUBST([HAVE_COPY_FILE_RANGE]) HAVE_DUP3=1; AC_SUBST([HAVE_DUP3]) HAVE_EUIDACCESS=1; AC_SUBST([HAVE_EUIDACCESS]) + HAVE_EXECVPE=1; AC_SUBST([HAVE_EXECVPE]) HAVE_FACCESSAT=1; AC_SUBST([HAVE_FACCESSAT]) HAVE_FCHDIR=1; AC_SUBST([HAVE_FCHDIR]) HAVE_FCHOWNAT=1; AC_SUBST([HAVE_FCHOWNAT]) @@ -198,6 +207,13 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], REPLACE_CLOSE=0; AC_SUBST([REPLACE_CLOSE]) REPLACE_DUP=0; AC_SUBST([REPLACE_DUP]) REPLACE_DUP2=0; AC_SUBST([REPLACE_DUP2]) + REPLACE_EXECL=0; AC_SUBST([REPLACE_EXECL]) + REPLACE_EXECLE=0; AC_SUBST([REPLACE_EXECLE]) + REPLACE_EXECLP=0; AC_SUBST([REPLACE_EXECLP]) + REPLACE_EXECV=0; AC_SUBST([REPLACE_EXECV]) + REPLACE_EXECVE=0; AC_SUBST([REPLACE_EXECVE]) + REPLACE_EXECVP=0; AC_SUBST([REPLACE_EXECVP]) + REPLACE_EXECVPE=0; AC_SUBST([REPLACE_EXECVPE]) REPLACE_FACCESSAT=0; AC_SUBST([REPLACE_FACCESSAT]) REPLACE_FCHOWNAT=0; AC_SUBST([REPLACE_FCHOWNAT]) REPLACE_FTRUNCATE=0; AC_SUBST([REPLACE_FTRUNCATE]) diff --git a/modules/unistd b/modules/unistd index 27a4b67..442678b 100644 --- a/modules/unistd +++ b/modules/unistd @@ -47,6 +47,13 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H -e 's/@''GNULIB_DUP3''@/$(GNULIB_DUP3)/g' \ -e 's/@''GNULIB_ENVIRON''@/$(GNULIB_ENVIRON)/g' \ -e 's/@''GNULIB_EUIDACCESS''@/$(GNULIB_EUIDACCESS)/g' \ + -e 's/@''GNULIB_EXECL''@/$(GNULIB_EXECL)/g' \ + -e 's/@''GNULIB_EXECLE''@/$(GNULIB_EXECLE)/g' \ + -e 's/@''GNULIB_EXECLP''@/$(GNULIB_EXECLP)/g' \ + -e 's/@''GNULIB_EXECV''@/$(GNULIB_EXECV)/g' \ + -e 's/@''GNULIB_EXECVE''@/$(GNULIB_EXECVE)/g' \ + -e 's/@''GNULIB_EXECVP''@/$(GNULIB_EXECVP)/g' \ + -e 's/@''GNULIB_EXECVPE''@/$(GNULIB_EXECVPE)/g' \ -e 's/@''GNULIB_FACCESSAT''@/$(GNULIB_FACCESSAT)/g' \ -e 's/@''GNULIB_FCHDIR''@/$(GNULIB_FCHDIR)/g' \ -e 's/@''GNULIB_FCHOWNAT''@/$(GNULIB_FCHOWNAT)/g' \ @@ -118,6 +125,7 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H -e 's|@''HAVE_COPY_FILE_RANGE''@|$(HAVE_COPY_FILE_RANGE)|g' \ -e 's|@''HAVE_DUP3''@|$(HAVE_DUP3)|g' \ -e 's|@''HAVE_EUIDACCESS''@|$(HAVE_EUIDACCESS)|g' \ + -e 's|@''HAVE_EXECVPE''@|$(HAVE_EXECVPE)|g' \ -e 's|@''HAVE_FACCESSAT''@|$(HAVE_FACCESSAT)|g' \ -e 's|@''HAVE_FCHDIR''@|$(HAVE_FCHDIR)|g' \ -e 's|@''HAVE_FCHOWNAT''@|$(HAVE_FCHOWNAT)|g' \ @@ -166,6 +174,13 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H -e 's|@''REPLACE_CLOSE''@|$(REPLACE_CLOSE)|g' \ -e 's|@''REPLACE_DUP''@|$(REPLACE_DUP)|g' \ -e 's|@''REPLACE_DUP2''@|$(REPLACE_DUP2)|g' \ + -e 's|@''REPLACE_EXECL''@|$(REPLACE_EXECL)|g' \ + -e 's|@''REPLACE_EXECLE''@|$(REPLACE_EXECLE)|g' \ + -e 's|@''REPLACE_EXECLP''@|$(REPLACE_EXECLP)|g' \ + -e 's|@''REPLACE_EXECV''@|$(REPLACE_EXECV)|g' \ + -e 's|@''REPLACE_EXECVE''@|$(REPLACE_EXECVE)|g' \ + -e 's|@''REPLACE_EXECVP''@|$(REPLACE_EXECVP)|g' \ + -e 's|@''REPLACE_EXECVPE''@|$(REPLACE_EXECVPE)|g' \ -e 's|@''REPLACE_FACCESSAT''@|$(REPLACE_FACCESSAT)|g' \ -e 's|@''REPLACE_FCHOWNAT''@|$(REPLACE_FCHOWNAT)|g' \ -e 's|@''REPLACE_FTRUNCATE''@|$(REPLACE_FTRUNCATE)|g' \ diff --git a/tests/test-unistd-c++.cc b/tests/test-unistd-c++.cc index 6d4c8fb..d866091 100644 --- a/tests/test-unistd-c++.cc +++ b/tests/test-unistd-c++.cc @@ -52,6 +52,41 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::dup2, int, (int, int)); SIGNATURE_CHECK (GNULIB_NAMESPACE::dup3, int, (int, int, int)); #endif +#if GNULIB_TEST_EXECL +SIGNATURE_CHECK (GNULIB_NAMESPACE::execl, int, + (const char *, const char *, ...)); +#endif + +#if GNULIB_TEST_EXECLE +SIGNATURE_CHECK (GNULIB_NAMESPACE::execle, int, + (const char *, const char *, ...)); +#endif + +#if GNULIB_TEST_EXECLP +SIGNATURE_CHECK (GNULIB_NAMESPACE::execlp, int, + (const char *, const char *, ...)); +#endif + +#if GNULIB_TEST_EXECV +SIGNATURE_CHECK (GNULIB_NAMESPACE::execv, int, + (const char *, char * const *)); +#endif + +#if GNULIB_TEST_EXECVE +SIGNATURE_CHECK (GNULIB_NAMESPACE::execve, int, + (const char *, char * const *, char * const *)); +#endif + +#if GNULIB_TEST_EXECVP +SIGNATURE_CHECK (GNULIB_NAMESPACE::execvp, int, + (const char *, char * const *)); +#endif + +#if GNULIB_TEST_EXECVPE +SIGNATURE_CHECK (GNULIB_NAMESPACE::execvpe, int, + (const char *, char * const *, char * const *)); +#endif + #if GNULIB_TEST_EUIDACCESS SIGNATURE_CHECK (GNULIB_NAMESPACE::euidaccess, int, (const char *, int)); #endif -- 2.7.4