public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Bastien Nocera <hadess@hadess.net>
To: Pauli Virtanen <pav@iki.fi>, linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH BlueZ v3 02/20] emulator: btvirt: allow specifying where server unix sockets are made
Date: Mon, 30 Mar 2026 14:30:46 +0200	[thread overview]
Message-ID: <ed949f2550f79a4bef19bd482bf8b069ad5b7e0c.camel@hadess.net> (raw)
In-Reply-To: <41d54c33641f8a6004b3cb9a616c746119e2b156.1774214693.git.pav@iki.fi>

On Sun, 2026-03-22 at 23:29 +0200, Pauli Virtanen wrote:
> Make --server to take optional path name where to create the various
> server sockets.
> ---
>  emulator/main.c | 37 ++++++++++++++++++++++++-------------
>  1 file changed, 24 insertions(+), 13 deletions(-)
> 
> diff --git a/emulator/main.c b/emulator/main.c
> index 456fcd98e..09d6e9adb 100644
> --- a/emulator/main.c
> +++ b/emulator/main.c
> @@ -18,6 +18,7 @@
>  #include <stdbool.h>
>  #include <getopt.h>
>  #include <sys/uio.h>
> +#include <limits.h>
>  
>  #include "src/shared/mainloop.h"
>  #include "src/shared/util.h"
> @@ -46,7 +47,7 @@ static void usage(void)
>  	printf("options:\n"
>  		"\t-d                    Enable debug\n"
>  		"\t-S                    Create local serial port\n"
> -		"\t-s                    Create local server
> sockets\n"
> +		"\t-s[path=/tmp]         Create local server
> sockets\n"
>  		"\t-t[port=45550]        Create a TCP server\n"
>  		"\t-l[num]               Number of local
> controllers\n"
>  		"\t-L                    Create LE only
> controller\n"
> @@ -60,7 +61,7 @@ static void usage(void)
>  static const struct option main_options[] = {
>  	{ "debug",   no_argument,       NULL, 'd' },
>  	{ "serial",  no_argument,       NULL, 'S' },
> -	{ "server",  no_argument,       NULL, 's' },
> +	{ "server",  optional_argument, NULL, 's' },
>  	{ "tcp",     optional_argument, NULL, 't' },
>  	{ "local",   optional_argument, NULL, 'l' },
>  	{ "le",      no_argument,       NULL, 'L' },
> @@ -88,6 +89,7 @@ int main(int argc, char *argv[])
>  	struct server *server5;
>  	bool debug_enabled = false;
>  	bool server_enabled = false;
> +	const char *server_path = "/tmp";
>  	uint16_t tcp_port = 0;
>  	bool serial_enabled = false;
>  	int letest_count = 0;
> @@ -100,7 +102,7 @@ int main(int argc, char *argv[])
>  	for (;;) {
>  		int opt;
>  
> -		opt = getopt_long(argc, argv,
> "dSst::l::LBAU::T::vh",
> +		opt = getopt_long(argc, argv,
> "dSs::t::l::LBAU::T::vh",
>  						main_options, NULL);
>  		if (opt < 0)
>  			break;
> @@ -114,6 +116,8 @@ int main(int argc, char *argv[])
>  			break;
>  		case 's':
>  			server_enabled = true;
> +			if (optarg)
> +				server_path = optarg;
>  			break;
>  		case 't':
>  			if (optarg)
> @@ -196,28 +200,35 @@ int main(int argc, char *argv[])
>  	}
>  
>  	if (server_enabled) {
> -		server1 = server_open_unix(SERVER_TYPE_BREDRLE,
> -						"/tmp/bt-server-
> bredrle");
> +		char path[PATH_MAX];
> +
> +		snprintf(path, sizeof(path), "%s/%s", server_path,
> +							"bt-server-
> bredrle");
> +		server1 = server_open_unix(SERVER_TYPE_BREDRLE,
> path);

If we were allowed to use new glib calls, this hand-rolled code should
probably use like g_build_filename():
https://docs.gtk.org/glib/func.build_filename.html
and g_auto:
https://docs.gtk.org/glib/auto-cleanup.html
to simplify the code.

Luiz, could we have have an update to maintainer-guidelines.rst to
reflect the current guidelines for using or adding glib calls to the
code?

Pauli, do you think we could have helpers for this sort of path
manipulation in src/shared? Not saying it needs to be to the level of
complexity of the g_build_filename() implementation, but snprintf()...:
https://github.com/GNOME/glib/blob/main/glib/gfileutils.c#L1926

Luiz, another question, could we start using __attribute__(cleanup())
in bluez?

Consider the following example, adapted from systemd:
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

static inline void freep(void *p) {
        free(*(void**) p); 
}

#define _cleanup_(f) __attribute__((cleanup(f)))
#define _cleanup_free_ _cleanup_(freep)

int main(int argc, char **argv)
{
        _cleanup_free_ char *foo = NULL;

        foo = strdup("my string");

        printf ("%s\n", foo);

        return 0;
}

Is that something we could use? Happy to send a patchset to implement
the basics of it, and cleanup a few places where that would make the
code more readable.

As the systemd coding style says in
https://systemd.io/CODING_STYLE/#memory-allocation

"Make use of _cleanup_free_ and friends. It makes your code much nicer
to read (and shorter)!"

>  		if (!server1)
>  			fprintf(stderr, "Failed to open BR/EDR/LE
> server\n");
>  
> -		server2 = server_open_unix(SERVER_TYPE_BREDR,
> -						"/tmp/bt-server-
> bredr");
> +		snprintf(path, sizeof(path), "%s/%s", server_path,
> +							"bt-server-
> bredr");
> +		server2 = server_open_unix(SERVER_TYPE_BREDR, path);
>  		if (!server2)
>  			fprintf(stderr, "Failed to open BR/EDR
> server\n");
>  
> -		server3 = server_open_unix(SERVER_TYPE_AMP,
> -						"/tmp/bt-server-
> amp");
> +		snprintf(path, sizeof(path), "%s/%s", server_path,
> +							"bt-server-
> amp");
> +		server3 = server_open_unix(SERVER_TYPE_AMP, path);
>  		if (!server3)
>  			fprintf(stderr, "Failed to open AMP
> server\n");
>  
> -		server4 = server_open_unix(SERVER_TYPE_LE,
> -						"/tmp/bt-server-
> le");
> +		snprintf(path, sizeof(path), "%s/%s", server_path,
> +							"bt-server-
> le");
> +		server4 = server_open_unix(SERVER_TYPE_LE, path);
>  		if (!server4)
>  			fprintf(stderr, "Failed to open LE
> server\n");
>  
> -		server5 = server_open_unix(SERVER_TYPE_MONITOR,
> -						"/tmp/bt-server-
> mon");
> +		snprintf(path, sizeof(path), "%s/%s", server_path,
> +							"bt-server-
> mon");
> +		server5 = server_open_unix(SERVER_TYPE_MONITOR,
> path);
>  		if (!server5)
>  			fprintf(stderr, "Failed to open monitor
> server\n");
>  	}

  reply	other threads:[~2026-03-30 12:30 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-22 21:29 [PATCH BlueZ v3 00/20] Functional/integration testing Pauli Virtanen
2026-03-22 21:29 ` [PATCH BlueZ v3 01/20] emulator: btvirt: check pkt lengths, don't get stuck on malformed Pauli Virtanen
2026-03-22 22:38   ` Functional/integration testing bluez.test.bot
2026-03-22 21:29 ` [PATCH BlueZ v3 02/20] emulator: btvirt: allow specifying where server unix sockets are made Pauli Virtanen
2026-03-30 12:30   ` Bastien Nocera [this message]
2026-03-30 14:01     ` Luiz Augusto von Dentz
2026-03-30 14:33       ` Bastien Nocera
2026-03-22 21:29 ` [PATCH BlueZ v3 03/20] emulator: btvirt: support SCO data packets Pauli Virtanen
2026-03-22 21:29 ` [PATCH BlueZ v3 04/20] emulator: btdev: clear more state on Reset Pauli Virtanen
2026-03-22 21:29 ` [PATCH BlueZ v3 05/20] test-runner: enable path argument for --unix Pauli Virtanen
2026-03-22 21:29 ` [PATCH BlueZ v3 06/20] test-runner: Add -o/--option option Pauli Virtanen
2026-03-22 21:29 ` [PATCH BlueZ v3 07/20] test-runner: allow source tree root for -k Pauli Virtanen
2026-03-22 21:29 ` [PATCH BlueZ v3 08/20] doc: enable CONFIG_VIRTIO_CONSOLE in tester config Pauli Virtanen
2026-03-22 21:29 ` [PATCH BlueZ v3 09/20] test-runner: use virtio-serial for implementing -u device forwarding Pauli Virtanen
2026-03-24 20:24   ` Luiz Augusto von Dentz
2026-03-24 21:00     ` Pauli Virtanen
2026-03-30 12:30   ` Bastien Nocera
2026-03-22 21:29 ` [PATCH BlueZ v3 10/20] doc: enable KVM paravirtualization & clock support in tester kernel config Pauli Virtanen
2026-03-22 21:30 ` [PATCH BlueZ v3 11/20] doc: add functional/integration testing documentation Pauli Virtanen
2026-03-22 21:30 ` [PATCH BlueZ v3 12/20] test: add functional/integration testing framework Pauli Virtanen
2026-03-22 21:30 ` [PATCH BlueZ v3 13/20] test: functional: add Pipewire-using audio streaming tests Pauli Virtanen
2026-03-22 21:30 ` [PATCH BlueZ v3 14/20] test: functional: add --btmon option to start btmon Pauli Virtanen
2026-03-22 21:31 ` [PATCH BlueZ v3 15/20] build: add functional testing target Pauli Virtanen
2026-03-22 21:31 ` [PATCH BlueZ v3 16/20] test: functional: impose Python code formatting Pauli Virtanen
2026-03-22 21:31 ` [PATCH BlueZ v3 17/20] test: functional: add option for building kernel image first Pauli Virtanen
2026-03-22 21:31 ` [PATCH BlueZ v3 18/20] test: functional: add custom Agent1 implementation for testing Pauli Virtanen
2026-03-22 21:31 ` [PATCH BlueZ v3 19/20] test: functional: warn on kernel warning/bug messages Pauli Virtanen
2026-03-22 21:31 ` [PATCH BlueZ v3 20/20] test: functional: add basic obex file transfer tests Pauli Virtanen
2026-03-30 12:30 ` [PATCH BlueZ v3 00/20] Functional/integration testing Bastien Nocera
2026-03-30 12:48   ` Pauli Virtanen
2026-03-30 13:04     ` Bastien Nocera

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=ed949f2550f79a4bef19bd482bf8b069ad5b7e0c.camel@hadess.net \
    --to=hadess@hadess.net \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=pav@iki.fi \
    /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