From 897448bd3753eab2c7b411221cfc33b283ae67a5 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 28 Sep 2022 11:39:25 +0200 Subject: sd-event: if signal nr has high bit set sd_event_add_signal() auto-block it via sigprocmask() So far we expected callers to block the signals manually. Which is usually a good idea, since they should do that before forking off threads and similar. But let's add a mode where we automatically block it for the caller, to simplify things. --- man/rules/meson.build | 4 +++- man/sd_event_add_signal.xml | 41 ++++++++++++++++++++++------------------- 2 files changed, 25 insertions(+), 20 deletions(-) (limited to 'man') diff --git a/man/rules/meson.build b/man/rules/meson.build index 2925dadc1e..7f4a42b139 100644 --- a/man/rules/meson.build +++ b/man/rules/meson.build @@ -555,7 +555,9 @@ manpages = [ ''], ['sd_event_add_signal', '3', - ['sd_event_signal_handler_t', 'sd_event_source_get_signal'], + ['SD_EVENT_SIGNAL_PROCMASK', + 'sd_event_signal_handler_t', + 'sd_event_source_get_signal'], ''], ['sd_event_add_time', '3', diff --git a/man/sd_event_add_signal.xml b/man/sd_event_add_signal.xml index b2aaff87c1..3e8536e961 100644 --- a/man/sd_event_add_signal.xml +++ b/man/sd_event_add_signal.xml @@ -19,6 +19,7 @@ sd_event_add_signal sd_event_source_get_signal sd_event_signal_handler_t + SD_EVENT_SIGNAL_PROCMASK Add a UNIX process signal event source to an event loop @@ -30,6 +31,8 @@ typedef struct sd_event_source sd_event_source; + SD_EVENT_SIGNAL_PROCMASK + typedef int (*sd_event_signal_handler_t) sd_event_source *s @@ -50,30 +53,26 @@ int sd_event_source_get_signal sd_event_source *source - Description - sd_event_add_signal() adds a new UNIX - process signal event source to an event loop. The event loop - object is specified in the event parameter, - and the event source object is returned in the - source parameter. The - signal parameter specifies the numeric - signal to be handled (see sd_event_add_signal() adds a new UNIX process signal event source to an event + loop. The event loop object is specified in the event parameter, and the event + source object is returned in the source parameter. The + signal parameter specifies the numeric signal to be handled (see signal7). The handler parameter is a function to call when the signal is received or NULL. The handler function will be passed the userdata pointer, which may be chosen freely by the caller. The handler also receives a pointer to a signalfd_siginfo structure containing information about the received signal. See - signalfd2 - for further information. The handler may return negative to signal an error (see below), other return - values are ignored. If handler is NULL, a default handler - that calls + signalfd2 for + further information. The handler may return negative to signal an error (see below), other return values + are ignored. If handler is NULL, a default handler that calls sd_event_exit3 will be used. @@ -81,14 +80,18 @@ threads before this function is called (using sigprocmask2 or pthread_sigmask3). - - By default, the event source is enabled permanently - (SD_EVENT_ON), but this may be changed with + project='man-pages'>pthread_sigmask3). For + convenience, if the special flag SD_EVENT_SIGNAL_PROCMASK is ORed into the specified + signal the signal will be automatically masked as necessary, for the calling thread. Note that this only + works reliably if the signal is already masked in all other threads of the process, or if there are no + other threads at the moment of invocation. + + By default, the event source is enabled permanently (SD_EVENT_ON), but this + may be changed with sd_event_source_set_enabled3. - If the handler function returns a negative error code, it will either be disabled after the - invocation, even if the SD_EVENT_ON mode was requested before, or it will cause the - loop to terminate, see + If the handler function returns a negative error code, it will either be disabled after the invocation, + even if the SD_EVENT_ON mode was requested before, or it will cause the loop to + terminate, see sd_event_source_set_exit_on_failure3. -- cgit v1.2.1 From baf3fdec27f0b3a1f3d39c7def2a778824cbee51 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 28 Sep 2022 11:42:05 +0200 Subject: sd-event: add helper for exiting event loop on SIGTERM/SIGINT In many (most?) of our event loops we want to exit once SIGTERM/SIGINT is seen. Add a common helper for that, that does the right things in a single call. --- man/rules/meson.build | 1 + man/sd_event_set_signal_exit.xml | 101 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 man/sd_event_set_signal_exit.xml (limited to 'man') diff --git a/man/rules/meson.build b/man/rules/meson.build index 7f4a42b139..4a497d59c4 100644 --- a/man/rules/meson.build +++ b/man/rules/meson.build @@ -583,6 +583,7 @@ manpages = [ ''], ['sd_event_now', '3', [], ''], ['sd_event_run', '3', ['sd_event_loop'], ''], + ['sd_event_set_signal_exit', '3', [], ''], ['sd_event_set_watchdog', '3', ['sd_event_get_watchdog'], ''], ['sd_event_source_get_event', '3', [], ''], ['sd_event_source_get_pending', '3', [], ''], diff --git a/man/sd_event_set_signal_exit.xml b/man/sd_event_set_signal_exit.xml new file mode 100644 index 0000000000..e5e675beec --- /dev/null +++ b/man/sd_event_set_signal_exit.xml @@ -0,0 +1,101 @@ + + + + + + + + sd_event_set_signal_exit + systemd + + + + sd_event_set_signal_exit + 3 + + + + sd_event_set_signal_exit + + Automatically leave event loop on SIGINT and SIGTERM + + + + + #include <systemd/sd-event.h> + + + int sd_event_set_signal_exit + sd_event *event + int b + + + + + + + Description + + sd_event_set_signal_exit() may be used to ensure the event loop terminates + once a SIGINT or SIGTERM signal is received. It is a + convencience wrapper around invocations of + sd_event_add_signal3 + for both signals. The two signals are automatically added to the calling thread's signal mask (if a + program is multi-threaded care should be taken to either invoke this function before the first thread is + started or to manually block the two signals process-wide first). + + If the parameter b is specified as true, the event loop will terminate on + SIGINT and SIGTERM. If specified as false, it will no + longer. When this functionality is turned off the calling thread's signal mask is restored to match the + state before it was turned on, for the two signals. By default the two signals are not handled by the + event loop, and Linux' default signal handling for them is in effect. + + It's customary for UNIX programs to exit on either of these two signals, hence it's typically a + good idea to enable this functionality for the main event loop of a program. + + + + Return Value + + sd_event_set_signal_exit() returns a positive non-zero value when the setting + was successfully changed. It returns a zero when the specified setting was already in effect. On failure, + it returns a negative errno-style error code. + + + Errors + + Returned errors may indicate the following problems: + + + + + -ECHILD + + The event loop has been created in a different process. + + + + -EINVAL + + The passed event loop object was invalid. + + + + + + + + + + See Also + + + systemd1, + sd-event3, + sd_event_new3, + sd_event_add_signal3 + + + + -- cgit v1.2.1 From b25d819aee10b79a1c972d25be81a238448134dd Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 27 Sep 2022 14:29:18 +0200 Subject: resolved: don't make monitoring optional The socket is only accessible to privileged clients anyway, no need to add another (user unfriendly) restriction via opt-in setting. let's just allow this for privileged clients, mirroring "busctl monitor", or "tcpdump" and similar, which all just work if you have privs. (This does not break API, since we never did a release witht the "Monitor" dbus property or config setting in place, i.e. with cb456374e096f0ebe9b70d7ddd98e16a4be24ee6) --- man/org.freedesktop.resolve1.xml | 5 ----- 1 file changed, 5 deletions(-) (limited to 'man') diff --git a/man/org.freedesktop.resolve1.xml b/man/org.freedesktop.resolve1.xml index d3aedbc13e..54f0a18418 100644 --- a/man/org.freedesktop.resolve1.xml +++ b/man/org.freedesktop.resolve1.xml @@ -149,7 +149,6 @@ node /org/freedesktop/resolve1 { readonly s DNSStubListener = '...'; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly s ResolvConfMode = '...'; - readonly b Monitor = ...; }; interface org.freedesktop.DBus.Peer { ... }; interface org.freedesktop.DBus.Introspectable { ... }; @@ -251,8 +250,6 @@ node /org/freedesktop/resolve1 { - - @@ -637,8 +634,6 @@ node /org/freedesktop/resolve1 { enabled. Possible values are yes (enabled), no (disabled), udp (only the UDP listener is enabled), and tcp (only the TCP listener is enabled). - - The Monitor boolean property reports whether DNS monitoring is enabled. -- cgit v1.2.1 From fffbf1dc996691298fd5e53f15c98e7d7257235a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 28 Sep 2022 12:46:21 +0200 Subject: resolvectl: add new "monitor" verb --- man/resolvectl.xml | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'man') diff --git a/man/resolvectl.xml b/man/resolvectl.xml index 19fb0780b5..a9cdfe9187 100644 --- a/man/resolvectl.xml +++ b/man/resolvectl.xml @@ -199,6 +199,19 @@ automatically, an explicit reverting is not necessary in that case. + + monitor + + Show a continous stream of local client resolution queries and their + responses. Whenever a local query is completed the query's DNS resource lookup key and resource + records are shown. Note that this displays queries issued locally only, and does not immediately + relate to DNS requests submitted to configured DNS servers or the LLMNR or MulticastDNS zones, as + lookups may be answered from the local cache, or might result in multiple DNS transactions (for + example to validate DNSSEC information). If CNAME/CNAME redirection chains are followed, a separate + query will be displayed for each element of the chain. Use to enable JSON + output. + + @@ -379,9 +392,17 @@ query response are shown. Otherwise, this output is suppressed. + + + + + + Short for + + + - -- cgit v1.2.1