All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] hostname: Fallback to static hostname if pretty hostname is not set
@ 2013-02-05 21:10 Szymon Janc
  2013-02-05 21:10 ` [PATCH 2/2] adapter: Set default adapter id sooner Szymon Janc
  2013-02-06  7:44 ` [PATCH 1/2] hostname: Fallback to static hostname if pretty hostname is not set Marcel Holtmann
  0 siblings, 2 replies; 7+ messages in thread
From: Szymon Janc @ 2013-02-05 21:10 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

If pretty hostname is not set fallback to static hostname (if it is
set). If static or pretty hostname is not set appropriate properties
are empty strings not NULLs. This behaviour is recomended by hostnamed.

Also fix setting adapter name to empty string if pretty hostname was
not set.
---
 plugins/hostname.c | 48 ++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 44 insertions(+), 4 deletions(-)

diff --git a/plugins/hostname.c b/plugins/hostname.c
index 0b75fac..92a71e0 100644
--- a/plugins/hostname.c
+++ b/plugins/hostname.c
@@ -53,22 +53,43 @@ 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;
+
+/*
+ * Fallback to static hostname only if empty pretty hostname was already
+ * received.
+ */
+static const char *get_hostname(void)
+{
+	if (pretty_hostname) {
+		if (g_str_equal(pretty_hostname, "") == FALSE)
+			return pretty_hostname;
+
+		if (static_hostname &&
+				g_str_equal(static_hostname, "") == FALSE)
+			return static_hostname;
+	}
+
+	return NULL;
+}
 
 static void update_name(struct btd_adapter *adapter, gpointer user_data)
 {
-	if (pretty_hostname == NULL)
+	const char *hostname = get_hostname();
+
+	if (hostname == NULL)
 		return;
 
 	if (btd_adapter_is_default(adapter)) {
-		DBG("name: %s", pretty_hostname);
+		DBG("name: %s", hostname);
 
-		adapter_set_name(adapter, pretty_hostname);
+		adapter_set_name(adapter, hostname);
 	} else {
 		uint16_t index = btd_adapter_get_index(adapter);
 		char *str;
 
 		/* Avoid "some device #0" names, start at #1 */
-		str = g_strdup_printf("%s #%u", pretty_hostname, index + 1);
+		str = g_strdup_printf("%s #%u", hostname, index + 1);
 
 		DBG("name: %s", str);
 
@@ -122,6 +143,24 @@ static void property_changed(GDBusProxy *proxy, const char *name,
 
 			adapter_foreach(update_name, NULL);
 		}
+	} else if (g_str_equal(name, "StaticHostname") == TRUE) {
+		if (iter == NULL) {
+			g_dbus_proxy_refresh_property(proxy, name);
+			return;
+		}
+
+		if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
+			const char *str;
+
+			dbus_message_iter_get_basic(iter, &str);
+
+			DBG("static hostname: %s", str);
+
+			g_free(static_hostname);
+			static_hostname = g_strdup(str);
+
+			adapter_foreach(update_name, NULL);
+		}
 	} else if (g_str_equal(name, "Chassis") == TRUE) {
 		if (iter == NULL) {
 			g_dbus_proxy_refresh_property(proxy, name);
@@ -277,6 +316,7 @@ static void hostname_exit(void)
 	}
 
 	g_free(pretty_hostname);
+	g_free(static_hostname);
 }
 
 BLUETOOTH_PLUGIN_DEFINE(hostname, VERSION, BLUETOOTH_PLUGIN_PRIORITY_DEFAULT,
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] adapter: Set default adapter id sooner
  2013-02-05 21:10 [PATCH 1/2] hostname: Fallback to static hostname if pretty hostname is not set Szymon Janc
