]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Revert "sd-id128: make id128_read() optionally take root directory"
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 3 Apr 2023 01:39:00 +0000 (10:39 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 4 Apr 2023 02:46:18 +0000 (11:46 +0900)
This reverts commit 830e52caa2bf1a29f56cb93e7ed85acb1bda11c3.

src/libsystemd/sd-id128/id128-util.c
src/libsystemd/sd-id128/id128-util.h
src/libsystemd/sd-id128/sd-id128.c
src/machine-id-setup/machine-id-setup-main.c
src/nspawn/nspawn.c

index 974aafa5b735b59925e3becb34459cb588e8a086..a009a110a96fdfb58ba67443eb508a75fb59276b 100644 (file)
@@ -4,7 +4,6 @@
 #include <fcntl.h>
 #include <unistd.h>
 
-#include "chase.h"
 #include "fd-util.h"
 #include "hexdecoct.h"
 #include "id128-util.h"
@@ -102,14 +101,12 @@ int id128_read_fd(int fd, Id128FormatFlag f, sd_id128_t *ret) {
         return r == -EINVAL ? -EUCLEAN : r;
 }
 
-int id128_read(const char *root, const char *p, Id128FormatFlag f, sd_id128_t *ret) {
+int id128_read(const char *p, Id128FormatFlag f, sd_id128_t *ret) {
         _cleanup_close_ int fd = -EBADF;
 
-        assert(p);
-
-        fd = chase_and_open(p, root, CHASE_PREFIX_ROOT, O_RDONLY|O_CLOEXEC|O_NOCTTY, /* ret_path = */ NULL);
+        fd = open(p, O_RDONLY|O_CLOEXEC|O_NOCTTY);
         if (fd < 0)
-                return fd;
+                return -errno;
 
         return id128_read_fd(fd, f, ret);
 }
@@ -187,9 +184,9 @@ int id128_get_product(sd_id128_t *ret) {
         /* Reads the systems product UUID from DMI or devicetree (where it is located on POWER). This is
          * particularly relevant in VM environments, where VM managers typically place a VM uuid there. */
 
-        r = id128_read(NULL, "/sys/class/dmi/id/product_uuid", ID128_FORMAT_UUID, &uuid);
+        r = id128_read("/sys/class/dmi/id/product_uuid", ID128_FORMAT_UUID, &uuid);
         if (r == -ENOENT)
-                r = id128_read(NULL, "/proc/device-tree/vm,uuid", ID128_FORMAT_UUID, &uuid);
+                r = id128_read("/proc/device-tree/vm,uuid", ID128_FORMAT_UUID, &uuid);
         if (r < 0)
                 return r;
 
index 2ebca8fd95145da6d6f9a6eac57acbede46f263a..e094de64419406c11a3b6226f3a8ee8ca0378741 100644 (file)
@@ -19,7 +19,7 @@ typedef enum Id128FormatFlag {
 } Id128FormatFlag;
 
 int id128_read_fd(int fd, Id128FormatFlag f, sd_id128_t *ret);
-int id128_read(const char *root, const char *p, Id128FormatFlag f, sd_id128_t *ret);
+int id128_read(const char *p, Id128FormatFlag f, sd_id128_t *ret);
 
 int id128_write_fd(int fd, Id128FormatFlag f, sd_id128_t id);
 int id128_write(const char *p, Id128FormatFlag f, sd_id128_t id);
index 03f0ddd182970901b01271ab422709c29e8e5166..5ce36cf2fc9c51d3586aa506bde5773d6921d212 100644 (file)
@@ -126,7 +126,7 @@ _public_ int sd_id128_get_machine(sd_id128_t *ret) {
         int r;
 
         if (sd_id128_is_null(saved_machine_id)) {
-                r = id128_read(NULL, "/etc/machine-id", ID128_FORMAT_PLAIN, &saved_machine_id);
+                r = id128_read("/etc/machine-id", ID128_FORMAT_PLAIN, &saved_machine_id);
                 if (r < 0)
                         return r;
 
@@ -144,7 +144,7 @@ _public_ int sd_id128_get_boot(sd_id128_t *ret) {
         int r;
 
         if (sd_id128_is_null(saved_boot_id)) {
-                r = id128_read(NULL, "/proc/sys/kernel/random/boot_id", ID128_FORMAT_UUID, &saved_boot_id);
+                r = id128_read("/proc/sys/kernel/random/boot_id", ID128_FORMAT_UUID, &saved_boot_id);
                 if (r == -ENOENT && proc_mounted() == 0)
                         return -ENOSYS;
                 if (r < 0)
index 2d2989086437fe2a2e3d4ec4a57cdfbc700bce33..5620bf9bafc750da7c1b8bd155548a846a94fac0 100644 (file)
@@ -158,11 +158,14 @@ static int run(int argc, char *argv[]) {
         }
 
         if (arg_commit) {
+                const char *etc_machine_id;
+
                 r = machine_id_commit(arg_root);
                 if (r < 0)
                         return r;
 
-                r = id128_read(arg_root, "/etc/machine-id", ID128_FORMAT_PLAIN, &id);
+                etc_machine_id = prefix_roota(arg_root, "/etc/machine-id");
+                r = id128_read(etc_machine_id, ID128_FORMAT_PLAIN, &id);
                 if (r < 0)
                         return log_error_errno(r, "Failed to read machine ID back: %m");
         } else {
index 982dffd1b89c1b7d99532edddf305b80de3e5597..9fbacb2713eae3e831c623bf53795310a730035f 100644 (file)
@@ -2828,6 +2828,7 @@ static int mount_tunnel_open(void) {
 }
 
 static int setup_machine_id(const char *directory) {
+        const char *etc_machine_id;
         sd_id128_t id;
         int r;
 
@@ -2838,7 +2839,9 @@ static int setup_machine_id(const char *directory) {
          * in the container and our idea of the container UUID will always be in sync (at least if PID 1 in the
          * container behaves nicely). */
 
-        r = id128_read(directory, "/etc/machine-id", ID128_FORMAT_PLAIN, &id);
+        etc_machine_id = prefix_roota(directory, "/etc/machine-id");
+
+        r = id128_read(etc_machine_id, ID128_FORMAT_PLAIN, &id);
         if (r < 0) {
                 if (!ERRNO_IS_MACHINE_ID_UNSET(r)) /* If the file is missing, empty, or uninitialized, we don't mind */
                         return log_error_errno(r, "Failed to read machine ID from container image: %m");