]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: introduce is_opened_file macro
authorMasatake YAMATO <yamato@redhat.com>
Thu, 10 Nov 2022 20:54:28 +0000 (05:54 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Wed, 23 Nov 2022 07:42:11 +0000 (16:42 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
misc-utils/lsfd-file.c
misc-utils/lsfd-sock.c
misc-utils/lsfd.h

index c82105c75ec3ce68abf38ac1b0b628bab571dc11..0c473fdded7f2ee46163afdd97c9488fb50ef5db 100644 (file)
@@ -153,11 +153,11 @@ static bool file_fill_column(struct proc *proc,
                        err(EXIT_FAILURE, _("failed to add output data"));
                return true;
        case COL_FD:
-               if (file->association < 0)
+               if (!is_opened_file(file))
                        return false;
                /* FALL THROUGH */
        case COL_ASSOC:
-               if (file->association >= 0)
+               if (is_opened_file(file))
                        xasprintf(&str, "%d", file->association);
                else {
                        int assoc = file->association * -1;
@@ -221,7 +221,7 @@ static bool file_fill_column(struct proc *proc,
                xasprintf(&str, "%u", proc->kthread);
                break;
        case COL_MNT_ID:
-               xasprintf(&str, "%d", file->association < 0? 0: file->mnt_id);
+               xasprintf(&str, "%d", is_opened_file(file)? file->mnt_id: 0);
                break;
        case COL_MODE:
                if (does_file_has_fdinfo_alike(file))
@@ -241,7 +241,7 @@ static bool file_fill_column(struct proc *proc,
        case COL_FLAGS: {
                struct ul_buffer buf = UL_INIT_BUFFER;
 
-               if (file->association < 0)
+               if (!is_opened_file(file))
                        return true;
 
                if (file->sys_flags == 0)
index e99e2350891d990f11daa15edf1b1c1476f75347..83f35e5d4fe1fa3117b505e9176f20ba89b7307d 100644 (file)
@@ -133,7 +133,7 @@ static void init_sock_content(struct file *file)
 
                assert(file->proc);
 
-               if (fd >= 0)
+               if (is_opened_file(file))
                        sprintf(path, "/proc/%d/fd/%d", file->proc->pid, fd);
                else
                        sprintf(path, "/proc/%d/map_files/%"PRIx64 "-%" PRIx64,
index ccf33ae41ce04dc933617f2cfa094cfa7b8a2390..d6329c69684ab32bcf4f7591add141ca24767561 100644 (file)
@@ -148,6 +148,7 @@ struct file {
        unsigned int mnt_id;
 };
 
+#define is_opened_file(_f) ((_f)->association >= 0)
 #define is_association(_f, a)  ((_f)->association < 0 && (_f)->association == -ASSOC_ ## a)
 
 struct file_class {