@ 2013-02-05 21:10 ` Szymon Janc
  2013-02-06  7:57   ` Marcel Holtmann
  2013-02-06  7:44 ` [PATCH 1/2] hostname: Fallback to static hostname if pretty hostname is not set Marcel Holtmann
  1 sibling, 1 reply; 7+ messages in thread
From: Szymon Janc @ 2013-02-05 21:10 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

When first adapter is registered set it as default before probing
drivers or profiles as those might depend on that e.g. hostname.

This fix hostname plugin setting default adapter name to 'foo #1'
instead of 'foo' if pretty hostname was received before probing
adapter drivers.
---
 src/adapter.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 9ddd2fc..276d897 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -5492,6 +5492,9 @@ static int adapter_register(struct btd_adapter *adapter)
 
 	btd_adapter_gatt_server_start(adapter);
 
+	if (default_adapter_id < 0)
+		default_adapter_id = adapter->dev_id;
+
 	load_config(adapter);
 	fix_storage(adapter);
 	load_drivers(adapter);
@@ -5506,9 +5509,6 @@ static int adapter_register(struct btd_adapter *adapter)
 
 	adapter->initialized = TRUE;
 
-	if (default_adapter_id < 0)
-		default_adapter_id = adapter->dev_id;
-
 	if (main_opts.did_source)
 		set_did(adapter, main_opts.did_vendor, main_opts.did_product,
 				main_opts.did_version, main_opts.did_source);
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] hostname: Fallback to static hostname if pretty hostname is not set
  2013-02-05 21:10 [PATCH 1/2] hostname: Fallback to static hostname if pretty hostname is not set Szymon Janc
  2013-02-05 21:10 ` [PATCH 2/2] adapter: Set default adapter id sooner Szymon Janc
@ 2013-02-06  7:44 ` Marcel Holtmann
  2013-02-06 20:29   ` Szymon Janc
  1 sibling, 1 reply; 7+ messages in thread
From: Marcel Holtmann @ 2013-02-06  7:44 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth

Hi Szymon,

> If pretty hostname is not set fallback to static hostname (if it is
> set). If static or pretty hostname is not set appropriate properties
> are empty strings not NULLs. This behaviour is recomended by hostnamed.
> 
> Also fix setting adapter name to empty string if pretty hostname was
> not set.

please do not squeeze to patches into one.

I am also not convinced that we should bother with the static hostname
at all. I left this out on purpose. My thinking here was that if we do
not have a pretty hostname, then why bother with trying to make
something useful out of the hostname, it would be ugly or wrong anyway.

Regards

Marcel



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] adapter: Set default adapter id sooner
  2013-02-05 21:10 ` [PATCH 2/2] adapter: Set default adapter id sooner Szymon Janc
@ 2013-02-06  7:57   ` Marcel Holtmann
  2013-02-06 19:54     ` Szymon Janc
  0 siblings, 1 reply; 7+ messages in thread
From: Marcel Holtmann @ 2013-02-06  7:57 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth

Hi Szymon,

> When first adapter is registered set it as default before probing
> drivers or profiles as those might depend on that e.g. hostname.
> 
> This fix hostname plugin setting default adapter name to 'foo #1'
> instead of 'foo' if pretty hostname was received before probing
> adapter drivers.

you find an issue that I meant to fix, but never got around so far. So I
do not like the magic default_adapter_id global variable.

I would prefer if we add a is_default or similar variable to btd_adapter
and make it change if one adapter goes away.

Regards

Marcel



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] adapter: Set default adapter id sooner
  2013-02-06  7:57   ` Marcel Holtmann
