Skip to content

Commit

Permalink
Log to syslog option for bluealsa-aplay
Browse files Browse the repository at this point in the history
When bluealsa-aplay is started via systemd log to syslog by default.
Also, this commit rearranges command line options parsing, so right now
the help text will be printed always when "--help" is given - even when
earlier options contain invalid values.
  • Loading branch information
arkq committed Nov 6, 2022
1 parent 50bfe9c commit c07432b
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/spellcheck-wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ hfpag
hfphf
hspag
hsphs
hVB
hVSB
ioplug
IPHONEACCEV
iter
Expand Down
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
6 changes: 5 additions & 1 deletion doc/bluealsa-aplay.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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$
Expand Down Expand Up @@ -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.

Expand Down
10 changes: 5 additions & 5 deletions doc/bluealsa.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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$
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion misc/systemd/bluealsa-aplay.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 24 additions & 23 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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(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)) {
Expand All @@ -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;
Expand Down
31 changes: 27 additions & 4 deletions utils/aplay/aplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand All @@ -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 */ :
Expand All @@ -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"
Expand All @@ -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(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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c07432b

Please sign in to comment.