diff --git a/.github/spellcheck-wordlist.txt b/.github/spellcheck-wordlist.txt index 4604067e8..480acf3c9 100644 --- a/.github/spellcheck-wordlist.txt +++ b/.github/spellcheck-wordlist.txt @@ -154,7 +154,7 @@ hfpag hfphf hspag hsphs -hVB +hVSB ioplug IPHONEACCEV iter diff --git a/configure.ac b/configure.ac index e421f58f3..b39ea1925 100644 --- a/configure.ac +++ b/configure.ac @@ -350,9 +350,9 @@ AC_SUBST([SYSTEMD_BLUEALSA_ARGS], [$systemdbluealsaargs]) AC_ARG_WITH([systemdbluealsaaplayargs], AS_HELP_STRING([--with-systemdbluealsaaplayargs=ARGS], [bluealsa-aplay arguments to - be used in bluealsa-aplay.service, defaults to empty if not specified]), + be used in bluealsa-aplay.service, defaults to '-S' if not specified]), [systemdbluealsaaplayargs="${withval}"], - [systemdbluealsaaplayargs=""]) + [systemdbluealsaaplayargs="-S"]) AC_SUBST([SYSTEMD_BLUEALSA_APLAY_ARGS], [$systemdbluealsaaplayargs]) AC_ARG_WITH([bluealsauser], diff --git a/doc/bluealsa-aplay.1.rst b/doc/bluealsa-aplay.1.rst index 3dac64460..599ff355d 100644 --- a/doc/bluealsa-aplay.1.rst +++ b/doc/bluealsa-aplay.1.rst @@ -6,7 +6,7 @@ bluealsa-aplay a simple bluealsa player ------------------------ -:Date: June 2022 +:Date: November 2022 :Manual section: 1 :Manual group: General Commands Manual :Version: $VERSION$ @@ -38,6 +38,10 @@ OPTIONS -V, --version Output the version number and exit. +-S, --syslog + Send output to system logger (``syslogd(8)``). + By default, log output is sent to stderr. + -v, --verbose Make the output more verbose. diff --git a/doc/bluealsa.8.rst b/doc/bluealsa.8.rst index 5f4ecd044..1c506ab74 100644 --- a/doc/bluealsa.8.rst +++ b/doc/bluealsa.8.rst @@ -6,7 +6,7 @@ bluealsa Bluetooth Audio ALSA Backend ---------------------------- -:Date: September 2022 +:Date: November 2022 :Manual section: 8 :Manual group: System Manager's Manual :Version: $VERSION$ @@ -33,15 +33,15 @@ OPTIONS -V, --version Output the version number and exit. +-S, --syslog + Send output to system logger (``syslogd(8)``). + By default, log output is sent to stderr. + -B NAME, --dbus=NAME BlueALSA D-Bus service name suffix. Without this option, **bluealsa** registers itself as an "org.bluealsa" D-Bus service. For more information see the EXAMPLES_ below. --S, --syslog - Send output to system logger (``syslogd(8)``). - By default, log output is sent to stderr. - -i hciX, --device=hciX HCI device to use. Can be specified multiple times to select more than one HCI. Because HCI numbering can change after a system reboot, this option diff --git a/misc/systemd/bluealsa-aplay.service.in b/misc/systemd/bluealsa-aplay.service.in index acd496ab6..8a187ac71 100644 --- a/misc/systemd/bluealsa-aplay.service.in +++ b/misc/systemd/bluealsa-aplay.service.in @@ -11,7 +11,7 @@ Requisite=dbus.service # $ sudo systemctl edit bluealsa-aplay # [Service] # ExecStart= -# ExecStart=@bindir@/bluealsa-aplay --pcm=my-playback-pcm +# ExecStart=@bindir@/bluealsa-aplay -S --pcm=my-playback-pcm [Service] Type=simple diff --git a/src/main.c b/src/main.c index 18da10624..2b1df2e56 100644 --- a/src/main.c +++ b/src/main.c @@ -145,12 +145,12 @@ static void g_bus_name_lost(GDBusConnection *conn, const char *name, void *userd int main(int argc, char **argv) { int opt; - const char *opts = "hVB:Si:p:c:"; + const char *opts = "hVSB:i:p:c:"; const struct option longopts[] = { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'V' }, - { "dbus", required_argument, NULL, 'B' }, { "syslog", no_argument, NULL, 'S' }, + { "dbus", required_argument, NULL, 'B' }, { "device", required_argument, NULL, 'i' }, { "profile", required_argument, NULL, 'p' }, { "codec", required_argument, NULL, 'c' }, @@ -191,31 +191,14 @@ int main(int argc, char **argv) { opterr = 0; while ((opt = getopt_long(argc, argv, opts, longopts, NULL)) != -1) switch (opt) { - case 'S' /* --syslog */ : - syslog = true; - break; - } - - log_open(argv[0], syslog); - - if (bluealsa_config_init() != 0) { - error("Couldn't initialize bluealsa config"); - return EXIT_FAILURE; - } - - /* parse options */ - optind = 0; opterr = 1; - while ((opt = getopt_long(argc, argv, opts, longopts, NULL)) != -1) - switch (opt) { - case 'h' /* --help */ : printf("Usage:\n" " %s -p PROFILE [OPTION]...\n" "\nOptions:\n" " -h, --help\t\t\tprint this help and exit\n" " -V, --version\t\t\tprint version and exit\n" - " -B, --dbus=NAME\t\tD-Bus service name suffix\n" " -S, --syslog\t\t\tsend output to syslog\n" + " -B, --dbus=NAME\t\tD-Bus service name suffix\n" " -i, --device=hciX\t\tHCI device(s) to use\n" " -p, --profile=NAME\t\tset enabled BT profiles\n" " -c, --codec=NAME\t\tset enabled BT audio codecs\n" @@ -273,6 +256,27 @@ int main(int argc, char **argv) { printf("%s\n", PACKAGE_VERSION); return EXIT_SUCCESS; + case 'S' /* --syslog */ : + syslog = true; + break; + } + + log_open(basename(argv[0]), syslog); + + if (bluealsa_config_init() != 0) { + error("Couldn't initialize bluealsa config"); + return EXIT_FAILURE; + } + + /* parse options */ + optind = 0; opterr = 1; + while ((opt = getopt_long(argc, argv, opts, longopts, NULL)) != -1) + switch (opt) { + case 'h' /* --help */ : + case 'V' /* --version */ : + case 'S' /* --syslog */ : + break; + case 'B' /* --dbus=NAME */ : snprintf(dbus_service, sizeof(dbus_service), BLUEALSA_SERVICE ".%s", optarg); if (!g_dbus_is_name(dbus_service)) { @@ -281,9 +285,6 @@ int main(int argc, char **argv) { } break; - case 'S' /* --syslog */ : - break; - case 'i' /* --device=HCI */ : g_array_append_val(config.hci_filter, optarg); break; diff --git a/test/bluealsa-mock.c b/test/bluealsa-mock.c index 587fa0cc2..51bc23763 100644 --- a/test/bluealsa-mock.c +++ b/test/bluealsa-mock.c @@ -682,7 +682,7 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - log_open(argv[0], false); + log_open(basename(argv[0]), false); assert(bluealsa_config_init() == 0); assert((config.dbus = g_test_dbus_connection_new_sync(NULL)) != NULL); diff --git a/utils/aplay/aplay.c b/utils/aplay/aplay.c index 07d85cf5d..3a6a80807 100644 --- a/utils/aplay/aplay.c +++ b/utils/aplay/aplay.c @@ -591,12 +591,12 @@ static void *pcm_worker_routine(struct pcm_worker *w) { pcm_open_retries = 0; if (verbose >= 2) { - printf("Used configuration for %s:\n" + info("Used configuration for %s:\n" " PCM buffer time: %u us (%zu bytes)\n" " PCM period time: %u us (%zu bytes)\n" " PCM format: %s\n" " Sampling rate: %u Hz\n" - " Channels: %u\n", + " Channels: %u", w->addr, buffer_time, snd_pcm_frames_to_bytes(w->pcm, buffer_size), period_time, snd_pcm_frames_to_bytes(w->pcm, period_size), @@ -854,10 +854,11 @@ static DBusHandlerResult dbus_signal_handler(DBusConnection *conn, DBusMessage * int main(int argc, char *argv[]) { int opt; - const char *opts = "hVvlLB:D:M:"; + const char *opts = "hVSvlLB:D:M:"; const struct option longopts[] = { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'V' }, + { "syslog", no_argument, NULL, 'S' }, { "verbose", no_argument, NULL, 'v' }, { "list-devices", no_argument, NULL, 'l' }, { "list-pcms", no_argument, NULL, 'L' }, @@ -874,6 +875,12 @@ int main(int argc, char *argv[]) { { 0, 0, 0, 0 }, }; + bool syslog = false; + + /* Check if syslog forwarding has been enabled. This check has to be + * done before anything else, so we can log early stage warnings and + * errors. */ + opterr = 0; while ((opt = getopt_long(argc, argv, opts, longopts, NULL)) != -1) switch (opt) { case 'h' /* --help */ : @@ -882,6 +889,7 @@ int main(int argc, char *argv[]) { "\nOptions:\n" " -h, --help\t\t\tprint this help and exit\n" " -V, --version\t\t\tprint version and exit\n" + " -S, --syslog\t\t\tsend output to syslog\n" " -v, --verbose\t\t\tmake output more verbose\n" " -l, --list-devices\t\tlist available BT audio devices\n" " -L, --list-pcms\t\tlist available BT audio PCMs\n" @@ -907,9 +915,27 @@ int main(int argc, char *argv[]) { printf("%s\n", PACKAGE_VERSION); return EXIT_SUCCESS; + case 'S' /* --syslog */ : + syslog = true; + break; + case 'v' /* --verbose */ : verbose++; break; + } + + log_open(basename(argv[0]), syslog); + dbus_threads_init_default(); + + /* parse options */ + optind = 0; opterr = 1; + while ((opt = getopt_long(argc, argv, opts, longopts, NULL)) != -1) + switch (opt) { + case 'h' /* --help */ : + case 'V' /* --version */ : + case 'S' /* --syslog */ : + case 'v' /* --verbose */ : + break; case 'l' /* --list-devices */ : list_bt_devices = true; @@ -962,9 +988,6 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - log_open(argv[0], false); - dbus_threads_init_default(); - DBusError err = DBUS_ERROR_INIT; if (!bluealsa_dbus_connection_ctx_init(&dbus_ctx, dbus_ba_service, &err)) { error("Couldn't initialize D-Bus context: %s", err.message); @@ -1003,7 +1026,7 @@ int main(int argc, char *argv[]) { for (i = 0; i < ba_addrs_count; i++, tmp += 19) ba2str(&ba_addrs[i], stpcpy(tmp, ", ")); - printf("Selected configuration:\n" + info("Selected configuration:\n" " BlueALSA service: %s\n" " PCM device: %s\n" " PCM buffer time: %u us\n" @@ -1011,7 +1034,7 @@ int main(int argc, char *argv[]) { " ALSA mixer device: %s\n" " ALSA mixer element: '%s',%u\n" " Bluetooth device(s): %s\n" - " Profile: %s\n", + " Profile: %s", dbus_ba_service, pcm_device, pcm_buffer_time, pcm_period_time, mixer_device, mixer_elem_name, mixer_elem_index, diff --git a/utils/cli/cli.c b/utils/cli/cli.c index 6493ccebf..eb1867bb5 100644 --- a/utils/cli/cli.c +++ b/utils/cli/cli.c @@ -360,7 +360,7 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - log_open(argv[0], false); + log_open(basename(argv[0]), false); dbus_threads_init_default(); DBusError err = DBUS_ERROR_INIT; diff --git a/utils/rfcomm/rfcomm.c b/utils/rfcomm/rfcomm.c index 0a5cc91c9..e5e6e69ce 100644 --- a/utils/rfcomm/rfcomm.c +++ b/utils/rfcomm/rfcomm.c @@ -112,7 +112,7 @@ int main(int argc, char *argv[]) { char dbus_ba_service[32] = BLUEALSA_SERVICE; - log_open(argv[0], false); + log_open(basename(argv[0]), false); while ((opt = getopt_long(argc, argv, opts, longopts, NULL)) != -1) switch (opt) {