chiark / gitweb /
copy: teach copy_bytes() sendfile() support, and then replace sendfile_full() by it
[elogind.git] / src / system-update-generator / system-update-generator.c
index 0cfccfb494bc3a96a4d4544cc2ade813ab408b66..4f22c9c3590bcda6021e0460166c9792b61616a3 100644 (file)
 #include "unit-name.h"
 #include "path-util.h"
 
+/*
+ * Implements the logic described in
+ * http://freedesktop.org/wiki/Software/systemd/SystemUpdates
+ */
+
 static const char *arg_dest = "/tmp";
 
 static int generate_symlink(void) {
-        struct stat st;
-        char *p;
+        const char *p = NULL;
 
-        if (lstat("/system-update", &st) < 0) {
+        if (access("/system-update", F_OK) < 0) {
                 if (errno == ENOENT)
                         return 0;
 
@@ -41,35 +45,27 @@ static int generate_symlink(void) {
                 return -EINVAL;
         }
 
-        p = strappend(arg_dest, "/default.target");
-        if (!p) {
-                log_error("Out of memory.");
-                return -ENOMEM;
-        }
-
+        p = strappenda(arg_dest, "/default.target");
         if (symlink(SYSTEM_DATA_UNIT_PATH "/system-update.target", p) < 0) {
-                free(p);
-                log_error("Failed to create symlink: %m");
+                log_error("Failed to create symlink %s: %m", p);
                 return -errno;
         }
 
-        free(p);
-
         return 0;
 }
 
 int main(int argc, char *argv[]) {
         int r;
 
-        if (argc > 2) {
-                log_error("This program takes one or no arguments.");
+        if (argc > 1 && argc != 4) {
+                log_error("This program takes three or no arguments.");
                 return EXIT_FAILURE;
         }
 
         if (argc > 1)
-                arg_dest = argv[1];
+                arg_dest = argv[2];
 
-        log_set_target(LOG_TARGET_AUTO);
+        log_set_target(LOG_TARGET_SAFE);
         log_parse_environment();
         log_open();