* [BlueZ 1/2] hostname: Add '' around printed strings
@ 2022-11-09 15:17 Bastien Nocera
2022-11-09 15:17 ` [BlueZ 2/2] hostname: Fallback to transient hostname Bastien Nocera
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Bastien Nocera @ 2022-11-09 15:17 UTC (permalink / raw
To: linux-bluetooth
Otherwise we can't see whether the string is nul, or empty.
---
plugins/hostname.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/plugins/hostname.c b/plugins/hostname.c
index 1a9513adb..14b6450b5 100644
--- a/plugins/hostname.c
+++ b/plugins/hostname.c
@@ -128,7 +128,7 @@ static void property_changed(GDBusProxy *proxy, const char *name,
dbus_message_iter_get_basic(iter, &str);
- DBG("pretty hostname: %s", str);
+ DBG("pretty hostname: '%s'", str);
g_free(pretty_hostname);
pretty_hostname = g_strdup(str);
@@ -146,7 +146,7 @@ static void property_changed(GDBusProxy *proxy, const char *name,
dbus_message_iter_get_basic(iter, &str);
- DBG("static hostname: %s", str);
+ DBG("static hostname: '%s'", str);
g_free(static_hostname);
static_hostname = g_strdup(str);
@@ -165,7 +165,7 @@ static void property_changed(GDBusProxy *proxy, const char *name,
dbus_message_iter_get_basic(iter, &str);
- DBG("chassis: %s", str);
+ DBG("chassis: '%s'", str);
for (i = 0; chassis_table[i].chassis; i++) {
if (strcmp(chassis_table[i].chassis, str))
--
2.37.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [BlueZ 2/2] hostname: Fallback to transient hostname
2022-11-09 15:17 [BlueZ 1/2] hostname: Add '' around printed strings Bastien Nocera
@ 2022-11-09 15:17 ` Bastien Nocera
2022-11-09 16:11 ` [BlueZ,1/2] hostname: Add '' around printed strings bluez.test.bot
2022-11-16 22:00 ` [BlueZ 1/2] " patchwork-bot+bluetooth
2 siblings, 0 replies; 4+ messages in thread
From: Bastien Nocera @ 2022-11-09 15:17 UTC (permalink / raw
To: linux-bluetooth
After pretty hostname, and static hostname, also support transient
hostname as a last resort before 'BlueZ X.XX'.
This happens on Fedora's Workstation installation as it calls
"hostnamectl set-hostname" on startup. In Fedora Silverblue, the default
hostname is set as fedora in /etc/os-release.
In both cases, we should fall back to that transient hostname, as bad as
it could be.
Note that the transient hostname needs to be monitored through the
kernel directly, as explained in:
https://www.freedesktop.org/software/systemd/man/org.freedesktop.hostname1.html
---
plugins/hostname.c | 53 ++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 51 insertions(+), 2 deletions(-)
diff --git a/plugins/hostname.c b/plugins/hostname.c
index 14b6450b5..a12afb282 100644
--- a/plugins/hostname.c
+++ b/plugins/hostname.c
@@ -16,6 +16,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/utsname.h>
#include "lib/bluetooth.h"
#include "lib/sdp.h"
@@ -44,8 +45,10 @@
static uint8_t major_class = MAJOR_CLASS_MISCELLANEOUS;
static uint8_t minor_class = MINOR_CLASS_UNCATEGORIZED;
-static char *pretty_hostname = NULL;
-static char *static_hostname = NULL;
+static char *pretty_hostname = NULL;
+static char *static_hostname = NULL;
+static char *transient_hostname = NULL;
+static guint hostname_id = 0;
/*
* Fallback to static hostname only if empty pretty hostname was already
@@ -60,6 +63,10 @@ static const char *get_hostname(void)
if (static_hostname &&
g_str_equal(static_hostname, "") == FALSE)
return static_hostname;
+
+ if (transient_hostname &&
+ g_str_equal(transient_hostname, "") == FALSE)
+ return transient_hostname;
}
return NULL;
@@ -181,6 +188,32 @@ static void property_changed(GDBusProxy *proxy, const char *name,
}
}
+static void read_transient_hostname(void)
+{
+ struct utsname u;
+
+ if (uname(&u) != 0) {
+ g_free(transient_hostname);
+ transient_hostname = NULL;
+ DBG("failed to read transient hostname");
+ return;
+ }
+
+ g_free(transient_hostname);
+ transient_hostname = g_strdup(u.nodename);
+
+ DBG("read transient hostname: '%s'", transient_hostname);
+}
+
+static gboolean hostname_cb(GIOChannel *io, GIOCondition cond,
+ gpointer user_data)
+{
+ DBG("transient hostname changed");
+ read_transient_hostname();
+ adapter_foreach(update_class, NULL);
+ return TRUE;
+}
+
static int hostname_probe(struct btd_adapter *adapter)
{
DBG("");
@@ -261,9 +294,11 @@ static GDBusProxy *hostname_proxy = NULL;
static int hostname_init(void)
{
DBusConnection *conn = btd_get_dbus_connection();
+ GIOChannel *hostname_io;
int err;
read_dmi_fallback();
+ read_transient_hostname();
hostname_client = g_dbus_client_new(conn, "org.freedesktop.hostname1",
"/org/freedesktop/hostname1");
@@ -289,6 +324,14 @@ static int hostname_init(void)
hostname_client = NULL;
}
+ hostname_io = g_io_channel_new_file("/proc/sys/kernel/hostname", "r", NULL);
+ if (hostname_io) {
+ hostname_id = g_io_add_watch(hostname_io, G_IO_ERR, hostname_cb, NULL);
+ g_io_channel_unref(hostname_io);
+ } else {
+ DBG("failed to open /proc/sys/kernel/hostname");
+ }
+
return err;
}
@@ -306,8 +349,14 @@ static void hostname_exit(void)
hostname_client = NULL;
}
+ if (hostname_id != 0) {
+ g_source_remove(hostname_id);
+ hostname_id = 0;
+ }
+
g_free(pretty_hostname);
g_free(static_hostname);
+ g_free(transient_hostname);
}
BLUETOOTH_PLUGIN_DEFINE(hostname, VERSION, BLUETOOTH_PLUGIN_PRIORITY_DEFAULT,
--
2.37.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* RE: [BlueZ,1/2] hostname: Add '' around printed strings
2022-11-09 15:17 [BlueZ 1/2] hostname: Add '' around printed strings Bastien Nocera
2022-11-09 15:17 ` [BlueZ 2/2] hostname: Fallback to transient hostname Bastien Nocera
@ 2022-11-09 16:11 ` bluez.test.bot
2022-11-16 22:00 ` [BlueZ 1/2] " patchwork-bot+bluetooth
2 siblings, 0 replies; 4+ messages in thread
From: bluez.test.bot @ 2022-11-09 16:11 UTC (permalink / raw
To: linux-bluetooth, hadess
[-- Attachment #1: Type: text/plain, Size: 2893 bytes --]
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=693693
---Test result---
Test Summary:
CheckPatch FAIL 2.47 seconds
GitLint PASS 1.55 seconds
Prep - Setup ELL PASS 27.77 seconds
Build - Prep PASS 0.72 seconds
Build - Configure PASS 8.90 seconds
Build - Make PASS 897.96 seconds
Make Check PASS 11.55 seconds
Make Check w/Valgrind PASS 297.53 seconds
Make Distcheck PASS 245.83 seconds
Build w/ext ELL - Configure PASS 8.99 seconds
Build w/ext ELL - Make PASS 87.66 seconds
Incremental Build w/ patches PASS 205.65 seconds
Scan Build PASS 519.08 seconds
Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script with rule in .checkpatch.conf
Output:
[BlueZ,2/2] hostname: Fallback to transient hostname
WARNING:COMMIT_LOG_LONG_LINE: Possible unwrapped commit description (prefer a maximum 75 chars per line)
#57:
https://www.freedesktop.org/software/systemd/man/org.freedesktop.hostname1.html
ERROR:INITIALISED_STATIC: do not initialise statics to NULL
#80: FILE: plugins/hostname.c:48:
+static char *pretty_hostname = NULL;
ERROR:INITIALISED_STATIC: do not initialise statics to NULL
#81: FILE: plugins/hostname.c:49:
+static char *static_hostname = NULL;
ERROR:INITIALISED_STATIC: do not initialise statics to NULL
#82: FILE: plugins/hostname.c:50:
+static char *transient_hostname = NULL;
ERROR:INITIALISED_STATIC: do not initialise statics to 0
#83: FILE: plugins/hostname.c:51:
+static guint hostname_id = 0;
WARNING:LONG_LINE: line length of 84 exceeds 80 columns
#147: FILE: plugins/hostname.c:327:
+ hostname_io = g_io_channel_new_file("/proc/sys/kernel/hostname", "r", NULL);
WARNING:LONG_LINE: line length of 87 exceeds 80 columns
#149: FILE: plugins/hostname.c:329:
+ hostname_id = g_io_add_watch(hostname_io, G_IO_ERR, hostname_cb, NULL);
/github/workspace/src/13037643.patch total: 4 errors, 3 warnings, 100 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/github/workspace/src/13037643.patch has style problems, please review.
NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
---
Regards,
Linux Bluetooth
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [BlueZ 1/2] hostname: Add '' around printed strings
2022-11-09 15:17 [BlueZ 1/2] hostname: Add '' around printed strings Bastien Nocera
2022-11-09 15:17 ` [BlueZ 2/2] hostname: Fallback to transient hostname Bastien Nocera
2022-11-09 16:11 ` [BlueZ,1/2] hostname: Add '' around printed strings bluez.test.bot
@ 2022-11-16 22:00 ` patchwork-bot+bluetooth
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+bluetooth @ 2022-11-16 22:00 UTC (permalink / raw
To: Bastien Nocera; +Cc: linux-bluetooth
Hello:
This series was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:
On Wed, 9 Nov 2022 16:17:55 +0100 you wrote:
> Otherwise we can't see whether the string is nul, or empty.
> ---
> plugins/hostname.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
Here is the summary with links:
- [BlueZ,1/2] hostname: Add '' around printed strings
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=e515f4b6e25c
- [BlueZ,2/2] hostname: Fallback to transient hostname
(no matching commit)
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-11-16 22:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-09 15:17 [BlueZ 1/2] hostname: Add '' around printed strings Bastien Nocera
2022-11-09 15:17 ` [BlueZ 2/2] hostname: Fallback to transient hostname Bastien Nocera
2022-11-09 16:11 ` [BlueZ,1/2] hostname: Add '' around printed strings bluez.test.bot
2022-11-16 22:00 ` [BlueZ 1/2] " patchwork-bot+bluetooth
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).