1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-02 19:21:53 +03:00

udev-rules: rewrite function to avoid clobbering arguments

If the attribute wasn't found, the last filename looked at was returned in
the input/output argument. This just seems bad style.

The return value was ignored, so change function to return void.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2016-02-20 23:00:45 -05:00
parent 99f16bb8d9
commit f4850a1d95

View File

@ -36,6 +36,7 @@
#include "glob-util.h" #include "glob-util.h"
#include "path-util.h" #include "path-util.h"
#include "stat-util.h" #include "stat-util.h"
#include "stdio-util.h"
#include "strbuf.h" #include "strbuf.h"
#include "string-util.h" #include "string-util.h"
#include "strv.h" #include "strv.h"
@ -686,41 +687,31 @@ static int import_parent_into_properties(struct udev_device *dev, const char *fi
return 0; return 0;
} }
static int attr_subst_subdir(char *attr, size_t len) { static void attr_subst_subdir(char *attr, size_t len) {
bool found = false; const char *pos, *tail, *path;
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *dent;
if (strstr(attr, "/*/")) { pos = strstr(attr, "/*/");
char *pos; if (!pos)
char dirname[UTIL_PATH_SIZE]; return;
const char *tail;
DIR *dir;
strscpy(dirname, sizeof(dirname), attr); tail = pos + 2;
pos = strstr(dirname, "/*/"); path = strndupa(attr, pos - attr + 1); /* include slash at end */
if (pos == NULL) dir = opendir(path);
return -1; if (dir == NULL)
pos[0] = '\0'; return;
tail = &pos[2];
dir = opendir(dirname);
if (dir != NULL) {
struct dirent *dent;
for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) { for (dent = readdir(dir); dent != NULL; dent = readdir(dir))
struct stat stats; if (dent->d_name[0] != '.') {
char n[strlen(dent->d_name) + 1 + strlen(tail) + 1];
if (dent->d_name[0] == '.') strscpyl(n, sizeof n, dent->d_name, "/", tail, NULL);
continue; if (faccessat(dirfd(dir), n, F_OK, 0)) {
strscpyl(attr, len, dirname, "/", dent->d_name, tail, NULL); strscpyl(attr, len, path, n, NULL);
if (stat(attr, &stats) == 0) { break;
found = true;
break;
}
} }
closedir(dir);
} }
}
return found;
} }
static int get_key(struct udev *udev, char **line, char **key, enum operation_type *op, char **value) { static int get_key(struct udev *udev, char **line, char **key, enum operation_type *op, char **value) {