File: | xlators/mgmt/glusterd/src/glusterd-log-ops.c |
Location: | line 44, column 30 |
Description: | Access to field 'rpc_err' results in a dereference of a null pointer (loaded from variable 'req') |
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 | #ifndef _CONFIG_H | |||||
11 | #define _CONFIG_H | |||||
12 | #include "config.h" | |||||
13 | #endif | |||||
14 | ||||||
15 | #include "common-utils.h" | |||||
16 | #include "cli1-xdr.h" | |||||
17 | #include "xdr-generic.h" | |||||
18 | #include "glusterd.h" | |||||
19 | #include "glusterd-op-sm.h" | |||||
20 | #include "glusterd-store.h" | |||||
21 | #include "glusterd-utils.h" | |||||
22 | #include "glusterd-volgen.h" | |||||
23 | ||||||
24 | #include <signal.h> | |||||
25 | ||||||
26 | int | |||||
27 | glusterd_handle_log_rotate (rpcsvc_request_t *req) | |||||
28 | { | |||||
29 | int32_t ret = -1; | |||||
30 | gf_cli_req cli_req = {{0,}}; | |||||
31 | dict_t *dict = NULL((void*)0); | |||||
32 | glusterd_op_t cli_op = GD_OP_LOG_ROTATE; | |||||
33 | char *volname = NULL((void*)0); | |||||
34 | char msg[2048] = {0,}; | |||||
35 | xlator_t *this = NULL((void*)0); | |||||
36 | ||||||
37 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-log-ops.c" , __FUNCTION__, 37, GF_LOG_ERROR, "Assertion failed: " "req") ; } while (0); } } while (0); | |||||
| ||||||
38 | this = THIS(*__glusterfs_this_location()); | |||||
39 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-log-ops.c" , __FUNCTION__, 39, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
40 | ||||||
41 | ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); | |||||
42 | if (ret < 0) { | |||||
43 | //failed to decode msg; | |||||
44 | req->rpc_err = GARBAGE_ARGS; | |||||
| ||||||
45 | goto out; | |||||
46 | } | |||||
47 | ||||||
48 | if (cli_req.dict.dict_len) { | |||||
49 | /* Unserialize the dictionary */ | |||||
50 | dict = dict_new (); | |||||
51 | ||||||
52 | ret = dict_unserialize (cli_req.dict.dict_val, | |||||
53 | cli_req.dict.dict_len, | |||||
54 | &dict); | |||||
55 | if (ret < 0) { | |||||
56 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-log-ops.c", __FUNCTION__, 58, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
57 | "failed to "do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-log-ops.c", __FUNCTION__, 58, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
58 | "unserialize req-buffer to dictionary")do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-log-ops.c", __FUNCTION__, 58, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0); | |||||
59 | snprintf (msg, sizeof (msg), "Unable to decode the " | |||||
60 | "command"); | |||||
61 | goto out; | |||||
62 | } | |||||
63 | } | |||||
64 | ||||||
65 | ret = dict_get_str (dict, "volname", &volname); | |||||
66 | if (ret) { | |||||
67 | snprintf (msg, sizeof (msg), "Failed to get volume name"); | |||||
68 | gf_log (this->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (this ->name, "glusterd-log-ops.c", __FUNCTION__, 68, GF_LOG_ERROR , "%s", msg); } while (0); | |||||
69 | goto out; | |||||
70 | } | |||||
71 | ||||||
72 | gf_log (this->name, GF_LOG_INFO, "Received log rotate req "do { do { if (0) printf ("Received log rotate req " "for volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-log-ops.c" , __FUNCTION__, 73, GF_LOG_INFO, "Received log rotate req " "for volume %s" , volname); } while (0) | |||||
73 | "for volume %s", volname)do { do { if (0) printf ("Received log rotate req " "for volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-log-ops.c" , __FUNCTION__, 73, GF_LOG_INFO, "Received log rotate req " "for volume %s" , volname); } while (0); | |||||
74 | ||||||
75 | ret = dict_set_uint64 (dict, "rotate-key", (uint64_t)time (NULL((void*)0))); | |||||
76 | if (ret) | |||||
77 | goto out; | |||||
78 | ||||||
79 | ret = glusterd_op_begin_synctask (req, GD_OP_LOG_ROTATE, dict); | |||||
80 | ||||||
81 | out: | |||||
82 | if (ret) { | |||||
83 | if (msg[0] == '\0') | |||||
84 | snprintf (msg, sizeof (msg), "Operation failed"); | |||||
85 | ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, | |||||
86 | dict, msg); | |||||
87 | } | |||||
88 | ||||||
89 | free (cli_req.dict.dict_val); | |||||
90 | return ret; | |||||
91 | } | |||||
92 | ||||||
93 | /* op-sm */ | |||||
94 | int | |||||
95 | glusterd_op_stage_log_rotate (dict_t *dict, char **op_errstr) | |||||
96 | { | |||||
97 | int ret = -1; | |||||
98 | char *volname = NULL((void*)0); | |||||
99 | glusterd_volinfo_t *volinfo = NULL((void*)0); | |||||
100 | gf_boolean_t exists = _gf_false; | |||||
101 | char msg[2048] = {0}; | |||||
102 | char *brick = NULL((void*)0); | |||||
103 | ||||||
104 | ret = dict_get_str (dict, "volname", &volname); | |||||
105 | if (ret) { | |||||
106 | gf_log ("", GF_LOG_ERROR, "Unable to get volume name")do { do { if (0) printf ("Unable to get volume name"); } while (0); _gf_log ("", "glusterd-log-ops.c", __FUNCTION__, 106, GF_LOG_ERROR , "Unable to get volume name"); } while (0); | |||||
107 | goto out; | |||||
108 | } | |||||
109 | ||||||
110 | exists = glusterd_check_volume_exists (volname); | |||||
111 | ret = glusterd_volinfo_find (volname, &volinfo); | |||||
112 | if (!exists) { | |||||
113 | snprintf (msg, sizeof (msg), "Volume %s does not exist", | |||||
114 | volname); | |||||
115 | gf_log ("", GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ("" , "glusterd-log-ops.c", __FUNCTION__, 115, GF_LOG_ERROR, "%s" , msg); } while (0); | |||||
116 | *op_errstr = gf_strdup (msg); | |||||
117 | ret = -1; | |||||
118 | goto out; | |||||
119 | } | |||||
120 | ||||||
121 | if (_gf_false == glusterd_is_volume_started (volinfo)) { | |||||
122 | snprintf (msg, sizeof (msg), "Volume %s needs to be started before" | |||||
123 | " log rotate.", volname); | |||||
124 | gf_log ("", GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ("" , "glusterd-log-ops.c", __FUNCTION__, 124, GF_LOG_ERROR, "%s" , msg); } while (0); | |||||
125 | *op_errstr = gf_strdup (msg); | |||||
126 | ret = -1; | |||||
127 | goto out; | |||||
128 | } | |||||
129 | ||||||
130 | ret = dict_get_str (dict, "brick", &brick); | |||||
131 | /* If no brick is specified, do log-rotate for | |||||
132 | all the bricks in the volume */ | |||||
133 | if (ret) { | |||||
134 | ret = 0; | |||||
135 | goto out; | |||||
136 | } | |||||
137 | ||||||
138 | ret = glusterd_volume_brickinfo_get_by_brick (brick, volinfo, NULL((void*)0)); | |||||
139 | if (ret) { | |||||
140 | snprintf (msg, sizeof (msg), "Incorrect brick %s " | |||||
141 | "for volume %s", brick, volname); | |||||
142 | gf_log ("", GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ("" , "glusterd-log-ops.c", __FUNCTION__, 142, GF_LOG_ERROR, "%s" , msg); } while (0); | |||||
143 | *op_errstr = gf_strdup (msg); | |||||
144 | goto out; | |||||
145 | } | |||||
146 | out: | |||||
147 | gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ("", "glusterd-log-ops.c", __FUNCTION__, 147, GF_LOG_DEBUG, "Returning %d" , ret); } while (0); | |||||
148 | ||||||
149 | return ret; | |||||
150 | } | |||||
151 | ||||||
152 | ||||||
153 | int | |||||
154 | glusterd_op_log_rotate (dict_t *dict) | |||||
155 | { | |||||
156 | int ret = -1; | |||||
157 | glusterd_conf_t *priv = NULL((void*)0); | |||||
158 | glusterd_volinfo_t *volinfo = NULL((void*)0); | |||||
159 | glusterd_brickinfo_t *brickinfo = NULL((void*)0); | |||||
160 | xlator_t *this = NULL((void*)0); | |||||
161 | char *volname = NULL((void*)0); | |||||
162 | char *brick = NULL((void*)0); | |||||
163 | char logfile[PATH_MAX4096] = {0,}; | |||||
164 | char pidfile[PATH_MAX4096] = {0,}; | |||||
165 | FILE *file = NULL((void*)0); | |||||
166 | pid_t pid = 0; | |||||
167 | uint64_t key = 0; | |||||
168 | int valid_brick = 0; | |||||
169 | glusterd_brickinfo_t *tmpbrkinfo = NULL((void*)0); | |||||
170 | ||||||
171 | this = THIS(*__glusterfs_this_location()); | |||||
172 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-log-ops.c" , __FUNCTION__, 172, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
173 | priv = this->private; | |||||
174 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-log-ops.c" , __FUNCTION__, 174, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); | |||||
175 | ||||||
176 | ret = dict_get_str (dict, "volname", &volname); | |||||
177 | if (ret) { | |||||
178 | gf_log ("", GF_LOG_ERROR, "volname not found")do { do { if (0) printf ("volname not found"); } while (0); _gf_log ("", "glusterd-log-ops.c", __FUNCTION__, 178, GF_LOG_ERROR, "volname not found" ); } while (0); | |||||
179 | goto out; | |||||
180 | } | |||||
181 | ||||||
182 | ret = dict_get_uint64 (dict, "rotate-key", &key); | |||||
183 | if (ret) { | |||||
184 | gf_log ("", GF_LOG_ERROR, "rotate key not found")do { do { if (0) printf ("rotate key not found"); } while (0) ; _gf_log ("", "glusterd-log-ops.c", __FUNCTION__, 184, GF_LOG_ERROR , "rotate key not found"); } while (0); | |||||
185 | goto out; | |||||
186 | } | |||||
187 | ||||||
188 | ret = dict_get_str (dict, "brick", &brick); | |||||
189 | /* If no brick is specified, do log-rotate for | |||||
190 | all the bricks in the volume */ | |||||
191 | if (ret) | |||||
192 | goto cont; | |||||
193 | ||||||
194 | ret = glusterd_brickinfo_new_from_brick (brick, &tmpbrkinfo); | |||||
195 | if (ret) { | |||||
196 | gf_log ("glusterd", GF_LOG_ERROR,do { do { if (0) printf ("cannot get brickinfo from brick"); } while (0); _gf_log ("glusterd", "glusterd-log-ops.c", __FUNCTION__ , 197, GF_LOG_ERROR, "cannot get brickinfo from brick"); } while (0) | |||||
197 | "cannot get brickinfo from brick")do { do { if (0) printf ("cannot get brickinfo from brick"); } while (0); _gf_log ("glusterd", "glusterd-log-ops.c", __FUNCTION__ , 197, GF_LOG_ERROR, "cannot get brickinfo from brick"); } while (0); | |||||
198 | goto out; | |||||
199 | } | |||||
200 | ||||||
201 | cont: | |||||
202 | ret = glusterd_volinfo_find (volname, &volinfo); | |||||
203 | if (ret) | |||||
204 | goto out; | |||||
205 | ||||||
206 | ret = -1; | |||||
207 | list_for_each_entry (brickinfo, &volinfo->bricks, brick_list)for (brickinfo = ((typeof(*brickinfo) *)((char *)((&volinfo ->bricks)->next)-(unsigned long)(&((typeof(*brickinfo ) *)0)->brick_list))); &brickinfo->brick_list != (& volinfo->bricks); brickinfo = ((typeof(*brickinfo) *)((char *)(brickinfo->brick_list.next)-(unsigned long)(&((typeof (*brickinfo) *)0)->brick_list)))) { | |||||
208 | if (uuid_compare (brickinfo->uuid, MY_UUID(__glusterd_uuid()))) | |||||
209 | continue; | |||||
210 | ||||||
211 | if (brick && | |||||
212 | (strcmp (tmpbrkinfo->hostname, brickinfo->hostname) || | |||||
213 | strcmp (tmpbrkinfo->path,brickinfo->path))) | |||||
214 | continue; | |||||
215 | ||||||
216 | valid_brick = 1; | |||||
217 | ||||||
218 | GLUSTERD_GET_BRICK_PIDFILE (pidfile, volinfo, brickinfo, priv)do { char exp_path[4096] = {0,}; char volpath[4096] = {0,}; snprintf (volpath, 4096, "%s/vols/%s", priv->workdir, volinfo-> volname);; do { int i = 0; for (i = 1; i < strlen (brickinfo ->path); i++) { exp_path[i-1] = brickinfo->path[i]; if ( exp_path[i-1] == '/') exp_path[i-1] = '-'; } } while (0); snprintf (pidfile, 4096, "%s/run/%s-%s.pid", volpath, brickinfo->hostname , exp_path); } while (0); | |||||
219 | file = fopen (pidfile, "r+"); | |||||
220 | if (!file) { | |||||
221 | gf_log ("", GF_LOG_ERROR, "Unable to open pidfile: %s",do { do { if (0) printf ("Unable to open pidfile: %s", pidfile ); } while (0); _gf_log ("", "glusterd-log-ops.c", __FUNCTION__ , 222, GF_LOG_ERROR, "Unable to open pidfile: %s", pidfile); } while (0) | |||||
222 | pidfile)do { do { if (0) printf ("Unable to open pidfile: %s", pidfile ); } while (0); _gf_log ("", "glusterd-log-ops.c", __FUNCTION__ , 222, GF_LOG_ERROR, "Unable to open pidfile: %s", pidfile); } while (0); | |||||
223 | ret = -1; | |||||
224 | goto out; | |||||
225 | } | |||||
226 | ||||||
227 | ret = fscanf (file, "%d", &pid); | |||||
228 | if (ret <= 0) { | |||||
229 | gf_log ("", GF_LOG_ERROR, "Unable to read pidfile: %s",do { do { if (0) printf ("Unable to read pidfile: %s", pidfile ); } while (0); _gf_log ("", "glusterd-log-ops.c", __FUNCTION__ , 230, GF_LOG_ERROR, "Unable to read pidfile: %s", pidfile); } while (0) | |||||
230 | pidfile)do { do { if (0) printf ("Unable to read pidfile: %s", pidfile ); } while (0); _gf_log ("", "glusterd-log-ops.c", __FUNCTION__ , 230, GF_LOG_ERROR, "Unable to read pidfile: %s", pidfile); } while (0); | |||||
231 | ret = -1; | |||||
232 | goto out; | |||||
233 | } | |||||
234 | fclose (file); | |||||
235 | file = NULL((void*)0); | |||||
236 | ||||||
237 | snprintf (logfile, PATH_MAX4096, "%s.%"PRIu64"ll" "u", | |||||
238 | brickinfo->logfile, key); | |||||
239 | ||||||
240 | ret = rename (brickinfo->logfile, logfile); | |||||
241 | if (ret) | |||||
242 | gf_log ("", GF_LOG_WARNING, "rename failed")do { do { if (0) printf ("rename failed"); } while (0); _gf_log ("", "glusterd-log-ops.c", __FUNCTION__, 242, GF_LOG_WARNING , "rename failed"); } while (0); | |||||
243 | ||||||
244 | ret = kill (pid, SIGHUP1); | |||||
245 | if (ret) { | |||||
246 | gf_log ("", GF_LOG_ERROR, "Unable to SIGHUP to %d", pid)do { do { if (0) printf ("Unable to SIGHUP to %d", pid); } while (0); _gf_log ("", "glusterd-log-ops.c", __FUNCTION__, 246, GF_LOG_ERROR , "Unable to SIGHUP to %d", pid); } while (0); | |||||
247 | goto out; | |||||
248 | } | |||||
249 | ret = 0; | |||||
250 | ||||||
251 | /* If request was for brick, only one iteration is enough */ | |||||
252 | if (brick) | |||||
253 | break; | |||||
254 | } | |||||
255 | ||||||
256 | if (ret && !valid_brick) | |||||
257 | ret = 0; | |||||
258 | ||||||
259 | out: | |||||
260 | if (tmpbrkinfo) | |||||
261 | glusterd_brickinfo_delete (tmpbrkinfo); | |||||
262 | ||||||
263 | return ret; | |||||
264 | } |