X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=libs%2Fsys%2Fluasrc%2Fsys.lua;h=3e2ce7f3194ad16f99d866100eb706d047d701b7;hp=a2c9a31119d17d4c5f863def1178799915bb7198;hb=4b9f7db1cea69524ca46098b446b0fe51e87091b;hpb=d7d27ffe6adfb42be253bf2a62e7cc4e209affaf diff --git a/libs/sys/luasrc/sys.lua b/libs/sys/luasrc/sys.lua index a2c9a3111..3e2ce7f31 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.