mirror of
https://github.com/systemd/systemd.git
synced 2025-08-30 05:49:54 +03:00
Merge pull request #11107 from keszybz/udevadm-info-args
Allow multiple args in udevadm info
This commit is contained in:
@ -76,39 +76,40 @@
|
|||||||
|
|
||||||
<refsect2><title>udevadm info
|
<refsect2><title>udevadm info
|
||||||
<arg choice="opt"><replaceable>options</replaceable></arg>
|
<arg choice="opt"><replaceable>options</replaceable></arg>
|
||||||
<arg choice="opt"><replaceable>devpath</replaceable>|<replaceable>file</replaceable></arg>
|
<arg choice="opt" rep="repeat"><replaceable>devpath</replaceable>|<replaceable>file</replaceable>|<replaceable>unit</replaceable></arg>
|
||||||
</title>
|
</title>
|
||||||
|
|
||||||
<para>Queries the udev database for device information
|
<para>Query the udev database for device information.</para>
|
||||||
stored in the udev database. It can also query the properties
|
|
||||||
of a device from its sysfs representation to help creating udev
|
<para>Positional arguments should be used to specify one or more devices. Each one may be a device name
|
||||||
rules that match this device.</para>
|
(in which case it must start with <filename>/dev/</filename>), a sys path (in which case it must start
|
||||||
|
with <filename>/sys/</filename>), or a systemd device unit name (in which case it must end with
|
||||||
|
<literal>.device</literal>, see
|
||||||
|
<citerefentry><refentrytitle>systemd.device</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
|
||||||
|
</para>
|
||||||
|
|
||||||
<variablelist>
|
<variablelist>
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><option>-q</option></term>
|
<term><option>-q</option></term>
|
||||||
<term><option>--query=<replaceable>TYPE</replaceable></option></term>
|
<term><option>--query=<replaceable>TYPE</replaceable></option></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>Query the database for the specified type of device
|
<para>Query the database for the specified type of device data.
|
||||||
data. It needs the <option>--path</option> or
|
|
||||||
<option>--name</option> to identify the specified device.
|
|
||||||
Valid <replaceable>TYPE</replaceable>s are:
|
Valid <replaceable>TYPE</replaceable>s are:
|
||||||
<constant>name</constant>, <constant>symlink</constant>,
|
<constant>name</constant>, <constant>symlink</constant>,
|
||||||
<constant>path</constant>, <constant>property</constant>,
|
<constant>path</constant>, <constant>property</constant>,
|
||||||
<constant>all</constant>.</para>
|
<constant>all</constant>.</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><option>-p</option></term>
|
<term><option>-p</option></term>
|
||||||
<term><option>--path=<replaceable>DEVPATH</replaceable></option></term>
|
<term><option>--path=<replaceable>DEVPATH</replaceable></option></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>The <filename>/sys</filename> path of the device to
|
<para>The <filename>/sys</filename> path of the device to query, e.g.
|
||||||
query, e.g.
|
<filename><optional>/sys</optional>/class/block/sda</filename>. This option is an alternative to
|
||||||
<filename><optional>/sys</optional>/class/block/sda</filename>.
|
the positional argument with a <filename>/sys/</filename> prefix. <command>udevadm info
|
||||||
Note that this option usually is not very useful, since
|
--path=/class/block/sda</command> is equivalent to <command>udevadm info
|
||||||
<command>udev</command> can guess the type of the
|
/sys/class/block/sda</command>.</para>
|
||||||
argument, so <command>udevadm info
|
|
||||||
--path=/class/block/sda</command> is equivalent to
|
|
||||||
<command>udevadm info /sys/class/block/sda</command>.</para>
|
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
@ -116,11 +117,9 @@
|
|||||||
<term><option>--name=<replaceable>FILE</replaceable></option></term>
|
<term><option>--name=<replaceable>FILE</replaceable></option></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>The name of the device node or a symlink to query,
|
<para>The name of the device node or a symlink to query,
|
||||||
e.g. <filename><optional>/dev</optional>/sda</filename>.
|
e.g. <filename><optional>/dev</optional>/sda</filename>. This option is an alternative to the
|
||||||
Note that this option usually is not very useful, since
|
positional argument with a <filename>/dev/</filename> prefix. <command>udevadm info
|
||||||
<command>udev</command> can guess the type of the
|
--name=sda</command> is equivalent to <command>udevadm info /dev/sda</command>.</para>
|
||||||
argument, so <command>udevadm info --name=sda</command> is
|
|
||||||
equivalent to <command>udevadm info /dev/sda</command>.</para>
|
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
@ -179,17 +178,17 @@
|
|||||||
|
|
||||||
<xi:include href="standard-options.xml" xpointer="help" />
|
<xi:include href="standard-options.xml" xpointer="help" />
|
||||||
</variablelist>
|
</variablelist>
|
||||||
|
|
||||||
<para>In addition, an optional positional argument can be used
|
|
||||||
to specify a device name or a sys path. It must start with
|
|
||||||
<filename>/dev</filename> or <filename>/sys</filename>
|
|
||||||
respectively.</para>
|
|
||||||
</refsect2>
|
</refsect2>
|
||||||
|
|
||||||
<refsect2><title>udevadm trigger
|
<refsect2><title>udevadm trigger
|
||||||
<arg choice="opt"><replaceable>options</replaceable></arg>
|
<arg choice="opt"><replaceable>options</replaceable></arg>
|
||||||
<arg choice="opt" rep="repeat"><replaceable>devpath</replaceable>|<replaceable>file</replaceable></arg></title>
|
<arg choice="opt" rep="repeat"><replaceable>devpath</replaceable>|<replaceable>file</replaceable>|<replaceable>unit</replaceable></arg>
|
||||||
|
</title>
|
||||||
<para>Request device events from the kernel. Primarily used to replay events at system coldplug time.</para>
|
<para>Request device events from the kernel. Primarily used to replay events at system coldplug time.</para>
|
||||||
|
|
||||||
|
<para>Takes one or more device specifications as arguments. See the description of <command>info</command>
|
||||||
|
above.</para>
|
||||||
|
|
||||||
<variablelist>
|
<variablelist>
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><option>-v</option></term>
|
<term><option>-v</option></term>
|
||||||
|
@ -22,6 +22,24 @@
|
|||||||
#include "udevadm.h"
|
#include "udevadm.h"
|
||||||
#include "udevadm-util.h"
|
#include "udevadm-util.h"
|
||||||
|
|
||||||
|
typedef enum ActionType {
|
||||||
|
ACTION_QUERY,
|
||||||
|
ACTION_ATTRIBUTE_WALK,
|
||||||
|
ACTION_DEVICE_ID_FILE,
|
||||||
|
} ActionType;
|
||||||
|
|
||||||
|
typedef enum QueryType {
|
||||||
|
QUERY_NAME,
|
||||||
|
QUERY_PATH,
|
||||||
|
QUERY_SYMLINK,
|
||||||
|
QUERY_PROPERTY,
|
||||||
|
QUERY_ALL,
|
||||||
|
} QueryType;
|
||||||
|
|
||||||
|
static bool arg_root = false;
|
||||||
|
static bool arg_export = false;
|
||||||
|
static const char *arg_export_prefix = NULL;
|
||||||
|
|
||||||
static bool skip_attribute(const char *name) {
|
static bool skip_attribute(const char *name) {
|
||||||
static const char* const skip[] = {
|
static const char* const skip[] = {
|
||||||
"uevent",
|
"uevent",
|
||||||
@ -62,7 +80,7 @@ static void print_all_attributes(sd_device *device, const char *key) {
|
|||||||
|
|
||||||
printf(" %s{%s}==\"%s\"\n", key, name, value);
|
printf(" %s{%s}==\"%s\"\n", key, name, value);
|
||||||
}
|
}
|
||||||
printf("\n");
|
puts("");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int print_device_chain(sd_device *device) {
|
static int print_device_chain(sd_device *device) {
|
||||||
@ -106,26 +124,31 @@ static int print_device_chain(sd_device *device) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_record(sd_device *device) {
|
static int print_record(sd_device *device) {
|
||||||
const char *str, *val;
|
const char *str, *val;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
(void) sd_device_get_devpath(device, &str);
|
(void) sd_device_get_devpath(device, &str);
|
||||||
printf("P: %s\n", str);
|
printf("P: %s\n", str);
|
||||||
|
|
||||||
if (sd_device_get_devname(device, &str) >= 0)
|
if (sd_device_get_devname(device, &str) >= 0) {
|
||||||
printf("N: %s\n", str + STRLEN("/dev/"));
|
assert_se(val = path_startswith(str, "/dev/"));
|
||||||
|
printf("N: %s\n", val);
|
||||||
|
}
|
||||||
|
|
||||||
if (device_get_devlink_priority(device, &i) >= 0)
|
if (device_get_devlink_priority(device, &i) >= 0)
|
||||||
printf("L: %i\n", i);
|
printf("L: %i\n", i);
|
||||||
|
|
||||||
FOREACH_DEVICE_DEVLINK(device, str)
|
FOREACH_DEVICE_DEVLINK(device, str) {
|
||||||
printf("S: %s\n", str + STRLEN("/dev/"));
|
assert_se(val = path_startswith(str, "/dev/"));
|
||||||
|
printf("S: %s\n", val);
|
||||||
|
}
|
||||||
|
|
||||||
FOREACH_DEVICE_PROPERTY(device, str, val)
|
FOREACH_DEVICE_PROPERTY(device, str, val)
|
||||||
printf("E: %s=%s\n", str, val);
|
printf("E: %s=%s\n", str, val);
|
||||||
|
|
||||||
printf("\n");
|
puts("");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int stat_device(const char *name, bool export, const char *prefix) {
|
static int stat_device(const char *name, bool export, const char *prefix) {
|
||||||
@ -223,8 +246,69 @@ static void cleanup_db(void) {
|
|||||||
cleanup_dir(dir5, 0, 1);
|
cleanup_dir(dir5, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int help(void) {
|
static int query_device(QueryType query, sd_device* device) {
|
||||||
|
int r;
|
||||||
|
|
||||||
|
assert(device);
|
||||||
|
|
||||||
|
switch(query) {
|
||||||
|
case QUERY_NAME: {
|
||||||
|
const char *node;
|
||||||
|
|
||||||
|
r = sd_device_get_devname(device, &node);
|
||||||
|
if (r < 0)
|
||||||
|
return log_error_errno(r, "No device node found: %m");
|
||||||
|
|
||||||
|
if (!arg_root)
|
||||||
|
assert_se(node = path_startswith(node, "/dev/"));
|
||||||
|
printf("%s\n", node);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
case QUERY_SYMLINK: {
|
||||||
|
const char *devlink, *prefix = "";
|
||||||
|
|
||||||
|
FOREACH_DEVICE_DEVLINK(device, devlink) {
|
||||||
|
if (!arg_root)
|
||||||
|
assert_se(devlink = path_startswith(devlink, "/dev/"));
|
||||||
|
printf("%s%s", prefix, devlink);
|
||||||
|
prefix = " ";
|
||||||
|
}
|
||||||
|
puts("");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
case QUERY_PATH: {
|
||||||
|
const char *devpath;
|
||||||
|
|
||||||
|
r = sd_device_get_devpath(device, &devpath);
|
||||||
|
if (r < 0)
|
||||||
|
return log_error_errno(r, "Failed to get device path: %m");
|
||||||
|
|
||||||
|
printf("%s\n", devpath);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
case QUERY_PROPERTY: {
|
||||||
|
const char *key, *value;
|
||||||
|
|
||||||
|
FOREACH_DEVICE_PROPERTY(device, key, value)
|
||||||
|
if (arg_export)
|
||||||
|
printf("%s%s='%s'\n", strempty(arg_export_prefix), key, value);
|
||||||
|
else
|
||||||
|
printf("%s=%s\n", key, value);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
case QUERY_ALL:
|
||||||
|
return print_record(device);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_not_reached("unknown query type");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int help(void) {
|
||||||
printf("%s info [OPTIONS] [DEVPATH|FILE]\n\n"
|
printf("%s info [OPTIONS] [DEVPATH|FILE]\n\n"
|
||||||
"Query sysfs or the udev database.\n\n"
|
"Query sysfs or the udev database.\n\n"
|
||||||
" -h --help Print this message\n"
|
" -h --help Print this message\n"
|
||||||
@ -251,10 +335,8 @@ static int help(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int info_main(int argc, char *argv[], void *userdata) {
|
int info_main(int argc, char *argv[], void *userdata) {
|
||||||
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
|
_cleanup_strv_free_ char **devices = NULL;
|
||||||
bool root = false, export = false;
|
|
||||||
_cleanup_free_ char *name = NULL;
|
_cleanup_free_ char *name = NULL;
|
||||||
const char *export_prefix = NULL;
|
|
||||||
int c, r;
|
int c, r;
|
||||||
|
|
||||||
static const struct option options[] = {
|
static const struct option options[] = {
|
||||||
@ -273,42 +355,26 @@ int info_main(int argc, char *argv[], void *userdata) {
|
|||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
enum action_type {
|
ActionType action = ACTION_QUERY;
|
||||||
ACTION_QUERY,
|
QueryType query = QUERY_ALL;
|
||||||
ACTION_ATTRIBUTE_WALK,
|
|
||||||
ACTION_DEVICE_ID_FILE,
|
|
||||||
} action = ACTION_QUERY;
|
|
||||||
|
|
||||||
enum query_type {
|
|
||||||
QUERY_NAME,
|
|
||||||
QUERY_PATH,
|
|
||||||
QUERY_SYMLINK,
|
|
||||||
QUERY_PROPERTY,
|
|
||||||
QUERY_ALL,
|
|
||||||
} query = QUERY_ALL;
|
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, "aced:n:p:q:rxP:RVh", options, NULL)) >= 0)
|
while ((c = getopt_long(argc, argv, "aced:n:p:q:rxP:RVh", options, NULL)) >= 0)
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'n':
|
case 'n':
|
||||||
if (device) {
|
case 'p': {
|
||||||
log_error("device already specified");
|
const char *prefix = c == 'n' ? "/dev/" : "/sys/";
|
||||||
return -EINVAL;
|
char *path;
|
||||||
}
|
|
||||||
|
|
||||||
r = find_device(optarg, "/dev/", &device);
|
path = path_join(path_startswith(optarg, prefix) ? NULL : prefix, optarg);
|
||||||
if (r < 0)
|
if (!path)
|
||||||
return log_error_errno(r, "device node not found: %m");
|
return log_oom();
|
||||||
break;
|
|
||||||
case 'p':
|
|
||||||
if (device) {
|
|
||||||
log_error("device already specified");
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
r = find_device(optarg, "/sys", &device);
|
r = strv_consume(&devices, path);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "syspath not found: %m");
|
return log_oom();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case 'q':
|
case 'q':
|
||||||
action = ACTION_QUERY;
|
action = ACTION_QUERY;
|
||||||
if (streq(optarg, "property") || streq(optarg, "env"))
|
if (streq(optarg, "property") || streq(optarg, "env"))
|
||||||
@ -327,7 +393,7 @@ int info_main(int argc, char *argv[], void *userdata) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
root = true;
|
arg_root = true;
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
action = ACTION_DEVICE_ID_FILE;
|
action = ACTION_DEVICE_ID_FILE;
|
||||||
@ -344,10 +410,10 @@ int info_main(int argc, char *argv[], void *userdata) {
|
|||||||
cleanup_db();
|
cleanup_db();
|
||||||
return 0;
|
return 0;
|
||||||
case 'x':
|
case 'x':
|
||||||
export = true;
|
arg_export = true;
|
||||||
break;
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
export_prefix = optarg;
|
arg_export_prefix = optarg;
|
||||||
break;
|
break;
|
||||||
case 'V':
|
case 'V':
|
||||||
return print_version();
|
return print_version();
|
||||||
@ -359,94 +425,44 @@ int info_main(int argc, char *argv[], void *userdata) {
|
|||||||
assert_not_reached("Unknown option");
|
assert_not_reached("Unknown option");
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (action) {
|
|
||||||
case ACTION_QUERY:
|
|
||||||
if (!device) {
|
|
||||||
if (!argv[optind]) {
|
|
||||||
help();
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
r = find_device(argv[optind], NULL, &device);
|
|
||||||
if (r < 0)
|
|
||||||
return log_error_errno(r, "Unknown device, --name=, --path=, or absolute path in /dev/ or /sys expected: %m");
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(query) {
|
if (action == ACTION_DEVICE_ID_FILE) {
|
||||||
case QUERY_NAME: {
|
if (argv[optind])
|
||||||
const char *node;
|
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||||
|
"Positional arguments are not allowed with -d/--device-id-of-file.");
|
||||||
|
assert(name);
|
||||||
|
return stat_device(name, arg_export, arg_export_prefix);
|
||||||
|
}
|
||||||
|
|
||||||
r = sd_device_get_devname(device, &node);
|
r = strv_extend_strv(&devices, argv + optind, false);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "no device node found: %m");
|
return log_error_errno(r, "Failed to build argument list: %m");
|
||||||
|
|
||||||
if (root)
|
if (strv_isempty(devices))
|
||||||
printf("%s\n", node);
|
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||||
else
|
"A device name or path is required");
|
||||||
printf("%s\n", node + STRLEN("/dev/"));
|
if (action == ACTION_ATTRIBUTE_WALK && strv_length(devices) > 1)
|
||||||
break;
|
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||||
}
|
"Only one device may be specified with -a/--attribute-walk");
|
||||||
case QUERY_SYMLINK: {
|
|
||||||
const char *devlink;
|
|
||||||
bool first = true;
|
|
||||||
|
|
||||||
FOREACH_DEVICE_DEVLINK(device, devlink) {
|
char **p;
|
||||||
if (!first)
|
STRV_FOREACH(p, devices) {
|
||||||
printf(" ");
|
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
|
||||||
if (root)
|
|
||||||
printf("%s", devlink);
|
|
||||||
else
|
|
||||||
printf("%s", devlink + STRLEN("/dev/"));
|
|
||||||
|
|
||||||
first = false;
|
r = find_device(*p, NULL, &device);
|
||||||
}
|
if (r == -EINVAL)
|
||||||
printf("\n");
|
return log_error_errno(r, "Bad argument \"%s\", expected an absolute path in /dev/ or /sys or a unit name: %m", *p);
|
||||||
break;
|
if (r < 0)
|
||||||
}
|
return log_error_errno(r, "Unknown device \"%s\": %m", *p);
|
||||||
case QUERY_PATH: {
|
|
||||||
const char *devpath;
|
|
||||||
|
|
||||||
r = sd_device_get_devpath(device, &devpath);
|
if (action == ACTION_QUERY)
|
||||||
if (r < 0)
|
r = query_device(query, device);
|
||||||
return log_error_errno(r, "Failed to get device path: %m");
|
else if (action == ACTION_ATTRIBUTE_WALK)
|
||||||
|
r = print_device_chain(device);
|
||||||
printf("%s\n", devpath);
|
else
|
||||||
return 0;
|
assert_not_reached("Unknown action");
|
||||||
}
|
|
||||||
case QUERY_PROPERTY: {
|
|
||||||
const char *key, *value;
|
|
||||||
|
|
||||||
FOREACH_DEVICE_PROPERTY(device, key, value)
|
|
||||||
if (export)
|
|
||||||
printf("%s%s='%s'\n", strempty(export_prefix), key, value);
|
|
||||||
else
|
|
||||||
printf("%s=%s\n", key, value);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case QUERY_ALL:
|
|
||||||
print_record(device);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
assert_not_reached("unknown query type");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ACTION_ATTRIBUTE_WALK:
|
|
||||||
if (!device && argv[optind]) {
|
|
||||||
r = find_device(argv[optind], NULL, &device);
|
|
||||||
if (r < 0)
|
|
||||||
return log_error_errno(r, "Unknown device, absolute path in /dev/ or /sys expected: %m");
|
|
||||||
}
|
|
||||||
if (!device) {
|
|
||||||
log_error("Unknown device, --name=, --path=, or absolute path in /dev/ or /sys expected.");
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
print_device_chain(device);
|
|
||||||
break;
|
|
||||||
case ACTION_DEVICE_ID_FILE:
|
|
||||||
r = stat_device(name, export, export_prefix);
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -6,18 +6,31 @@
|
|||||||
#include "device-private.h"
|
#include "device-private.h"
|
||||||
#include "path-util.h"
|
#include "path-util.h"
|
||||||
#include "udevadm-util.h"
|
#include "udevadm-util.h"
|
||||||
|
#include "unit-name.h"
|
||||||
|
|
||||||
int find_device(const char *id, const char *prefix, sd_device **ret) {
|
int find_device(const char *id, const char *prefix, sd_device **ret) {
|
||||||
_cleanup_free_ char *buf = NULL;
|
_cleanup_free_ char *path = NULL;
|
||||||
|
int r;
|
||||||
|
|
||||||
assert(id);
|
assert(id);
|
||||||
assert(ret);
|
assert(ret);
|
||||||
|
|
||||||
if (prefix && !path_startswith(id, prefix)) {
|
if (prefix) {
|
||||||
buf = path_join(prefix, id);
|
if (!path_startswith(id, prefix)) {
|
||||||
if (!buf)
|
id = path = path_join(prefix, id);
|
||||||
return -ENOMEM;
|
if (!path)
|
||||||
id = buf;
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* In cases where the argument is generic (no prefix specified),
|
||||||
|
* check if the argument looks like a device unit name. */
|
||||||
|
if (unit_name_is_valid(id, UNIT_NAME_PLAIN) &&
|
||||||
|
unit_name_to_type(id) == UNIT_DEVICE) {
|
||||||
|
r = unit_name_to_path(id, &path);
|
||||||
|
if (r < 0)
|
||||||
|
return log_debug_errno(r, "Failed to convert \"%s\" to a device path: %m", id);
|
||||||
|
id = path;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path_startswith(id, "/sys/"))
|
if (path_startswith(id, "/sys/"))
|
||||||
|
Reference in New Issue
Block a user