aboutsummaryrefslogtreecommitdiffstats
path: root/src/spawn-posix.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* spawn: Care about closefrom/close call is interrupted.NIIBE Yutaka2025-01-141-62/+54
| | | | | | | | | | | | * src/spawn-posix.c (closefrom_really): Handle interrupted call of closefrom. (close_except): Likewise for call of close. (_gpgrt_close_all_fds): Use closefrom_really and close_except. -- GnuPG-bug-id: 7478 Signed-off-by: NIIBE Yutaka <[email protected]>
* spawn: Use closefrom when available.NIIBE Yutaka2025-01-081-2/+46
| | | | | | | | | * configure.ac (AC_CHECK_FUNCS): Check closefrom. * src/spawn-posix.c [HAVE_CLOSEFROM]: Use closefrom if possible. -- Signed-off-by: NIIBE Yutaka <[email protected]>
* spawn: Shorter identifier gpgrt_spawn_actions_set_env_rev.NIIBE Yutaka2024-10-161-2/+2
| | | | | | | | | | | | | | | | | | * src/gpg-error.def.in: Rename to gpgrt_spawn_actions_set_env_rev. * src/gpg-error.h.in: Likewise. * src/gpg-error.vers: Likewise. * src/gpgrt-int.h: Likewise. * src/spawn-posix.c: Likewise. * src/spawn-w32.c: Likewise. * src/visibility.c: Likewise. * src/visibility.h: Likewise. * tests/t-spawn.c (run_test): Use gpgrt_spawn_actions_set_env_rev. -- Fixes-commit: 1860f6407f834b681c21f67db7236eaad161524c GnuPG-bug-id: 7307 Signed-off-by: NIIBE Yutaka <[email protected]>
* spawn: Add new function to modify environment.NIIBE Yutaka2024-10-111-6/+41
| | | | | | | | | | | | | | | | | | | | | | | | * src/gpg-error.def.in (gpgrt_spawn_actions_set_envchange): New. * src/gpg-error.vers (gpgrt_spawn_actions_set_envchange): New. * src/gpg-error.h.in (gpgrt_spawn_actions_set_envchange): New. * src/gpgrt-int.h (_gpgrt_spawn_actions_set_envchange): New. * src/spawn-posix.c (struct gpgrt_spawn_actions): New field ENVCHANGE. (prepare_environ): New. (my_exec): Take care of ENVCHANGE. (_gpgrt_spawn_actions_set_envchange): New. * src/spawn-w32.c (struct gpgrt_spawn_actions): New field ENVCHANGE. (prepare_env_block): New. (_gpgrt_spawn_actions_set_envchange): New. (spawn_detached, _gpgrt_process_spawn): Take care of ENVCHANGE. * src/visibility.c (gpgrt_spawn_actions_set_envchange): New. * src/visibility.h (gpgrt_spawn_actions_set_envchange): New. * tests/Makefile.am (TESTS): Add t-spawn. * tests/t-spawn.c: New. -- GnuPG-bug-id: 7307 Signed-off-by: NIIBE Yutaka <[email protected]>
* posix: Fix forgotten _gpgrt_post_syscall on error path.NIIBE Yutaka2024-09-191-0/+1
| | | | | | | | * src/spawn-posix.c (do_create_pipe_and_estream): Call post_syscall. -- Signed-off-by: NIIBE Yutaka <[email protected]>
* posix: Fix memory leak for spawn.NIIBE Yutaka2024-09-191-0/+1
| | | | | | | | * src/spawn-posix.c (spawn_detached): Free ARGV. -- Signed-off-by: NIIBE Yutaka <[email protected]>
* core: Declare environ for macOS and others.Werner Koch2024-06-201-0/+3
| | | | | | | * src/spawn-posix.c (environ): Declare. -- GnuPG-bug-id: 7169
* spawn: New flag GPGRT_PROCESS_NO_EUID_CHECKWerner Koch2024-06-191-7/+9
| | | | | | * src/gpg-error.h.in (GPGRT_PROCESS_NO_EUID_CHECK): New. * src/spawn-posix.c (spawn_detached): Move check to ... (_gpgrt_process_spawn): here and skip if flag is set.
* spawn: Keep struct definitions at the top of the file.Werner Koch2024-06-191-18/+27
| | | | | * src/spawn-posix.c: Move include and struct defs around. * src/spawn-w32.c: Move struct defs around.
* spawn: Support the use case in libassuan where PGMNAME==NULL.NIIBE Yutaka2024-06-071-4/+17
| | | | | | | | | | | * src/spawn-posix.c (my_exec): When PGMNAME==NULL, just fork. (_gpgrt_process_spawn): Support PGMNAME==NULL use case. * src/spawn-w32.c (_gpgrt_process_spawn): Return GPG_ERR_INV_ARG, when PGMNAME==NULL. -- Signed-off-by: NIIBE Yutaka <[email protected]>
* Cleanup spawn API implementation.NIIBE Yutaka2024-06-061-1/+1
| | | | | | -- Signed-off-by: NIIBE Yutaka <[email protected]>
* spawn: Avoid bumping the error counter.Werner Koch2024-06-051-6/+6
| | | | | | | | | | | | | | | * src/spawn-posix.c: Use log_info instead of log_error. * src/spawn-w32.c: Ditto. (spawn_detached): Fix copying of hd[2] (_gpgrt_process_spawn): Ditto. -- The spawn function might be used to run helper processes which are non-critical for the operation of the program. For example to display help. Bumping the error counter via gpgrt_log_error would then let the entire program fail which might be surprising. It is better to just print an informational message and let the caller decide what to do with the returned error code.
* spawn: Expose spawn functions API.NIIBE Yutaka2024-06-051-14/+3
| | | | | | | | | | | | | * src/gpg-error.def.in: Update. * src/gpg-error.vers: Update. * src/gpg-error.h.in: Add declarations. * src/visibility.c: Add implementations. * src/visibility.h: Expose them. -- GnuPG-bug-id: 6249 Signed-off-by: NIIBE Yutaka <[email protected]>
* spawn: Allow NULL for ACT.NIIBE Yutaka2024-05-301-2/+10
| | | | | | | | | * src/spawn-posix.c (_gpgrt_process_spawn): ACT may be null. * src/spawn-w32.c (_gpgrt_process_spawn): Likewise. -- Signed-off-by: NIIBE Yutaka <[email protected]>
* Fix process termination check at release.NIIBE Yutaka2024-05-291-1/+1
| | | | | | | | | | * src/spawn-posix.c (_gpgrt_process_release): When NOT terminated, terminate and wait. * src/spawn-w32.c (_gpgrt_process_release): Likewise. -- Signed-off-by: NIIBE Yutaka <[email protected]>
* Fix how environment variables are specified for spawn.NIIBE Yutaka2024-05-291-5/+6
| | | | | | | | | | | | | * src/gpgrt-int.h (_gpgrt_spawn_actions_set_envvars) [HAVE_W32_SYSTEM]: Assume use with GetEnvironmentStrings. (_gpgrt_spawn_actions_set_environ) [!HAVE_W32_SYSTEM]: New. * src/spawn-posix.c: Follow the change. * src/spawn-w32.c: Can specify envvars now. -- Signed-off-by: NIIBE Yutaka <[email protected]>
* Cleaner semantics for _gpgrt_process_spawn without a callback.NIIBE Yutaka2024-05-291-41/+89
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * src/gpg-error.h.in (@define:struct_spawn_cb_arg@): Remove. (gpgrt_spawn_actions_t): New. (@define:spawn_actions_functions@): New. * src/gpgrt-int.h (_gpgrt_spawn_actions_new) (_gpgrt_spawn_actions_release, _gpgrt_spawn_actions_set_envvars) (_gpgrt_spawn_actions_set_redirect): New. [HAVE_W32_SYSTEM] (_gpgrt_spawn_actions_set_inherit_handles): New. [!HAVE_W32_SYSTEM] (_gpgrt_spawn_actions_set_inherit_fds) (_gpgrt_spawn_actions_set_atfork): New. (_gpgrt_process_spawn): Use gpgrt_spawn_actions_t. (_gpgrt_spawn_helper): Remove. * src/mkheader.c: Emit gpgrt_spawn_actions_* definition. * src/spawn-posix.c(_gpgrt_spawn_actions_new) (_gpgrt_spawn_actions_release, _gpgrt_spawn_actions_set_envvars) (_gpgrt_spawn_actions_set_redirect) (_gpgrt_spawn_actions_set_inherit_fds) (_gpgrt_spawn_actions_set_atfork): New. (spawn_detached, _gpgrt_process_spawn): Use gpgrt_spawn_actions_t. (_gpgrt_spawn_helper): Remove. * src/spawn-w32.c: Ditto, with _gpgrt_spawn_actions_set_inherit_handles, but no _gpgrt_spawn_actions_set_atfork. -- GnuPG-bug-id: 6249 Signed-off-by: NIIBE Yutaka <[email protected]>
* Import spawn functions from GnuPG master.NIIBE Yutaka2024-05-281-559/+505
| | | | | | | | | | | | | | | | | | | | | | | | | | | * src/gpg-error.h.in (@define:gpgrt_process_t@): Remove. (@define:struct_spawn_cb_arg@): New. (enum gpgrt_process_requests): New. (GPGRT_PROCESS_DETACHED, GPGRT_PROCESS_STDIN_PIPE) (GPGRT_PROCESS_STDOUT_PIPE, GPGRT_PROCESS_STDERR_PIPE) (GPGRT_PROCESS_STDINOUT_SOCKETPAIR, GPGRT_PROCESS_STDIN_KEEP) (GPGRT_PROCESS_STDOUT_KEEP, GPGRT_PROCESS_STDERR_KEEP) (GPGRT_PROCESS_STDFDS_SETTING, GPGRT_PROCESS_STREAM_NONBLOCK): New. * src/gpgrt-int.h (_gpgrt_process_spawn, _gpgrt_process_terminate) (_gpgrt_process_get_fds, _gpgrt_process_get_streams) (_gpgrt_process_ctl, _gpgrt_process_wait, _gpgrt_process_release) (_gpgrt_process_wait_list, _gpgrt_spawn_helper): New. * src/mkheader.c: Emit definition of struct_spawn_cb_arg. * src/spawn-posix.c (_gpgrt_process_spawn, _gpgrt_process_terminate) (_gpgrt_process_get_fds, _gpgrt_process_get_streams) (_gpgrt_process_ctl, _gpgrt_process_wait, _gpgrt_process_release) (_gpgrt_process_wait_list, _gpgrt_spawn_helper): New. * src/spawn-w32.c: Ditto. -- GnuPG-bug-id: 6249 Signed-off-by: NIIBE Yutaka <[email protected]>
* spawn: Introduce gpgrt_process_t and use it for spawn API.NIIBE Yutaka2022-11-041-27/+74
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * configure.ac (AC_FUNC_FORK): No use. * src/gpg-error.h.in (@define:gpgrt_process_t@): New. (@define:pid_t@): Remove. (gpgrt_spawn_process, gpgrt_spawn_process_fd): Use gpgrt_process_t. (gpgrt_wait_process, gpgrt_wait_processes): Likewise. (gpgrt_kill_process, gpgrt_release_process): Likewise. * src/gpgrt-int.h (_gpgrt_spawn_process): Likewise. (_gpgrt_spawn_process_fd): Likewise. (_gpgrt_wait_process, _gpgrt_wait_processes): Likewise. (_gpgrt_kill_process, _gpgrt_release_process): Likewise. * src/mkheader.c (write_special): Handle @define:gpgrt_process_t@. Remove handling of @define:pid_t@. * src/spawn-posix.c (_gpgrt_spawn_process): Use gpgrt_process_t. (_gpgrt_spawn_process_fd): Likewise. (_gpgrt_wait_process, _gpgrt_wait_processes): Likewise. (_gpgrt_kill_process, _gpgrt_release_process): Likewise. * src/spawn-w32.c (_gpgrt_spawn_process): Use gpgrt_process_t. (_gpgrt_spawn_process_fd): Likewise. (_gpgrt_wait_process, _gpgrt_wait_processes): Likewise. (_gpgrt_kill_process, _gpgrt_release_process): Likewise. -- GnuPG-bug-id: 6249 Signed-off-by: NIIBE Yutaka <[email protected]>
* spawn: Fix spawn_cb of gpgrt_spawn_process_fd.NIIBE Yutaka2022-10-311-8/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * src/gpg-error.def.in (gpgrt_close_all_fds): New. * src/gpg-error.vers (gpgrt_close_all_fds): New. * src/gpg-error.h.in (GPGRT_SPAWN_INHERIT_FILE): New. (gpgrt_spawn_process_fd): SPAWN_CB having return value. * src/gpgrt-int.h (_gpgrt_spawn_process_fd): SPAWN_CB change. * src/spawn-posix.c (_gpgrt_close_all_fds): Rename from close_all_fds, and export it. (do_exec): Support the case not closing fds. (_gpgrt_spawn_process_fd): Handle return value of SPAWN_CB to determine closing all fds or not. * src/spawn-w32.c (_gpgrt_spawn_process_fd): Run SPAWN_CB. (_gpgrt_close_all_fds): New. * src/visibility.c (gpgrt_close_all_fds): New. * src/visibility.h (gpgrt_close_all_fds): New. -- Now, we have the API of gpgrt_spawn_process_fd for POSIX and Windows. Giving portable semantics for spawning a process is difficult, and it is still difficult for users to writing a function for SPAWN_CB with portability, but gpgrt_spawn_process_fd gives the feature of spawning a process. GnuPG-bug-id: 6249 Signed-off-by: NIIBE Yutaka <[email protected]>
* gpgrt_spawn_process, gpgrt_spawn_process_fd: Change the API.NIIBE Yutaka2022-10-201-13/+12
| | | | | | | | | | | | | | | | | | | | * src/gpg-error.h.in (gpgrt_spawn_process): Remove PREEXEC argument. (gpgrt_spawn_process_fd): Add AFTER_FORK_CB and AFTER_FORK_CB_ARG. * src/gpgrt-int.h (_gpgrt_spawn_process): Remove PREEXEC argument. (_gpgrt_spawn_process_fd): Add AFTER_FORK_CB and AFTER_FORK_CB_ARG. * src/spawn-posix.c (do_exec): Remove PREEXEC argument. (_gpgrt_spawn_process): Remove PREEXEC argument. (_gpgrt_spawn_process_fd): Add AFTER_FORK_CB and AFTER_FORK_CB_ARG. (_gpgrt_spawn_process_detached): Follow the change of do_exec. * src/spawn-w32.c (_gpgrt_spawn_process): Remove PREEXEC argument. (_gpgrt_spawn_process_fd): Add AFTER_FORK_CB and AFTER_FORK_CB_ARG. * src/visibility.c (gpgrt_spawn_process): Remove PREEXEC argument. (gpgrt_spawn_process_fd): Add AFTER_FORK_CB and AFTER_FORK_CB_ARG. -- GnuPG-bug-id: 6249 Signed-off-by: NIIBE Yutaka <[email protected]>
* spawn: Update changes from gnupg.NIIBE Yutaka2022-10-191-5/+14
| | | | | | | | | | | | | | | | | | | * src/gpg-error.h.in (GPGRT_SPAWN_KEEP_STDIN): New. (GPGRT_SPAWN_KEEP_STDOUT, GPGRT_SPAWN_KEEP_STDERR): New. * src/gpgrt-int.h: Add comment. * src/spawn-posix.c (do_exec): Add the argument FLAGS. (_gpgrt_spawn_process): Add FLAGS. (_gpgrt_spawn_process_fd): Follow the change. (_gpgrt_spawn_process_detached): Likewise. * src/spawn-w32.c (_gpgrt_spawn_process): Handle FLAGS. -- This commit imports GnuPG master commit of: 6d6438a361d25f3b269f702e017f5e39fd1f5c38 GnuPG-bug-id: 6249 Signed-off-by: NIIBE Yutaka <[email protected]>
* Remove Windows CE support.NIIBE Yutaka2022-06-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * contrib/*: Remove. * Makefile.am: Remove contrib. * autogen.sh: Remove Windows CE support. * configure.ac (have_w32ce_system): Remove. * src/Makefile.am [HAVE_W32CE_SYSTEM] (extra_cppflags): Remove. (gpg_extra_headers): Remove. (EXTRA_DIST): Remove mkw32errmap.c and w32ce-add.h (BUILT_SOURCES): Remove mkw32errmap.map.c. (tmp_files): Remove mkw32errmap.tab.h mkw32errmap.map.c (CLEANFILES): Likewise. * src/estream-printf.c [HAVE_W32CE_SYSTEM]: Remove. * src/estream.c [HAVE_W32CE_SYSTEM]: Remove. * src/gpg-error.def.in [HAVE_W32CE_SYSTEM]: Remove. * src/gpgrt-int.h: Fix comment. * src/init.c [HAVE_W32CE_SYSTEM]: Remove. * src/init.h [HAVE_W32CE_SYSTEM]: Remove. * src/mkheader.c: Remove Windows CE support. * src/mkw32errmap.c, src/w32ce-add.h: Remove. * src/spawn-posix.c [HAVE_W32CE_SYSTEM]: Remove. * src/spawn-w32.c [HAVE_W32CE_SYSTEM]: Remove. * src/sysutils.c [HAVE_W32CE_SYSTEM]: Remove. * src/w32-estream.c [HAVE_W32CE_SYSTEM]: Remove. * src/w32-reg.c [HAVE_W32CE_SYSTEM]: Remove. * tests/Makefile.am [HAVE_W32CE_SYSTEM]: Remove. -- GnuPG-bug-id: 5912 Signed-off-by: NIIBE Yutaka <[email protected]>
* core: Fix gpgrt_wait_processes, by skipping invalid PID.NIIBE Yutaka2021-04-081-1/+6
| | | | | | | | | | | | | * src/spawn-posix.c (_gpgrt_wait_processes): Skip invalid PID. -- The API itself is not good to handle multiple processes. Given the API, skipping invalid PID is better for usefulness. GnuPG-bug-id: 5381 Reported-by: Jakub Jelen <[email protected]> Signed-off-by: NIIBE Yutaka <[email protected]>
* Portability fix for PID.NIIBE Yutaka2019-06-181-1/+1
| | | | | | | | | | * src/spawn-posix.c (gpgrt_wait_processes): Cast to int. -- On some systems (like Solaris), pid_t is long int. Signed-off-by: NIIBE Yutaka <[email protected]>
* core: New functions gpgrt_abort and gpgrt_add_emergency_cleanup.Werner Koch2019-01-041-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | * src/init.c (emergency_cleanup_list): New gloabl var. (_gpgrt_add_emergency_cleanup): New. (_gpgrt_abort): New. Repalce all calls to abort by this. Also replace all assert by either log_assert or a stderr output followed by a _gpgrt_abort. (run_emergency_cleanup): New. * src/visibility.c (gpgrt_add_emergency_cleanup): New public API. (gpgrt_abort): New public API. -- Libgcrypt uses its own assert function which makes sure to terminate the secure memory. This is safe as log as an assert is triggered internally in Libgcrypt. GnuPG runs emergency cleanup handlers right before log_fatal etc to tell Libgcrypt to terminate the secure memory. With the move of the logging function to gpgrt in gnupg 2.3 this did not anymore. Thus we now provide a mechanism in gpgrt to do right that. Eventually Libgcrypt can also make use of this. What this does not handle are calls to abort or failed asserts in external libraries or in libc. We can't do anything about it in a library because a library may not setup signal handlers. Signed-off-by: Werner Koch <[email protected]>
* core: Wrap blocking system calls of the spawn functions.Werner Koch2017-11-291-1/+20
| | | | Signed-off-by: Werner Koch <[email protected]>
* core: Implement the spawn functions.Werner Koch2017-11-291-206/+187
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * src/gpg-error.h.in (GPGRT_SPAWN_NONBLOCK): New const. (GPGRT_SPAWN_RUN_ASFW): New const. (GPGRT_SPAWN_DETACHED): New const. (gpgrt_make_pipe): New function. (gpgrt_create_pipe): New macro. (gpgrt_create_inbound_pipe): New macro. (gpgrt_create_outbound_pipe): New macro. (gpgrt_spawn_process): New function. (gpgrt_spawn_process_fd): New function. (gpgrt_spawn_process_detached): New function. (gpgrt_wait_process): New function. (gpgrt_wait_processes): New function. (gpgrt_kill_process): New function. (gpgrt_release_process): New function. * src/gpg-error.def.in, src/gpg-error.vers: Add new functions. * src/visibility.c, src/visibility.h: Add wrappers for new functions. * src/spawn-posix.c: Rework to better fit the use in gpgrt. Rename all public function with a _gpgrt prefix. * src/spawn-w32.c: Ditto. * src/gpgrt-int.h: Likewise. * src/Makefile.am (arch_sources): Add spawn-posix.c and spawn-w32.c. * src/w32-add.h: Add pid_t typedef as a temporary hack. * configure.ac: Check for signal.h and getrlimit. (AC_FUNC_FORK): New. -- This does build but porting the tests and further changes are required. Don't assume that the API for the new fucntions is stable. Signed-off-by: Werner Koch <[email protected]>
* Import and relicense exechelp* functions from GnuPG.Werner Koch2017-11-291-0/+887
* src/spawn-posix.c: New. Taken from GnuPG's exechelp-posix.c. * src/spawn-w32.c: New. Taken from GnuPG's exechelp-w32.c. * src/gpgrt-int.h: Include prototypes from GnuPG's exechelp.h. -- The original files were under (LGPL-3.0+ OR GPL-2.0+) and have entirely been written by g10 Code employees. Being the responsible person at g10 Code, I endorse the license change to LGPL-2.1. Signed-off-by: Werner Koch <[email protected]>