mirror of
https://github.com/NikitaIvanovV/ctpv.git
synced 2024-11-24 13:53:07 +01:00
Fix: zsh doesn't exit with 141 code
This commit is contained in:
parent
ca85b5c017
commit
2542e530c4
@ -1,4 +1,5 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <signal.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
@ -115,7 +116,7 @@ static void check_init_previews(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int run(Preview *p, int *exitcode)
|
static int run(Preview *p, int *exitcode, int *signal)
|
||||||
{
|
{
|
||||||
int pipe_fds[2];
|
int pipe_fds[2];
|
||||||
ERRCHK_RET(pipe(pipe_fds) == -1, FUNCFAILED("pipe"), ERRNOS);
|
ERRCHK_RET(pipe(pipe_fds) == -1, FUNCFAILED("pipe"), ERRNOS);
|
||||||
@ -124,7 +125,7 @@ static int run(Preview *p, int *exitcode)
|
|||||||
|
|
||||||
char *script = prepend_helpers(p->script, p->script_len);
|
char *script = prepend_helpers(p->script, p->script_len);
|
||||||
char *args[] = SHELL_ARGS(script);
|
char *args[] = SHELL_ARGS(script);
|
||||||
int ret = spawn(args, NULL, exitcode, spawn_redirect, sp_arg);
|
int ret = spawn(args, NULL, exitcode, signal, spawn_redirect, sp_arg);
|
||||||
|
|
||||||
free(script);
|
free(script);
|
||||||
close(pipe_fds[1]);
|
close(pipe_fds[1]);
|
||||||
@ -179,7 +180,7 @@ int preview_run(const char *ext, const char *mimetype, PreviewArgs *pa)
|
|||||||
|
|
||||||
Preview *p;
|
Preview *p;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
int exitcode;
|
int exitcode, signal;
|
||||||
char mimetype_c[MIMETYPE_MAX], *t, *s;
|
char mimetype_c[MIMETYPE_MAX], *t, *s;
|
||||||
|
|
||||||
strncpy(mimetype_c, mimetype, LEN(mimetype_c) - 1);
|
strncpy(mimetype_c, mimetype, LEN(mimetype_c) - 1);
|
||||||
@ -192,7 +193,8 @@ run:
|
|||||||
return ERR;
|
return ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
ERRCHK_RET_OK(run(p, &exitcode));
|
ERRCHK_RET_OK(run(p, &exitcode, &signal));
|
||||||
|
|
||||||
switch (exitcode) {
|
switch (exitcode) {
|
||||||
case FAILED_PREVIEW_EC:
|
case FAILED_PREVIEW_EC:
|
||||||
i++;
|
i++;
|
||||||
@ -202,6 +204,9 @@ run:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (signal == SIGPIPE)
|
||||||
|
exitcode = 0;
|
||||||
|
|
||||||
return exitcode == 0 ? OK : ERR;
|
return exitcode == 0 ? OK : ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ static void kill_ueberzug(void)
|
|||||||
PRINTINTERR(FUNCFAILED("kill"), ERRNOS);
|
PRINTINTERR(FUNCFAILED("kill"), ERRNOS);
|
||||||
}
|
}
|
||||||
|
|
||||||
spawn_wait(ueberzug_pid, NULL);
|
spawn_wait(ueberzug_pid, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sig_handler_exit(int s)
|
static void sig_handler_exit(int s)
|
||||||
@ -67,7 +67,7 @@ static int listen(char *fifo)
|
|||||||
|
|
||||||
char *args[] = { "ueberzug", "layer", NULL };
|
char *args[] = { "ueberzug", "layer", NULL };
|
||||||
int sp_arg[] = { pipe_fds[1], pipe_fds[0], STDIN_FILENO };
|
int sp_arg[] = { pipe_fds[1], pipe_fds[0], STDIN_FILENO };
|
||||||
if (spawn(args, &ueberzug_pid, NULL, spawn_redirect, sp_arg) != OK)
|
if (spawn(args, &ueberzug_pid, NULL, NULL, spawn_redirect, sp_arg) != OK)
|
||||||
ret = ERR;
|
ret = ERR;
|
||||||
|
|
||||||
close(pipe_fds[0]);
|
close(pipe_fds[0]);
|
||||||
@ -126,7 +126,7 @@ exit:
|
|||||||
static int check_ueberzug(int *exitcode)
|
static int check_ueberzug(int *exitcode)
|
||||||
{
|
{
|
||||||
char *args[] = SHELL_ARGS("command -v ueberzug > /dev/null");
|
char *args[] = SHELL_ARGS("command -v ueberzug > /dev/null");
|
||||||
return spawn(args, NULL, exitcode, NULL, NULL);
|
return spawn(args, NULL, exitcode, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void get_fifo_name(char *buf, size_t len, const char *id_s)
|
static void get_fifo_name(char *buf, size_t len, const char *id_s)
|
||||||
@ -176,7 +176,7 @@ static int run_script(char *script, size_t script_len, char *arg)
|
|||||||
char *s = prepend_helpers(script, script_len);
|
char *s = prepend_helpers(script, script_len);
|
||||||
char *args[] = SHELL_ARGS(s, arg);
|
char *args[] = SHELL_ARGS(s, arg);
|
||||||
int exitcode;
|
int exitcode;
|
||||||
ERRCHK_GOTO_OK(spawn(args, NULL, &exitcode, NULL, NULL), ret, cleanup);
|
ERRCHK_GOTO_OK(spawn(args, NULL, &exitcode, NULL, NULL, NULL), ret, cleanup);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
free(s);
|
free(s);
|
||||||
|
23
src/utils.c
23
src/utils.c
@ -20,13 +20,24 @@ int spawn_redirect(const void *arg)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int spawn_wait(pid_t pid, int *exitcode)
|
int spawn_wait(pid_t pid, int *exitcode, int *signal)
|
||||||
{
|
{
|
||||||
int stat;
|
int stat;
|
||||||
ERRCHK_RET(waitpid(pid, &stat, 0) == -1, FUNCFAILED("waitpid"), ERRNOS);
|
ERRCHK_RET(waitpid(pid, &stat, 0) == -1, FUNCFAILED("waitpid"), ERRNOS);
|
||||||
|
|
||||||
if (exitcode && WIFEXITED(stat))
|
if (exitcode)
|
||||||
*exitcode = WEXITSTATUS(stat);
|
*exitcode = -1;
|
||||||
|
|
||||||
|
if (signal)
|
||||||
|
*signal = -1;
|
||||||
|
|
||||||
|
if (WIFEXITED(stat)) {
|
||||||
|
if (exitcode)
|
||||||
|
*exitcode = WEXITSTATUS(stat);
|
||||||
|
} else if (WIFSIGNALED(stat)) {
|
||||||
|
if (signal)
|
||||||
|
*signal = WTERMSIG(stat);
|
||||||
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
@ -39,7 +50,7 @@ int spawn_wait(pid_t pid, int *exitcode)
|
|||||||
*
|
*
|
||||||
* cfunc is a function to call when child process is created
|
* cfunc is a function to call when child process is created
|
||||||
*/
|
*/
|
||||||
int spawn(char *args[], pid_t *cpid, int *exitcode, int (*cfunc)(const void *),
|
int spawn(char *args[], pid_t *cpid, int *exitcode, int *signal, int (*cfunc)(const void *),
|
||||||
const void *carg)
|
const void *carg)
|
||||||
{
|
{
|
||||||
if (exitcode)
|
if (exitcode)
|
||||||
@ -64,8 +75,8 @@ int spawn(char *args[], pid_t *cpid, int *exitcode, int (*cfunc)(const void *),
|
|||||||
if (cpid)
|
if (cpid)
|
||||||
*cpid = pid;
|
*cpid = pid;
|
||||||
|
|
||||||
if (exitcode)
|
if (exitcode || signal)
|
||||||
ERRCHK_RET_OK(spawn_wait(pid, exitcode));
|
ERRCHK_RET_OK(spawn_wait(pid, exitcode, signal));
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,9 @@
|
|||||||
extern char *program;
|
extern char *program;
|
||||||
|
|
||||||
int spawn_redirect(const void *arg);
|
int spawn_redirect(const void *arg);
|
||||||
int spawn_wait(pid_t pid, int *exitcode);
|
int spawn_wait(pid_t pid, int *exitcode, int *signal);
|
||||||
int spawn(char *args[], pid_t *cpid, int *exitcode, int (*cfunc)(const void *),
|
int spawn(char *args[], pid_t *cpid, int *exitcode, int *signal,
|
||||||
const void *carg);
|
int (*cfunc)(const void *), const void *carg);
|
||||||
|
|
||||||
int strcmpnull(const char *s1, const char *s2);
|
int strcmpnull(const char *s1, const char *s2);
|
||||||
int strlennull(const char *s);
|
int strlennull(const char *s);
|
||||||
|
Loading…
Reference in New Issue
Block a user