aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2019-12-23 19:39:32 +0100
committerToni Uhlig <matzeton@googlemail.com>2019-12-23 19:39:32 +0100
commitbb5865eb200957ec28aed0c6734403bc941a2c71 (patch)
tree54539c25ec59fdf0670c253f6fab0e727d029b7e
parent055033764bd3f7ae6c85e596b6e22c756f5c34e8 (diff)
print command line and arguments
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r--progressbar.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/progressbar.c b/progressbar.c
index 0785c42..38e1da9 100644
--- a/progressbar.c
+++ b/progressbar.c
@@ -185,11 +185,12 @@ static int read_and_parse_fd_pos(struct file_info * const finfo)
return 0;
}
-static int read_proc_cmdline(char * dest, size_t size,
+static void read_proc_cmdline(char * dest, size_t size,
const char * const proc_pid)
{
int cmdline_fd;
char buf[MAX_CMDLINE_LEN];
+ ssize_t bytes_read;
assert(dest && size && proc_pid);
@@ -197,17 +198,20 @@ static int read_proc_cmdline(char * dest, size_t size,
"/proc", proc_pid) <= 0)
{
dest[0] = '\0';
- return -1;
}
cmdline_fd = open(buf, 0);
- if (read(cmdline_fd, buf, sizeof buf) <= 0)
- {
+ bytes_read = read(cmdline_fd, buf, sizeof buf);
+ if (bytes_read <= 0) {
dest[0] = '\0';
- return -1;
}
close(cmdline_fd);
- return snprintf(dest, size, "%.*s", MAX_CMDLINE_LEN, buf);
+ while (--bytes_read) {
+ if (buf[bytes_read - 1] == '\0') {
+ buf[bytes_read - 1] = ' ';
+ }
+ }
+ strncpy(dest, buf, size);
}
static int reset_terminal_output(struct file_info * const finfo)