aboutsummaryrefslogtreecommitdiffstats
path: root/src/spawn-w32.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* spawn:w32: Fix a memory leak on an error path.NIIBE Yutaka2024-11-141-4/+4
| | | | | | | | | | * src/spawn-w32.c (spawn_detached): Make sure to release lpAttributeList. (_gpgrt_process_spawn): Likewise. -- 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-2/+208
| | | | | | | | | | | | | | | | | | | | | | | | * 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]>
* w32: Fix releasing memory for UTF-8 text.NIIBE Yutaka2024-10-101-8/+8
| | | | | | | | | * src/spawn-w32.c (spawn_detached): Use _gpgrt_free_wchar. (_gpgrt_process_spawn): Likewise. -- Signed-off-by: NIIBE Yutaka <[email protected]>
* w32:spawn: Remove unused function get_max_fds.NIIBE Yutaka2024-09-161-21/+0
| | | | | | | | * src/spawn-w32.c (get_max_fds): Remove. -- Signed-off-by: NIIBE Yutaka <[email protected]>
* w32: Clarify the environment block encoding.NIIBE Yutaka2024-09-061-0/+3
| | | | | | | | | | | | | | * src/spawn-w32.c (_gpgrt_spawn_actions_set_envvars): It's an ASCII string. -- In future, we can extend it as UTF-8 string. When doing so, we will detect ASCII or utf-8, and if needed, convert it to Unicode wchar string with four-byte-zero terminated, and let the flag have CREATE_UNICODE_ENVIRONMENT. Signed-off-by: NIIBE Yutaka <[email protected]>
* w32: Add GPGRT_PROCESS_ALLOW_SET_FG for gpgrt_process_spawn.NIIBE Yutaka2024-08-271-2/+1
| | | | | | | | | | | | * src/gpg-error.h.in (GPGRT_PROCESS_ALLOW_SET_FG): New. * src/spawn-w32.c (_gpgrt_process_spawn): Support the flag. -- When GPGME will use gpgrt_process_spawn in future, this flag will be needed to support GPGME_SPAWN_ALLOW_SET_FG. Signed-off-by: NIIBE Yutaka <[email protected]>
* spawn: Keep struct definitions at the top of the file.Werner Koch2024-06-191-16/+24
| | | | | * 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-1/+7
| | | | | | | | | | | * 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]>
* spawn: Add new GPGRT_PROCESS_NO_CONSOLE for Windows.NIIBE Yutaka2024-06-061-0/+1
| | | | | | | | | | | | | * src/gpg-error.h.in (GPGRT_PROCESS_NO_CONSOLE): New. * src/spawn-w32.c (_gpgrt_process_spawn): Handle GPGRT_PROCESS_NO_CONSOLE. -- This may be used to support ASSUAN_PIPE_CONNECT_DETACHED in libassuan. 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:w32: Allow for up to 32 inherited handles.Werner Koch2024-06-051-2/+2
| | | | | | | | * src/spawn-w32.c (spawn_detached): Increase array size. (_gpgrt_process_spawn): Ditto. -- The former limit of 16 might be a bit too low for some use cases.
* spawn: Avoid bumping the error counter.Werner Koch2024-06-051-14/+16
| | | | | | | | | | | | | | | * 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:w32: Fix setting of dwFlags for CreateProcess.NIIBE Yutaka2024-06-041-1/+2
| | | | | | | | | * src/spawn-w32.c (_gpgrt_process_spawn): Only set STARTF_USESTDHANDLES with active handles. -- Signed-off-by: NIIBE Yutaka <[email protected]>
* spawn: Allow NULL for ACT.NIIBE Yutaka2024-05-301-0/+9
| | | | | | | | | * 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-4/+4
| | | | | | | | | | | | | * 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-46/+98
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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-513/+657
| | | | | | | | | | | | | | | | | | | | | | | | | | | * 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-44/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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-5/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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-6/+8
| | | | | | | | | | | | | | | | | | | | * 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/+8
| | | | | | | | | | | | | | | | | | | * 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]>
* w32: Fix handle_to_pid for MinGW-w64.NIIBE Yutaka2022-03-291-7/+10
| | | | | | | | | * src/spawn-w32.c (handle_to_pid): Use pid_t to coerce the type. -- GnuPG-bug-id: 4656 Signed-off-by: NIIBE Yutaka <[email protected]>
* New public function gpgrt_access.Werner Koch2020-10-191-2/+4
| | | | | | | | | | | | | | | | | | | | | | * src/gpg-error.h.in (gpgrt_access): New. * src/gpg-error.vers. src/gpg-error.def.in: Add new function. * src/sysutils.c (any8bitchar): New. (_gpgrt_access): New. * src/visibility.c (gpgrt_access): New. * src/spawn-w32.c (_gpgrt_spawn_process_detached): Use it. * src/argparse.c (try_versioned_conffile): Use it. * tests/t-stringutils.c (check_access): New simple test. -- This is basically a wrapper to allow handling of utf8 encoded file names on Windows. This also fixes the case for versioned config files in directories with non-ascii characters. The new test needs to be run manually on Windows using a directory with Unicode characters. GnuPG-bug-id: 5098
* w32: Fix HANDLE to internal fd conversion.NIIBE Yutaka2019-07-241-6/+21
| | | | | | | | | | * src/spawn-w32.c (handle_to_fd): Use intptr_t type. -- See the section of _open_osfhandle in C Run-Time Library Reference. 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]>
* Fix a typo.NIIBE Yutaka2018-11-071-1/+1
| | | | | | * src/spawn-w32.c (src/spawn-w32.c): Fix to use pid_to_handle. Signed-off-by: NIIBE Yutaka <[email protected]>
* core: Wrap blocking system calls of the spawn functions.Werner Koch2017-11-291-9/+24
| | | | Signed-off-by: Werner Koch <[email protected]>
* core: Implement the spawn functions.Werner Koch2017-11-291-219/+183
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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/+925
* 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]>