diff options
author | Andrew Morton <akpm@osdl.org> | 2006-12-10 05:19:55 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.osdl.org> | 2006-12-10 12:55:41 -0500 |
commit | d2f7bf13461e8ead863126ee1e8ba92105959ecc (patch) | |
tree | a99a212c83306dd15676a53471c2232fcd2f7df3 /Documentation/accounting/getdelays.c | |
parent | 4a7864ca638e0a38307962ee8ef122822a351b65 (diff) |
[PATCH] getdelays: various fixes
- Various cleanups
- Report errors to stderr, not stdout
- A printf was missing a \n and was hiding from me.
Cc: Jay Lan <jlan@sgi.com>
Cc: Shailabh Nagar <nagar@watson.ibm.com>
Cc: Balbir Singh <balbir@in.ibm.com>
Cc: Chris Sturtivant <csturtiv@sgi.com>
Cc: Tony Ernst <tee@sgi.com>
Cc: Guillaume Thouvenin <guillaume.thouvenin@bull.net>
Cc: David Wright <daw@sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'Documentation/accounting/getdelays.c')
-rw-r--r-- | Documentation/accounting/getdelays.c | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/Documentation/accounting/getdelays.c b/Documentation/accounting/getdelays.c index bf2b0e2f87e1..93dd04f86a27 100644 --- a/Documentation/accounting/getdelays.c +++ b/Documentation/accounting/getdelays.c | |||
@@ -7,6 +7,8 @@ | |||
7 | * Copyright (C) Balbir Singh, IBM Corp. 2006 | 7 | * Copyright (C) Balbir Singh, IBM Corp. 2006 |
8 | * Copyright (c) Jay Lan, SGI. 2006 | 8 | * Copyright (c) Jay Lan, SGI. 2006 |
9 | * | 9 | * |
10 | * Compile with | ||
11 | * gcc -I/usr/src/linux/include getdelays.c -o getdelays | ||
10 | */ | 12 | */ |
11 | 13 | ||
12 | #include <stdio.h> | 14 | #include <stdio.h> |
@@ -35,13 +37,19 @@ | |||
35 | #define NLA_DATA(na) ((void *)((char*)(na) + NLA_HDRLEN)) | 37 | #define NLA_DATA(na) ((void *)((char*)(na) + NLA_HDRLEN)) |
36 | #define NLA_PAYLOAD(len) (len - NLA_HDRLEN) | 38 | #define NLA_PAYLOAD(len) (len - NLA_HDRLEN) |
37 | 39 | ||
38 | #define err(code, fmt, arg...) do { printf(fmt, ##arg); exit(code); } while (0) | 40 | #define err(code, fmt, arg...) \ |
39 | int done = 0; | 41 | do { \ |
40 | int rcvbufsz=0; | 42 | fprintf(stderr, fmt, ##arg); \ |
41 | 43 | exit(code); \ | |
42 | char name[100]; | 44 | } while (0) |
43 | int dbg=0, print_delays=0; | 45 | |
46 | int done; | ||
47 | int rcvbufsz; | ||
48 | char name[100]; | ||
49 | int dbg; | ||
50 | int print_delays; | ||
44 | __u64 stime, utime; | 51 | __u64 stime, utime; |
52 | |||
45 | #define PRINTF(fmt, arg...) { \ | 53 | #define PRINTF(fmt, arg...) { \ |
46 | if (dbg) { \ | 54 | if (dbg) { \ |
47 | printf(fmt, ##arg); \ | 55 | printf(fmt, ##arg); \ |
@@ -78,8 +86,9 @@ static int create_nl_socket(int protocol) | |||
78 | if (rcvbufsz) | 86 | if (rcvbufsz) |
79 | if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, | 87 | if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, |
80 | &rcvbufsz, sizeof(rcvbufsz)) < 0) { | 88 | &rcvbufsz, sizeof(rcvbufsz)) < 0) { |
81 | printf("Unable to set socket rcv buf size to %d\n", | 89 | fprintf(stderr, "Unable to set socket rcv buf size " |
82 | rcvbufsz); | 90 | "to %d\n", |
91 | rcvbufsz); | ||
83 | return -1; | 92 | return -1; |
84 | } | 93 | } |
85 | 94 | ||
@@ -277,7 +286,7 @@ int main(int argc, char *argv[]) | |||
277 | mypid = getpid(); | 286 | mypid = getpid(); |
278 | id = get_family_id(nl_sd); | 287 | id = get_family_id(nl_sd); |
279 | if (!id) { | 288 | if (!id) { |
280 | printf("Error getting family id, errno %d", errno); | 289 | fprintf(stderr, "Error getting family id, errno %d\n", errno); |
281 | goto err; | 290 | goto err; |
282 | } | 291 | } |
283 | PRINTF("family id %d\n", id); | 292 | PRINTF("family id %d\n", id); |
@@ -288,7 +297,7 @@ int main(int argc, char *argv[]) | |||
288 | &cpumask, strlen(cpumask) + 1); | 297 | &cpumask, strlen(cpumask) + 1); |
289 | PRINTF("Sent register cpumask, retval %d\n", rc); | 298 | PRINTF("Sent register cpumask, retval %d\n", rc); |
290 | if (rc < 0) { | 299 | if (rc < 0) { |
291 | printf("error sending register cpumask\n"); | 300 | fprintf(stderr, "error sending register cpumask\n"); |
292 | goto err; | 301 | goto err; |
293 | } | 302 | } |
294 | } | 303 | } |
@@ -298,7 +307,7 @@ int main(int argc, char *argv[]) | |||
298 | cmd_type, &tid, sizeof(__u32)); | 307 | cmd_type, &tid, sizeof(__u32)); |
299 | PRINTF("Sent pid/tgid, retval %d\n", rc); | 308 | PRINTF("Sent pid/tgid, retval %d\n", rc); |
300 | if (rc < 0) { | 309 | if (rc < 0) { |
301 | printf("error sending tid/tgid cmd\n"); | 310 | fprintf(stderr, "error sending tid/tgid cmd\n"); |
302 | goto done; | 311 | goto done; |
303 | } | 312 | } |
304 | } | 313 | } |
@@ -310,13 +319,15 @@ int main(int argc, char *argv[]) | |||
310 | PRINTF("received %d bytes\n", rep_len); | 319 | PRINTF("received %d bytes\n", rep_len); |
311 | 320 | ||
312 | if (rep_len < 0) { | 321 | if (rep_len < 0) { |
313 | printf("nonfatal reply error: errno %d\n", errno); | 322 | fprintf(stderr, "nonfatal reply error: errno %d\n", |
323 | errno); | ||
314 | continue; | 324 | continue; |
315 | } | 325 | } |
316 | if (msg.n.nlmsg_type == NLMSG_ERROR || | 326 | if (msg.n.nlmsg_type == NLMSG_ERROR || |
317 | !NLMSG_OK((&msg.n), rep_len)) { | 327 | !NLMSG_OK((&msg.n), rep_len)) { |
318 | struct nlmsgerr *err = NLMSG_DATA(&msg); | 328 | struct nlmsgerr *err = NLMSG_DATA(&msg); |
319 | printf("fatal reply error, errno %d\n", err->error); | 329 | fprintf(stderr, "fatal reply error, errno %d\n", |
330 | err->error); | ||
320 | goto done; | 331 | goto done; |
321 | } | 332 | } |
322 | 333 | ||
@@ -365,7 +376,9 @@ int main(int argc, char *argv[]) | |||
365 | goto done; | 376 | goto done; |
366 | break; | 377 | break; |
367 | default: | 378 | default: |
368 | printf("Unknown nested nla_type %d\n", na->nla_type); | 379 | fprintf(stderr, "Unknown nested" |
380 | " nla_type %d\n", | ||
381 | na->nla_type); | ||
369 | break; | 382 | break; |
370 | } | 383 | } |
371 | len2 += NLA_ALIGN(na->nla_len); | 384 | len2 += NLA_ALIGN(na->nla_len); |
@@ -374,7 +387,8 @@ int main(int argc, char *argv[]) | |||
374 | break; | 387 | break; |
375 | 388 | ||
376 | default: | 389 | default: |
377 | printf("Unknown nla_type %d\n", na->nla_type); | 390 | fprintf(stderr, "Unknown nla_type %d\n", |
391 | na->nla_type); | ||
378 | break; | 392 | break; |
379 | } | 393 | } |
380 | na = (struct nlattr *) (GENLMSG_DATA(&msg) + len); | 394 | na = (struct nlattr *) (GENLMSG_DATA(&msg) + len); |