chiark / gitweb /
Unifiy free() usage
[elogind.git] / src / shared / generator.c
index d48b400b31535af16b9f7cad2570ad80c7668416..e58bbea77ccf7ec306fa009a853056c315a13cdd 100644 (file)
 static int write_fsck_sysroot_service(const char *dir, const char *what) {
         const char *unit;
         _cleanup_free_ char *device = NULL;
+        _cleanup_free_ char *escaped;
         _cleanup_fclose_ FILE *f = NULL;
         int r;
 
+        escaped = cescape(what);
+        if (!escaped)
+                return log_oom();
+
         unit = strjoina(dir, "/systemd-fsck-root.service");
         log_debug("Creating %s", unit);
 
@@ -61,15 +66,16 @@ static int write_fsck_sysroot_service(const char *dir, const char *what) {
                 "[Service]\n"
                 "Type=oneshot\n"
                 "RemainAfterExit=yes\n"
-                "ExecStart=/usr/lib/systemd/systemd-fsck %2$s\n"
+                "ExecStart=" SYSTEMD_FSCK_PATH " %4$s\n"
                 "TimeoutSec=0\n",
                 program_invocation_short_name,
                 what,
-                device);
+                device,
+                escaped);
 
-        fflush(f);
-        if (ferror(f))
-                return log_error_errno(errno, "Failed to write unit file %s: %m", unit);
+        r = fflush_and_check(f);
+        if (r < 0)
+                return log_error_errno(r, "Failed to write unit file %s: %m", unit);
 
         return 0;
 }