1998-10-29 23:45:59 +01:00
|
|
|
/*
|
|
|
|
* Advanced Linux Sound Architecture Control Program
|
2000-08-25 16:34:26 +02:00
|
|
|
* Copyright (c) by Abramo Bagnara <abramo@alsa-project.org>
|
2007-10-15 10:25:17 +02:00
|
|
|
* Jaroslav Kysela <perex@perex.cz>
|
1998-10-29 23:45:59 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2017-11-14 14:28:51 +01:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
1998-10-29 23:45:59 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1998-10-31 20:50:16 +01:00
|
|
|
#include "aconfig.h"
|
1999-01-30 20:12:34 +01:00
|
|
|
#include "version.h"
|
1998-10-29 23:45:59 +01:00
|
|
|
#include <getopt.h>
|
|
|
|
#include <stdarg.h>
|
2000-08-25 16:34:26 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
2013-04-05 11:51:51 +02:00
|
|
|
#include <syslog.h>
|
2013-04-10 09:42:40 +02:00
|
|
|
#include <sched.h>
|
2005-05-10 12:55:24 +02:00
|
|
|
#include "alsactl.h"
|
1998-10-29 23:45:59 +01:00
|
|
|
|
2010-11-23 02:59:18 +01:00
|
|
|
#ifndef SYS_ASOUNDRC
|
|
|
|
#define SYS_ASOUNDRC "/var/lib/alsa/asound.state"
|
|
|
|
#endif
|
2013-04-05 11:51:51 +02:00
|
|
|
#ifndef SYS_PIDFILE
|
|
|
|
#define SYS_PIDFILE "/var/run/alsactl.pid"
|
|
|
|
#endif
|
2014-05-06 21:32:19 +02:00
|
|
|
#ifndef SYS_LOCKPATH
|
|
|
|
#define SYS_LOCKPATH "/var/lock"
|
|
|
|
#endif
|
1998-10-29 23:45:59 +01:00
|
|
|
|
|
|
|
int debugflag = 0;
|
2007-11-14 11:54:38 +01:00
|
|
|
int force_restore = 1;
|
2008-09-18 09:40:02 +02:00
|
|
|
int ignore_nocards = 0;
|
2013-04-05 11:51:51 +02:00
|
|
|
int do_lock = 0;
|
|
|
|
int use_syslog = 0;
|
2000-08-25 16:34:26 +02:00
|
|
|
char *command;
|
2008-08-14 16:46:27 +02:00
|
|
|
char *statefile = NULL;
|
2014-05-07 11:13:41 +02:00
|
|
|
char *lockfile = SYS_LOCKFILE;
|
1998-10-29 23:45:59 +01:00
|
|
|
|
2013-04-05 13:42:15 +02:00
|
|
|
#define TITLE 0x0100
|
|
|
|
#define HEADER 0x0200
|
|
|
|
#define FILEARG 0x0400
|
|
|
|
#define ENVARG 0x0800
|
|
|
|
#define INTARG 0x1000
|
|
|
|
#define EMPCMD 0x2000
|
|
|
|
#define CARDCMD 0x4000
|
|
|
|
#define KILLCMD 0x8000
|
|
|
|
|
|
|
|
struct arg {
|
|
|
|
int sarg;
|
|
|
|
char *larg;
|
|
|
|
char *comment;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct arg args[] = {
|
|
|
|
{ TITLE, NULL, "Usage: alsactl <options> command" },
|
|
|
|
{ HEADER, NULL, "global options:" },
|
|
|
|
{ 'h', "help", "this help" },
|
|
|
|
{ 'd', "debug", "debug mode" },
|
|
|
|
{ 'v', "version", "print version of this program" },
|
|
|
|
{ HEADER, NULL, "Available state options:" },
|
|
|
|
{ FILEARG | 'f', "file", "configuration file (default " SYS_ASOUNDRC ")" },
|
|
|
|
{ 'l', "lock", "use file locking to serialize concurrent access" },
|
2014-05-07 11:13:41 +02:00
|
|
|
{ 'L', "no-lock", "do not use file locking to serialize concurrent access" },
|
|
|
|
{ FILEARG | 'O', "lock-state-file", "state lock file path (default " SYS_LOCKFILE ")" },
|
2013-04-05 13:42:15 +02:00
|
|
|
{ 'F', "force", "try to restore the matching controls as much as possible" },
|
|
|
|
{ 0, NULL, " (default mode)" },
|
|
|
|
{ 'g', "ignore", "ignore 'No soundcards found' error" },
|
|
|
|
{ 'P', "pedantic", "do not restore mismatching controls (old default)" },
|
|
|
|
{ 'I', "no-init-fallback", "" },
|
|
|
|
{ 0, NULL, "don't initialize even if restore fails" },
|
|
|
|
{ FILEARG | 'r', "runstate", "save restore and init state to this file (only errors)" },
|
|
|
|
{ 0, NULL, " default settings is 'no file set'" },
|
|
|
|
{ 'R', "remove", "remove runstate file at first, otherwise append errors" },
|
|
|
|
{ INTARG | 'p', "period", "store period in seconds for the daemon command" },
|
|
|
|
{ FILEARG | 'e', "pid-file", "pathname for the process id (daemon mode)" },
|
|
|
|
{ HEADER, NULL, "Available init options:" },
|
|
|
|
{ ENVARG | 'E', "env", "set environment variable for init phase (NAME=VALUE)" },
|
|
|
|
{ FILEARG | 'i', "initfile", "main configuation file for init phase" },
|
|
|
|
{ 0, NULL, " (default " DATADIR "/init/00main)" },
|
|
|
|
{ 'b', "background", "run daemon in background" },
|
|
|
|
{ 's', "syslog", "use syslog for messages" },
|
2013-04-10 09:42:40 +02:00
|
|
|
{ INTARG | 'n', "nice", "set the process priority (see 'man nice')" },
|
|
|
|
{ 'c', "sched-idle", "set the process scheduling policy to idle (SCHED_IDLE)" },
|
2020-05-14 19:54:04 +02:00
|
|
|
#ifdef HAVE_ALSA_USE_CASE_H
|
2020-05-14 19:34:18 +02:00
|
|
|
{ 'D', "ucm-defaults", "execute also the UCM 'defaults' section" },
|
2020-10-02 05:45:43 +02:00
|
|
|
{ 'U', "no-ucm", "don't init with UCM" },
|
2020-05-14 19:54:04 +02:00
|
|
|
#endif
|
2013-04-05 13:42:15 +02:00
|
|
|
{ HEADER, NULL, "Available commands:" },
|
|
|
|
{ CARDCMD, "store", "save current driver setup for one or each soundcards" },
|
|
|
|
{ EMPCMD, NULL, " to configuration file" },
|
|
|
|
{ CARDCMD, "restore", "load current driver setup for one or each soundcards" },
|
|
|
|
{ EMPCMD, NULL, " from configuration file" },
|
|
|
|
{ CARDCMD, "nrestore", "like restore, but notify the daemon to rescan soundcards" },
|
|
|
|
{ CARDCMD, "init", "initialize driver to a default state" },
|
|
|
|
{ CARDCMD, "daemon", "store state periodically for one or each soundcards" },
|
|
|
|
{ CARDCMD, "rdaemon", "like daemon but do the state restore at first" },
|
|
|
|
{ KILLCMD, "kill", "notify daemon to quit, rescan or save_and_quit" },
|
2013-11-26 11:44:40 +01:00
|
|
|
{ CARDCMD, "monitor", "monitor control events" },
|
2021-03-07 19:58:33 +01:00
|
|
|
{ EMPCMD, "dump-state", "dump the state (for all cards)" },
|
|
|
|
{ EMPCMD, "dump-cfg", "dump the configuration (expanded, for all cards)" },
|
2013-04-05 13:42:15 +02:00
|
|
|
{ 0, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
1998-11-27 16:13:57 +01:00
|
|
|
static void help(void)
|
1998-10-29 23:45:59 +01:00
|
|
|
{
|
2013-04-05 13:42:15 +02:00
|
|
|
struct arg *n = args, *a;
|
|
|
|
char *larg, sa[4], buf[32];
|
|
|
|
int sarg;
|
|
|
|
|
|
|
|
sa[0] = '-';
|
|
|
|
sa[2] = ',';
|
|
|
|
sa[3] = '\0';
|
|
|
|
while (n->comment) {
|
|
|
|
a = n;
|
|
|
|
n++;
|
|
|
|
sarg = a->sarg;
|
|
|
|
if (sarg & (HEADER|TITLE)) {
|
|
|
|
printf("%s%s\n", (sarg & HEADER) != 0 ? "\n" : "",
|
|
|
|
a->comment);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
buf[0] = '\0';
|
|
|
|
larg = a->larg;
|
|
|
|
if (sarg & (EMPCMD|CARDCMD|KILLCMD)) {
|
|
|
|
if (sarg & CARDCMD)
|
|
|
|
strcat(buf, "<card>");
|
|
|
|
else if (sarg & KILLCMD)
|
|
|
|
strcat(buf, "<cmd>");
|
2021-03-07 19:58:33 +01:00
|
|
|
printf(" %-10s %-6s %s\n", larg ? larg : "",
|
2013-04-05 13:42:15 +02:00
|
|
|
buf, a->comment);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
sa[1] = a->sarg;
|
|
|
|
sprintf(buf, "%s%s%s", sa[1] ? sa : "",
|
|
|
|
larg ? "--" : "", larg ? larg : "");
|
|
|
|
if (sarg & ENVARG)
|
|
|
|
strcat(buf, " #=#");
|
|
|
|
else if (sarg & (FILEARG|INTARG))
|
|
|
|
strcat(buf, " #");
|
|
|
|
printf(" %-15s %s\n", buf, a->comment);
|
|
|
|
}
|
2000-08-25 16:34:26 +02:00
|
|
|
}
|
|
|
|
|
2021-03-07 19:58:33 +01:00
|
|
|
static int dump_config_tree(snd_config_t *top)
|
|
|
|
{
|
|
|
|
snd_output_t *out;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = snd_output_stdio_attach(&out, stdout, 0);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
err = snd_config_save(top, out);
|
|
|
|
snd_output_close(out);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dump_state(const char *file)
|
|
|
|
{
|
|
|
|
snd_config_t *top;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = load_configuration(file, &top, NULL);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
err = dump_config_tree(top);
|
|
|
|
snd_config_delete(top);
|
|
|
|
snd_config_update_free_global();
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dump_configuration(void)
|
|
|
|
{
|
|
|
|
snd_config_t *top, *cfg2;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = snd_config_update_ref(&top);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
/* expand cards.* tree */
|
|
|
|
snd_config_search_definition(top, "cards", "dummy", &cfg2);
|
|
|
|
err = dump_config_tree(top);
|
|
|
|
snd_config_unref(top);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-04-10 09:42:40 +02:00
|
|
|
#define NO_NICE (-100000)
|
|
|
|
|
|
|
|
static void do_nice(int use_nice, int sched_idle)
|
|
|
|
{
|
|
|
|
struct sched_param sched_param;
|
|
|
|
|
|
|
|
if (use_nice != NO_NICE && nice(use_nice) < 0)
|
|
|
|
error("nice(%i): %s", use_nice, strerror(errno));
|
|
|
|
if (sched_idle) {
|
|
|
|
if (sched_getparam(0, &sched_param) >= 0) {
|
|
|
|
sched_param.sched_priority = 0;
|
2020-04-16 12:35:21 +02:00
|
|
|
if (sched_setscheduler(0, SCHED_IDLE, &sched_param) < 0)
|
2013-04-10 09:42:40 +02:00
|
|
|
error("sched_setparam failed: %s", strerror(errno));
|
|
|
|
} else {
|
|
|
|
error("sched_getparam failed: %s", strerror(errno));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-27 16:13:57 +01:00
|
|
|
int main(int argc, char *argv[])
|
1998-10-29 23:45:59 +01:00
|
|
|
{
|
2008-11-21 13:10:02 +01:00
|
|
|
static const char *const devfiles[] = {
|
2008-08-18 16:57:18 +02:00
|
|
|
"/dev/snd/controlC",
|
|
|
|
"/dev/snd/pcmC",
|
|
|
|
"/dev/snd/midiC",
|
|
|
|
"/dev/snd/hwC",
|
|
|
|
NULL
|
|
|
|
};
|
2000-08-25 16:34:26 +02:00
|
|
|
char *cfgfile = SYS_ASOUNDRC;
|
2008-07-31 15:45:08 +02:00
|
|
|
char *initfile = DATADIR "/init/00main";
|
2013-04-05 11:51:51 +02:00
|
|
|
char *pidfile = SYS_PIDFILE;
|
2009-02-18 15:34:57 +01:00
|
|
|
char *cardname, ncardname[16];
|
2013-04-05 11:51:51 +02:00
|
|
|
char *cmd;
|
2021-02-26 19:28:03 +01:00
|
|
|
char *const *extra_args;
|
2009-02-18 15:34:57 +01:00
|
|
|
const char *const *tmp;
|
2008-08-18 16:47:33 +02:00
|
|
|
int removestate = 0;
|
2008-11-13 09:28:43 +01:00
|
|
|
int init_fallback = 1; /* new default behavior */
|
2013-04-05 11:51:51 +02:00
|
|
|
int period = 5*60;
|
|
|
|
int background = 0;
|
2013-04-08 14:49:31 +02:00
|
|
|
int daemoncmd = 0;
|
2013-04-10 09:42:40 +02:00
|
|
|
int use_nice = NO_NICE;
|
|
|
|
int sched_idle = 0;
|
2020-05-14 19:34:18 +02:00
|
|
|
int initflags = 0;
|
2013-04-05 13:42:15 +02:00
|
|
|
struct arg *a;
|
|
|
|
struct option *o;
|
|
|
|
int i, j, k, res;
|
|
|
|
struct option *long_option;
|
|
|
|
char *short_option;
|
1998-11-27 16:13:57 +01:00
|
|
|
|
2013-04-05 13:42:15 +02:00
|
|
|
long_option = calloc(ARRAY_SIZE(args), sizeof(struct option));
|
|
|
|
if (long_option == NULL)
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
short_option = malloc(128);
|
|
|
|
if (short_option == NULL) {
|
|
|
|
free(long_option);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
for (i = j = k = 0; i < ARRAY_SIZE(args); i++) {
|
|
|
|
a = &args[i];
|
|
|
|
if ((a->sarg & 0xff) == 0)
|
|
|
|
continue;
|
|
|
|
o = &long_option[j];
|
2013-04-08 14:49:31 +02:00
|
|
|
o->name = a->larg;
|
2013-04-05 13:42:15 +02:00
|
|
|
o->has_arg = (a->sarg & (ENVARG|FILEARG|INTARG)) != 0;
|
|
|
|
o->flag = NULL;
|
|
|
|
o->val = a->sarg & 0xff;
|
|
|
|
j++;
|
|
|
|
short_option[k++] = o->val;
|
|
|
|
if (o->has_arg)
|
|
|
|
short_option[k++] = ':';
|
|
|
|
}
|
|
|
|
short_option[k] = '\0';
|
2000-08-25 16:34:26 +02:00
|
|
|
command = argv[0];
|
1998-11-27 16:13:57 +01:00
|
|
|
while (1) {
|
|
|
|
int c;
|
|
|
|
|
2013-04-05 13:42:15 +02:00
|
|
|
if ((c = getopt_long(argc, argv, short_option, long_option,
|
|
|
|
NULL)) < 0)
|
1998-11-27 16:13:57 +01:00
|
|
|
break;
|
|
|
|
switch (c) {
|
|
|
|
case 'h':
|
2005-01-31 18:49:04 +01:00
|
|
|
help();
|
2013-04-05 13:42:15 +02:00
|
|
|
res = EXIT_SUCCESS;
|
|
|
|
goto out;
|
1998-11-27 16:13:57 +01:00
|
|
|
case 'f':
|
2000-08-25 16:34:26 +02:00
|
|
|
cfgfile = optarg;
|
1998-11-27 16:13:57 +01:00
|
|
|
break;
|
2013-04-05 11:51:51 +02:00
|
|
|
case 'l':
|
|
|
|
do_lock = 1;
|
|
|
|
break;
|
2014-05-07 11:13:41 +02:00
|
|
|
case 'L':
|
|
|
|
do_lock = -1;
|
|
|
|
break;
|
|
|
|
case 'O':
|
|
|
|
lockfile = optarg;
|
|
|
|
break;
|
2002-09-06 17:21:01 +02:00
|
|
|
case 'F':
|
|
|
|
force_restore = 1;
|
|
|
|
break;
|
2008-09-18 09:40:02 +02:00
|
|
|
case 'g':
|
|
|
|
ignore_nocards = 1;
|
|
|
|
break;
|
2008-07-31 15:45:08 +02:00
|
|
|
case 'E':
|
|
|
|
if (putenv(optarg)) {
|
|
|
|
fprintf(stderr, "environment string '%s' is wrong\n", optarg);
|
2013-04-05 13:42:15 +02:00
|
|
|
res = EXIT_FAILURE;
|
|
|
|
goto out;
|
2008-07-31 15:45:08 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
initfile = optarg;
|
|
|
|
break;
|
2008-11-13 09:28:43 +01:00
|
|
|
case 'I':
|
|
|
|
init_fallback = 0;
|
|
|
|
break;
|
2020-05-14 19:34:18 +02:00
|
|
|
case 'D':
|
|
|
|
initflags |= FLAG_UCM_DEFAULTS;
|
|
|
|
break;
|
2020-10-02 05:45:43 +02:00
|
|
|
case 'U':
|
|
|
|
initflags |= FLAG_UCM_DISABLED;
|
|
|
|
break;
|
2008-08-14 16:46:27 +02:00
|
|
|
case 'r':
|
|
|
|
statefile = optarg;
|
|
|
|
break;
|
2008-08-18 16:47:33 +02:00
|
|
|
case 'R':
|
|
|
|
removestate = 1;
|
|
|
|
break;
|
2007-11-14 11:54:38 +01:00
|
|
|
case 'P':
|
|
|
|
force_restore = 0;
|
|
|
|
break;
|
2013-04-05 11:51:51 +02:00
|
|
|
case 'p':
|
|
|
|
period = atoi(optarg);
|
|
|
|
if (period < 10)
|
|
|
|
period = 5*60;
|
|
|
|
else if (period > 24*60*60)
|
|
|
|
period = 24*60*60;
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
pidfile = optarg;
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
background = 1;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
use_syslog = 1;
|
|
|
|
break;
|
2013-04-10 09:42:40 +02:00
|
|
|
case 'n':
|
|
|
|
use_nice = atoi(optarg);
|
|
|
|
if (use_nice < -20)
|
|
|
|
use_nice = -20;
|
|
|
|
else if (use_nice > 19)
|
|
|
|
use_nice = 19;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
sched_idle = 1;
|
|
|
|
break;
|
1998-11-27 16:13:57 +01:00
|
|
|
case 'd':
|
|
|
|
debugflag = 1;
|
|
|
|
break;
|
|
|
|
case 'v':
|
1999-01-30 20:12:34 +01:00
|
|
|
printf("alsactl version " SND_UTIL_VERSION_STR "\n");
|
2013-04-05 13:42:15 +02:00
|
|
|
res = EXIT_SUCCESS;
|
|
|
|
goto out;
|
2002-12-04 15:41:32 +01:00
|
|
|
case '?': // error msg already printed
|
2005-01-31 18:49:04 +01:00
|
|
|
help();
|
2013-04-05 13:42:15 +02:00
|
|
|
res = EXIT_FAILURE;
|
|
|
|
goto out;
|
2002-12-04 15:41:32 +01:00
|
|
|
default: // should never happen
|
|
|
|
fprintf(stderr,
|
|
|
|
"Invalid option '%c' (%d) not handled??\n", c, c);
|
1998-11-27 16:13:57 +01:00
|
|
|
}
|
|
|
|
}
|
2013-04-05 13:42:15 +02:00
|
|
|
free(short_option);
|
2013-04-10 09:42:40 +02:00
|
|
|
short_option = NULL;
|
2013-04-05 13:42:15 +02:00
|
|
|
free(long_option);
|
|
|
|
long_option = NULL;
|
1998-11-27 16:13:57 +01:00
|
|
|
if (argc - optind <= 0) {
|
|
|
|
fprintf(stderr, "alsactl: Specify command...\n");
|
2013-04-05 13:42:15 +02:00
|
|
|
res = 0;
|
|
|
|
goto out;
|
1998-11-27 16:13:57 +01:00
|
|
|
}
|
2002-12-04 15:41:32 +01:00
|
|
|
|
2008-08-14 16:46:27 +02:00
|
|
|
cardname = argc - optind > 1 ? argv[optind + 1] : NULL;
|
2008-09-11 13:39:42 +02:00
|
|
|
for (tmp = devfiles; cardname != NULL && *tmp != NULL; tmp++) {
|
2008-08-18 16:57:18 +02:00
|
|
|
int len = strlen(*tmp);
|
|
|
|
if (!strncmp(cardname, *tmp, len)) {
|
|
|
|
long l = strtol(cardname + len, NULL, 0);
|
|
|
|
sprintf(ncardname, "%li", l);
|
|
|
|
cardname = ncardname;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-26 19:28:03 +01:00
|
|
|
extra_args = argc - optind > 2 ? argv + optind + 2 : NULL;
|
|
|
|
|
2013-04-05 11:51:51 +02:00
|
|
|
/* the global system file should be always locked */
|
2014-05-07 11:13:41 +02:00
|
|
|
if (strcmp(cfgfile, SYS_ASOUNDRC) == 0 && do_lock >= 0)
|
2013-04-05 11:51:51 +02:00
|
|
|
do_lock = 1;
|
|
|
|
|
|
|
|
/* when running in background, use syslog for reports */
|
|
|
|
if (background) {
|
|
|
|
use_syslog = 1;
|
2021-03-05 21:43:45 +01:00
|
|
|
if (daemon(0, 0)) {
|
|
|
|
syslog(LOG_INFO, "alsactl " SND_UTIL_VERSION_STR " daemon cannot be started: %s", strerror(errno));
|
2021-03-07 20:00:15 +01:00
|
|
|
res = EXIT_FAILURE;
|
2021-03-05 21:43:45 +01:00
|
|
|
goto out;
|
|
|
|
}
|
2013-04-05 11:51:51 +02:00
|
|
|
}
|
|
|
|
|
2013-04-08 14:49:31 +02:00
|
|
|
cmd = argv[optind];
|
|
|
|
daemoncmd = strcmp(cmd, "daemon") == 0 || strcmp(cmd, "rdaemon") == 0;
|
|
|
|
|
2013-04-05 11:51:51 +02:00
|
|
|
if (use_syslog) {
|
|
|
|
openlog("alsactl", LOG_CONS|LOG_PID, LOG_DAEMON);
|
2013-04-08 14:49:31 +02:00
|
|
|
if (daemoncmd)
|
|
|
|
syslog(LOG_INFO, "alsactl " SND_UTIL_VERSION_STR " daemon started");
|
2013-04-05 11:51:51 +02:00
|
|
|
}
|
|
|
|
|
2020-05-14 19:09:45 +02:00
|
|
|
snd_lib_error_set_handler(error_handler);
|
|
|
|
|
2013-04-05 11:51:51 +02:00
|
|
|
if (!strcmp(cmd, "init")) {
|
2020-05-14 19:34:18 +02:00
|
|
|
res = init(initfile, initflags, cardname);
|
2013-04-03 11:13:41 +02:00
|
|
|
snd_config_update_free_global();
|
2013-04-05 11:51:51 +02:00
|
|
|
} else if (!strcmp(cmd, "store")) {
|
2008-08-14 16:46:27 +02:00
|
|
|
res = save_state(cfgfile, cardname);
|
2013-04-05 11:51:51 +02:00
|
|
|
} else if (!strcmp(cmd, "restore") ||
|
|
|
|
!strcmp(cmd, "rdaemon") ||
|
|
|
|
!strcmp(cmd, "nrestore")) {
|
2008-08-18 16:47:33 +02:00
|
|
|
if (removestate)
|
|
|
|
remove(statefile);
|
2020-05-14 19:34:18 +02:00
|
|
|
res = load_state(cfgfile, initfile, initflags, cardname, init_fallback);
|
2013-04-10 09:42:40 +02:00
|
|
|
if (!strcmp(cmd, "rdaemon")) {
|
|
|
|
do_nice(use_nice, sched_idle);
|
2013-04-05 11:51:51 +02:00
|
|
|
res = state_daemon(cfgfile, cardname, period, pidfile);
|
2013-04-10 09:42:40 +02:00
|
|
|
}
|
2013-04-05 11:51:51 +02:00
|
|
|
if (!strcmp(cmd, "nrestore"))
|
|
|
|
res = state_daemon_kill(pidfile, "rescan");
|
|
|
|
} else if (!strcmp(cmd, "daemon")) {
|
2013-04-10 09:42:40 +02:00
|
|
|
do_nice(use_nice, sched_idle);
|
2013-04-05 11:51:51 +02:00
|
|
|
res = state_daemon(cfgfile, cardname, period, pidfile);
|
|
|
|
} else if (!strcmp(cmd, "kill")) {
|
|
|
|
res = state_daemon_kill(pidfile, cardname);
|
2013-11-26 11:44:40 +01:00
|
|
|
} else if (!strcmp(cmd, "monitor")) {
|
|
|
|
res = monitor(cardname);
|
2021-02-26 19:28:03 +01:00
|
|
|
} else if (!strcmp(cmd, "clean")) {
|
|
|
|
res = clean(cardname, extra_args);
|
2021-03-07 19:58:33 +01:00
|
|
|
} else if (!strcmp(cmd, "dump-state")) {
|
|
|
|
res = dump_state(cfgfile);
|
|
|
|
} else if (!strcmp(cmd, "dump-cfg")) {
|
|
|
|
res = dump_configuration();
|
1998-11-27 16:13:57 +01:00
|
|
|
} else {
|
2013-04-05 11:51:51 +02:00
|
|
|
fprintf(stderr, "alsactl: Unknown command '%s'...\n", cmd);
|
2002-12-04 15:41:32 +01:00
|
|
|
res = -ENODEV;
|
1998-11-27 16:13:57 +01:00
|
|
|
}
|
|
|
|
|
2008-08-19 13:28:22 +02:00
|
|
|
snd_config_update_free_global();
|
2013-04-05 11:51:51 +02:00
|
|
|
if (use_syslog) {
|
2013-04-08 14:49:31 +02:00
|
|
|
if (daemoncmd)
|
|
|
|
syslog(LOG_INFO, "alsactl daemon stopped");
|
2013-04-05 11:51:51 +02:00
|
|
|
closelog();
|
|
|
|
}
|
2010-02-14 19:07:25 +01:00
|
|
|
return res < 0 ? -res : 0;
|
2013-04-05 13:42:15 +02:00
|
|
|
|
|
|
|
out:
|
|
|
|
free(short_option);
|
|
|
|
free(long_option);
|
|
|
|
return res;
|
1998-10-29 23:45:59 +01:00
|
|
|
}
|