plugins/mod_version.lua

changeset 3483
443139c396c5
parent 3421
d3852a4d37e2
--- a/plugins/mod_version.lua	Tue Aug 31 15:23:41 2010 +0100
+++ b/plugins/mod_version.lua	Tue Aug 31 15:32:36 2010 +0100
@@ -10,7 +10,7 @@
 
 module:add_feature("jabber:iq:version");
 
-local version = "the best operating system ever!";
+local version;
 
 local query = st.stanza("query", {xmlns = "jabber:iq:version"})
 	:tag("name"):text("Prosody"):up()
@@ -20,15 +20,23 @@
 	if os.getenv("WINDIR") then
 		version = "Windows";
 	else
-		local uname = io.popen(module:get_option("os_version_command") or "uname");
-		if uname then
-			version = uname:read("*a");
-		else
-			version = "an OS";
+		local os_version_command = module:get_option("os_version_command");
+		local ok pposix = pcall(require, "pposix");
+		if not os_version_command and (ok and pposix and pposix.uname) then
+			version = pposix.uname().sysname;
+		end
+		if not version then
+			local uname = io.popen(os_version_command or "uname");
+			if uname then
+				version = uname:read("*a");
+			end
+			uname:close();
 		end
 	end
-	version = version:match("^%s*(.-)%s*$") or version;
-	query:tag("os"):text(version):up();
+	if version then
+		version = version:match("^%s*(.-)%s*$") or version;
+		query:tag("os"):text(version):up();
+	end
 end
 
 module:hook("iq/host/jabber:iq:version:query", function(event)

mercurial