Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 324439
b: refs/heads/master
c: 44c8b25
h: refs/heads/master
i:
  324437: 3015452
  324435: 4379c91
  324431: a9d41bf
v: v3
  • Loading branch information
Ben Hutchings authored and Greg Kroah-Hartman committed Sep 10, 2012
1 parent 2e5e98e commit 84eb4e3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 436473bc2173499ae274d0f50111d1e355006caf
refs/heads/master: 44c8b25fb3b4b67442426abdc2371e750f7a393e
59 changes: 55 additions & 4 deletions trunk/tools/hv/hv_kvp_daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ void kvp_get_os_info(void)

uname(&uts_buf);
os_build = uts_buf.release;
os_name = uts_buf.sysname;
processor_arch = uts_buf.machine;

/*
Expand All @@ -465,20 +466,70 @@ void kvp_get_os_info(void)
if (p)
*p = '\0';

/*
* Parse the /etc/os-release file if present:
* http://www.freedesktop.org/software/systemd/man/os-release.html
*/
file = fopen("/etc/os-release", "r");
if (file != NULL) {
while (fgets(buf, sizeof(buf), file)) {
char *value, *q;

/* Ignore comments */
if (buf[0] == '#')
continue;

/* Split into name=value */
p = strchr(buf, '=');
if (!p)
continue;
*p++ = 0;

/* Remove quotes and newline; un-escape */
value = p;
q = p;
while (*p) {
if (*p == '\\') {
++p;
if (!*p)
break;
*q++ = *p++;
} else if (*p == '\'' || *p == '"' ||
*p == '\n') {
++p;
} else {
*q++ = *p++;
}
}
*q = 0;

if (!strcmp(buf, "NAME")) {
p = strdup(value);
if (!p)
break;
os_name = p;
} else if (!strcmp(buf, "VERSION_ID")) {
p = strdup(value);
if (!p)
break;
os_major = p;
}
}
fclose(file);
return;
}

/* Fallback for older RH/SUSE releases */
file = fopen("/etc/SuSE-release", "r");
if (file != NULL)
goto kvp_osinfo_found;
file = fopen("/etc/redhat-release", "r");
if (file != NULL)
goto kvp_osinfo_found;
/*
* Add code for other supported platforms.
*/

/*
* We don't have information about the os.
*/
os_name = uts_buf.sysname;
return;

kvp_osinfo_found:
Expand Down

0 comments on commit 84eb4e3

Please sign in to comment.