Pass seperate dev_t var to device_path_parse_major_minor
authorYunQiang Su <syq@debian.org>
Tue, 25 Dec 2018 11:01:17 +0000 (19:01 +0800)
committerMichael Biebl <biebl@debian.org>
Thu, 27 Dec 2018 13:03:57 +0000 (13:03 +0000)
MIPS/O32's st_rdev member of struct stat is unsigned long, which
is 32bit, while dev_t is defined as 64bit, which make some problems
in device_path_parse_major_minor.

Don't pass st.st_rdev to device_path_parse_major_minor, while pass
a seperate var, and then assign into struct stat.

Gbp-Pq: Topic debian
Gbp-Pq: Name Pass-seperate-dev_t-var-to-device_path_parse_major_minor.patch

src/core/cgroup.c

index a7ce3fceaabd93a3144ae26026e6b39c3e037af4..1e0bfd8cb45615b10b6749d41f17dc24b00e0a34 100644 (file)
@@ -397,17 +397,20 @@ static void cgroup_xattr_apply(Unit *u) {
 
 static int lookup_block_device(const char *p, dev_t *ret) {
         struct stat st = {};
+        dev_t st_rdev;
         int r;
 
         assert(p);
         assert(ret);
 
-        r = device_path_parse_major_minor(p, &st.st_mode, &st.st_rdev);
+        r = device_path_parse_major_minor(p, &st.st_mode, &st_rdev);
         if (r == -ENODEV) { /* not a parsable device node, need to go to disk */
                 if (stat(p, &st) < 0)
                         return log_warning_errno(errno, "Couldn't stat device '%s': %m", p);
         } else if (r < 0)
                 return log_warning_errno(r, "Failed to parse major/minor from path '%s': %m", p);
+        else
+                st.st_rdev = (__typeof__ (st.st_rdev))st_rdev;
 
         if (S_ISCHR(st.st_mode)) {
                 log_warning("Device node '%s' is a character device, but block device needed.", p);
@@ -437,6 +440,7 @@ static int lookup_block_device(const char *p, dev_t *ret) {
 
 static int whitelist_device(BPFProgram *prog, const char *path, const char *node, const char *acc) {
         struct stat st = {};
+        dev_t st_rdev;
         int r;
 
         assert(path);
@@ -445,7 +449,7 @@ static int whitelist_device(BPFProgram *prog, const char *path, const char *node
         /* Some special handling for /dev/block/%u:%u, /dev/char/%u:%u, /run/systemd/inaccessible/chr and
          * /run/systemd/inaccessible/blk paths. Instead of stat()ing these we parse out the major/minor directly. This
          * means clients can use these path without the device node actually around */
-        r = device_path_parse_major_minor(node, &st.st_mode, &st.st_rdev);
+        r = device_path_parse_major_minor(node, &st.st_mode, &st_rdev);
         if (r < 0) {
                 if (r != -ENODEV)
                         return log_warning_errno(r, "Couldn't parse major/minor from device path '%s': %m", node);
@@ -457,7 +461,8 @@ static int whitelist_device(BPFProgram *prog, const char *path, const char *node
                         log_warning("%s is not a device.", node);
                         return -ENODEV;
                 }
-        }
+        } else
+                st.st_rdev = (__typeof__ (st.st_rdev))st_rdev;
 
         if (cg_all_unified() > 0) {
                 if (!prog)