Software /
code /
prosody
Changeset
3483:443139c396c5
mod_version: Use pposix.uname() if available and os_version_command not set
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 31 Aug 2010 15:32:36 +0100 |
parents | 3482:e1a4f7b15caf |
children | 3484:66910810a9f7 |
files | plugins/mod_version.lua |
diffstat | 1 files changed, 16 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- 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)