mirror of
https://github.com/systemd/systemd
synced 2024-09-06 16:56:43 +00:00
journal-remote: Use sd_event_set_signal_exit()
This also fixes bugs in the previous code where we pass the server object as userdata to sd_event_add_signal which means that sd-event tries to use the value of the server pointer as its exit code when a signal is triggered.
This commit is contained in:
parent
fc4a9c9ce6
commit
dcd332ae00
|
@ -535,24 +535,6 @@ static int dispatch_http_event(sd_event_source *event,
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
|
|
||||||
static int setup_signals(RemoteServer *s) {
|
|
||||||
int r;
|
|
||||||
|
|
||||||
assert(s);
|
|
||||||
|
|
||||||
assert_se(sigprocmask_many(SIG_SETMASK, NULL, SIGINT, SIGTERM) >= 0);
|
|
||||||
|
|
||||||
r = sd_event_add_signal(s->events, &s->sigterm_event, SIGTERM, NULL, s);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
r = sd_event_add_signal(s->events, &s->sigint_event, SIGINT, NULL, s);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int setup_raw_socket(RemoteServer *s, const char *address) {
|
static int setup_raw_socket(RemoteServer *s, const char *address) {
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
@ -580,9 +562,9 @@ static int create_remoteserver(
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
r = setup_signals(s);
|
r = sd_event_set_signal_exit(s->events, true);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "Failed to set up signals: %m");
|
return log_error_errno(r, "Failed to install SIGINT/SIGTERM handlers: %m");
|
||||||
|
|
||||||
n = sd_listen_fds(true);
|
n = sd_listen_fds(true);
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
|
|
|
@ -375,8 +375,6 @@ void journal_remote_server_destroy(RemoteServer *s) {
|
||||||
writer_unref(s->_single_writer);
|
writer_unref(s->_single_writer);
|
||||||
hashmap_free(s->writers);
|
hashmap_free(s->writers);
|
||||||
|
|
||||||
sd_event_source_unref(s->sigterm_event);
|
|
||||||
sd_event_source_unref(s->sigint_event);
|
|
||||||
sd_event_source_unref(s->listen_event);
|
sd_event_source_unref(s->listen_event);
|
||||||
sd_event_unref(s->events);
|
sd_event_unref(s->events);
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ struct RemoteServer {
|
||||||
size_t active;
|
size_t active;
|
||||||
|
|
||||||
sd_event *events;
|
sd_event *events;
|
||||||
sd_event_source *sigterm_event, *sigint_event, *listen_event;
|
sd_event_source *listen_event;
|
||||||
|
|
||||||
Hashmap *writers;
|
Hashmap *writers;
|
||||||
Writer *_single_writer;
|
Writer *_single_writer;
|
||||||
|
|
|
@ -378,38 +378,6 @@ static int open_file_for_upload(Uploader *u, const char *filename) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dispatch_sigterm(sd_event_source *event,
|
|
||||||
const struct signalfd_siginfo *si,
|
|
||||||
void *userdata) {
|
|
||||||
Uploader *u = ASSERT_PTR(userdata);
|
|
||||||
|
|
||||||
log_received_signal(LOG_INFO, si);
|
|
||||||
|
|
||||||
close_fd_input(u);
|
|
||||||
close_journal_input(u);
|
|
||||||
|
|
||||||
sd_event_exit(u->events, 0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int setup_signals(Uploader *u) {
|
|
||||||
int r;
|
|
||||||
|
|
||||||
assert(u);
|
|
||||||
|
|
||||||
assert_se(sigprocmask_many(SIG_SETMASK, NULL, SIGINT, SIGTERM) >= 0);
|
|
||||||
|
|
||||||
r = sd_event_add_signal(u->events, &u->sigterm_event, SIGTERM, dispatch_sigterm, u);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
r = sd_event_add_signal(u->events, &u->sigint_event, SIGINT, dispatch_sigterm, u);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int setup_uploader(Uploader *u, const char *url, const char *state_file) {
|
static int setup_uploader(Uploader *u, const char *url, const char *state_file) {
|
||||||
int r;
|
int r;
|
||||||
const char *host, *proto = "";
|
const char *host, *proto = "";
|
||||||
|
@ -449,9 +417,9 @@ static int setup_uploader(Uploader *u, const char *url, const char *state_file)
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "sd_event_default failed: %m");
|
return log_error_errno(r, "sd_event_default failed: %m");
|
||||||
|
|
||||||
r = setup_signals(u);
|
r = sd_event_set_signal_exit(u->events, true);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "Failed to set up signals: %m");
|
return log_error_errno(r, "Failed to install SIGINT/SIGTERM handlers: %m");
|
||||||
|
|
||||||
(void) sd_watchdog_enabled(false, &u->watchdog_usec);
|
(void) sd_watchdog_enabled(false, &u->watchdog_usec);
|
||||||
|
|
||||||
|
@ -475,8 +443,6 @@ static void destroy_uploader(Uploader *u) {
|
||||||
close_fd_input(u);
|
close_fd_input(u);
|
||||||
close_journal_input(u);
|
close_journal_input(u);
|
||||||
|
|
||||||
sd_event_source_unref(u->sigterm_event);
|
|
||||||
sd_event_source_unref(u->sigint_event);
|
|
||||||
sd_event_unref(u->events);
|
sd_event_unref(u->events);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ typedef enum {
|
||||||
|
|
||||||
typedef struct Uploader {
|
typedef struct Uploader {
|
||||||
sd_event *events;
|
sd_event *events;
|
||||||
sd_event_source *sigint_event, *sigterm_event;
|
|
||||||
|
|
||||||
char *url;
|
char *url;
|
||||||
CURL *easy;
|
CURL *easy;
|
||||||
|
|
Loading…
Reference in a new issue