Merge pull request #12072 from poettering/string-table-fixes

three small string table fixes
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2019-03-22 16:49:56 +01:00 committed by GitHub
commit 4210e60eb6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 21 deletions

View file

@ -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; \

View file

@ -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)

View file

@ -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) {