NeoMutt
2025-12-11-1039-g550ac6
Teaching an old dog new tricks
DOXYGEN
Toggle main menu visibility
Loading...
Searching...
No Matches
system.c
Go to the documentation of this file.
1
23
29
30
#include "config.h"
31
#include <signal.h>
32
#include <stdbool.h>
33
#include <stdlib.h>
34
#include <sys/types.h>
35
#include <sys/wait.h>
// IWYU pragma: keep
36
#include <unistd.h>
37
#include "
mutt/lib.h
"
38
#include "
core/lib.h
"
39
#include "
imap/lib.h
"
40
51
int
mutt_system
(
const
char
*cmd)
52
{
53
int
rc = -1;
54
struct
sigaction act = { 0 };
55
struct
sigaction oldtstp = { 0 };
56
struct
sigaction oldcont = { 0 };
57
pid_t pid;
58
59
if
(!cmd || (*cmd ==
'\0'
))
60
return
0;
61
62
/* must ignore SIGINT and SIGQUIT */
63
64
mutt_sig_block_system
();
65
66
act.sa_handler = SIG_DFL;
67
/* we want to restart the waitpid() below */
68
#ifdef SA_RESTART
69
act.sa_flags = SA_RESTART;
70
#endif
71
sigemptyset(&act.sa_mask);
72
sigaction(SIGTSTP, &act, &oldtstp);
73
sigaction(SIGCONT, &act, &oldcont);
74
75
pid = fork();
76
if
(pid == 0)
77
{
78
act.sa_flags = 0;
79
80
mutt_sig_unblock_system
(
false
);
81
mutt_sig_reset_child_signals
();
82
83
execle(
EXEC_SHELL
,
"sh"
,
"-c"
, cmd, NULL,
NeoMutt
->
env
);
84
_exit(127);
/* execl error */
85
}
86
else
if
(pid != -1)
87
{
88
rc =
imap_wait_keep_alive
(pid);
89
}
90
91
sigaction(SIGCONT, &oldcont, NULL);
92
sigaction(SIGTSTP, &oldtstp, NULL);
93
94
/* reset SIGINT, SIGQUIT and SIGCHLD */
95
mutt_sig_unblock_system
(
true
);
96
97
rc = (pid != -1) ? (WIFEXITED(rc) ? WEXITSTATUS(rc) : -1) : -1;
98
99
return
rc;
100
}
lib.h
Convenience wrapper for the core headers.
lib.h
IMAP network mailbox.
imap_wait_keep_alive
int imap_wait_keep_alive(pid_t pid)
Wait for a process to change state.
Definition
util.c:1033
EXEC_SHELL
#define EXEC_SHELL
Default shell to use for executing commands.
Definition
filter.h:30
lib.h
Convenience wrapper for the library headers.
mutt_sig_reset_child_signals
void mutt_sig_reset_child_signals(void)
Reset ignored signals back to the default.
Definition
signal.c:336
mutt_sig_block_system
void mutt_sig_block_system(void)
Block signals before calling exec().
Definition
signal.c:260
mutt_sig_unblock_system
void mutt_sig_unblock_system(bool restore)
Restore previously blocked signals.
Definition
signal.c:284
NeoMutt
Container for Accounts, Notifications.
Definition
neomutt.h:41
NeoMutt::env
char ** env
Private copy of the environment variables.
Definition
neomutt.h:57
mutt_system
int mutt_system(const char *cmd)
Run an external command.
Definition
system.c:51