From a0fbf18d3b69923c9d88606ccb7d8df0e8bb1d00 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 7 Nov 2023 02:41:01 +0200 Subject: [PATCH] meminfo: better format for files without permissions --- userspace/meminfo/main.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/userspace/meminfo/main.cpp b/userspace/meminfo/main.cpp index 539daadb..0c7001cb 100644 --- a/userspace/meminfo/main.cpp +++ b/userspace/meminfo/main.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -30,8 +31,6 @@ int main() if (!is_only_digits(proc_ent->d_name)) continue; - printf("process: "); - { strcpy(path_buffer, proc_ent->d_name); strcat(path_buffer, "/cmdline"); @@ -39,10 +38,13 @@ int main() int fd = openat(dirfd(proc), path_buffer, O_RDONLY); if (fd == -1) { - perror("openat"); + if (errno != EACCES) + perror("openat"); continue; } + printf("process: "); + while (ssize_t nread = read(fd, path_buffer, sizeof(path_buffer) - 1)) { if (nread < 0) @@ -61,10 +63,12 @@ int main() written += printf("%s ", path_buffer + written); } + printf("\n"); + close(fd); } - printf("\n pid: %s\n", proc_ent->d_name); + printf(" pid: %s\n", proc_ent->d_name); { strcpy(path_buffer, proc_ent->d_name);