Skip to content

Commit 7ff8983

Browse files
sandreimalindima
authored andcommitted
Rework the SIGPIPE handler
With this change the VMM will no longer exit() on this signal, but the metrics and logs will record the event. Signed-off-by: Andrei Sandu <[email protected]>
1 parent 8fd0165 commit 7ff8983

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/vmm/src/signal_handler.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,6 @@ generate_handler!(
105105
empty_fn
106106
);
107107

108-
generate_handler!(
109-
sigpipe_handler,
110-
SIGPIPE,
111-
FC_EXIT_CODE_SIGPIPE,
112-
METRICS.signals.sigpipe,
113-
empty_fn
114-
);
115-
116108
generate_handler!(
117109
sigsys_handler,
118110
SIGSYS,
@@ -128,13 +120,34 @@ generate_handler!(
128120
METRICS.signals.sighup,
129121
empty_fn
130122
);
123+
131124
generate_handler!(
132125
sigill_handler,
133126
SIGILL,
134127
FC_EXIT_CODE_SIGILL,
135128
METRICS.signals.sigill,
136129
empty_fn
137130
);
131+
132+
#[inline(always)]
133+
extern "C" fn sigpipe_handler(num: c_int, info: *mut siginfo_t, _unused: *mut c_void) {
134+
// Just record the metric and allow the process to continue, the EPIPE error needs
135+
// to be handled at caller level.
136+
137+
// Safe because we're just reading some fields from a supposedly valid argument.
138+
let si_signo = unsafe { (*info).si_signo };
139+
let si_code = unsafe { (*info).si_code };
140+
141+
if num != si_signo || num != SIGPIPE {
142+
error!("Received invalid signal {}, code {}.", si_signo, si_code);
143+
return;
144+
}
145+
146+
METRICS.signals.sigpipe.inc();
147+
148+
error!("Received signal {}, code {}.", si_signo, si_code);
149+
}
150+
138151
/// Registers all the required signal handlers.
139152
///
140153
/// Custom handlers are installed for: `SIGBUS`, `SIGSEGV`, `SIGSYS`

0 commit comments

Comments
 (0)