new post: lua_demo

This commit is contained in:
dongdigua 2023-07-26 14:40:43 +08:00
parent eefe383bba
commit 62c77227b3
6 changed files with 86 additions and 3 deletions

View File

@ -52,10 +52,10 @@ yes, deprecated, so I need to change it in my packages
** [[https://lwn.net/Articles/912202][LWN: Packaging Rust for Fedora]]
not mail, but interesting
* Review Request I'm interested in
It will be good if I can review for them...
* BZs I'm interested in
** [[https://bugzilla.redhat.com/show_bug.cgi?id=2183700][Review Request: nim - A statically typed compiled systems programming language]]
** [[https://bugzilla.redhat.com/show_bug.cgi?id=2192986][Review Request: hyprland - Dynamic tiling Wayland compositor that doesn't sacrifice on its looks]]
** [[https://bugzilla.redhat.com/show_bug.cgi?id=2152222][Update vis editor to 0.8]]
* Footnotes
[fn:1] [[https://acyanbird.github.io/2022/10/15/向EPEL请求新的包][向EPEL请求新的包(群主写的)]]

View File

@ -159,6 +159,9 @@ funny byte
*** [[https://xeiaso.net/blog/🥺][🥺]]
*** [[https://xeiaso.net/blog/HVE-BC1750-0001][HVE-BC1750-0001: Deceptive Information Disclosure Vulnerability in Human Interaction Protocols]]
** [[https://lantian.pub/][蓝天]]
:PROPERTIES:
:CUSTOM_ID: lantian
:END:
大佬!
*** [[https://lantian.pub/article/chat/how-i-nuked-my-btrfs-partition.lantian/][我把硬盘换到了新电脑上,这是 Btrfs 上的数据发生的变化]]
[[https://lantian.pub/usr/uploads/202112/chubbyemu.jpg.thumb.png]]
@ -591,3 +594,4 @@ BSD asm
** [[https://cohost.org/blackle/post/42994-div-style-pointer][CSS 的机械装置 (from ruanyifeng 252)]]
** [[https://oldcompcz.github.io/jgs/][jgs ASCII art]]
** TODO [[http://retrobase.cn][retrobase 识旧知新]]
** [[https://www.zzzuckerberg.com][Legal Lullabies]]

67
org/lua_demo.org Normal file
View File

@ -0,0 +1,67 @@
#+TITLE: Run a Lua Demo
#+DATE: <2023-07-25 二>
#+OPTIONS: \n:nil
Lua is everywhere.
Neovim uses lua, Vis uses lua; when I visited [[./internet_collections.org::#lantian][Lantian]]'s website[fn:1], it's running [[https://openresty.org/][OpenResty]];
when I'm [[https://bookfere.com/post/970.html][jailbreaking]] Kindle, it uses a lua script and [[https://github.com/koreader/koreader][Koreader]] uses lua.
So I want to learn a little lua, just enough to handle daily tasks.
I visited lua.org and found the [[https://www.lua.org/cgi-bin/demo][demo]]. The idea of knowing how it works immediately came to my mind.
By searching on DDG[fn:2] I fount it have a hidden demo program called demo,
it's just the script for running demo (talk about that later why I'm sure about it).
I copied it and added the essential html in the print block,
put it on the server, use [[https://man.openbsd.org/slowcgi.8][slowcgi(8)]] to serve it with [[https://man.openbsd.org/httpd.8][httpd(8)]].
Then I got "No such file or directory".
I carefully checked the path and permission, but the error still exists
Finally StackOverflow taught me that the execution environment should also
be located in the chroot environment. For security, chroot is needed.
Well, just [[https://blog.syndcat.com/?p=181][statically]] link lua[fn:3].
#+BEGIN_SRC makefile
MYLDFLAGS= -static
#+END_SRC
It runs well, but the =-- continue HTML began in shell script= line
indicates it's not the only file in the CGI application.
I found the rest of them at [[https://web.tecgraf.puc-rio.br/~lhf/ftp/lua/#demo]] from [[http://lua-users.org/lists/lua-l/][lua-l]] mailing list.
It contains 3 files
#+BEGIN_EXAMPLE
demo the CGI script
demo.html the HTML page
demo.lua the Lua program that runs user programs
#+END_EXAMPLE
The shell script takes =QUERY_STRING= and replace textarea with =$QUERY_STRING.lua=.
So demo?demo just prints the demo.lua itself in the same directory.
I thought my single-file solution is better because it don't need to fork twice and perform file IO,
and it can be even better.
I added resource limit according to [[https://www.lua.org/pil/][PIL]] chapter 25 "SandBoxing"
#+BEGIN_SRC lua
local steplimit = 100
local memlimit = 100
local count = 0
local function step ()
count = count + 1
if collectgarbage("count") > memlimit then
error("DoSer uses too much memory")
end
if count > steplimit then
error("DoSer uses too much CPU")
end
end
debug.sethook(step, "", 100)
#+END_SRC
source code: https://github.com/dongdigua/demo.lua
* Footnotes
[fn:1] I found his page all empty so I sent him an email, he quickly fixed it.
[fn:2] DuckDuckGo, not DongDiGua
[fn:3] If =make freebsd= don't work, try =make generic=

View File

@ -22,6 +22,7 @@
** [[https://github.com/dongdigua/configs/tree/main/kernel][定制 Linux Kernel]] :git:
* 2022 春, 暑假
** 2022.4 开始使用 emacs
** 2022.4 [[https://github.com/dongdigua/a_docker_site][尝试 Docker]] :git:
** 2022.5 创建博客 dongdigua.github.io :git:blog:
** 2022.5 学习 Rust

View File

@ -188,7 +188,7 @@ samba 分为 smbd, nmbd, winbindd.
所以这使我必须得用 port 精简功能了.
然后解压 ports tree 的时候死机了, 拔电然后文件系统坏了...
还是 NFS 吧, 反正我又不用 Windows.
还是 NFS 吧, Need For Speed, 反正我又不用 Windows.
至于权限, -mapall=freebsd 就行
* LED
@ -228,6 +228,16 @@ load_rc_config $name
run_rc_command "$1"
#+END_SRC
* obhttpd
OpenBSD 的软件向来很棒!
httpd 其实算是一个比较年轻的软件, [[https://www.openbsd.org/papers/httpd-asiabsdcon2015.pdf][这里]]有关于为什么 OpenBSD 要自己做一个 Web Server 的历史
重载配置:
#+BEGIN_SRC sh
sudo pkill -HUP obhttpd
#+END_SRC
(slowcgi 很重要的一点: 如果用 chroot 也需要把运行时等一切文件都放在里面)
* Ref
- [[https://feng.si/posts/2019/06/freebsd-and-risc-v-the-future-of-open-source-iot-ecosystem/][FreeBSD 与 RISC-V: 开源物联网生态系统的未来]]

View File

@ -1,5 +1,6 @@
## Table of Contents
### Posts (sorted by time)
- [2023-07-25 : Run a Lua Demo](lua_demo)<br>
- [2023-07-10 : 在 NanoPi R2S 上运行 FreeBSD](nanopi_freebsd)<br>
- [2023-06-08 : Org: Disable Gnus Loading when Org is Loaded](gmi/org_load_gnus_disable.gmi.txt)<br>
- [2023-06-07 : Org Preserve Source Bock Highlighting when Exporting Non-Interactively](org_export_highlight)<br>