Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp1556861iol; Fri, 10 Jun 2022 09:49:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJuYOjfK56xUdo5kq5seMJoo2SqrO99VqyJ7Emqs4e7SMKaM7tR+7Sz0POAodAhndKx6Uw X-Received: by 2002:a17:90b:3591:b0:1e3:25d3:e78e with SMTP id mm17-20020a17090b359100b001e325d3e78emr612176pjb.29.1654879778791; Fri, 10 Jun 2022 09:49:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654879778; cv=none; d=google.com; s=arc-20160816; b=pgXfJ0C0G2DEiFE03M6qjctBhCDcOp2f1pXlqqnvcbZOhdPMxBgdVT1KaCdCFa8UMZ 3f6XTRhR7xJ5hwD7dzci68VmEgdmop3LyZ9V1RZIsWwl53Xa2NkSsr2hRP8AQFeepo4w MRA0ZoKbMoNRxiZIpUJsu2xAQhXgq8ItOEMvR8kQLw6W6Bnng6e/W2u7JgQuwOQ7Gu+A LD1nmyKvbBTHeuTORLZ5E7Ip/3egouWXGJNHOw2+vSt1SbwuwHqeO8qfohOOeA7+56DW 1lsdVFZBnOOCuz1JOK6HNJ1bgif71xyvDt3KG9MEqmpY4zdVefa26CigtJbCA5s7Cyvx 09mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=g40JQVDu8ltC4xfYH6vExl5I92/rhoMzL0xdNs/sMZM=; b=o+H8Fgc9wWBkjsszdDYgfYIrz0wyVtJ+HiHLX9WpqGLHNoeK0aB65vit+yiFnMpVb2 FTq3OGTkC0h8pKMoQjbpTXCKAYllKLbblksg6kAszlhndR8/4uqzSh/WRNA/Yy7QYrg6 3wWWI6jF7EiqQpPmuV61AJKnVVJ37TS4kCHUOkY3m82prPqZyVCA/VBl3j5XJyiocWZr bV+Am5dgNsJNS+jePPtT7G3QV6rf1LvgXzunHKXUqwSH6i7cPUvutf6H5mFA3KJowz3b +CeYPm+9xWtQLZxNccbk67wUSaaAEWlWJOSEffNgshRLKWwEr38d6tvx9+ckp19a3jEF 3M6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Ww38OQH6; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j3-20020a170903028300b0015d56a3c9d0si46039142plr.534.2022.06.10.09.49.13; Fri, 10 Jun 2022 09:49:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Ww38OQH6; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349752AbiFJQil (ORCPT + 99 others); Fri, 10 Jun 2022 12:38:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349832AbiFJQih (ORCPT ); Fri, 10 Jun 2022 12:38:37 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 504EF580C0 for ; Fri, 10 Jun 2022 09:38:31 -0700 (PDT) Received: from localhost.localdomain (67.227.121.78.rev.sfr.net [78.121.227.67]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: fdanis) by madras.collabora.co.uk (Postfix) with ESMTPSA id 110856601723 for ; Fri, 10 Jun 2022 17:38:30 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1654879110; bh=Lc7PC9+oSIwJ7vQ2nt3r75oW/nmzfWTl+CMq2453Qj0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Ww38OQH6raGihlnus5obeMIHICINHePSfAnfgVJZUL1fzKZNAdfiVK2UIrMDD1QNd Obu6URxCsbwbBSd5eVWX5N2guRGhfsDNx0i2lBDtSc+2oFPZGdFcsrCOb3A9l5e/Kv G3CfulsTnyWlgwZAkxPbpa2I7Vft9aJ9pl20OGDQK+4RH4RzSO9PGk0ddxv4+rweet M/P90JKLEhNdfc5soMV3Uo2+ykPNQYJbpgAp7h/ErktFsq8fkxlLr9vQjP5mfvLdkF fRBgFaIbVO7RpxJySSnEdIRRer+54qrIfPIbubCrnSpqMkz5aewlCRQdrSiYJ0yBgh NJVY8Y6MnfJHg== From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Danis?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v3 1/4] test-runner: Add DBus session support Date: Fri, 10 Jun 2022 18:38:17 +0200 Message-Id: <20220610163820.79105-2-frederic.danis@collabora.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220610163820.79105-1-frederic.danis@collabora.com> References: <20220610163820.79105-1-frederic.danis@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Audio daemons requests access to DBus session to start --- tools/test-runner.c | 97 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 85 insertions(+), 12 deletions(-) diff --git a/tools/test-runner.c b/tools/test-runner.c index 945a16a77..9fc8e7b33 100644 --- a/tools/test-runner.c +++ b/tools/test-runner.c @@ -47,6 +47,7 @@ static int test_argc; static bool run_auto = false; static bool start_dbus = false; +static bool start_dbus_session; static bool start_daemon = false; static bool start_emulator = false; static bool start_monitor = false; @@ -251,9 +252,11 @@ static void start_qemu(void) "acpi=off pci=noacpi noapic quiet ro init=%s " "bluetooth.enable_ecred=1" "TESTHOME=%s TESTDBUS=%u TESTDAEMON=%u " + "TESTDBUSSESSION=%u XDG_RUNTIME_DIR=/run/user/0 " "TESTMONITOR=%u TESTEMULATOR=%u TESTDEVS=%d " "TESTAUTO=%u TESTARGS=\'%s\'", initcmd, cwd, start_dbus, start_daemon, + start_dbus_session, start_monitor, start_emulator, num_devs, run_auto, testargs); @@ -420,19 +423,63 @@ static void create_dbus_system_conf(void) mkdir("/run/dbus", 0755); } -static pid_t start_dbus_daemon(void) +static void create_dbus_session_conf(void) +{ + FILE *fp; + + fp = fopen("/etc/dbus-1/session.conf", "we"); + if (!fp) + return; + + fputs("\n", fp); + fputs("\n", fp); + fputs("session\n", fp); + fputs("unix:path=/run/user/0/bus\n", fp); + fputs("\n", fp); + fputs("\n", fp); + fputs("\n", fp); + fputs("\n", fp); + fputs("\n", fp); + fputs("\n", fp); + fputs("\n", fp); + fputs("\n", fp); + fputs("\n", fp); + fputs("\n", fp); + fputs("\n", fp); + fputs("\n", fp); + fputs("\n", fp); + + fclose(fp); + + if (symlink("/etc/dbus-1/session.conf", + "/usr/share/dbus-1/session.conf") < 0) + perror("Failed to create session.conf symlink"); + + mkdir("/run/user", 0755); + mkdir("/run/user/0", 0755); +} + +static pid_t start_dbus_daemon(bool session) { char *argv[3], *envp[1]; pid_t pid; int i; + char *bus_type = session ? "session" : "system"; + char *socket_path = session ? + "/run/user/0/bus" : "/run/dbus/system_bus_socket"; argv[0] = "/usr/bin/dbus-daemon"; - argv[1] = "--system"; + if (session) + argv[1] = "--session"; + else + argv[1] = "--system"; argv[2] = NULL; envp[0] = NULL; - printf("Starting D-Bus daemon\n"); + printf("Starting D-Bus %s daemon\n", bus_type); pid = fork(); if (pid < 0) { @@ -445,13 +492,13 @@ static pid_t start_dbus_daemon(void) exit(EXIT_SUCCESS); } - printf("D-Bus daemon process %d created\n", pid); + printf("D-Bus %s daemon process %d created\n", bus_type, pid); for (i = 0; i < 20; i++) { struct stat st; - if (!stat("/run/dbus/system_bus_socket", &st)) { - printf("Found D-Bus daemon socket\n"); + if (!stat(socket_path, &st)) { + printf("Found D-Bus %s daemon socket\n", bus_type); return pid; } @@ -666,7 +713,8 @@ static void run_command(char *cmdname, char *home) char *argv[9], *envp[3]; int pos = 0, idx = 0; int serial_fd; - pid_t pid, dbus_pid, daemon_pid, monitor_pid, emulator_pid; + pid_t pid, dbus_pid, daemon_pid, monitor_pid, emulator_pid, + dbus_session_pid; if (num_devs) { const char *node = "/dev/ttyS1"; @@ -684,10 +732,16 @@ static void run_command(char *cmdname, char *home) if (start_dbus) { create_dbus_system_conf(); - dbus_pid = start_dbus_daemon(); + dbus_pid = start_dbus_daemon(false); } else dbus_pid = -1; + if (start_dbus_session) { + create_dbus_session_conf(); + dbus_session_pid = start_dbus_daemon(true); + } else + dbus_session_pid = -1; + if (start_daemon) daemon_pid = start_bluetooth_daemon(home); else @@ -780,7 +834,12 @@ start_next: printf("Process %d continued\n", corpse); if (corpse == dbus_pid) { - printf("D-Bus daemon terminated\n"); + printf("D-Bus system daemon terminated\n"); + dbus_pid = -1; + } + + if (corpse == dbus_session_pid) { + printf("D-Bus session daemon terminated\n"); dbus_pid = -1; } @@ -814,6 +873,9 @@ start_next: if (dbus_pid > 0) kill(dbus_pid, SIGTERM); + if (dbus_session_pid > 0) + kill(dbus_session_pid, SIGTERM); + if (emulator_pid > 0) kill(dbus_pid, SIGTERM); @@ -874,10 +936,16 @@ static void run_tests(void) ptr = strstr(cmdline, "TESTDBUS=1"); if (ptr) { - printf("D-Bus daemon requested\n"); + printf("D-Bus system daemon requested\n"); start_dbus = true; } + ptr = strstr(cmdline, "TESTDBUSSESSION=1"); + if (ptr) { + printf("D-Bus session daemon requested\n"); + start_dbus_session = true; + } + ptr = strstr(cmdline, "TESTDAEMON=1"); if (ptr) { printf("bluetoothd requested\n"); @@ -914,7 +982,8 @@ static void usage(void) printf("\ttest-runner [options] [--] [args]\n"); printf("Options:\n" "\t-a, --auto Find tests and run them\n" - "\t-b, --dbus Start D-Bus daemon\n" + "\t-b, --dbus Start D-Bus system daemon\n" + "\t-s, --dbus-session Start D-Bus session daemon\n" "\t-d, --daemon Start bluetoothd\n" "\t-m, --monitor Start btmon\n" "\t-l, --emulator Start btvirt\n" @@ -928,6 +997,7 @@ static const struct option main_options[] = { { "all", no_argument, NULL, 'a' }, { "auto", no_argument, NULL, 'a' }, { "dbus", no_argument, NULL, 'b' }, + { "dbus-session", no_argument, NULL, 's' }, { "unix", no_argument, NULL, 'u' }, { "daemon", no_argument, NULL, 'd' }, { "emulator", no_argument, NULL, 'l' }, @@ -953,7 +1023,7 @@ int main(int argc, char *argv[]) for (;;) { int opt; - opt = getopt_long(argc, argv, "aubdlmq:k:vh", main_options, + opt = getopt_long(argc, argv, "aubdslmq:k:vh", main_options, NULL); if (opt < 0) break; @@ -968,6 +1038,9 @@ int main(int argc, char *argv[]) case 'b': start_dbus = true; break; + case 's': + start_dbus_session = true; + break; case 'd': start_dbus = true; start_daemon = true; -- 2.25.1