]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: use read_full_virtual_file() where appropriate
authorLennart Poettering <lennart@poettering.net>
Wed, 17 Mar 2021 17:43:42 +0000 (18:43 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 17 Mar 2021 17:43:42 +0000 (18:43 +0100)
Wherever we read virtual files we better should use
read_full_virtual_file(), to make sure we get a consistent response
given how weird the kernel's handling with partial read on such file
systems is.

src/basic/cgroup-util.c
src/basic/mountpoint-util.c
src/basic/process-util.c
src/coredump/coredump.c
src/libsystemd/sd-bus/bus-creds.c
src/libsystemd/sd-device/sd-device.c
src/pstore/pstore.c
src/shared/acpi-fpdt.c

index 0b252eb28fb82c9b35aaa8a402da66108d7e8f7c..8dd3f8cd95018b46a9cef8800e3835e665b908da 100644 (file)
@@ -100,7 +100,7 @@ int cg_read_event(
         if (r < 0)
                 return r;
 
-        r = read_full_file(events, &content, NULL);
+        r = read_full_virtual_file(events, &content, NULL);
         if (r < 0)
                 return r;
 
index adf10a454813b447d9f4d1a8b747f4e409503af6..c8f6675eb8676b88855c70115f86ba52ffffcc0d 100644 (file)
@@ -114,7 +114,7 @@ static int fd_fdinfo_mnt_id(int fd, const char *filename, int flags, int *ret_mn
                 xsprintf(path, "/proc/self/fdinfo/%i", subfd);
         }
 
-        r = read_full_file(path, &fdinfo, NULL);
+        r = read_full_virtual_file(path, &fdinfo, NULL);
         if (r == -ENOENT) /* The fdinfo directory is a relatively new addition */
                 return -EOPNOTSUPP;
         if (r < 0)
index d3eb3ad18bade336795f54c0cb9f3164567d9cca..eb257144f02ee1a2538d1067650c78ff2a27d384 100644 (file)
@@ -1548,7 +1548,7 @@ int pidfd_get_pid(int fd, pid_t *ret) {
 
         xsprintf(path, "/proc/self/fdinfo/%i", fd);
 
-        r = read_full_file(path, &fdinfo, NULL);
+        r = read_full_virtual_file(path, &fdinfo, NULL);
         if (r == -ENOENT) /* if fdinfo doesn't exist we assume the process does not exist */
                 return -ESRCH;
         if (r < 0)
index 72e859a565dafb7a1e7429f1aa921aae82ea7d78..2fb2404500e88c026241b69ad03c71178ac831e8 100644 (file)
@@ -1125,23 +1125,23 @@ static int gather_pid_metadata(struct iovec_wrapper *iovw, Context *context) {
                 (void) iovw_put_string_field_free(iovw, "COREDUMP_OPEN_FDS=", t);
 
         p = procfs_file_alloca(pid, "status");
-        if (read_full_file(p, &t, NULL) >= 0)
+        if (read_full_virtual_file(p, &t, NULL) >= 0)
                 (void) iovw_put_string_field_free(iovw, "COREDUMP_PROC_STATUS=", t);
 
         p = procfs_file_alloca(pid, "maps");
-        if (read_full_file(p, &t, NULL) >= 0)
+        if (read_full_virtual_file(p, &t, NULL) >= 0)
                 (void) iovw_put_string_field_free(iovw, "COREDUMP_PROC_MAPS=", t);
 
         p = procfs_file_alloca(pid, "limits");
-        if (read_full_file(p, &t, NULL) >= 0)
+        if (read_full_virtual_file(p, &t, NULL) >= 0)
                 (void) iovw_put_string_field_free(iovw, "COREDUMP_PROC_LIMITS=", t);
 
         p = procfs_file_alloca(pid, "cgroup");
-        if (read_full_file(p, &t, NULL) >=0)
+        if (read_full_virtual_file(p, &t, NULL) >=0)
                 (void) iovw_put_string_field_free(iovw, "COREDUMP_PROC_CGROUP=", t);
 
         p = procfs_file_alloca(pid, "mountinfo");
-        if (read_full_file(p, &t, NULL) >=0)
+        if (read_full_virtual_file(p, &t, NULL) >=0)
                 (void) iovw_put_string_field_free(iovw, "COREDUMP_PROC_MOUNTINFO=", t);
 
         if (get_process_cwd(pid, &t) >= 0)
index 3134d8ef1723aac663de573ab174c3ccf535b1b1..5e748fdb462b986bf4877327e0ca51886e3c6e5c 100644 (file)
@@ -1002,7 +1002,7 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
                 const char *p;
 
                 p = procfs_file_alloca(pid, "cmdline");
-                r = read_full_file(p, &c->cmdline, &c->cmdline_size);
+                r = read_full_virtual_file(p, &c->cmdline, &c->cmdline_size);
                 if (r == -ENOENT)
                         return -ESRCH;
                 if (r < 0) {
index 964ef1318edfeaf2efb75d07567e0a659bfe8f45..e556a6f838ca9237913c5b747296c8b8d0ae40d7 100644 (file)
@@ -513,7 +513,7 @@ int device_read_uevent_file(sd_device *device) {
 
         path = strjoina(syspath, "/uevent");
 
-        r = read_full_file(path, &uevent, &uevent_len);
+        r = read_full_virtual_file(path, &uevent, &uevent_len);
         if (r == -EACCES) {
                 /* empty uevent files may be write-only */
                 device->uevent_loaded = true;
index 9d59c608c1516d98126dc979f00edc3433945bd9..6ce38f10a3e08dcb653a85b59379898be1a372b8 100644 (file)
@@ -342,7 +342,7 @@ static int list_files(PStoreList *list, const char *sourcepath) {
                 size_t buf_size;
 
                 /* Now read contents of pstore file */
-                r = read_full_file(ifd_path, &buf, &buf_size);
+                r = read_full_virtual_file(ifd_path, &buf, &buf_size);
                 if (r < 0) {
                         log_warning_errno(r, "Failed to read file %s, skipping: %m", ifd_path);
                         continue;
index 11244537991e60c57c0eb956a258da6e113a50be..cccea2f72752dd116e2c19b1e90bf367331ee2b2 100644 (file)
@@ -72,7 +72,7 @@ int acpi_get_boot_usec(usec_t *loader_start, usec_t *loader_exit) {
         struct acpi_fpdt_boot_header hbrec;
         struct acpi_fpdt_boot brec;
 
-        r = read_full_file("/sys/firmware/acpi/tables/FPDT", &buf, &l);
+        r = read_full_virtual_file("/sys/firmware/acpi/tables/FPDT", &buf, &l);
         if (r < 0)
                 return r;