Merge pull request #12072 from poettering/string-table-fixes
three small string table fixes
This commit is contained in:
commit
4210e60eb6
|
@ -59,13 +59,13 @@ ssize_t string_table_lookup(const char * const *table, size_t len, const char *k
|
|||
|
||||
#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name,type,max,scope) \
|
||||
scope type name##_from_string(const char *s) { \
|
||||
type i; \
|
||||
unsigned u = 0; \
|
||||
type i; \
|
||||
if (!s) \
|
||||
return (type) -1; \
|
||||
for (i = 0; i < (type) ELEMENTSOF(name##_table); i++) \
|
||||
if (streq_ptr(name##_table[i], s)) \
|
||||
return i; \
|
||||
i = (type) string_table_lookup(name##_table, ELEMENTSOF(name##_table), s); \
|
||||
if (i >= 0) \
|
||||
return i; \
|
||||
if (safe_atou(s, &u) >= 0 && u <= max) \
|
||||
return (type) u; \
|
||||
return (type) -1; \
|
||||
|
|
|
@ -2185,26 +2185,21 @@ int bus_exec_context_set_transient_property(
|
|||
}
|
||||
|
||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||
char ***dirs = NULL;
|
||||
ExecDirectoryType i;
|
||||
ExecDirectory *d;
|
||||
|
||||
for (i = 0; i < _EXEC_DIRECTORY_TYPE_MAX; i++)
|
||||
if (streq(name, exec_directory_type_to_string(i))) {
|
||||
dirs = &c->directories[i].paths;
|
||||
break;
|
||||
}
|
||||
|
||||
assert(dirs);
|
||||
assert_se((i = exec_directory_type_from_string(name)) >= 0);
|
||||
d = c->directories + i;
|
||||
|
||||
if (strv_isempty(l)) {
|
||||
*dirs = strv_free(*dirs);
|
||||
d->paths = strv_free(d->paths);
|
||||
unit_write_settingf(u, flags, name, "%s=", name);
|
||||
} else {
|
||||
_cleanup_free_ char *joined = NULL;
|
||||
|
||||
r = strv_extend_strv(dirs, l, true);
|
||||
r = strv_extend_strv(&d->paths, l, true);
|
||||
if (r < 0)
|
||||
return -ENOMEM;
|
||||
return r;
|
||||
|
||||
joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS);
|
||||
if (!joined)
|
||||
|
|
|
@ -18,9 +18,10 @@
|
|||
#include "device-util.h"
|
||||
#include "dirent-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "string-table.h"
|
||||
#include "string-util.h"
|
||||
#include "udevadm.h"
|
||||
#include "udevadm-util.h"
|
||||
#include "udevadm.h"
|
||||
|
||||
typedef enum ActionType {
|
||||
ACTION_QUERY,
|
||||
|
@ -50,12 +51,8 @@ static bool skip_attribute(const char *name) {
|
|||
"subsystem",
|
||||
"module",
|
||||
};
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < ELEMENTSOF(skip); i++)
|
||||
if (streq(name, skip[i]))
|
||||
return true;
|
||||
return false;
|
||||
return string_table_lookup(skip, ELEMENTSOF(skip), name) >= 0;
|
||||
}
|
||||
|
||||
static void print_all_attributes(sd_device *device, const char *key) {
|
||||
|
|
Loading…
Reference in a new issue