]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: use strextendf_with_separator()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 20 May 2021 05:36:14 +0000 (14:36 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 20 May 2021 12:57:04 +0000 (21:57 +0900)
src/nspawn/nspawn-mount.c

index dbebc49ae778837db6dea2b309623041e094c781..c28e42993524f04f58895120cb2d7e9abb57fafc 100644 (file)
@@ -382,39 +382,28 @@ int tmpfs_patch_options(
                 const char *selinux_apifs_context,
                 char **ret) {
 
-        char *buf = NULL;
+        _cleanup_free_ char *buf = NULL;
 
-        if (uid_shift != UID_INVALID) {
-                if (asprintf(&buf, "%s%suid=" UID_FMT ",gid=" UID_FMT,
-                             strempty(options), options ? "," : "",
-                             uid_shift, uid_shift) < 0)
-                        return -ENOMEM;
+        assert(ret);
 
-                options = buf;
+        if (options) {
+                buf = strdup(options);
+                if (!buf)
+                        return -ENOMEM;
         }
 
-#if HAVE_SELINUX
-        if (selinux_apifs_context) {
-                char *t;
-
-                t = strjoin(strempty(options), options ? "," : "",
-                            "context=\"", selinux_apifs_context, "\"");
-                free(buf);
-                if (!t)
+        if (uid_shift != UID_INVALID)
+                if (strextendf_with_separator(&buf, ",", "uid=" UID_FMT ",gid=" UID_FMT, uid_shift, uid_shift) < 0)
                         return -ENOMEM;
 
-                buf = t;
-        }
-#endif
-
-        if (!buf && options) {
-                buf = strdup(options);
-                if (!buf)
+#if HAVE_SELINUX
+        if (selinux_apifs_context)
+                if (!strextend_with_separator(&buf, ",", "context=\"", selinux_apifs_context, "\""))
                         return -ENOMEM;
-        }
-        *ret = buf;
+#endif
 
-        return !!buf;
+        *ret = TAKE_PTR(buf);
+        return !!*ret;
 }
 
 int mount_sysfs(const char *dest, MountSettingsMask mount_settings) {