diff options
author | Jorge Lucangeli Obes | 2016-04-25 17:38:05 -0500 |
---|---|---|
committer | Jorge Lucangeli Obes | 2016-04-25 18:31:15 -0500 |
commit | 5c1b3afbd4983aa0ba318711d74e565e72afb804 (patch) | |
tree | 2220482429ceab531eebc548c9f9507995a52a38 /toolbox | |
parent | 47f808d09f3f2ecfff62dfb6ff57090ff106469a (diff) | |
download | platform-system-core-5c1b3afbd4983aa0ba318711d74e565e72afb804.tar.gz platform-system-core-5c1b3afbd4983aa0ba318711d74e565e72afb804.tar.xz platform-system-core-5c1b3afbd4983aa0ba318711d74e565e72afb804.zip |
Fix 'ps.c' formatting.
Insert a space between 'if'/'while' and their clause.
Also insert a space after ',' for arguments.
This was done with clang-format.
Bug: None
Change-Id: I5315eba3d5d8ac68996a373dc7c8e1bc45165824
Diffstat (limited to 'toolbox')
-rw-r--r-- | toolbox/ps.c | 65 |
1 files changed, 32 insertions, 33 deletions
diff --git a/toolbox/ps.c b/toolbox/ps.c index 633c48ea5..3b3c8a1ae 100644 --- a/toolbox/ps.c +++ b/toolbox/ps.c | |||
@@ -60,7 +60,7 @@ static int ps_line(int pid, int tid) | |||
60 | snprintf(statline, sizeof(statline), "/proc/%d", tid ? tid : pid); | 60 | snprintf(statline, sizeof(statline), "/proc/%d", tid ? tid : pid); |
61 | stat(statline, &stats); | 61 | stat(statline, &stats); |
62 | 62 | ||
63 | if(tid) { | 63 | if (tid) { |
64 | snprintf(statline, sizeof(statline), "/proc/%d/task/%d/stat", pid, tid); | 64 | snprintf(statline, sizeof(statline), "/proc/%d/task/%d/stat", pid, tid); |
65 | cmdline[0] = 0; | 65 | cmdline[0] = 0; |
66 | snprintf(macline, sizeof(macline), "/proc/%d/task/%d/attr/current", pid, tid); | 66 | snprintf(macline, sizeof(macline), "/proc/%d/task/%d/attr/current", pid, tid); |
@@ -69,21 +69,21 @@ static int ps_line(int pid, int tid) | |||
69 | snprintf(cmdline, sizeof(cmdline), "/proc/%d/cmdline", pid); | 69 | snprintf(cmdline, sizeof(cmdline), "/proc/%d/cmdline", pid); |
70 | snprintf(macline, sizeof(macline), "/proc/%d/attr/current", pid); | 70 | snprintf(macline, sizeof(macline), "/proc/%d/attr/current", pid); |
71 | int fd = open(cmdline, O_RDONLY); | 71 | int fd = open(cmdline, O_RDONLY); |
72 | if(fd == 0) { | 72 | if (fd == 0) { |
73 | r = 0; | 73 | r = 0; |
74 | } else { | 74 | } else { |
75 | r = read(fd, cmdline, 1023); | 75 | r = read(fd, cmdline, 1023); |
76 | close(fd); | 76 | close(fd); |
77 | if(r < 0) r = 0; | 77 | if (r < 0) r = 0; |
78 | } | 78 | } |
79 | cmdline[r] = 0; | 79 | cmdline[r] = 0; |
80 | } | 80 | } |
81 | 81 | ||
82 | int fd = open(statline, O_RDONLY); | 82 | int fd = open(statline, O_RDONLY); |
83 | if(fd == 0) return -1; | 83 | if (fd == 0) return -1; |
84 | r = read(fd, statline, 1023); | 84 | r = read(fd, statline, 1023); |
85 | close(fd); | 85 | close(fd); |
86 | if(r < 0) return -1; | 86 | if (r < 0) return -1; |
87 | statline[r] = 0; | 87 | statline[r] = 0; |
88 | 88 | ||
89 | ptr = statline; | 89 | ptr = statline; |
@@ -142,19 +142,19 @@ static int ps_line(int pid, int tid) | |||
142 | 142 | ||
143 | nexttok(&ptr); // tty | 143 | nexttok(&ptr); // tty |
144 | 144 | ||
145 | if(tid != 0) { | 145 | if (tid != 0) { |
146 | ppid = pid; | 146 | ppid = pid; |
147 | pid = tid; | 147 | pid = tid; |
148 | } | 148 | } |
149 | 149 | ||
150 | pw = getpwuid(stats.st_uid); | 150 | pw = getpwuid(stats.st_uid); |
151 | if(pw == 0 || (display_flags & SHOW_NUMERIC_UID)) { | 151 | if (pw == 0 || (display_flags & SHOW_NUMERIC_UID)) { |
152 | snprintf(user,sizeof(user),"%d",(int)stats.st_uid); | 152 | snprintf(user, sizeof(user), "%d", (int)stats.st_uid); |
153 | } else { | 153 | } else { |
154 | strcpy(user,pw->pw_name); | 154 | strcpy(user, pw->pw_name); |
155 | } | 155 | } |
156 | 156 | ||
157 | if(ppid_filter != 0 && ppid != ppid_filter) { | 157 | if (ppid_filter != 0 && ppid != ppid_filter) { |
158 | return 0; | 158 | return 0; |
159 | } | 159 | } |
160 | 160 | ||
@@ -196,7 +196,7 @@ static int ps_line(int pid, int tid) | |||
196 | print_exe_abi(pid); | 196 | print_exe_abi(pid); |
197 | } | 197 | } |
198 | printf("%s", cmdline[0] ? cmdline : name); | 198 | printf("%s", cmdline[0] ? cmdline : name); |
199 | if(display_flags&SHOW_TIME) | 199 | if (display_flags & SHOW_TIME) |
200 | printf(" (u:%d, s:%d)", utime, stime); | 200 | printf(" (u:%d, s:%d)", utime, stime); |
201 | 201 | ||
202 | printf("\n"); | 202 | printf("\n"); |
@@ -210,13 +210,13 @@ static void print_exe_abi(int pid) | |||
210 | 210 | ||
211 | snprintf(exeline, sizeof(exeline), "/proc/%d/exe", pid); | 211 | snprintf(exeline, sizeof(exeline), "/proc/%d/exe", pid); |
212 | fd = open(exeline, O_RDONLY); | 212 | fd = open(exeline, O_RDONLY); |
213 | if(fd == 0) { | 213 | if (fd == 0) { |
214 | printf(" "); | 214 | printf(" "); |
215 | return; | 215 | return; |
216 | } | 216 | } |
217 | r = read(fd, exeline, 5 /* 4 byte ELFMAG + 1 byte EI_CLASS */); | 217 | r = read(fd, exeline, 5 /* 4 byte ELFMAG + 1 byte EI_CLASS */); |
218 | close(fd); | 218 | close(fd); |
219 | if(r < 0) { | 219 | if (r < 0) { |
220 | printf(" "); | 220 | printf(" "); |
221 | return; | 221 | return; |
222 | } | 222 | } |
@@ -245,12 +245,12 @@ void ps_threads(int pid) | |||
245 | 245 | ||
246 | snprintf(tmp,sizeof(tmp),"/proc/%d/task",pid); | 246 | snprintf(tmp,sizeof(tmp),"/proc/%d/task",pid); |
247 | d = opendir(tmp); | 247 | d = opendir(tmp); |
248 | if(d == 0) return; | 248 | if (d == 0) return; |
249 | 249 | ||
250 | while((de = readdir(d)) != 0){ | 250 | while ((de = readdir(d)) != 0) { |
251 | if(isdigit(de->d_name[0])){ | 251 | if (isdigit(de->d_name[0])) { |
252 | int tid = atoi(de->d_name); | 252 | int tid = atoi(de->d_name); |
253 | if(tid == pid) continue; | 253 | if (tid == pid) continue; |
254 | ps_line(pid, tid); | 254 | ps_line(pid, tid); |
255 | } | 255 | } |
256 | } | 256 | } |
@@ -264,24 +264,24 @@ int ps_main(int argc, char **argv) | |||
264 | int pidfilter = 0; | 264 | int pidfilter = 0; |
265 | int threads = 0; | 265 | int threads = 0; |
266 | 266 | ||
267 | while(argc > 1){ | 267 | while (argc > 1) { |
268 | if(!strcmp(argv[1],"-t")) { | 268 | if (!strcmp(argv[1], "-t")) { |
269 | threads = 1; | 269 | threads = 1; |
270 | } else if(!strcmp(argv[1],"-n")) { | 270 | } else if (!strcmp(argv[1], "-n")) { |
271 | display_flags |= SHOW_NUMERIC_UID; | 271 | display_flags |= SHOW_NUMERIC_UID; |
272 | } else if(!strcmp(argv[1],"-x")) { | 272 | } else if (!strcmp(argv[1], "-x")) { |
273 | display_flags |= SHOW_TIME; | 273 | display_flags |= SHOW_TIME; |
274 | } else if(!strcmp(argv[1], "-Z")) { | 274 | } else if (!strcmp(argv[1], "-Z")) { |
275 | display_flags |= SHOW_MACLABEL; | 275 | display_flags |= SHOW_MACLABEL; |
276 | } else if(!strcmp(argv[1],"-P")) { | 276 | } else if (!strcmp(argv[1], "-P")) { |
277 | display_flags |= SHOW_POLICY; | 277 | display_flags |= SHOW_POLICY; |
278 | } else if(!strcmp(argv[1],"-p")) { | 278 | } else if (!strcmp(argv[1], "-p")) { |
279 | display_flags |= SHOW_PRIO; | 279 | display_flags |= SHOW_PRIO; |
280 | } else if(!strcmp(argv[1],"-c")) { | 280 | } else if (!strcmp(argv[1], "-c")) { |
281 | display_flags |= SHOW_CPU; | 281 | display_flags |= SHOW_CPU; |
282 | } else if(!strcmp(argv[1],"--abi")) { | 282 | } else if (!strcmp(argv[1], "--abi")) { |
283 | display_flags |= SHOW_ABI; | 283 | display_flags |= SHOW_ABI; |
284 | } else if(!strcmp(argv[1],"--ppid")) { | 284 | } else if (!strcmp(argv[1], "--ppid")) { |
285 | if (argc < 3) { | 285 | if (argc < 3) { |
286 | /* Bug 26554285: Use printf because some apps require at least | 286 | /* Bug 26554285: Use printf because some apps require at least |
287 | * one line of output to stdout even for errors. | 287 | * one line of output to stdout even for errors. |
@@ -324,18 +324,17 @@ int ps_main(int argc, char **argv) | |||
324 | (display_flags&SHOW_ABI)?"ABI " : ""); | 324 | (display_flags&SHOW_ABI)?"ABI " : ""); |
325 | 325 | ||
326 | d = opendir("/proc"); | 326 | d = opendir("/proc"); |
327 | if(d == 0) return -1; | 327 | if (d == 0) return -1; |
328 | 328 | ||
329 | while((de = readdir(d)) != 0){ | 329 | while ((de = readdir(d)) != 0) { |
330 | if(isdigit(de->d_name[0])){ | 330 | if (isdigit(de->d_name[0])) { |
331 | int pid = atoi(de->d_name); | 331 | int pid = atoi(de->d_name); |
332 | if(!pidfilter || (pidfilter == pid)) { | 332 | if (!pidfilter || (pidfilter == pid)) { |
333 | ps_line(pid, 0); | 333 | ps_line(pid, 0); |
334 | if(threads) ps_threads(pid); | 334 | if (threads) ps_threads(pid); |
335 | } | 335 | } |
336 | } | 336 | } |
337 | } | 337 | } |
338 | closedir(d); | 338 | closedir(d); |
339 | return 0; | 339 | return 0; |
340 | } | 340 | } |
341 | |||