]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-event: allow sd_event_source_is_enabled() to return false for NULL
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 14 Jun 2022 12:37:21 +0000 (14:37 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 30 Jun 2022 08:35:27 +0000 (10:35 +0200)
This is a natural use case, and instead of defining a wrapper to do this
for us, let's just make this part of the API. Calling with NULL was not
allowed, so this is not a breaking change to the interface.

(After sd_event_source_is_enabled was originally added, we introduced
sd_event_source_disable_unref() and other similar functions which accept
NULL. So not accepting NULL here is likely to confuse people. Let's just
make the API usable with minimal fuss.)

man/sd_event_source_set_enabled.xml
src/journal/managed-journal-file.c
src/libsystemd/sd-event/event-util.c
src/libsystemd/sd-event/event-util.h
src/libsystemd/sd-event/sd-event.c
src/network/netdev/wireguard.c

index c8ae169c177e0d023aa5364953d86cedd4cee797..d6cdf85eda910cf990153bfedf4ed43f44bd7701 100644 (file)
     loop wakeups and will not be dispatched, until they are enabled
     again.</para>
 
-    <para><function>sd_event_source_get_enabled()</function> may be
-    used to query whether the event source object
-    <parameter>source</parameter> is currently enabled or not. It
-    returns the enablement state (one of <constant>SD_EVENT_ON</constant>,
-    <constant>SD_EVENT_OFF</constant>, <constant>SD_EVENT_ONESHOT</constant>)
-    in <parameter>enabled</parameter>, if it is not <constant>NULL</constant>.
-    It also returns true if the event source is not disabled.</para>
+    <para><function>sd_event_source_get_enabled()</function> may be used to query whether the event source
+    object <parameter>source</parameter> is currently enabled or not. If both the
+    <parameter>source</parameter> and the output parameter <parameter>enabled</parameter> are
+    <constant>NULL</constant>, this function returns false. Otherwise, <parameter>source</parameter> must be
+    a valid pointer to an <structname>sd_event_source</structname> object. If the output parameter
+    <parameter>enabled</parameter> is not <constant>NULL</constant>, it is set to the enablement state (one
+    of <constant>SD_EVENT_ON</constant>, <constant>SD_EVENT_OFF</constant>,
+    <constant>SD_EVENT_ONESHOT</constant>). The function also returns true if the event source is not
+    disabled.</para>
 
     <para>Event source objects are enabled when they are first created
     with calls such as
index 5c34d14ddcb04756aba5f29fa8d7b91a7a214a86..2672679458f2b88c2e2b35f2b82000393f46ad40 100644 (file)
@@ -375,12 +375,9 @@ ManagedJournalFile* managed_journal_file_close(ManagedJournalFile *f) {
         }
 #endif
 
-        if (f->file->post_change_timer) {
-                if (sd_event_source_get_enabled(f->file->post_change_timer, NULL) > 0)
-                        journal_file_post_change(f->file);
-
-                sd_event_source_disable_unref(f->file->post_change_timer);
-        }
+        if (sd_event_source_get_enabled(f->file->post_change_timer, NULL) > 0)
+                journal_file_post_change(f->file);
+        sd_event_source_disable_unref(f->file->post_change_timer);
 
         managed_journal_file_set_offline(f, true);
 
index 8c24e7db635ffe9b836683a23115442a5079a3f1..3a7afe9ae3c4ec56ac9f023b794f02763983d2c3 100644 (file)
@@ -116,13 +116,6 @@ int event_source_disable(sd_event_source *s) {
         return sd_event_source_set_enabled(s, SD_EVENT_OFF);
 }
 
-int event_source_is_enabled(sd_event_source *s) {
-        if (!s)
-                return false;
-
-        return sd_event_source_get_enabled(s, NULL);
-}
-
 int event_add_time_change(sd_event *e, sd_event_source **ret, sd_event_io_handler_t callback, void *userdata) {
         _cleanup_(sd_event_source_unrefp) sd_event_source *s = NULL;
         _cleanup_close_ int fd = -1;
index abd043bdcc9341552ca85e7eb861b694cc7839ce..7bab42ed8fed75656b626aeb0a9f5e4828918ea7 100644 (file)
@@ -28,6 +28,5 @@ int event_reset_time_relative(
                 const char *description,
                 bool force_reset);
 int event_source_disable(sd_event_source *s);
-int event_source_is_enabled(sd_event_source *s);
 
 int event_add_time_change(sd_event *e, sd_event_source **ret, sd_event_io_handler_t callback, void *userdata);
index 50f2bb280448a4b52e8fdb2e3936ce27b28c09ca..94431d0725ca0f0d254a137ed49f91bd696bd448 100644 (file)
@@ -2413,6 +2413,10 @@ fail:
 }
 
 _public_ int sd_event_source_get_enabled(sd_event_source *s, int *ret) {
+        /* Quick mode: the event source doesn't exist and we only want to query boolean enablement state. */
+        if (!s && !ret)
+                return false;
+
         assert_return(s, -EINVAL);
         assert_return(!event_pid_changed(s->event), -ECHILD);
 
index 2667a9fb2a581c8d2c6d8f85c8439b3ab9d451c0..99ec09c641130da5b603caf050c25473f3c1e993 100644 (file)
@@ -405,7 +405,7 @@ static int peer_resolve_endpoint(WireguardPeer *peer) {
                 /* Not necessary to resolve the endpoint. */
                 return 0;
 
-        if (event_source_is_enabled(peer->resolve_retry_event_source) > 0)
+        if (sd_event_source_get_enabled(peer->resolve_retry_event_source, NULL) > 0)
                 /* Timer event source is enabled. The endpoint will be resolved later. */
                 return 0;