summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlastair Poole <netstar@gmail.com>2021-09-19 20:37:57 +0100
committerAlastair Poole <netstar@gmail.com>2021-09-19 20:37:57 +0100
commita6ac72bff5fbb7636f510dc986d0726906037c0a (patch)
treea28abc12c47c597714e0362521ccd642ce847a07
parent98883e5c1a8b377775448d9616bde9f848fe7ee3 (diff)
process: ...
-rw-r--r--src/bin/system/process.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/src/bin/system/process.c b/src/bin/system/process.c
index 244de91..69ed426 100644
--- a/src/bin/system/process.c
+++ b/src/bin/system/process.c
@@ -161,37 +161,47 @@ _mem_size(Proc_Info *proc)
161static void 161static void
162_cmd_args(Proc_Info *p, char *name, size_t len) 162_cmd_args(Proc_Info *p, char *name, size_t len)
163{ 163{
164 char buf[8192]; 164 char path[PATH_MAX];
165 char line[4096];
165 int pid = p->pid; 166 int pid = p->pid;
166 167
167 snprintf(buf, sizeof(buf), "/proc/%d/exe", pid); 168 snprintf(path, sizeof(path), "/proc/%d/exe", pid);
168 char *link = ecore_file_readlink(buf); 169 char *link = ecore_file_readlink(path);
169 if (link) 170 if (link)
170 { 171 {
171 snprintf(name, len, "%s", ecore_file_file_get(link)); 172 snprintf(name, len, "%s", ecore_file_file_get(link));
172 free(link); 173 free(link);
173 } 174 }
174 175
175 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid); 176 snprintf(path, sizeof(path), "/proc/%d/cmdline", pid);
176 FILE *f = fopen(buf, "r"); 177 FILE *f = fopen(path, "r");
177 if (f) 178 if (f)
178 { 179 {
179 if (fgets(buf, sizeof(buf), f)) 180 if (fgets(line, sizeof(line), f))
180 { 181 {
181 Eina_Strbuf *b = eina_strbuf_new(); 182 int sz = ftell(f);
182 const char *n; 183 Eina_Strbuf *buf = eina_strbuf_new();
183 184
184 if (ecore_file_exists(buf)) 185 if (ecore_file_exists(line))
185 snprintf(name, len, "%s", ecore_file_file_get(buf)); 186 snprintf(name, len, "%s", ecore_file_file_get(line));
186 187
187 n = buf; 188 const char *cp = line;
188 while (n && *n && (*n + 1)) 189 for (int i = 0; i < sz; i++)
189 { 190 {
190 eina_strbuf_append(b, n); 191 if (line[i] == '\0')
191 n = strchr(n, '\0') + 1; 192 {
192 if (n && *n && (*n + 1)) eina_strbuf_append(b, " "); 193 if (*cp)
194 eina_strbuf_append(buf, cp);
195 if ((i + 1) < sz)
196 {
197 i++;
198 cp = &line[i];
199 if (*cp)
200 eina_strbuf_append(buf, " ");
201 }
202 }
193 } 203 }
194 p->arguments = eina_strbuf_release(b); 204 p->arguments = eina_strbuf_release(buf);
195 } 205 }
196 fclose(f); 206 fclose(f);
197 } 207 }