翻舊帳

顯示具有 心得 標籤的文章。 顯示所有文章
顯示具有 心得 標籤的文章。 顯示所有文章

2024年4月30日 星期二

Linux 的 timezone 設定問題

 昨天遇到一個謎團.

系統開機, 會先以正常的方式同步網路時間:
1. 使用 zoneinfo 的檔案更換 /etc/localtime
2. NTP client sync

接著詢問私網的 server, 獲得特定時區的差, 重新同步一次時間
3. 詢問時間差
4. 把 /etc/localtime 換回 UTC
5. NTP client sync, 另外加上時間差

謎團在於, 系統看到的時間, 與 daemon 裡看到的時間不同步.

舉例, #1 把時區設定為 Asia/Taipei, 做完 #5 之後, 會發現, Linux 系統跟 state machine daemon 的時間會差 8 個小時. Linux 系統使用 date, 會看到時區是 UTC, daemon 裡看到的時區應該是 CST(GMT+8).

很明顯, daemon 在 #4 之後沒有跟著變為 UTC.

如果在 #1, #4 變動 timezone 之後, 使用 setenv("TZ", timezone string, 1) 呢?

1. 使用 zoneinfo 的檔案更換 /etc/localtime, setenv("TZ", timezone string, 1)
2. NTP client sync
3. 詢問時間差
4. 把 /etc/localtime 換回 UTC, setenv("TZ", "UTC", 1)
5. NTP client sync, 另外加上時間差

則會出現另一個問題: daemon 裡看到的時區會回到 UTC, 但 Linux 系統裡面看到的時區則停在 CST(GMT+8). 此時回到 Linux 系統, 使用 "set" command 查詢系統參數, 會看到 TZ='Asia/Taipei'.

也就是說, #4 即使 setenv(), 也僅作用於 deamon, Linux 系統卻沒有跟著變動.
怪異的是, #1 的 setenv(), 則會作用在 Linux 系統. 因為當我把 setenv() 拿掉的時候, Linux 系統中的 TZ, 就都不會存在.

我的猜測是, 系統設定值在每個 process 應該是獨立的? 可是這樣無法說明為什麼 #1 的 setenv() 會波及 Linux 系統.

2023年6月26日 星期一

2022年10月4日 星期二

[Yocto] [marking as unpacked only, configuration required on target.]

手上專案用到 Yocto 當作 Framework, 在新增一個元件 ksmbd-tools 的時候, 遇到 libglib-2.0 無法正常 install rootfs 的問題. log 如下:

WARNING: core-image-1.0-r0 do_rootfs: libglib-2.0-0.postinst returned 126, marking as unpacked only, configuration required on target.
ERROR: core-image-1.0-r0 do_rootfs: Postinstall scriptlets of ['libglib-2'] have failed. If the intention is to defer them to first boot, then please place them into pkg_postinst_ontarget_${PN} (). Deferring to first boot via 'exit 1' is no longer supported.
Details of the failure are in /home/lily/build/tmp/work/k-distro-linux-musl/core-image/1.0-r0/temp/log.do_rootfs.
ERROR: Logfile of failure stored in: /home/lily/build/tmp/work/k-distro-linux-musl/core-image/1.0-r0/temp/log.do_rootfs.27578

一開始完全沒有頭緒, Yocto 給出的建議有跟沒有一樣.
Google 所有關鍵字, 找到的文章, 要嘛沒有人回應, 要嘛回應的作法跟我遇到的問題無關.
最後只好硬著頭皮看 log: "/home/lily/build/tmp/work/k-distro-linux-musl/core-image/1.0-r0/temp/log.do_rootfs"

Log 裡面搜尋 glib, 看到如下訊息:

/home/lily/build/tmp/work/k-distro-linux-musl/core-image/1.0-r0/rootfs//var/lib/opkg/info/libglib-2.0-0.postinst: line 4: /home/lily/build/tmp/work/k-distro-linux-musl/core-image/1.0-r0/intercept_scripts-d488f44e3055645f044198b3d91612186d1ffb5bb926320b07b99ff8c208a402/postinst_intercept: Permission denied

很好, 至少是個我能解決的問題.

搜尋了一輪, 發現這是個 script, 而且是從 Yocto 標準 script pool 複製過來的. 位置如下:
/scripts/postinst-intercepts/postinst_intercept

把這個檔案用 chmod 改成可執行: chmod 777 postinst-intercepts/postinst_intercept
然後 commit/push, 從此解掉這個問題.

2022年9月14日 星期三

Windows 更新後無法存取網路芳鄰

這個月初某個 Windows update 過後, 我突然無法登入公司系統.
"Invalid date parameter", 甚麼鬼?

