Fixed unwanted recvfrom() with signal handler logs

This commit is contained in:
Gerhard Rieger 2023-05-08 22:33:12 +02:00
parent 77ef274f76
commit eeeebe6cb2
4 changed files with 16 additions and 9 deletions

View file

@ -56,6 +56,9 @@ Corrections:
Procan tries to find out VSOCK CID only when running as root
The mechanism for deferring logs from signal handlers had an issue that
caused lots of unwanted recvfrom() calls.
Features:
VSOCK, VSOCK-L support options pf, socktype, prototype (currently
useless)

15
error.c
View file

@ -58,9 +58,9 @@ static void msg2(
int level, int exitcode, int handler, const char *text);
static void _msg(int level, const char *buff, const char *syslp);
sig_atomic_t diag_in_handler; /* !=0 indicates to msg() that in signal handler */
sig_atomic_t diag_immediate_msg; /* !=0 prints messages even from within signal handler instead of deferring them */
sig_atomic_t diag_immediate_exit; /* !=0 calls exit() from diag_exit() even when in signal handler. For system() */
volatile sig_atomic_t diag_in_handler; /* !=0 indicates to msg() that in signal handler */
volatile sig_atomic_t diag_immediate_msg; /* !=0 prints messages even from within signal handler instead of deferring them */
volatile sig_atomic_t diag_immediate_exit; /* !=0 calls exit() from diag_exit() even when in signal handler. For system() */
static struct wordent facilitynames[] = {
{"auth", (void *)LOG_AUTH},
@ -108,7 +108,7 @@ struct sermsg {
static int diaginitialized;
static int diag_sock_send = -1;
static int diag_sock_recv = -1;
static int diag_msg_avail = 0; /* !=0: messages from within signal handler may be waiting */
static volatile sig_atomic_t diag_msg_avail = 0; /* !=0: messages from within signal handler may be waiting */
static int diag_sock_pair(void) {
@ -278,7 +278,6 @@ void msg(int level, const char *format, ...) {
/* in normal program flow (not in signal handler) */
/* first flush the queue of datagrams from the socket */
if (diag_msg_avail && !diag_in_handler) {
diag_msg_avail = 0; /* _before_ flush to prevent inconsistent state when signal occurs inbetween */
diag_flush();
}
@ -418,6 +417,11 @@ void diag_flush(void) {
struct diag_dgram recv_dgram;
char exitmsg[20];
if (diag_msg_avail == 0) {
return;
}
diag_msg_avail = 0;
if (!diagopts.signalsafe) {
return;
}
@ -500,6 +504,7 @@ void diag_exit(int status) {
|MSG_NOSIGNAL
#endif
);
diag_msg_avail = 1;
return;
}
_diag_exit(status);

View file

@ -228,9 +228,9 @@ struct diag_dgram {
char text[TEXTLEN];
} ;
extern sig_atomic_t diag_in_handler;
extern sig_atomic_t diag_immediate_msg;
extern sig_atomic_t diag_immediate_exit;
extern volatile sig_atomic_t diag_in_handler;
extern volatile sig_atomic_t diag_immediate_msg;
extern volatile sig_atomic_t diag_immediate_exit;
extern void diag_set(char what, const char *arg);
extern void diag_set_int(char what, int arg);

View file

@ -85,7 +85,6 @@ const char copyright_ssleay[] = "This product includes software written by Tim H
bool havelock;
int main(int argc, const char *argv[]) {
const char **arg1, *a;
char *mainwaitstring;