process: arg list.

This commit is contained in:
Alastair Poole 2021-09-23 08:35:51 +01:00
parent 71870b1073
commit fca5360b16
1 changed files with 25 additions and 16 deletions

View File

@ -159,37 +159,46 @@ _mem_size(Proc_Info *proc)
static void static void
_cmd_args(Proc_Info *p, char *name, size_t len) _cmd_args(Proc_Info *p, char *name, size_t len)
{ {
char buf[8192]; char path[PATH_MAX];
char line[4096];
int pid = p->pid; int pid = p->pid;
snprintf(buf, sizeof(buf), "/proc/%d/exe", pid); snprintf(path, sizeof(path), "/proc/%i/exe", pid);
char *link = ecore_file_readlink(buf); char *link = ecore_file_readlink(path);
if (link) if (link)
{ {
snprintf(name, len, "%s", ecore_file_file_get(link)); snprintf(name, len, "%s", ecore_file_file_get(link));
free(link); free(link);
} }
snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid); snprintf(path, sizeof(path), "/proc/%i/cmdline", pid);
FILE *f = fopen(buf, "r"); FILE *f = fopen(path, "r");
if (f) if (f)
{ {
if (fgets(buf, sizeof(buf), f)) if (fgets(line, sizeof(line), f))
{ {
Eina_Strbuf *b = eina_strbuf_new(); int sz = ftell(f);
const char *n; Eina_Strbuf *buf = eina_strbuf_new();
if (ecore_file_exists(buf)) snprintf(name, len, "%s", ecore_file_file_get(line));
snprintf(name, len, "%s", ecore_file_file_get(buf));
n = buf; const char *cp = line;
while (n && *n && (*n + 1)) for (int i = 0; i < sz; i++)
{ {
eina_strbuf_append(b, n); if (line[i] == '\0')
n = strchr(n, '\0') + 1; {
if (n && *n && (*n + 1)) eina_strbuf_append(b, " "); if (*cp)
eina_strbuf_append(buf, cp);
if ((i + 1) < sz)
{
i++;
cp = &line[i];
if (*cp)
eina_strbuf_append(buf, " ");
}
}
} }
p->arguments = eina_strbuf_release(b); p->arguments = eina_strbuf_release(buf);
} }
fclose(f); fclose(f);
} }