chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
sd-rtnl: message - add support for getting prefixlen from address messages
[elogind.git]
/
src
/
login
/
sysfs-show.c
diff --git
a/src/login/sysfs-show.c
b/src/login/sysfs-show.c
index 05cb787a68b04219fc11c1e94e20c76b0497bcba..9bd9152bed3cef9406bc9ef31060fc2fe781f10a 100644
(file)
--- a/
src/login/sysfs-show.c
+++ b/
src/login/sysfs-show.c
@@
-42,10
+42,10
@@
static int show_sysfs_one(
assert(prefix);
while (*item) {
assert(prefix);
while (*item) {
+ _cleanup_udev_device_unref_ struct udev_device *d = NULL;
struct udev_list_entry *next, *lookahead;
struct udev_list_entry *next, *lookahead;
- struct udev_device *d;
const char *sn, *name, *sysfs, *subsystem, *sysname;
const char *sn, *name, *sysfs, *subsystem, *sysname;
-
char *l, *k
;
+
_cleanup_free_ char *k = NULL, *l = NULL
;
bool is_master;
sysfs = udev_list_entry_get_name(*item);
bool is_master;
sysfs = udev_list_entry_get_name(*item);
@@
-64,7
+64,6
@@
static int show_sysfs_one(
/* Explicitly also check for tag 'seat' here */
if (!streq(seat, sn) || !udev_device_has_tag(d, "seat")) {
/* Explicitly also check for tag 'seat' here */
if (!streq(seat, sn) || !udev_device_has_tag(d, "seat")) {
- udev_device_unref(d);
*item = udev_list_entry_get_next(*item);
continue;
}
*item = udev_list_entry_get_next(*item);
continue;
}
@@
-86,21
+85,17
@@
static int show_sysfs_one(
if (path_startswith(lookahead_sysfs, sub) &&
!path_startswith(lookahead_sysfs, sysfs)) {
if (path_startswith(lookahead_sysfs, sub) &&
!path_startswith(lookahead_sysfs, sysfs)) {
-
struct udev_device *lookahead_d
;
+
_cleanup_udev_device_unref_ struct udev_device *lookahead_d = NULL
;
lookahead_d = udev_device_new_from_syspath(udev, lookahead_sysfs);
if (lookahead_d) {
const char *lookahead_sn;
lookahead_d = udev_device_new_from_syspath(udev, lookahead_sysfs);
if (lookahead_d) {
const char *lookahead_sn;
- bool found;
lookahead_sn = udev_device_get_property_value(d, "ID_SEAT");
if (isempty(lookahead_sn))
lookahead_sn = "seat0";
lookahead_sn = udev_device_get_property_value(d, "ID_SEAT");
if (isempty(lookahead_sn))
lookahead_sn = "seat0";
- found = streq(seat, lookahead_sn) && udev_device_has_tag(lookahead_d, "seat");
- udev_device_unref(lookahead_d);
-
- if (found)
+ if (streq(seat, lookahead_sn) && udev_device_has_tag(lookahead_d, "seat"))
break;
}
}
break;
}
}
@@
-109,43
+104,43
@@
static int show_sysfs_one(
}
k = ellipsize(sysfs, n_columns, 20);
}
k = ellipsize(sysfs, n_columns, 20);
- printf("%s%s%s\n", prefix, draw_special_char(lookahead ? DRAW_TREE_BRANCH : DRAW_TREE_RIGHT),
- k ? k : sysfs);
- free(k);
+ if (!k)
+ return -ENOMEM;
+
+ printf("%s%s%s\n", prefix, draw_special_char(lookahead ? DRAW_TREE_BRANCH : DRAW_TREE_RIGHT), k);
if (asprintf(&l,
"%s%s:%s%s%s%s",
is_master ? "[MASTER] " : "",
subsystem, sysname,
if (asprintf(&l,
"%s%s:%s%s%s%s",
is_master ? "[MASTER] " : "",
subsystem, sysname,
- name ? " \"" : "", name ? name : "", name ? "\"" : "") < 0) {
- udev_device_unref(d);
+ name ? " \"" : "", name ? name : "", name ? "\"" : "") < 0)
return -ENOMEM;
return -ENOMEM;
- }
- k = ellipsize(l, n_columns, 70);
- printf("%s%s%s\n", prefix, lookahead ? draw_special_char(DRAW_TREE_VERT) : " ",
- k ? k : l);
free(k);
free(k);
- free(l);
+ k = ellipsize(l, n_columns, 70);
+ if (!k)
+ return -ENOMEM;
+
+ printf("%s%s%s\n", prefix, lookahead ? draw_special_char(DRAW_TREE_VERTICAL) : " ", k);
*item = next;
if (*item) {
*item = next;
if (*item) {
-
char *p
;
+
_cleanup_free_ char *p = NULL
;
- p = strappend(prefix, lookahead ? draw_special_char(DRAW_TREE_VERT) : " ");
- show_sysfs_one(udev, seat, item, sysfs, p ? p : prefix, n_columns - 2);
- free(p);
- }
+ p = strappend(prefix, lookahead ? draw_special_char(DRAW_TREE_VERTICAL) : " ");
+ if (!p)
+ return -ENOMEM;
- udev_device_unref(d);
+ show_sysfs_one(udev, seat, item, sysfs, p, n_columns - 2);
+ }
}
return 0;
}
int show_sysfs(const char *seat, const char *prefix, unsigned n_columns) {
}
return 0;
}
int show_sysfs(const char *seat, const char *prefix, unsigned n_columns) {
- _cleanup_udev_unref_ struct udev *udev;
_cleanup_udev_enumerate_unref_ struct udev_enumerate *e = NULL;
_cleanup_udev_enumerate_unref_ struct udev_enumerate *e = NULL;
+ _cleanup_udev_unref_ struct udev *udev = NULL;
struct udev_list_entry *first = NULL;
int r;
struct udev_list_entry *first = NULL;
int r;
@@
-184,6
+179,8
@@
int show_sysfs(const char *seat, const char *prefix, unsigned n_columns) {
first = udev_enumerate_get_list_entry(e);
if (first)
show_sysfs_one(udev, seat, &first, "/", prefix, n_columns);
first = udev_enumerate_get_list_entry(e);
if (first)
show_sysfs_one(udev, seat, &first, "/", prefix, n_columns);
+ else
+ printf("%s%s%s\n", prefix, draw_special_char(DRAW_TREE_RIGHT), "(none)");
return r;
}
return r;
}