Debian 的 64-bit time_t 計畫

在「Debian: 64-bit time_t transition in progress」這邊看到 Debian 的 mailing list 上的討論:「64-bit time_t transition in progress」,另外官方也有整理 wiki page:「64-bit time」。

因為技術上無法表示 2038/01/19 以後的時間,確定會 breaking ABI 將 time_t 從 32-bit 變成 64-bit,而現在要想辦法搞定 32-bit 平台上面可以處理這樣的改變:

The goal of this transition is to ensure that 32-bit architectures in trixie (whether they are currently release architectures, or out of archive, etc) will be capable of handling current and future timestamps referring to times beyond 2038.

離 2038/01/17 還有約 13 年多...

用 shebang 掛起 Docker instance

週末偶而會看到一些奇怪的 side project,像是用 shebang (#!) 直接跑起一個 Docker instance 的方式:「Show HN: #!/usr/bin/env docker run (gist.github.com)」,程式碼在 gist 上:「adtac/595b5823ef73b329167b815757bbce9f」。

可以看到裡面主要的內容都是 Dockerfile,然後重點在開頭的 shebang command,把這些 Dockerfile 的指令倒進去跑 docker build:

#!/usr/bin/env -S bash -c "docker run -p 8080:8080 -it --rm \$(docker build --progress plain -f \$0 . 2>&1 | tee /dev/stderr | grep -oP 'sha256:[0-9a-f]*')"

記得這邊處理後面參數的部分有 undefined behavior,在 id=38989173 這邊也有人提到了:

Beware of portability: it relies on a non-standard behavior from some operating systems. It only works on OSs that treat all the text after the first space as argument(s) to the shebanged executable; rather than just treating the whole string as an executable path (that can happen to contain spaces).

但這主要是好玩,也就還好了...

跑 ldd 有可能會執行裡面的程式碼

Daily Lobsters 上看到「ldd(1) and untrusted binaries」這篇,這次的重點在 ldd 的 manpage ldd(1) 裡提到可能會執行裡面的程式碼,所以不適合拿來處理 untrusted binary:

Be aware, however, that in some circumstances, some versions of ldd may attempt to obtain the dependency information by directly executing the program. Thus, you should never employ ldd on an untrusted executable, since this may result in the execution of arbitrary code.

另外在原文裡面的 comment 有人提到 macOS 上面沒有 ldd,而是用其他工具給出類似的資訊,看起來是避開了這種實作方式:

macOS and other Darwin-based systems, which use Mach-O rather than ELF, and have an 4.x/SVR4-inspired dynamic linking mechanism (not surprising, given that the person who did a lot of the work on the 4.x system left Sun to go to NeXT), but don't have an "ldd" program. Instead, there's "otool -L", which produces output such as [...]

FreeBSD 上的 ldd(1) manpage 上沒有提到安全問題,但從他的實作描述看起來也不太妙:

ldd lists the dependencies of an executable by setting rtld(1) environment variables and running the executable in a child process.

回到原來主題,Linux manpage 裡面提到的 objdump 跟 ldd 的功能還是差蠻多的啊?不知道合理的替代品到底是什麼...

月份傳回值 0 表示一月的考古

Hacker News 上看到「History of Zero-Based Months? (jefftk.com)」這篇,在考古為什麼常常看到 function 在傳回「月份」時是以 0 表示一月。從這篇提到的「Why is day of the month 1-indexed but the month is 0-indexed in C? (twitter.com/hillelogram)」則是 2020 年的討論。

在討論裡面有提到 hillelogram 的 tweet,裡面有個看起來算合理的考古過程...

試著用 Thread Reader 產生單頁 (讀起來會比較好讀),但不知道為什麼一直失敗,結果往 Internet Archive 翻資料,倒是有 2020 年當初生成出來的版本

另外還是列出原來第一則 tweet:

作者在研究這個題目的時候,馬上可以想到的是 C 語言裡面的月份就是 0-indexed,而其他程式語言都很有可能會是因為 C 語言的關係一路把這個特性繼承下去:

直接跳到最後面作者的猜測,他覺得可能是為了讓後續使用起來更方便的關係。

其他的欄位大多都是透過類似 sprintf("%d") 的方式直接輸出數字,所以用 1-indexed 讓人直接讀,而月份則會透過 array 來轉字串,所以用 0-indexes 讓程式轉:

So that's my best guess: the programmers were working with constrained resources and could optimize `asctime` tricky pointer arithmetic on the month and day-of-week, so made them 0-indexed. Day-of-month is just for displaying to the user, so is 1-indexed.

沒辦法確定,但就是一種猜測,看起來還蠻... 合理... 的?

第四堂:「Data Wrangling」

有陣子沒寫了,來還個債...

這個系列是從『MIT 的「The Missing Semester of Your CS Education」』這邊延伸出來的,這邊講的是「Data Wrangling」這篇。

這篇是在講 pipe 的用法,在講這些工具之前,其實有個很重要的概念應該要說明 (但沒有在這篇文章裡被提到),也就是 Unix philosophy,這個哲學是指 unix 環境下的工具,都會設計成只做好一件事情。

而要怎麼把這些工具串起來,最常見的就是 pipe,你可以在文章裡看到 grepsedsort 這些工具的用法,以及怎麼用 pipe 串起來。

這邊剛好也可以提一下,利用 pipe 可以把不同功能打散到不同的 process 上,剛好也可以稍微利用到現在常見的多 CPU 的環境。

另外上面因為提到了 grep,文章內花了不少篇幅在講 Regular expression 這個在 CS 課程裡面也是重要的基礎。

會放這種篇幅長度,一方面是 Regular expression 的實用性很高,另外一方面,學術上與自動機理論中的 DFANFA 都有關,算是學習計算理論的起點:

然後後面就有提到 AWK 這個工具,這邊要注意的是,雖然可以用 Perl 之類的工具作到類似的事情 (而且更強大),但 AWK 有被放到 POSIX 標準裡,所以在各種作業系統內幾乎都一定會出現,加上語法算是簡單,學起來還是很有幫助...

然後再最後面的段落冒出一個 gnuplot 畫個圖,以及示範 xargs 這種神器要怎麼用 (這邊會更建議看一下 manpage,可以配合 find 之類的工具用,並且平行化同時處理)。

然後最後示範了 binary data 怎麼處理。

comm 的用法...

最近在 Twitter 上看到不少 shell 指令的說明,這則 tweet 是講 comm 這個指令:

1 是只有第一個檔案有的內容,2 是只有第二個檔案有的內容,而 3 是兩者都有的內容,而且檔案內容需要排序過。

當你 -1 時表示幹掉 1 的部份,-2 代表幹掉 2 的部份,-3 代表幹掉 3 的部份,然後可以疊起來用... 不過平常還是用 diff 比較多,每次看到 comm 的說明都是玩過再熟悉一下,然後就丟著 XD

Windows 10 將支援 AF_UNIX (Unix Socket)

在「Unix sockets come to Windows」這邊看到微軟的說明文「AF_UNIX comes to Windows」,Windows 10 將要引入 AF_UNIX 了:

Beginning in Insider Build 17063, you’ll be able to use the unix socket (AF_UNIX) address family on Windows to communicate between Win32 processes. Unix sockets allow inter-process communication (IPC) between processes on the same machine.

所以這讓跨 process 溝通的方式又多了一種,而 Unix 的程式如果要移植到 Windows 上,至少這塊有相容... (相容性與 bug 還不知道情況 XD)

CUPS 從 GPLv2 變成 Apache License, Version 2.0 了

CUPS 是處理印表機的軟體,在 macOS 以及其他各種 Unix-like 環境下都會使用。

在「CUPS relicensed to Apache v2」這邊看到 relicense 的消息,正式的公告則是在「CUPS License Change Coming」這邊可以看到:

Apple is excited to announce that starting with CUPS 2.3 we will be providing CUPS under the terms of the Apache License, Version 2.0.

剛好 GPLv2Apache License, Version 2.0 之間不相容,這樣跳過去算是趣味趣味...

用 awk 取代 grep 的工作

在「SKIP grep, use AWK」這篇看到關於使用 awk 取代 grep 的介紹。

作者提到這樣的替換:

$ [data is generated] | grep something | awk '{print $2}'
$ [data is generated] | awk '/something/ {print $2}'

還有這樣直接替換 grep 的方式:

$ [data is generated] | awk '/something/'

以及 -v 的替換:

$ [data is generated] | awk '/something/ {next} 1'
$ [data is generated] | awk '! /something/'

不過感覺還好耶...

StackOverflow 上離開 Vim 方法的文章...

被拿出來當 PR 宣傳了:「Stack Overflow: Helping One Million Developers Exit Vim」。

由於 Vim 是 Unix-like 系統一定會內建的 editor,所以常常被拿來放在 tutorial 裡面 (考慮到普及性,但完全不熟的初學者就...),或是不小心在輸入 vipw 或是 visudo 之類的指令就中獎了:

可以看到 pageview 破一百萬次了 XDDD 而且流量也都很穩定:

依照地區來拆開的話:(不過沒有照人口數正規化...)

然後做交叉分析,看這些卡在 Vim 的人平常是看什麼其他的文章:

回到資料分析的角度來看,這些東西可以透過有 cookie 的 access log 做到。有 access log 後可以用 Google CloudBigQuery,也可以用 AWS 家的 Amazon Athena 做。