File: | xlators/features/marker/utils/src/procdiggy.c |
Location: | line 105, column 34 |
Description: | Value stored to 'ret' is never read |
1 | /* |
2 | Copyright (c) 2011-2012 Red Hat, Inc. <http://www.redhat.com> |
3 | This file is part of GlusterFS. |
4 | |
5 | This file is licensed to you under your choice of the GNU Lesser |
6 | General Public License, version 3 or any later version (LGPLv3 or |
7 | later), or the GNU General Public License, version 2 (GPLv2), in all |
8 | cases as published by the Free Software Foundation. |
9 | */ |
10 | |
11 | #ifndef _CONFIG_H |
12 | #define _CONFIG_H |
13 | #include "config.h" |
14 | #endif |
15 | |
16 | #include <stdlib.h> |
17 | #include <stdio.h> |
18 | #include <unistd.h> |
19 | #include <string.h> |
20 | #include <ctype.h> |
21 | #include <sys/param.h> /* for PATH_MAX */ |
22 | |
23 | #include "common-utils.h" |
24 | #include "procdiggy.h" |
25 | |
26 | pid_t |
27 | pidinfo (pid_t pid, char **name) |
28 | { |
29 | char buf[NAME_MAX255 * 2] = {0,}; |
30 | FILE *f = NULL((void*)0); |
31 | char path[PATH_MAX4096] = {0,}; |
32 | char *p = NULL((void*)0); |
33 | int ret = 0; |
34 | |
35 | sprintf (path, PROC"/proc""/%d/status", pid); |
36 | |
37 | f = fopen (path, "r"); |
38 | if (!f) |
39 | return -1; |
40 | |
41 | if (name) |
42 | *name = NULL((void*)0); |
43 | for (;;) { |
44 | size_t len; |
45 | memset (buf, 0, sizeof (buf)); |
46 | if (fgets (buf, sizeof (buf), f) == NULL((void*)0) || |
47 | (len = strlen (buf)) == 0 || |
48 | buf[len - 1] != '\n') { |
49 | pid = -1; |
50 | goto out; |
51 | } |
52 | buf[len - 1] = '\0'; |
53 | |
54 | if (name && !*name) { |
55 | p = strtail (buf, "Name:"); |
56 | if (p) { |
57 | while (isspace (*++p)((*__ctype_b_loc ())[(int) ((*++p))] & (unsigned short int ) _ISspace)); |
58 | *name = gf_strdup (p); |
59 | if (!*name) { |
60 | pid = -2; |
61 | goto out; |
62 | } |
63 | continue; |
64 | } |
65 | } |
66 | |
67 | p = strtail (buf, "PPid:"); |
68 | if (p) |
69 | break; |
70 | } |
71 | |
72 | while (isspace (*++p)((*__ctype_b_loc ())[(int) ((*++p))] & (unsigned short int ) _ISspace)); |
73 | ret = gf_string2int (p, &pid); |
74 | if (ret == -1) |
75 | pid = -1; |
76 | |
77 | out: |
78 | fclose (f); |
79 | if (pid == -1 && name && *name) |
80 | GF_FREE (name)__gf_free (name); |
81 | if (pid == -2) |
82 | fprintf (stderrstderr, "out of memory\n"); |
83 | return pid; |
84 | } |
85 | |
86 | int |
87 | prociter (int (*proch) (pid_t pid, pid_t ppid, char *tmpname, void *data), |
88 | void *data) |
89 | { |
90 | char *name = NULL((void*)0); |
91 | DIR *d = NULL((void*)0); |
92 | struct dirent *de = NULL((void*)0); |
93 | pid_t pid = -1; |
94 | pid_t ppid = -1; |
95 | int ret = 0; |
96 | |
97 | d = opendir (PROC"/proc"); |
98 | if (!d) |
99 | return -1; |
100 | while (errno(*__errno_location ()) = 0, de = readdir (d)) { |
101 | if (gf_string2int (de->d_name, &pid) != -1 && pid >= 0) { |
102 | ppid = pidinfo (pid, &name); |
103 | switch (ppid) { |
104 | case -1: continue; |
105 | case -2: ret = -1; break; |
Value stored to 'ret' is never read | |
106 | } |
107 | ret = proch (pid, ppid, name, data); |
108 | GF_FREE (name)__gf_free (name); |
109 | if (ret) |
110 | break; |
111 | } |
112 | } |
113 | closedir (d); |
114 | if (!de && errno(*__errno_location ())) { |
115 | fprintf (stderrstderr, "failed to traverse "PROC"/proc"" (%s)\n", |
116 | strerror (errno(*__errno_location ()))); |
117 | ret = -1; |
118 | } |
119 | |
120 | return ret; |
121 | } |