@ 2013-02-06 19:54     ` Szymon Janc
  0 siblings, 0 replies; 7+ messages in thread
From: Szymon Janc @ 2013-02-06 19:54 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth

On Wednesday 06 February 2013 09:57:44 Marcel Holtmann wrote:

Hi Marcel,
 
> > When first adapter is registered set it as default before probing
> > drivers or profiles as those might depend on that e.g. hostname.
> > 
> > This fix hostname plugin setting default adapter name to 'foo #1'
> > instead of 'foo' if pretty hostname was received before probing
> > adapter drivers.
> 
> you find an issue that I meant to fix, but never got around so far. So I
> do not like the magic default_adapter_id global variable.
> 
> I would prefer if we add a is_default or similar variable to btd_adapter
> and make it change if one adapter goes away.

OK, will send v2 which address that.

-- 
Szymon K. Janc
szymon@janc.net.pl

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] hostname: Fallback to static hostname if pretty hostname is not set
  2013-02-06  7:44 ` [PATCH 1/2] hostname: Fallback to static hostname if pretty hostname is not set Marcel Holtmann
@ 2013-02-06 20:29   ` Szymon Janc
  2013-02-07  8:31     ` Marcel Holtmann
  0 siblings, 1 reply; 7+ messages in thread
From: Szymon Janc @ 2013-02-06 20:29 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth

On Wednesday 06 February 2013 09:44:08 Marcel Holtmann wrote:

Hi Marcel,
 
> > If pretty hostname is not set fallback to static hostname (if it is
> > set). If static or pretty hostname is not set appropriate properties
> > are empty strings not NULLs. This behaviour is recomended by hostnamed.
> > 
> > Also fix setting adapter name to empty string if pretty hostname was
> > not set.
> 
> please do not squeeze to patches into one.

Will split that in v2.

> 
> I am also not convinced that we should bother with the static hostname
> at all. I left this out on purpose. My thinking here was that if we do
> not have a pretty hostname, then why bother with trying to make
> something useful out of the hostname, it would be ugly or wrong anyway.

Maybe not that fancy as pretty hostname but at least know to user(e.g for
some reason my Fedora doesn't have pretty hostname set and falling back to 
static hostname makes adapter name somewhat reasonable).
Also falling back to static hostname will allow hostname plugin to number
adapters' names. Yet, maybe main.conf parsing should be fixed instead to 
properly substitute %h/%d as stated in comment. Currently name is simply set 
to string '%h-%d' in such case...

-- 
Szymon K. Janc
szymon@janc.net.pl

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] hostname: Fallback to static hostname if pretty hostname is not set
  2013-02-06 20:29   ` Szymon Janc
@ 2013-02-07  8:31     ` Marcel Holtmann
  0 siblings, 0 replies; 7+ messages in thread
From: Marcel Holtmann @ 2013-02-07  8:31 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth

Hi Syzmon,

> > I am also not convinced that we should bother with the static hostname
> > at all. I left this out on purpose. My thinking here was that if we do
> > not have a pretty hostname, then why bother with trying to make
> > something useful out of the hostname, it would be ugly or wrong anyway.
> 
> Maybe not that fancy as pretty hostname but at least know to user(e.g for
> some reason my Fedora doesn't have pretty hostname set and falling back to 
> static hostname makes adapter name somewhat reasonable).
> Also falling back to static hostname will allow hostname plugin to number
> adapters' names. Yet, maybe main.conf parsing should be fixed instead to 
> properly substitute %h/%d as stated in comment. Currently name is simply set 
> to string '%h-%d' in such case...

I actually want to get rid of main.conf for default installs. And you
might have seen this already. We do not install it anymore. The defaults
should work as good as possible. Goal is to actually create stateless
systems without requiring /etc.

Regards

Marcel



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-02-07  8:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-05 21:10 [PATCH 1/2] hostname: Fallback to static hostname if pretty hostname is not set Szymon Janc
2013-02-05 21:10 ` [PATCH 2/2] adapter: Set default adapter id sooner Szymon Janc
2013-02-06  7:57   ` Marcel Holtmann
2013-02-06 19:54     ` Szymon Janc
2013-02-06  7:44 ` [PATCH 1/2] hostname: Fallback to static hostname if pretty hostname is not set Marcel Holtmann
2013-02-06 20:29   ` Szymon Janc
2013-02-07  8:31     ` Marcel Holtmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.