From patchwork Mon Nov 20 21:53:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13462164 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1501D38FB6 for ; Mon, 20 Nov 2023 21:53:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 89141730F7 for ; Mon, 20 Nov 2023 16:53:35 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:230d:b2c9:c388:f96b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 40DFB7310A for ; Mon, 20 Nov 2023 16:53:35 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 1/2] service: Add and leverage 'clear_error'. Date: Mon, 20 Nov 2023 13:53:28 -0800 Message-ID: <20231120215329.786768-2-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231120215329.786768-1-gerickson@nuovations.com> References: <20231120215329.786768-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 There are a suffient number of instantiations of the following implementation pattern: set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN); to clear or reset the "Error" service property where it makes sense to embody this in a single function, 'clear_error'. This introduces and leverages the 'clear_error' function to embody this pattern. --- src/service.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/service.c b/src/service.c index 9808028637dd..b30e75b9ac13 100644 --- a/src/service.c +++ b/src/service.c @@ -183,6 +183,8 @@ static void complete_online_check(struct connman_service *service, bool success, int err); static bool service_downgrade_online_state(struct connman_service *service); +static bool connman_service_is_default(const struct connman_service *service); +static void clear_error(struct connman_service *service); struct find_data { const char *path; @@ -3992,7 +3994,7 @@ int __connman_service_set_passphrase(struct connman_service *service, if (service->hidden_service && service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY) - set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN); + clear_error(service); return 0; } @@ -4374,7 +4376,7 @@ static DBusMessage *set_property(DBusConnection *conn, * have the same effect as user connecting the VPN = * clear previous error and change state to idle. */ - set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN); + clear_error(service); if (service->state == CONNMAN_SERVICE_STATE_FAILURE) { service->state = CONNMAN_SERVICE_STATE_IDLE; @@ -4674,6 +4676,11 @@ static void set_error(struct connman_service *service, DBUS_TYPE_STRING, &str); } +static void clear_error(struct connman_service *service) +{ + set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN); +} + static void remove_timeout(struct connman_service *service) { if (service->timeout > 0) { @@ -4715,7 +4722,7 @@ static DBusMessage *clear_property(DBusConnection *conn, DBUS_TYPE_INVALID); if (g_str_equal(name, "Error")) { - set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN); + clear_error(service); __connman_service_clear_error(service); service_complete(service); @@ -6795,7 +6802,7 @@ static void request_input_cb(struct connman_service *service, if (err >= 0) { /* We forget any previous error. */ - set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN); + clear_error(service); __connman_service_connect(service, CONNMAN_SERVICE_CONNECT_REASON_USER); @@ -7017,7 +7024,7 @@ static int service_indicate_state(struct connman_service *service) break; case CONNMAN_SERVICE_STATE_READY: - set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN); + clear_error(service); if (service->new_service && __connman_stats_service_register(service) == 0) { @@ -7084,7 +7091,7 @@ static int service_indicate_state(struct connman_service *service) break; case CONNMAN_SERVICE_STATE_DISCONNECT: - set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN); + clear_error(service); reply_pending(service, ECONNABORTED); From patchwork Mon Nov 20 21:53:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13462165 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C455938FBC for ; Mon, 20 Nov 2023 21:53:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 9147273108 for ; Mon, 20 Nov 2023 16:53:38 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:230d:b2c9:c388:f96b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 4A14F73145 for ; Mon, 20 Nov 2023 16:53:38 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 2/2] service: Document '{clear,set}_error'. Date: Mon, 20 Nov 2023 13:53:29 -0800 Message-ID: <20231120215329.786768-3-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231120215329.786768-1-gerickson@nuovations.com> References: <20231120215329.786768-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This adds documentation to the '{clear,set}_error' functions. --- src/service.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/service.c b/src/service.c index b30e75b9ac13..85315548c2fe 100644 --- a/src/service.c +++ b/src/service.c @@ -4650,6 +4650,24 @@ static DBusMessage *set_property(DBusConnection *conn, return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); } +/** + * @brief + * Set the specified network service "Error" property. + * + * This sets the specified network service "Error" property to the + * provided value. + * + * @note + * This function results in a D-Bus property changed signal for the + * network service "Error" property. + * + * @param[in,out] service A pointer to the mutable network service + * for which to set the "Error" property. + * @param[in] error The error value to set. + * + * @sa clear_error + * + */ static void set_error(struct connman_service *service, enum connman_service_error error) { @@ -4676,6 +4694,25 @@ static void set_error(struct connman_service *service, DBUS_TYPE_STRING, &str); } +/** + * @brief + * Clear or reset the specified network service "Error" property. + * + * This sets the specified network service "Error" property to the + * initialization value of #CONNMAN_SERVICE_ERROR_UNKNOWN, + * effectively clearing or resetting the property. + * + * @note + * This function results in a D-Bus property changed signal for the + * network service "Error" property. + * + * @param[in,out] service A pointer to the mutable network service + * for which to clear or reset the "Error" + * property. + * + * @sa set_error + * + */ static void clear_error(struct connman_service *service) { set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);