Skip to content

Commit 63c372c

Browse files
committed
util: rework strappenda(), and rename it strjoina()
After all it is now much more like strjoin() than strappend(). At the same time, add support for NULL sentinels, even if they are normally not necessary.
1 parent 44de0ef commit 63c372c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+248
-237
lines changed

src/cgls/cgls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ int main(int argc, char *argv[]) {
203203
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
204204
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
205205

206-
m = strappenda("/run/systemd/machines/", arg_machine);
206+
m = strjoina("/run/systemd/machines/", arg_machine);
207207
r = parse_env_file(m, NEWLINE, "SCOPE", &scope, NULL);
208208
if (r < 0) {
209209
log_error_errno(r, "Failed to get machine path: %m");

src/core/busname.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ static int busname_verify(BusName *n) {
205205
return -EINVAL;
206206
}
207207

208-
e = strappenda(n->name, ".busname");
208+
e = strjoina(n->name, ".busname");
209209
if (!unit_has_name(UNIT(n), e)) {
210210
log_unit_error(UNIT(n)->id, "%s's Name= setting doesn't match unit name. Refusing.", UNIT(n)->id);
211211
return -EINVAL;

src/core/dbus-cgroup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ int bus_cgroup_set_property(
574574
c->device_policy = p;
575575
u->cgroup_realized_mask &= ~CGROUP_DEVICE;
576576

577-
buf = strappenda("DevicePolicy=", policy);
577+
buf = strjoina("DevicePolicy=", policy);
578578
unit_write_drop_in_private(u, mode, name, buf);
579579
}
580580

src/core/execute.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,9 +1582,9 @@ static int exec_child(
15821582

15831583
if (context->private_tmp && runtime) {
15841584
if (runtime->tmp_dir)
1585-
tmp = strappenda(runtime->tmp_dir, "/tmp");
1585+
tmp = strjoina(runtime->tmp_dir, "/tmp");
15861586
if (runtime->var_tmp_dir)
1587-
var = strappenda(runtime->var_tmp_dir, "/tmp");
1587+
var = strjoina(runtime->var_tmp_dir, "/tmp");
15881588
}
15891589

15901590
r = setup_namespace(
@@ -2588,7 +2588,7 @@ void exec_command_dump(ExecCommand *c, FILE *f, const char *prefix) {
25882588
assert(f);
25892589

25902590
prefix = strempty(prefix);
2591-
prefix2 = strappenda(prefix, "\t");
2591+
prefix2 = strjoina(prefix, "\t");
25922592

25932593
cmd = exec_command_line(c->argv);
25942594
fprintf(f,

src/core/machine-id-setup.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static int generate(char id[34], const char *root) {
7373
if (isempty(root))
7474
dbus_machine_id = "/var/lib/dbus/machine-id";
7575
else
76-
dbus_machine_id = strappenda(root, "/var/lib/dbus/machine-id");
76+
dbus_machine_id = strjoina(root, "/var/lib/dbus/machine-id");
7777

7878
/* First, try reading the D-Bus machine id, unless it is a symlink */
7979
fd = open(dbus_machine_id, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
@@ -199,7 +199,7 @@ int machine_id_commit(const char *root) {
199199
else {
200200
char *x;
201201

202-
x = strappenda(root, "/etc/machine-id");
202+
x = strjoina(root, "/etc/machine-id");
203203
etc_machine_id = path_kill_slashes(x);
204204
}
205205

@@ -281,10 +281,10 @@ int machine_id_setup(const char *root) {
281281
} else {
282282
char *x;
283283

284-
x = strappenda(root, "/etc/machine-id");
284+
x = strjoina(root, "/etc/machine-id");
285285
etc_machine_id = path_kill_slashes(x);
286286

287-
x = strappenda(root, "/run/machine-id");
287+
x = strjoina(root, "/run/machine-id");
288288
run_machine_id = path_kill_slashes(x);
289289
}
290290

src/core/manager.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,8 +2106,7 @@ void manager_send_unit_audit(Manager *m, Unit *u, int type, bool success) {
21062106
return;
21072107
}
21082108

2109-
msg = strappenda("unit=", p);
2110-
2109+
msg = strjoina("unit=", p);
21112110
if (audit_log_user_comm_message(audit_fd, type, msg, "systemd", NULL, NULL, NULL, success) < 0) {
21122111
if (errno == EPERM)
21132112
/* We aren't allowed to send audit messages?

src/core/mount.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ static void mount_enter_remounting(Mount *m) {
976976
const char *o;
977977

978978
if (m->parameters_fragment.options)
979-
o = strappenda("remount,", m->parameters_fragment.options);
979+
o = strjoina("remount,", m->parameters_fragment.options);
980980
else
981981
o = "remount";
982982

src/core/namespace.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,40 +157,40 @@ static int mount_dev(BindMount *m) {
157157
if (!mkdtemp(temporary_mount))
158158
return -errno;
159159

160-
dev = strappenda(temporary_mount, "/dev");
160+
dev = strjoina(temporary_mount, "/dev");
161161
(void)mkdir(dev, 0755);
162162
if (mount("tmpfs", dev, "tmpfs", MS_NOSUID|MS_STRICTATIME, "mode=755") < 0) {
163163
r = -errno;
164164
goto fail;
165165
}
166166

167-
devpts = strappenda(temporary_mount, "/dev/pts");
167+
devpts = strjoina(temporary_mount, "/dev/pts");
168168
(void)mkdir(devpts, 0755);
169169
if (mount("/dev/pts", devpts, NULL, MS_BIND, NULL) < 0) {
170170
r = -errno;
171171
goto fail;
172172
}
173173

174-
devptmx = strappenda(temporary_mount, "/dev/ptmx");
174+
devptmx = strjoina(temporary_mount, "/dev/ptmx");
175175
symlink("pts/ptmx", devptmx);
176176

177-
devshm = strappenda(temporary_mount, "/dev/shm");
177+
devshm = strjoina(temporary_mount, "/dev/shm");
178178
(void)mkdir(devshm, 01777);
179179
r = mount("/dev/shm", devshm, NULL, MS_BIND, NULL);
180180
if (r < 0) {
181181
r = -errno;
182182
goto fail;
183183
}
184184

185-
devmqueue = strappenda(temporary_mount, "/dev/mqueue");
185+
devmqueue = strjoina(temporary_mount, "/dev/mqueue");
186186
(void)mkdir(devmqueue, 0755);
187187
mount("/dev/mqueue", devmqueue, NULL, MS_BIND, NULL);
188188

189-
devhugepages = strappenda(temporary_mount, "/dev/hugepages");
189+
devhugepages = strjoina(temporary_mount, "/dev/hugepages");
190190
(void)mkdir(devhugepages, 0755);
191191
mount("/dev/hugepages", devhugepages, NULL, MS_BIND, NULL);
192192

193-
devlog = strappenda(temporary_mount, "/dev/log");
193+
devlog = strjoina(temporary_mount, "/dev/log");
194194
symlink("/run/systemd/journal/dev-log", devlog);
195195

196196
NULSTR_FOREACH(d, devnodes) {
@@ -280,7 +280,7 @@ static int mount_kdbus(BindMount *m) {
280280
if (!mkdtemp(temporary_mount))
281281
return log_error_errno(errno, "Failed create temp dir: %m");
282282

283-
root = strappenda(temporary_mount, "/kdbus");
283+
root = strjoina(temporary_mount, "/kdbus");
284284
(void)mkdir(root, 0755);
285285
if (mount("tmpfs", root, "tmpfs", MS_NOSUID|MS_STRICTATIME, "mode=777") < 0) {
286286
r = -errno;
@@ -295,7 +295,7 @@ static int mount_kdbus(BindMount *m) {
295295
goto fail;
296296
}
297297

298-
busnode = strappenda(root, "/bus");
298+
busnode = strjoina(root, "/bus");
299299
if (mknod(busnode, (st.st_mode & ~07777) | 0600, st.st_rdev) < 0) {
300300
log_error_errno(errno, "mknod() for %s failed: %m", busnode);
301301
r = -errno;
@@ -566,7 +566,7 @@ static int setup_one_tmp_dir(const char *id, const char *prefix, char **path) {
566566
RUN_WITH_UMASK(0000) {
567567
char *y;
568568

569-
y = strappenda(x, "/tmp");
569+
y = strjoina(x, "/tmp");
570570

571571
if (mkdir(y, 0777 | S_ISVTX) < 0)
572572
return -errno;
@@ -594,7 +594,7 @@ int setup_tmp_dirs(const char *id, char **tmp_dir, char **var_tmp_dir) {
594594
if (r < 0) {
595595
char *t;
596596

597-
t = strappenda(a, "/tmp");
597+
t = strjoina(a, "/tmp");
598598
rmdir(t);
599599
rmdir(a);
600600

src/core/service.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ static int service_add_extras(Service *s) {
562562
if (r < 0)
563563
return r;
564564

565-
n = strappenda(s->bus_name, ".busname");
565+
n = strjoina(s->bus_name, ".busname");
566566
r = unit_add_dependency_by_name(UNIT(s), UNIT_AFTER, n, NULL, true);
567567
if (r < 0)
568568
return r;
@@ -619,7 +619,7 @@ static void service_dump(Unit *u, FILE *f, const char *prefix) {
619619
assert(s);
620620

621621
prefix = strempty(prefix);
622-
prefix2 = strappenda(prefix, "\t");
622+
prefix2 = strjoina(prefix, "\t");
623623

624624
fprintf(f,
625625
"%sService State: %s\n"
@@ -1123,7 +1123,7 @@ static int service_spawn(
11231123
}
11241124

11251125
if (is_control && UNIT(s)->cgroup_path) {
1126-
path = strappenda(UNIT(s)->cgroup_path, "/control");
1126+
path = strjoina(UNIT(s)->cgroup_path, "/control");
11271127
cg_create(SYSTEMD_CGROUP_CONTROLLER, path);
11281128
} else
11291129
path = UNIT(s)->cgroup_path;
@@ -1489,7 +1489,7 @@ static void service_kill_control_processes(Service *s) {
14891489
if (!UNIT(s)->cgroup_path)
14901490
return;
14911491

1492-
p = strappenda(UNIT(s)->cgroup_path, "/control");
1492+
p = strjoina(UNIT(s)->cgroup_path, "/control");
14931493
cg_kill_recursive(SYSTEMD_CGROUP_CONTROLLER, p, SIGKILL, true, true, true, NULL);
14941494
}
14951495

src/core/socket.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ static int socket_add_device_link(Socket *s) {
266266
if (!s->bind_to_device || streq(s->bind_to_device, "lo"))
267267
return 0;
268268

269-
t = strappenda("/sys/subsystem/net/devices/", s->bind_to_device);
269+
t = strjoina("/sys/subsystem/net/devices/", s->bind_to_device);
270270
return unit_add_node_link(UNIT(s), t, false);
271271
}
272272

@@ -473,7 +473,7 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
473473
assert(f);
474474

475475
prefix = strempty(prefix);
476-
prefix2 = strappenda(prefix, "\t");
476+
prefix2 = strjoina(prefix, "\t");
477477

478478
fprintf(f,
479479
"%sSocket State: %s\n"

0 commit comments

Comments
 (0)