From: Grant Erickson <gerickson@nuovations.com>
To: connman@lists.linux.dev
Subject: [PATCH] service: Deduplicate online check config query and log.
Date: Mon, 6 Nov 2023 11:33:32 -0800 [thread overview]
Message-ID: <C6B61007-3C60-43AC-86FC-9C3412A5613A@nuovations.com> (raw)
Identical logic with an identical log statement was used in both
'start_online_check' and 'start_wispr_if_connected'. This deduplicates
that code into a single common, file-scope function,
'online_check_enabled_check', and leverages it in the two locations it
was previously duplicated in.
---
src/service.c | 42 ++++++++++++++++++++++++++++++++++--------
1 file changed, 34 insertions(+), 8 deletions(-)
diff --git a/src/service.c b/src/service.c
index 13e22c30..03e23618 100644
--- a/src/service.c
+++ b/src/service.c
@@ -1599,6 +1599,38 @@ static void cancel_online_check(struct connman_service *service)
}
}
+/**
+ * @brief
+ * Check whether an online check is enabled for the specified
+ * service.
+ *
+ * This determines whether "online" HTTP-based Internet reachability
+ * checks are enabled for the specified network service. If not, an
+ * information-level message is logged.
+ *
+ * @param[in] service A pointer to the immutable service for which
+ * to determine whether "online" HTTP-based
+ * Internet reachability checks are enabled.
+ *
+ * @returns
+ * True if "online" HTTP-based Internet reachability * checks are
+ * enabled for the specified network service; otherwise, false.
+ *
+ * @sa start_online_check
+ * @sa start_wispr_if_connected
+ *
+ */
+static bool online_check_enabled_check(const struct connman_service *service)
+{
+ if (!connman_setting_get_bool("EnableOnlineCheck")) {
+ connman_info("Online check disabled. "
+ "Default service remains in READY state.");
+ return false;
+ }
+
+ return true;
+}
+
/**
* @brief
* Start an "online" HTTP-based Internet reachability check for the
@@ -1634,11 +1666,8 @@ static void start_online_check(struct connman_service *service,
type,
__connman_ipconfig_type2string(type));
- if (!connman_setting_get_bool("EnableOnlineCheck")) {
- connman_info("Online check disabled. "
- "Default service remains in READY state.");
+ if (!online_check_enabled_check(service))
return;
- }
if (type == CONNMAN_IPCONFIG_TYPE_IPV6 || check_proxy_setup(service)) {
cancel_online_check(service);
@@ -1874,11 +1903,8 @@ static void start_wispr_if_connected(struct connman_service *service)
service,
connman_service_get_identifier(service));
- if (!connman_setting_get_bool("EnableOnlineCheck")) {
- connman_info("Online check disabled. "
- "Default service remains in READY state.");
+ if (!online_check_enabled_check(service))
return;
- }
if (__connman_service_is_connected_state(service,
CONNMAN_IPCONFIG_TYPE_IPV4))
--
2.42.0
next reply other threads:[~2023-11-06 19:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-06 19:33 Grant Erickson [this message]
2023-11-07 19:02 ` [PATCH] service: Deduplicate online check config query and log Marcel Holtmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=C6B61007-3C60-43AC-86FC-9C3412A5613A@nuovations.com \
--to=gerickson@nuovations.com \
--cc=connman@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).