]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/locale/localed.c
Merge branch 'hostnamectl-dot-v2'
[thirdparty/systemd.git] / src / locale / localed.c
index 88756542fdb1d90b76f84c5f2e01d2019a4926b4..cb4052fdd5124c8fde4eb66387f1b0a8a6b12542 100644 (file)
@@ -99,11 +99,6 @@ static const char* nonempty(const char *s) {
         return isempty(s) ? NULL : s;
 }
 
-static void free_and_replace(char **s, char *v) {
-        free(*s);
-        *s = v;
-}
-
 static bool startswith_comma(const char *s, const char *prefix) {
         const char *t;
 
@@ -476,15 +471,25 @@ static int x11_write_data(Context *c) {
                 fprintf(f, "        Option \"XkbOptions\" \"%s\"\n", c->x11_options);
 
         fputs("EndSection\n", f);
-        fflush(f);
 
-        if (ferror(f) || rename(temp_path, "/etc/X11/xorg.conf.d/00-keyboard.conf") < 0) {
+        r = fflush_and_check(f);
+        if (r < 0)
+                goto fail;
+
+        if (rename(temp_path, "/etc/X11/xorg.conf.d/00-keyboard.conf") < 0) {
                 r = -errno;
-                unlink("/etc/X11/xorg.conf.d/00-keyboard.conf");
-                unlink(temp_path);
-                return r;
-        } else
-                return 0;
+                goto fail;
+        }
+
+        return 0;
+
+fail:
+        (void) unlink("/etc/X11/xorg.conf.d/00-keyboard.conf");
+
+        if (temp_path)
+                (void) unlink(temp_path);
+
+        return r;
 }
 
 static int vconsole_reload(sd_bus *bus) {