聯繫 MIS, 他說這個錯誤是因為我的電腦沒辦法用 Samba 連上公司的 NAS.
我在網路上搜尋好幾個解法, 包括打開 service, 寫入 regedit, 都沒用!!

束手無策的我, 終於在今天, 因為無法連上 build server的 samba, 決定一了百了重灌 windows!
沒想到, 連 MIS 提供的 Install USB 也沒辦法正常執行...
我索性打開控制台->程式和功能, 想移除最近安裝的 Update, 卻發現找不到那個 Update. 這? 我還有甚麼招數?

就在這個moment. 我瞄到一旁"開啟或關閉Windows功能".
靈光一閃. "不會吧?"
正所謂山重水複疑無路, 柳暗花明又一村.
它媽的是誰把我的 "SMB1.0/CIFS" 全部移除了??!!!!

把這個元件相關的全部打勾, 重開機讓他重新安裝啟動, 所有功能就正常了.

2020年2月19日 星期三

LoRa Gateway: SX1301/1308的SPI無論怎麼寫, 讀出來都是預設值

症狀:

1. lora_pkt_fwd load fw failed
ERROR: Failed to load fw 1
ERROR: Version of calibration firmware not expected, actual:0 expected:2

2. util_spi_stress 4 test items all failed

3. spidev_test write SX1301/1308 register but always get default value


原因:

SX1301/1308 處於 reset 狀態.
因為 SX1301/1308 的 reset 方向跟一般的 IC 相反.

2018年7月17日 星期二

'AM_PROG_LIBTOOL’ not found 以及 syntax error near unexpected token `-Wall'

找了一個下午, 原來是autogen.sh裏頭, 以-I指定的search path只適用於某台build server.

在server上, 以 grep -r "AM_PROG_LIBTOOL" /usr/share/* 找出正確路徑後加在 autogen.sh 裡面, 即可避免這個問題.

error: version mismatch. This is Automake

簡單說, 這一包 source code 使用的 Automake 版本, 跟系統中找到的不同, 就會發生這種錯誤.

解決方法也很簡單.
進入source code目錄, 執行 autoreconf 即可.

2017年11月28日 星期二

µPD720201 init fail on Linux

開機過程中, 掛載driver時出現 stall on CPU 2 的訊息.
/proc/bus/pci/devices 裡面看得到µPD720201的編號, 卻沒有辦法正確init.

原因很簡單, µPD720201需要外部的ROM存放FW, 如果ROM沒有上或是裡面沒有燒FW, 就會出現這個狀況.

2017年10月13日 星期五

free(): invalid next size (fast)

我參考Linux man page的code:
#define _GNU_SOURCE
#include
#include

int
main(void)
{
FILE *fp;
char *line = NULL;
size_t len = 0;
ssize_t read;

fp = fopen("/etc/motd", "r");
if (fp == NULL)
exit(EXIT_FAILURE);

while ((read = getline(&line, &len, fp)) != -1) {
printf("Retrieved line of length %zu :\n", read);
printf("%s", line);
}

free(line);
exit(EXIT_SUCCESS);
}

針對getline()產生的line buffer, 在最後將它free, 卻得到free(): invalid next size (fast).

最後我改用另一種寫法, 先malloc一塊夠大的buffer給line pointer, 然後, 然後就沒有error了.
len = 512;
line = malloc(len);
while( (ret = getline(&line, (size_t *)&len, fp)) != -1 ) {
if(line[0] == '#') continue; //comment
}
if(line != NULL) free(line);

2017年9月1日 星期五

編譯 toolchain, 出現 texi 相關的文件 error

output/toolchain/gcc-4.3.5/gcc/doc/cppopts.texi:757: @itemx must follow @item
make[2]: *** [doc/cpp.info] Error 1

編譯 buildroot 時, 遇到的問題.
這個問題是因為 textinfo 版本太新所造成的.
解法在此: https://git.busybox.net/buildroot/commit/?id=62322acb2ce186d544ab21fe253ccc8561a68a48

2017年8月31日 星期四

編譯的時候, 出現 undefined reference 錯誤

1. 沒有指定 library (-l)
2. 沒有指向 library 的目錄 (-L)
3. 參考到的 library 版本有問題
4. 參考路徑的順序有錯

第四點比較玄奇, 沒想到的話會花一點時間.
有可能參考路徑中有不只一個同名的 library, 但是這幾個檔案也許不是同一個編譯器做出來的, 也許不是同一個版本產生出來的, 也許是make clean的時候忘記去清掉上一次編譯出來的檔案.
Related Posts Plugin for WordPress, Blogger...