diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2009-02-01 17:08:40 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2009-02-01 17:08:40 +0000 |
commit | 4b9f7db1cea69524ca46098b446b0fe51e87091b (patch) | |
tree | 13b2078e06fa466c76aaf09ca7c7320733f8f5f1 /libs/sys/luasrc | |
parent | d7d27ffe6adfb42be253bf2a62e7cc4e209affaf (diff) |
libs/sys: extend luci.sys.hostname() to allow setting a new name
modules/admin-{full,mini}: update the hostname at runtime
Diffstat (limited to 'libs/sys/luasrc')
-rw-r--r-- | libs/sys/luasrc/sys.lua | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/libs/sys/luasrc/sys.lua b/libs/sys/luasrc/sys.lua index a2c9a31119..3e2ce7f319 100644 --- a/libs/sys/luasrc/sys.lua +++ b/libs/sys/luasrc/sys.lua @@ -129,10 +129,16 @@ end -- @return Table containing all variables if no variable name is given getenv = posix.getenv ---- Determine the current hostname. +--- Get or set the current hostname. +-- @param String containing a new hostname to set (optional) -- @return String containing the system hostname -function hostname() - return posix.uname("%n") +function hostname(newname) + if type(newname) == "string" and #newname > 0 then + luci.fs.writefile( "/proc/sys/kernel/hostname", newname .. "\n" ) + return newname + else + return posix.uname("%n") + end end --- Returns the contents of a documented referred by an URL. |