diff options
| author | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2026-08-02 14:53:26 +0200 |
|---|---|---|
| committer | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2026-08-02 14:53:26 +0200 |
| commit | 66b6992e1b58179567c6bcfade309fb905890001 (patch) | |
| tree | 74de66c07762d025ce3d2ae6139f6275893afb86 /src/spawn.c | |
| parent | affac915ea52886eea9bc49b43e5173ad6d14147 (diff) | |
teco_parse_shell_command_line() is now public
It can also be useful for spawning $SCITECO_CLIPBOARD_SET/GET processes (currently via popen())
and for launching language servers.
Diffstat (limited to 'src/spawn.c')
| -rw-r--r-- | src/spawn.c | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/src/spawn.c b/src/spawn.c index b1cd305..507d1cd 100644 --- a/src/spawn.c +++ b/src/spawn.c @@ -118,7 +118,7 @@ teco_spawn_init(void) #endif } -static gchar ** +gchar ** teco_parse_shell_command_line(const gchar *cmdline, GError **error) { gchar **argv; @@ -142,7 +142,6 @@ teco_parse_shell_command_line(const gchar *cmdline, GError **error) argv[2] = g_strdup("/c"); argv[3] = g_strdup(cmdline); argv[4] = NULL; - return argv; } #elif defined(G_OS_UNIX) if (!(teco_ed & TECO_ED_SHELLEMU)) { @@ -162,11 +161,33 @@ teco_parse_shell_command_line(const gchar *cmdline, GError **error) argv[1] = g_strdup("-c"); argv[2] = g_strdup(cmdline); argv[3] = NULL; - return argv; } #endif + else if (!g_shell_parse_argv(cmdline, NULL, &argv, error)) + return NULL; + +#if defined(__FreeBSD__) && __FreeBSD__ < 16 + /* + * FIXME: g_spawn_async_with_pipes() will internally call + * posix_spawnp() which uses a tiny 4kb stack which can + * easily result in memory corruption if the path does not + * contain '/', ie. must be resolved against $PATH. + * See also https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=295991 + * As a workaround, only pass down absolute paths. + * This is not perfect: It will use $PATH from the environment, + * so you cannot overwrite it from within SciTECO. + */ + gchar *program = g_find_program_in_path(argv[0]); + if (!program) { + g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, + "Program \"%s\" not found", argv[0]); + return NULL; + } + g_free(argv[0]); + argv[0] = program; +#endif /* __FreeBSD__ < 16 */ - return g_shell_parse_argv(cmdline, NULL, &argv, error) ? argv : NULL; + return argv; } static gboolean @@ -296,27 +317,6 @@ teco_state_execute_done(teco_machine_main_t *ctx, teco_string_t str, GError **er if (!argv) goto gerror; -#if defined(__FreeBSD__) && __FreeBSD__ < 16 - /* - * FIXME: g_spawn_async_with_pipes() will internally call - * posix_spawnp() which uses a tiny 4kb stack which can - * easily result in memory corruption if the path does not - * contain '/', ie. must be resolved against $PATH. - * See also https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=295991 - * As a workaround, only pass down absolute paths. - * This is not perfect: It will use $PATH from the environment, - * so you cannot overwrite it from within SciTECO. - */ - gchar *program = g_find_program_in_path(argv[0]); - if (!program) { - g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, - "Program \"%s\" not found", argv[0]); - goto gerror; - } - g_free(argv[0]); - argv[0] = program; -#endif /* __FreeBSD__ < 16 */ - envp = teco_qreg_table_get_environ(&teco_qreg_table_globals, error); if (!envp) goto gerror; |
