Skip to content
Browse files

fixed: linux distro name finder

This was completely broken if lsb_release did not exist. We actually check the
release files now.

Also, /etc/buildroot-release added.
  • Loading branch information...
1 parent db4d032 commit 7290a72e3c6be0cb1bc38c8646fcbb1b5915a578 theuni committed Apr 4, 2012
Showing with 25 additions and 14 deletions.
  1. +25 −14 xbmc/utils/SystemInfo.cpp
View
39 xbmc/utils/SystemInfo.cpp
@@ -504,29 +504,40 @@ CStdString CSysInfo::GetLinuxDistro()
"/etc/gentoo-release",
"/etc/slackware-version",
"/etc/arch-release",
+ "/etc/buildroot-release",
NULL };
+ CStdString result("");
- FILE* pipe = popen("unset PYTHONHOME; unset PYTHONPATH; lsb_release -d | cut -f2", "r");
-
- for (int i = 0; !pipe && release_file[i]; i++)
- {
- CStdString cmd = "cat ";
- cmd += release_file[i];
-
- pipe = popen(cmd.c_str(), "r");
- }
-
- CStdString result = "Unknown";
+ FILE* pipe = popen("unset PYTHONHOME; unset PYTHONPATH; lsb_release -d 2>/dev/null | cut -f2", "r");
if (pipe)
{
char buffer[256] = {'\0'};
if (fread(buffer, sizeof(char), sizeof(buffer), pipe) > 0 && !ferror(pipe))
result = buffer;
- else
- CLog::Log(LOGWARNING, "Unable to determine Linux distribution");
pclose(pipe);
+ if (!result.IsEmpty())
+ return result.Trim();
}
- return result.Trim();
+
+ FILE* file = NULL;
+ for (int i = 0; result.IsEmpty() && release_file[i]; i++)
+ {
+ file = fopen(release_file[i], "r");
+ if (file)
+ {
+ char buffer[256] = {'\0'};
+ if (fgets(buffer, sizeof(buffer), file))
+ {
+ result = buffer;
+ if (!result.IsEmpty())
+ return result.Trim();
+ }
+ fclose(file);
+ }
+ }
+
+ CLog::Log(LOGWARNING, "Unable to determine Linux distribution");
+ return "Unknown";
}
#endif

0 comments on commit 7290a72

Please sign in to comment.
Something went wrong with that request. Please try again.