]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: convert more cases do DEVNUM_FORMAT_STR()/DEVNUM_FORMAT_VAL()
authorLennart Poettering <lennart@poettering.net>
Fri, 21 Apr 2023 10:34:37 +0000 (12:34 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 21 Apr 2023 10:41:15 +0000 (12:41 +0200)
Let's use our nice macros a bit more.

(Not comprehensive)

src/journal/journalctl.c
src/libsystemd/sd-device/sd-device.c
src/login/logind-session.c
src/shutdown/umount.c

index 5c07caa8f35077b6993569d7eae6a8db67e37a8f..12119b302c649dbe3c4c314b2731d664322b6cc4 100644 (file)
@@ -26,6 +26,7 @@
 #include "chase.h"
 #include "chattr-util.h"
 #include "constants.h"
+#include "devnum-util.h"
 #include "dissect-image.h"
 #include "fd-util.h"
 #include "fileio.h"
@@ -194,7 +195,7 @@ static int add_matches_for_device(sd_journal *j, const char *devpath) {
 
         r = sd_device_new_from_stat_rdev(&device, &st);
         if (r < 0)
-                return log_error_errno(r, "Failed to get device from devnum %u:%u: %m", major(st.st_rdev), minor(st.st_rdev));
+                return log_error_errno(r, "Failed to get device from devnum " DEVNUM_FORMAT_STR ": %m", DEVNUM_FORMAT_VAL(st.st_rdev));
 
         for (d = device; d; ) {
                 _cleanup_free_ char *match = NULL;
@@ -224,7 +225,7 @@ static int add_matches_for_device(sd_journal *j, const char *devpath) {
                         if (r < 0)
                                 return log_error_errno(r, "Failed to stat() device node \"%s\": %m", devnode);
 
-                        r = asprintf(&match1, "_KERNEL_DEVICE=%c%u:%u", S_ISBLK(st.st_mode) ? 'b' : 'c', major(st.st_rdev), minor(st.st_rdev));
+                        r = asprintf(&match1, "_KERNEL_DEVICE=%c" DEVNUM_FORMAT_STR, S_ISBLK(st.st_mode) ? 'b' : 'c', DEVNUM_FORMAT_VAL(st.st_rdev));
                         if (r < 0)
                                 return log_oom();
 
index e2eac651bd27fb3911fee97a7e454a6a7ded51ef..2c7b97ab4daa08fbd2c65ae160cac35397974029 100644 (file)
@@ -301,7 +301,7 @@ int device_new_from_mode_and_devnum(sd_device **ret, mode_t mode, dev_t devnum)
         if (major(devnum) == 0)
                 return -ENODEV;
 
-        if (asprintf(&syspath, "/sys/dev/%s/%u:%u", t, major(devnum), minor(devnum)) < 0)
+        if (asprintf(&syspath, "/sys/dev/%s/" DEVNUM_FORMAT_STR, t, DEVNUM_FORMAT_VAL(devnum)) < 0)
                 return -ENOMEM;
 
         r = sd_device_new_from_syspath(&dev, syspath);
@@ -1654,9 +1654,9 @@ int device_get_device_id(sd_device *device, const char **ret) {
 
                 if (sd_device_get_devnum(device, &devnum) >= 0) {
                         /* use dev_t — b259:131072, c254:0 */
-                        if (asprintf(&id, "%c%u:%u",
+                        if (asprintf(&id, "%c" DEVNUM_FORMAT_STR,
                                      streq(subsystem, "block") ? 'b' : 'c',
-                                     major(devnum), minor(devnum)) < 0)
+                                     DEVNUM_FORMAT_VAL(devnum)) < 0)
                                 return -ENOMEM;
                 } else if (sd_device_get_ifindex(device, &ifindex) >= 0) {
                         /* use netdev ifindex — n3 */
index 1daa102071c458c8cf1970d7dae8e162eee962dc..e7c917cdeef4e9b231831063aa0d7d483f831b30 100644 (file)
@@ -197,7 +197,7 @@ static void session_save_devices(Session *s, FILE *f) {
         if (!hashmap_isempty(s->devices)) {
                 fprintf(f, "DEVICES=");
                 HASHMAP_FOREACH(sd, s->devices)
-                        fprintf(f, "%u:%u ", major(sd->dev), minor(sd->dev));
+                        fprintf(f, DEVNUM_FORMAT_STR " ", DEVNUM_FORMAT_VAL(sd->dev));
                 fprintf(f, "\n");
         }
 }
index ebd5a754c5cefbd9ee1ac9cb695c4dd92b66f1b7..93e082d77eaa353528a71f757ec31779bfe2177d 100644 (file)
@@ -26,6 +26,7 @@
 #include "chase.h"
 #include "constants.h"
 #include "device-util.h"
+#include "devnum-util.h"
 #include "dirent-util.h"
 #include "escape.h"
 #include "fd-util.h"
@@ -890,7 +891,7 @@ static int dm_points_list_detach(MountPoint **head, bool *changed, bool last_try
                         continue;
                 }
 
-                log_info("Detaching DM %s (%u:%u).", m->path, major(m->devnum), minor(m->devnum));
+                log_info("Detaching DM %s (" DEVNUM_FORMAT_STR ").", m->path, DEVNUM_FORMAT_VAL(m->devnum));
                 r = delete_dm(m);
                 if (r < 0) {
                         log_full_errno(last_try ? LOG_ERR : LOG_INFO, r, "Could not detach DM %s: %m", m->path);
@@ -920,7 +921,7 @@ static int md_points_list_detach(MountPoint **head, bool *changed, bool last_try
                         continue;
                 }
 
-                log_info("Stopping MD %s (%u:%u).", m->path, major(m->devnum), minor(m->devnum));
+                log_info("Stopping MD %s (" DEVNUM_FORMAT_STR ").", m->path, DEVNUM_FORMAT_VAL(m->devnum));
                 r = delete_md(m);
                 if (r < 0) {
                         log_full_errno(last_try ? LOG_ERR : LOG_INFO, r, "Could not stop MD %s: %m", m->path);