diff options
| -rw-r--r-- | src/interface-curses/interface.c | 39 | ||||
| -rw-r--r-- | src/spawn.c | 11 | ||||
| -rw-r--r-- | src/spawn.h | 13 |
3 files changed, 30 insertions, 33 deletions
diff --git a/src/interface-curses/interface.c b/src/interface-curses/interface.c index fbac2cb..b304e12 100644 --- a/src/interface-curses/interface.c +++ b/src/interface-curses/interface.c @@ -43,10 +43,6 @@ #include <glib/gprintf.h> #include <glib/gstdio.h> -#ifdef G_OS_UNIX -#include <sys/wait.h> -#endif - #include <curses.h> #ifdef HAVE_TIGETSTR @@ -70,6 +66,7 @@ #include "error.h" #include "view.h" #include "memory.h" +#include "spawn.h" #include "interface.h" #include "curses-utils.h" #include "curses-info-popup.h" @@ -1544,25 +1541,24 @@ teco_interface_set_clipboard(const gchar *name, const gchar *str, gsize str_len, *sel = get_selection_by_name(name); } + errno = ENOMEM; FILE *pipe = popen(command.data, "w"); if (!pipe) { g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, - "Cannot spawn process from %s", reg_name); + "Cannot spawn process from %s: %s", reg_name, g_strerror(errno)); return FALSE; } size_t len = fwrite(str, 1, str_len, pipe); - int status = pclose(pipe); - if (status < 0 || !WIFEXITED(status)) { + gint status = pclose(pipe); + if (status < 0) { g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, - "Error reaping process from %s", reg_name); + "Error running process from %s: %s", reg_name, g_strerror(errno)); return FALSE; } - if (WEXITSTATUS(status) != 0) { - g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, - "Process from %s returned with exit code %d", - reg_name, WEXITSTATUS(status)); + if (!teco_spawn_check_wait_status(status, error)) { + g_prefix_error(error, "Error running process from %s: ", reg_name); return FALSE; } @@ -1600,10 +1596,11 @@ teco_interface_get_clipboard(const gchar *name, gchar **str, gsize *len, GError *sel = get_selection_by_name(name); } + errno = ENOMEM; FILE *pipe = popen(command.data, "r"); if (!pipe) { g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, - "Cannot spawn process from %s", reg_name); + "Cannot spawn process from %s: %s", reg_name, g_strerror(errno)); return FALSE; } @@ -1617,20 +1614,18 @@ teco_interface_get_clipboard(const gchar *name, gchar **str, gsize *len, GError teco_string_append(&ret, buffer, read_len); } while (read_len == sizeof(buffer)); - int status = pclose(pipe); - if (status < 0 || !WIFEXITED(status)) { + gint status = pclose(pipe); + if (status < 0) { g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, - "Error reaping process from %s", reg_name); + "Error running process from %s: %s", reg_name, g_strerror(errno)); return FALSE; } /* * You may have to add a `|| true` for instance to xclip if it * could fail for empty selections. */ - if (WEXITSTATUS(status) != 0) { - g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, - "Process from %s returned with exit code %d", - reg_name, WEXITSTATUS(status)); + if (!teco_spawn_check_wait_status(status, error)) { + g_prefix_error(error, "Error running process from %s: ", reg_name); return FALSE; } @@ -1962,7 +1957,7 @@ teco_interface_process_mevent(MEVENT *event, GError **error) * Furthermore due to ncurses bugs the order * of events is arbitrary. * Therefore we ignore BUTTON2_PRESSED and synthesize - * PRESSED and RELEASED evnts on BUTTON2_RELEASED: + * PRESSED and RELEASED events on BUTTON2_RELEASED: */ if (teco_mouse.button == 2) { if (teco_mouse.type == TECO_MOUSE_PRESSED) @@ -2023,7 +2018,7 @@ teco_interface_blocking_getch(void) * If we would reset the mouse mask with every wgetch(), which resets * the internal button state, we would receive bogus BUTTON3_PRESSED events * repeatedly. - * An upstream ncurses patch will probably be merged soon. + * An upstream ncurses patch has been merged since NCURSES_VERSION_PATCH >= 20250913. */ static gboolean old_mousekey = FALSE; gboolean new_mousekey = (teco_ed & TECO_ED_MOUSEKEY) != 0; diff --git a/src/spawn.c b/src/spawn.c index 644bf31..a4bf381 100644 --- a/src/spawn.c +++ b/src/spawn.c @@ -49,17 +49,6 @@ #include "error.h" #include "spawn.h" -/* - * Glib v2.70 deprecates g_spawn_check_exit_status(), - * renaming it to g_spawn_check_wait_status(). - * This leaves no way to work on both new and old versions without warnings. - */ -#if GLIB_CHECK_VERSION(2,70,0) -#define teco_spawn_check_wait_status g_spawn_check_wait_status -#else -#define teco_spawn_check_wait_status g_spawn_check_exit_status -#endif - static void teco_spawn_child_watch_cb(GPid pid, gint status, gpointer data); static gboolean teco_spawn_stdin_watch_cb(GIOChannel *chan, GIOCondition condition, gpointer data); diff --git a/src/spawn.h b/src/spawn.h index 5d2a5a4..bac27ca 100644 --- a/src/spawn.h +++ b/src/spawn.h @@ -16,8 +16,21 @@ */ #pragma once +#include <glib.h> + #include "parser.h" +/* + * Glib v2.70 deprecates g_spawn_check_exit_status(), + * renaming it to g_spawn_check_wait_status(). + * This leaves no way to work on both new and old versions without warnings. + */ +#if GLIB_CHECK_VERSION(2,70,0) +#define teco_spawn_check_wait_status g_spawn_check_wait_status +#else +#define teco_spawn_check_wait_status g_spawn_check_exit_status +#endif + gchar **teco_parse_shell_command_line(const gchar *cmdline, GError **error); extern teco_state_t teco_state_execute; |
