--- zabbix-2.4.2/src/libs/zbxsysinfo/linux/software.c 2014-11-05 06:01:42.000000000 -0200 +++ zabbix-2.4.2-patched/src/libs/zbxsysinfo/linux/software.c 2014-12-09 19:35:22.000000000 -0200 @@ -29,6 +29,8 @@ # include #endif +static int sw_os_name_parser(FILE *f, char *line); + int SYSTEM_SW_ARCH(AGENT_REQUEST *request, AGENT_RESULT *result) { struct utsname name; @@ -49,6 +51,7 @@ char *type, line[MAX_STRING_LEN]; int ret = SYSINFO_RET_FAIL; FILE *f = NULL; + int systemd = 0; if (1 < request->nparam) { @@ -78,6 +81,15 @@ } else if (0 == strcmp(type, "name")) { + /* Looking first for systemd file */ + if (NULL != (f = fopen(SW_OS_NAME_SYSTEMD, "r"))) + { + systemd = 1; + if (FAIL == sw_os_name_parser(f, line)) + { + return ret; + } + } if (NULL == (f = fopen(SW_OS_NAME, "r"))) { SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot open " SW_OS_NAME ": %s", @@ -91,7 +103,7 @@ return ret; } - if (NULL != fgets(line, sizeof(line), f)) + if (systemd || NULL != fgets(line, sizeof(line), f)) { ret = SYSINFO_RET_OK; zbx_rtrim(line, ZBX_WHITESPACE); @@ -105,6 +117,21 @@ return ret; } +static int sw_os_name_parser(FILE *f, char *line) +{ + char tmp_line[MAX_STRING_LEN]; + + while (NULL != fgets(tmp_line, sizeof(tmp_line), f)) + { + if (0 != strncmp(tmp_line, "PRETTY_NAME", 11)) + continue; + if (1 != sscanf(tmp_line, "PRETTY_NAME=\"%[^\"]", line)) + return FAIL; + else + return SUCCEED; + } +} + static int dpkg_parser(const char *line, char *package, size_t max_package_len) { char fmt[32], tmp[32];