local unix = require 'unix' Write('\r\n') Write('redbean\r\n') Write('

UNIX Information Demo

\r\n') Write('\r\n') Write('
\r\n') Write('
unix.getuid()\r\n') Write('
%d\r\n' % {unix.getuid()}) Write('
unix.getgid()\r\n') Write('
%d\r\n' % {unix.getgid()}) Write('
unix.getpid()\r\n') Write('
%d\r\n' % {unix.getpid()}) Write('
unix.getppid()\r\n') Write('
%d\r\n' % {unix.getppid()}) Write('
unix.getpgrp()\r\n') Write('
%d\r\n' % {unix.getpgrp()}) Write('
unix.umask()\r\n') mask = unix.umask(027) unix.umask(mask) Write('
%.4o\r\n' % {mask}) Write('
unix.getsid(0)\r\n') sid, err = unix.getsid(0) if sid then Write('
%d\r\n' % {sid}) else Write('
%s\r\n' % {err}) end Write('
unix.gethostname()\r\n') Write('
%s\r\n' % {EscapeHtml(assert(unix.gethostname()))}) Write('
unix.getcwd()\r\n') Write('
%s\r\n' % {EscapeHtml(assert(unix.getcwd()))}) function PrintResourceLimit(name, id) soft, hard = unix.getrlimit(id) Write('
getrlimit(%s)\r\n' % {name}) if soft then Write('
') Write('soft ') if soft == -1 then Write('∞') else Write('%d' % {soft}) end Write('
\r\n') Write('hard ') if hard == -1 then Write('∞') else Write('%d' % {hard}) end Write('\r\n') else Write('
%s\r\n' % {EscapeHtml(tostring(hard))}) end end PrintResourceLimit('RLIMIT_AS', unix.RLIMIT_AS) PrintResourceLimit('RLIMIT_RSS', unix.RLIMIT_RSS) PrintResourceLimit('RLIMIT_CPU', unix.RLIMIT_CPU) PrintResourceLimit('RLIMIT_FSIZE', unix.RLIMIT_FSIZE) PrintResourceLimit('RLIMIT_NPROC', unix.RLIMIT_NPROC) PrintResourceLimit('RLIMIT_NOFILE', unix.RLIMIT_NOFILE) Write('
unix.siocgifconf()\r\n') Write('
\r\n') ifs, err = unix.siocgifconf() if ifs then for i = 1,#ifs do if ifs[i].netmask ~= 0 then cidr = 32 - Bsf(ifs[i].netmask) else cidr = 0 end Write('%s %s/%d
\r\n' % {EscapeHtml(ifs[i].name), FormatIp(ifs[i].ip), cidr}) end else Write('%s\r\n' % {err}) end enabled, err = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_DEBUG) Write('
unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_DEBUG)\r\n') if enabled then -- is nil on error Write('
%d\r\n' % {enabled}) -- should be 0 or 1 else Write('
%s\r\n' % {err}) end enabled, err = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_ACCEPTCONN) Write('
unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_ACCEPTCONN)\r\n') if enabled then -- is nil on error Write('
%d\r\n' % {enabled}) -- should be 0 or 1 else Write('
%s\r\n' % {err}) end enabled, err = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_REUSEADDR) Write('
unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_REUSEADDR)\r\n') if enabled then -- is nil on error Write('
%d\r\n' % {enabled}) -- should be 0 or 1 else Write('
%s\r\n' % {err}) end enabled, err = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_REUSEPORT) Write('
unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_REUSEPORT)\r\n') if enabled then -- is nil on error Write('
%d\r\n' % {enabled}) -- should be 0 or 1 else Write('
%s\r\n' % {err}) end enabled, err = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_KEEPALIVE) Write('
unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_KEEPALIVE)\r\n') if enabled then -- is nil on error Write('
%s\r\n' % {enabled}) -- should be 0 or 1 else Write('
%s\r\n' % {err}) end enabled, err = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_NODELAY) Write('
unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_NODELAY)\r\n') if enabled then -- is nil on error Write('
%s\r\n' % {enabled}) -- should be 0 or 1 else Write('
%s\r\n' % {err}) end secs, nanos = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_RCVTIMEO) Write('
unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_RCVTIMEO)\r\n') if secs then -- is nil on error Write('
%d seconds + %d nanoseconds\r\n' % {secs, nanos}) else err = nanos Write('
%s\r\n' % {err}) end secs, nanos = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_SNDTIMEO) Write('
unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_SNDTIMEO)\r\n') if secs then -- is nil on error Write('
%d seconds + %d nanoseconds\r\n' % {secs, nanos}) else err = nanos -- unix.Errno is always second result Write('
%s\r\n' % {err}) end enabled, err = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_DONTROUTE) Write('
unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_DONTROUTE)\r\n') if enabled then -- is nil if error Write('
%d\r\n' % {enabled}) -- should be 0 or 1 else Write('
%s\r\n' % {err}) end bytes, err = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_SNDBUF) Write('
unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_SNDBUF)\r\n') if bytes then -- is nil if error Write('
%d\r\n' % {bytes}) else Write('
%s\r\n' % {err}) end bytes, err = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_RCVBUF) Write('
unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_RCVBUF)\r\n') if bytes then -- is nil if error Write('
%d\r\n' % {bytes}) else Write('
%s\r\n' % {err}) end bytes, err = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_FASTOPEN) Write('
unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_FASTOPEN)\r\n') if bytes then -- is nil if error Write('
%d\r\n' % {bytes}) else Write('
%s\r\n' % {err}) end enabled, err = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_BROADCAST) Write('
unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_BROADCAST)\r\n') if enabled then -- is nil if error Write('
%d\r\n' % {enabled}) -- should be 1 or 0 else Write('
%s\r\n' % {err}) end enabled, err = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_CORK) Write('
unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_CORK)\r\n') if enabled then -- is nil if error Write('
%d\r\n' % {enabled}) -- should be 1 or 0 else Write('
%s\r\n' % {err}) end enabled, err = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_QUICKACK) Write('
unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_QUICKACK)\r\n') if enabled then Write('
%d\r\n' % {enabled}) else Write('
%s\r\n' % {err}) end enabled, err = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_DEFER_ACCEPT) Write('
unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_DEFER_ACCEPT)\r\n') if enabled then Write('
%s\r\n' % {enabled}) else Write('
%s\r\n' % {err}) end enabled, err = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_FASTOPEN_CONNECT) Write('
unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_FASTOPEN_CONNECT)\r\n') if err then Write('
%s\r\n' % {err}) else Write('
%s\r\n' % {enabled}) end bytes, err = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_SNDLOWAT) Write('
unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_SNDLOWAT)\r\n') if bytes then Write('
%d\r\n' % {bytes}) else Write('
%s\r\n' % {err}) end bytes, err = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_RCVLOWAT) Write('
unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_RCVLOWAT)\r\n') if bytes then Write('
%d\r\n' % {bytes}) else Write('
%s\r\n' % {err}) end bytes, err = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_KEEPCNT) Write('
unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_KEEPCNT)\r\n') if bytes then Write('
%d\r\n' % {bytes}) else Write('
%s\r\n' % {err}) end bytes, err = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_MAXSEG) Write('
unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_MAXSEG)\r\n') if bytes then Write('
%d\r\n' % {bytes}) else Write('
%s\r\n' % {err}) end bytes, err = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_SYNCNT) Write('
unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_SYNCNT)\r\n') if bytes then Write('
%d\r\n' % {bytes}) else Write('
%s\r\n' % {err}) end bytes, err = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_NOTSENT_LOWAT) Write('
unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_NOTSENT_LOWAT)\r\n') if bytes then Write('
%d\r\n' % {bytes}) else Write('
%s\r\n' % {err}) end bytes, err = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_WINDOW_CLAMP) Write('
unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_WINDOW_CLAMP)\r\n') if bytes then Write('
%d\r\n' % {bytes}) else Write('
%s\r\n' % {err}) end bytes, err = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_KEEPIDLE) Write('
unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_KEEPIDLE)\r\n') if bytes then Write('
%d\r\n' % {bytes}) else Write('
%s\r\n' % {err}) end bytes, err = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_KEEPINTVL) Write('
unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_KEEPINTVL)\r\n') if bytes then Write('
%d\r\n' % {bytes}) else Write('
%s\r\n' % {err}) end Write('
unix.environ()\r\n') Write('
\r\n') Write('\r\n')