udevadm-trigger: introduce --quiet option

This may be useful to invoke the command by non-privileged users.
This commit is contained in:
Yu Watanabe 2021-02-20 16:31:40 +09:00
parent 0e789e6d48
commit 6c99c26500
4 changed files with 17 additions and 2 deletions

View file

@ -212,6 +212,13 @@
<para>Do not actually trigger the event.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-q</option></term>
<term><option>--quiet</option></term>
<listitem>
<para>Suppress error logging in triggering events.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-t</option></term>
<term><option>--type=<replaceable>TYPE</replaceable></option></term>

View file

@ -51,7 +51,7 @@ _udevadm() {
[INFO_STANDALONE]='-r --root -a --attribute-walk -x --export -e --export-db -c --cleanup-db
-w --wait-for-initialization'
[INFO_ARG]='-q --query -p --path -n --name -P --export-prefix -d --device-id-of-file'
[TRIGGER_STANDALONE]='-v --verbose -n --dry-run -w --settle --wait-daemon'
[TRIGGER_STANDALONE]='-v --verbose -n --dry-run -q --quiet -w --settle --wait-daemon'
[TRIGGER_ARG]='-t --type -c --action -s --subsystem-match -S --subsystem-nomatch
-a --attr-match -A --attr-nomatch -p --property-match
-g --tag-match -y --sysname-match --name-match -b --parent-match'

View file

@ -21,6 +21,7 @@ _udevadm_trigger(){
_arguments \
'--verbose[Print the list of devices which will be triggered.]' \
'--dry-run[Do not actually trigger the event.]' \
'--quiet[Suppress error logging in triggering events.]' \
'--type=[Trigger a specific type of devices.]:types:(devices subsystems failed)' \
'--action=[Type of event to be triggered.]:actions:(add change remove)' \
'--subsystem-match=[Trigger events for devices which belong to a matching subsystem.]' \

View file

@ -23,6 +23,7 @@
static bool arg_verbose = false;
static bool arg_dry_run = false;
static bool arg_quiet = false;
static int exec_list(sd_device_enumerator *e, sd_device_action_t action, Set **settle_set) {
const char *action_str;
@ -70,6 +71,7 @@ static int exec_list(sd_device_enumerator *e, sd_device_action_t action, Set **s
bool ignore = IN_SET(r, -ENOENT, -ENODEV);
int level =
arg_quiet ? LOG_DEBUG :
r == -ENOENT ? LOG_DEBUG :
r == -ENODEV ? LOG_WARNING : LOG_ERR;
@ -144,6 +146,7 @@ static int help(void) {
" -V --version Show package version\n"
" -v --verbose Print the list of devices while running\n"
" -n --dry-run Do not actually trigger the events\n"
" -q --quiet Suppress error logging in triggering events\n"
" -t --type= Type of events to trigger\n"
" devices sysfs devices (default)\n"
" subsystems sysfs subsystems and drivers\n"
@ -174,6 +177,7 @@ int trigger_main(int argc, char *argv[], void *userdata) {
static const struct option options[] = {
{ "verbose", no_argument, NULL, 'v' },
{ "dry-run", no_argument, NULL, 'n' },
{ "quiet", no_argument, NULL, 'q' },
{ "type", required_argument, NULL, 't' },
{ "action", required_argument, NULL, 'c' },
{ "subsystem-match", required_argument, NULL, 's' },
@ -217,7 +221,7 @@ int trigger_main(int argc, char *argv[], void *userdata) {
if (r < 0)
return r;
while ((c = getopt_long(argc, argv, "vnt:c:s:S:a:A:p:g:y:b:wVh", options, NULL)) >= 0) {
while ((c = getopt_long(argc, argv, "vnqt:c:s:S:a:A:p:g:y:b:wVh", options, NULL)) >= 0) {
_cleanup_free_ char *buf = NULL;
const char *key, *val;
@ -228,6 +232,9 @@ int trigger_main(int argc, char *argv[], void *userdata) {
case 'n':
arg_dry_run = true;
break;
case 'q':
arg_quiet = true;
break;
case 't':
if (streq(optarg, "devices"))
device_type = TYPE_DEVICES;