]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
stat-util: add new macros for declaring statx variable
authorLennart Poettering <lennart@poettering.net>
Tue, 1 Sep 2020 16:24:44 +0000 (18:24 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 3 Sep 2020 13:02:16 +0000 (15:02 +0200)
Let's deal with the msan initialization issue once for all cases instead
of over and over again.

src/basic/mountpoint-util.c
src/basic/stat-util.h
src/basic/xattr-util.c
src/tmpfiles/tmpfiles.c

index 2ad27ce83057af45995b37dd421211a3794bf58e..681da7402457c2508fb85bd35fe9dcb4439ee573 100644 (file)
@@ -13,6 +13,7 @@
 #include "mountpoint-util.h"
 #include "parse-util.h"
 #include "path-util.h"
+#include "stat-util.h"
 #include "stdio-util.h"
 #include "strv.h"
 
@@ -135,13 +136,8 @@ int fd_is_mount_point(int fd, const char *filename, int flags) {
         _cleanup_free_ struct file_handle *h = NULL, *h_parent = NULL;
         int mount_id = -1, mount_id_parent = -1;
         bool nosupp = false, check_st_dev = true;
+        STRUCT_STATX_DEFINE(sx);
         struct stat a, b;
-        struct statx sx
-#if HAS_FEATURE_MEMORY_SANITIZER
-                = {}
-#  warning "Explicitly initializing struct statx, to work around msan limitation. Please remove as soon as msan has been updated to not require this."
-#endif
-                ;
         int r;
 
         assert(fd >= 0);
@@ -298,15 +294,7 @@ int path_is_mount_point(const char *t, const char *root, int flags) {
 }
 
 int path_get_mnt_id(const char *path, int *ret) {
-        union {
-                struct statx sx;
-                struct new_statx nsx;
-        } buf
-#if HAS_FEATURE_MEMORY_SANITIZER
-                = {}
-#  warning "Explicitly initializing struct statx, to work around msan limitation. Please remove as soon as msan has been updated to not require this."
-#endif
-                ;
+        STRUCT_NEW_STATX_DEFINE(buf);
         int r;
 
         if (statx(AT_FDCWD, path, AT_SYMLINK_NOFOLLOW|AT_NO_AUTOMOUNT, STATX_MNT_ID, &buf.sx) < 0) {
index 59aedcb7c4d727bfa1ecce990e6148c3c6cb21be..b14451b4e7efe746b37fe390e03024b19884482e 100644 (file)
@@ -91,3 +91,22 @@ int device_path_parse_major_minor(const char *path, mode_t *ret_mode, dev_t *ret
 int proc_mounted(void);
 
 bool stat_inode_unmodified(const struct stat *a, const struct stat *b);
+
+#if HAS_FEATURE_MEMORY_SANITIZER
+#  warning "Explicitly initializing struct statx, to work around msan limitation. Please remove as soon as msan has been updated to not require this."
+#  define STRUCT_STATX_DEFINE(var)              \
+        struct statx var = {}
+#  define STRUCT_NEW_STATX_DEFINE(var)          \
+        union {                                 \
+                struct statx sx;                \
+                struct new_statx nsx;           \
+        } var = {}
+#else
+#  define STRUCT_STATX_DEFINE(var)              \
+        struct statx var
+#  define STRUCT_NEW_STATX_DEFINE(var)          \
+        union {                                 \
+                struct statx sx;                \
+                struct new_statx nsx;           \
+        } var
+#endif
index 0125a9c2c08bf67171ceb4e58483f534e8bf41bc..fe0735ed3daba371a5941da665a9a51712b69e78 100644 (file)
@@ -12,6 +12,7 @@
 #include "macro.h"
 #include "missing_syscall.h"
 #include "sparse-endian.h"
+#include "stat-util.h"
 #include "stdio-util.h"
 #include "string-util.h"
 #include "time-util.h"
@@ -154,12 +155,7 @@ static int parse_crtime(le64_t le, usec_t *usec) {
 }
 
 int fd_getcrtime_at(int dirfd, const char *name, usec_t *ret, int flags) {
-        struct_statx sx
-#if HAS_FEATURE_MEMORY_SANITIZER
-                = {}
-#  warning "Explicitly initializing struct statx, to work around msan limitation. Please remove as soon as msan has been updated to not require this."
-#endif
-                ;
+        STRUCT_STATX_DEFINE(sx);
         usec_t a, b;
         le64_t le;
         size_t n;
index 7ab655cd6f40223a308180c331b0d1c4daaf8a06..36e31d046c724ae2081947f66c3f0ba4f15b6be0 100644 (file)
@@ -544,12 +544,7 @@ static int dir_cleanup(
                          * file systems such as overlayfs better where each file is originating from a
                          * different st_dev. */
 
-                        struct statx sx
-#if HAS_FEATURE_MEMORY_SANITIZER
-                                = {}
-#  warning "Explicitly initializing struct statx, to work around msan limitation. Please remove as soon as msan has been updated to not require this."
-#endif
-                                ;
+                        STRUCT_STATX_DEFINE(sx);
 
                         if (statx(dirfd(d), dent->d_name,
                                   AT_SYMLINK_NOFOLLOW|AT_NO_AUTOMOUNT,
@@ -2293,17 +2288,11 @@ static int clean_item_instance(Item *i, const char* instance) {
         _cleanup_closedir_ DIR *d = NULL;
         uint32_t dev_major, dev_minor;
         nsec_t atime_nsec, mtime_nsec;
+        STRUCT_STATX_DEFINE(sx);
         int mountpoint = -1;
         usec_t cutoff, n;
         uint64_t ino;
 
-        struct statx sx
-#if HAS_FEATURE_MEMORY_SANITIZER
-                = {}
-#  warning "Explicitly initializing struct statx, to work around msan limitation. Please remove as soon as msan has been updated to not require this."
-#endif
-                ;
-
         assert(i);
 
         if (!i->age_set)