mirror of
https://github.com/systemd/systemd.git
synced 2024-10-30 23:21:22 +03:00
util: allow strappenda to take any number of args
This makes strappenda3 redundant, so we remove its usage and definition. Add a few tests along the way for sanity.
This commit is contained in:
parent
d06441da04
commit
8085f163c5
@ -169,7 +169,7 @@ static int add_dbus(const char *path, const char *fname, const char *type) {
|
|||||||
assert(path);
|
assert(path);
|
||||||
assert(fname);
|
assert(fname);
|
||||||
|
|
||||||
p = strappenda3(path, "/", fname);
|
p = strappenda(path, "/", fname);
|
||||||
r = config_parse(NULL, p, NULL,
|
r = config_parse(NULL, p, NULL,
|
||||||
"D-BUS Service\0",
|
"D-BUS Service\0",
|
||||||
config_item_table_lookup, table,
|
config_item_table_lookup, table,
|
||||||
|
@ -432,7 +432,7 @@ static int add_root_mount(void) {
|
|||||||
else if (arg_root_rw >= 0 ||
|
else if (arg_root_rw >= 0 ||
|
||||||
(!mount_test_option(arg_root_options, "ro") &&
|
(!mount_test_option(arg_root_options, "ro") &&
|
||||||
!mount_test_option(arg_root_options, "rw")))
|
!mount_test_option(arg_root_options, "rw")))
|
||||||
opts = strappenda3(arg_root_options, ",", arg_root_rw > 0 ? "rw" : "ro");
|
opts = strappenda(arg_root_options, ",", arg_root_rw > 0 ? "rw" : "ro");
|
||||||
else
|
else
|
||||||
opts = arg_root_options;
|
opts = arg_root_options;
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ static int add_symlink(const char *fservice, const char *tservice) {
|
|||||||
assert(tservice);
|
assert(tservice);
|
||||||
|
|
||||||
from = strappenda(SYSTEM_DATA_UNIT_PATH "/", fservice);
|
from = strappenda(SYSTEM_DATA_UNIT_PATH "/", fservice);
|
||||||
to = strappenda3(arg_dest, "/getty.target.wants/", tservice);
|
to = strappenda(arg_dest, "/getty.target.wants/", tservice);
|
||||||
|
|
||||||
mkdir_parents_label(to, 0755);
|
mkdir_parents_label(to, 0755);
|
||||||
|
|
||||||
|
@ -1061,7 +1061,7 @@ static int unit_file_load(
|
|||||||
assert(path);
|
assert(path);
|
||||||
|
|
||||||
if (!isempty(root_dir))
|
if (!isempty(root_dir))
|
||||||
path = strappenda3(root_dir, "/", path);
|
path = strappenda(root_dir, "/", path);
|
||||||
|
|
||||||
fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|(allow_symlink ? 0 : O_NOFOLLOW));
|
fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|(allow_symlink ? 0 : O_NOFOLLOW));
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
|
@ -845,29 +845,19 @@ int unlink_noerrno(const char *path);
|
|||||||
(void *) memset(_new_, 0, _len_); \
|
(void *) memset(_new_, 0, _len_); \
|
||||||
})
|
})
|
||||||
|
|
||||||
#define strappenda(a, b) \
|
#define strappenda(a, ...) \
|
||||||
({ \
|
({ \
|
||||||
const char *_a_ = (a), *_b_ = (b); \
|
int _len = strlen(a); \
|
||||||
char *_c_; \
|
unsigned _i; \
|
||||||
size_t _x_, _y_; \
|
char *_d_, *_p_; \
|
||||||
_x_ = strlen(_a_); \
|
const char *_appendees_[] = { __VA_ARGS__ }; \
|
||||||
_y_ = strlen(_b_); \
|
for (_i = 0; _i < ELEMENTSOF(_appendees_); _i++) \
|
||||||
_c_ = alloca(_x_ + _y_ + 1); \
|
_len += strlen(_appendees_[_i]); \
|
||||||
strcpy(stpcpy(_c_, _a_), _b_); \
|
_d_ = alloca(_len + 1); \
|
||||||
_c_; \
|
_p_ = stpcpy(_d_, a); \
|
||||||
})
|
for (_i = 0; _i < ELEMENTSOF(_appendees_); _i++) \
|
||||||
|
_p_ = stpcpy(_p_, _appendees_[_i]); \
|
||||||
#define strappenda3(a, b, c) \
|
_d_; \
|
||||||
({ \
|
|
||||||
const char *_a_ = (a), *_b_ = (b), *_c_ = (c); \
|
|
||||||
char *_d_; \
|
|
||||||
size_t _x_, _y_, _z_; \
|
|
||||||
_x_ = strlen(_a_); \
|
|
||||||
_y_ = strlen(_b_); \
|
|
||||||
_z_ = strlen(_c_); \
|
|
||||||
_d_ = alloca(_x_ + _y_ + _z_ + 1); \
|
|
||||||
strcpy(stpcpy(stpcpy(_d_, _a_), _b_), _c_); \
|
|
||||||
_d_; \
|
|
||||||
})
|
})
|
||||||
|
|
||||||
#define procfs_file_alloca(pid, field) \
|
#define procfs_file_alloca(pid, field) \
|
||||||
|
@ -4827,7 +4827,7 @@ static int switch_root(sd_bus *bus, char **args) {
|
|||||||
const char *root_systemd_path = NULL, *root_init_path = NULL;
|
const char *root_systemd_path = NULL, *root_init_path = NULL;
|
||||||
|
|
||||||
root_systemd_path = strappenda(root, "/" SYSTEMD_BINARY_PATH);
|
root_systemd_path = strappenda(root, "/" SYSTEMD_BINARY_PATH);
|
||||||
root_init_path = strappenda3(root, "/", init);
|
root_init_path = strappenda(root, "/", init);
|
||||||
|
|
||||||
/* If the passed init is actually the same as the
|
/* If the passed init is actually the same as the
|
||||||
* systemd binary, then let's suppress it. */
|
* systemd binary, then let's suppress it. */
|
||||||
|
@ -907,6 +907,19 @@ static void test_strshorten(void) {
|
|||||||
assert_se(strlen(strshorten(s, 0)) == 0);
|
assert_se(strlen(strshorten(s, 0)) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_strappenda(void) {
|
||||||
|
char *actual;
|
||||||
|
|
||||||
|
actual = strappenda("", "foo", "bar");
|
||||||
|
assert_se(streq(actual, "foobar"));
|
||||||
|
|
||||||
|
actual = strappenda("foo", "bar", "baz");
|
||||||
|
assert_se(streq(actual, "foobarbaz"));
|
||||||
|
|
||||||
|
actual = strappenda("foo", "", "bar", "baz");
|
||||||
|
assert_se(streq(actual, "foobarbaz"));
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
log_parse_environment();
|
log_parse_environment();
|
||||||
log_open();
|
log_open();
|
||||||
@ -965,6 +978,7 @@ int main(int argc, char *argv[]) {
|
|||||||
test_read_one_char();
|
test_read_one_char();
|
||||||
test_ignore_signals();
|
test_ignore_signals();
|
||||||
test_strshorten();
|
test_strshorten();
|
||||||
|
test_strappenda();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user