diff options
author | Olaf Hering <olaf@aepfle.de> | 2011-03-22 05:02:17 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2011-04-05 00:33:25 -0400 |
commit | 7989f7d5ea65b10d2d4c8249aca75690d4d71e17 (patch) | |
tree | 670395a11fa31332b69e8438cf70b83f5a4483a1 /drivers | |
parent | 22356585712d1ff08fbfed152edd8b386873b238 (diff) |
staging: hv: update dist release parsing in hv_kvp_daemon
The current code to parse the distribution file handles only files with
at least 3 lines. openSuSE has 2 lines and Redhat only one (according to
google).
Update the parser to handle up to three lines properly. Also make the
buffer allocation dynamic and remove a few casts to avoid compiler
warnings.
Signed-off-by: Olaf Hering <olaf@aepfle.de>
Acked-by: KY Srinivasan <kys@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/staging/hv/tools/hv_kvp_daemon.c | 90 |
1 files changed, 57 insertions, 33 deletions
diff --git a/drivers/staging/hv/tools/hv_kvp_daemon.c b/drivers/staging/hv/tools/hv_kvp_daemon.c index f5a2dd694611..f51264031376 100644 --- a/drivers/staging/hv/tools/hv_kvp_daemon.c +++ b/drivers/staging/hv/tools/hv_kvp_daemon.c | |||
@@ -102,22 +102,22 @@ static char kvp_send_buffer[4096]; | |||
102 | static char kvp_recv_buffer[4096]; | 102 | static char kvp_recv_buffer[4096]; |
103 | static struct sockaddr_nl addr; | 103 | static struct sockaddr_nl addr; |
104 | 104 | ||
105 | static char os_name[100]; | 105 | static char *os_name = ""; |
106 | static char os_major[50]; | 106 | static char *os_major = ""; |
107 | static char os_minor[50]; | 107 | static char *os_minor = ""; |
108 | static char processor_arch[50]; | 108 | static char *processor_arch; |
109 | static char os_build[100]; | 109 | static char *os_build; |
110 | static char *lic_version; | 110 | static char *lic_version; |
111 | static struct utsname uts_buf; | ||
111 | 112 | ||
112 | void kvp_get_os_info(void) | 113 | void kvp_get_os_info(void) |
113 | { | 114 | { |
114 | FILE *file; | 115 | FILE *file; |
115 | char *eol; | 116 | char *p, buf[512]; |
116 | struct utsname buf; | ||
117 | 117 | ||
118 | uname(&buf); | 118 | uname(&uts_buf); |
119 | strcpy(os_build, buf.release); | 119 | os_build = uts_buf.release; |
120 | strcpy(processor_arch, buf.machine); | 120 | processor_arch= uts_buf.machine; |
121 | 121 | ||
122 | file = fopen("/etc/SuSE-release", "r"); | 122 | file = fopen("/etc/SuSE-release", "r"); |
123 | if (file != NULL) | 123 | if (file != NULL) |
@@ -132,21 +132,46 @@ void kvp_get_os_info(void) | |||
132 | /* | 132 | /* |
133 | * We don't have information about the os. | 133 | * We don't have information about the os. |
134 | */ | 134 | */ |
135 | strcpy(os_name, "Linux"); | 135 | os_name = uts_buf.sysname; |
136 | strcpy(os_major, "0"); | ||
137 | strcpy(os_minor, "0"); | ||
138 | return; | 136 | return; |
139 | 137 | ||
140 | kvp_osinfo_found: | 138 | kvp_osinfo_found: |
141 | fgets(os_name, 99, file); | 139 | /* up to three lines */ |
142 | eol = index(os_name, '\n'); | 140 | p = fgets(buf, sizeof(buf), file); |
143 | *eol = '\0'; | 141 | if (p) { |
144 | fgets(os_major, 49, file); | 142 | p = strchr(buf, '\n'); |
145 | eol = index(os_major, '\n'); | 143 | if (p) |
146 | *eol = '\0'; | 144 | *p = '\0'; |
147 | fgets(os_minor, 49, file); | 145 | p = strdup(buf); |
148 | eol = index(os_minor, '\n'); | 146 | if (!p) |
149 | *eol = '\0'; | 147 | goto done; |
148 | os_name = p; | ||
149 | |||
150 | /* second line */ | ||
151 | p = fgets(buf, sizeof(buf), file); | ||
152 | if (p) { | ||
153 | p = strchr(buf, '\n'); | ||
154 | if (p) | ||
155 | *p = '\0'; | ||
156 | p = strdup(buf); | ||
157 | if (!p) | ||
158 | goto done; | ||
159 | os_major = p; | ||
160 | |||
161 | /* third line */ | ||
162 | p = fgets(buf, sizeof(buf), file); | ||
163 | if (p) { | ||
164 | p = strchr(buf, '\n'); | ||
165 | if (p) | ||
166 | *p = '\0'; | ||
167 | p = strdup(buf); | ||
168 | if (p) | ||
169 | os_minor = p; | ||
170 | } | ||
171 | } | ||
172 | } | ||
173 | |||
174 | done: | ||
150 | fclose(file); | 175 | fclose(file); |
151 | return; | 176 | return; |
152 | } | 177 | } |
@@ -293,7 +318,7 @@ netlink_send(int fd, struct cn_msg *msg) | |||
293 | return sendmsg(fd, &message, 0); | 318 | return sendmsg(fd, &message, 0); |
294 | } | 319 | } |
295 | 320 | ||
296 | main(void) | 321 | int main(void) |
297 | { | 322 | { |
298 | int fd, len, sock_opt; | 323 | int fd, len, sock_opt; |
299 | int error; | 324 | int error; |
@@ -301,9 +326,10 @@ main(void) | |||
301 | struct pollfd pfd; | 326 | struct pollfd pfd; |
302 | struct nlmsghdr *incoming_msg; | 327 | struct nlmsghdr *incoming_msg; |
303 | struct cn_msg *incoming_cn_msg; | 328 | struct cn_msg *incoming_cn_msg; |
329 | struct hv_ku_msg *hv_msg; | ||
330 | char *p; | ||
304 | char *key_value; | 331 | char *key_value; |
305 | char *key_name; | 332 | char *key_name; |
306 | int key_index; | ||
307 | 333 | ||
308 | daemon(1, 0); | 334 | daemon(1, 0); |
309 | openlog("KVP", 0, LOG_USER); | 335 | openlog("KVP", 0, LOG_USER); |
@@ -373,9 +399,10 @@ main(void) | |||
373 | * Driver is registering with us; stash away the version | 399 | * Driver is registering with us; stash away the version |
374 | * information. | 400 | * information. |
375 | */ | 401 | */ |
376 | lic_version = malloc(strlen(incoming_cn_msg->data) + 1); | 402 | p = (char *)incoming_cn_msg->data; |
403 | lic_version = malloc(strlen(p) + 1); | ||
377 | if (lic_version) { | 404 | if (lic_version) { |
378 | strcpy(lic_version, incoming_cn_msg->data); | 405 | strcpy(lic_version, p); |
379 | syslog(LOG_INFO, "KVP LIC Version: %s", | 406 | syslog(LOG_INFO, "KVP LIC Version: %s", |
380 | lic_version); | 407 | lic_version); |
381 | } else { | 408 | } else { |
@@ -389,14 +416,11 @@ main(void) | |||
389 | continue; | 416 | continue; |
390 | } | 417 | } |
391 | 418 | ||
392 | key_index = | 419 | hv_msg = (struct hv_ku_msg *)incoming_cn_msg->data; |
393 | ((struct hv_ku_msg *)incoming_cn_msg->data)->kvp_index; | 420 | key_name = (char *)hv_msg->kvp_key; |
394 | key_name = | 421 | key_value = (char *)hv_msg->kvp_value; |
395 | ((struct hv_ku_msg *)incoming_cn_msg->data)->kvp_key; | ||
396 | key_value = | ||
397 | ((struct hv_ku_msg *)incoming_cn_msg->data)->kvp_value; | ||
398 | 422 | ||
399 | switch (key_index) { | 423 | switch (hv_msg->kvp_index) { |
400 | case FullyQualifiedDomainName: | 424 | case FullyQualifiedDomainName: |
401 | kvp_get_domain_name(key_value, | 425 | kvp_get_domain_name(key_value, |
402 | HV_KVP_EXCHANGE_MAX_VALUE_SIZE); | 426 | HV_KVP_EXCHANGE_MAX_VALUE_SIZE); |