This commit is contained in:
Your Name 2024-07-10 22:59:28 +03:00
parent 1b9dc6d7dc
commit 0737916f1a
11 changed files with 71 additions and 35 deletions

View file

@ -2,22 +2,23 @@
char mu_hs_buf[MU_HUMAN_BUF_SIZE + 1];
char *mu_humansize(off_t n, off_t block) {
char *mu_humansize(off_t n, int block) {
memset(mu_hs_buf, '\0', sizeof(mu_hs_buf));
char *postfixes = "BKMGTPE";
size_t i = 0;
double size = n;
size_t i;
for (i = 0; i < strlen(postfixes) && size >= block; i++)
size /= block;
while (size > (off_t)block) {
size /= (off_t)block;
i++;
}
if (i)
snprintf(mu_hs_buf, sizeof(mu_hs_buf), "%.1f%c", size, postfixes[i]);
else
snprintf(mu_hs_buf, sizeof(mu_hs_buf), "%ju", n);
snprintf(mu_hs_buf, sizeof(mu_hs_buf), "%jd", n);
return mu_hs_buf;
}

View file

@ -7,5 +7,5 @@
#define MU_HUMAN_BUF_SIZE 16
char *mu_humansize(off_t n, off_t block);
char *mu_humansize(off_t n, int block);
#endif

View file

@ -1,6 +1,6 @@
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>
#include "parse_mode.h"
#define U (S_ISUID | S_IRWXU)
#define G (S_ISGID | S_IRWXG)

View file

@ -1,7 +1,7 @@
#ifndef _PARSE_MOUNT_H
#define _PARSE_MOUNT_H
#include <sys/mount.h>
#include <stdlib.h>
#include <sys/mount.h>
typedef struct {
char *opt;

View file

@ -44,10 +44,7 @@ int mu_proc_status(const char *prog_name, const pid_t pid, struct mu_proc *proc_
val++;
/* Write values */
if (!strncmp(token, "Name", 4))
strcpy(proc_s->prog, val);
else if (!strncmp(token, "Uid", 3))
if (!strncmp(token, "Uid", 3))
proc_s->uid = strtoul(val, 0L, 10);
else if (!strncmp(token, "Gid", 3))
@ -78,6 +75,11 @@ int mu_proc_stat(const char *prog_name, const pid_t pid, struct mu_proc *proc_s)
fscanf(fp, "%ld %ld %ld %ld %ld %ld %llu %lu %ld", &proc_s->cutime, &proc_s->cstime, &proc_s->priority, &proc_s->nice, &proc_s->num_threads, &proc_s->itrealvalue, &proc_s->starttime, &proc_s->vsize, &proc_s->rss);
fclose(fp);
/* Remove ( and ) from string */
size_t len = strlen(proc_s->cmdline) - 1;
proc_s->cmdline[len] = '\0';
memmove(proc_s->cmdline, proc_s->cmdline + 1, len);
return 0;
}

View file

@ -7,7 +7,6 @@
struct mu_proc {
/* from status */
char prog[PATH_MAX + 1];
uid_t uid;
gid_t gid;
long vmrss;