星期五, 12月 26, 2014

Escaping from alternative charset (weird characters in tmux)

When I'm playing mud, sometimes my terminal run into a queer mode that leaves the characters all messed up:
After some research I found that it's because the terminal went into the 'Alternative charset' mode, that translate some characters to symbols (See the last section of man 5 termcap). As for the reason why it went into this mode, it's because that I accidentally echoed '^N' into the terminal. To escape, you can simply echo '^O' to restore the state. most common way:

$ cat
or you can use echo, if your shell supports entering special characters
$ echo ^V^O
If you want to reproduce this, just change the ^O above to ^N then you'll find yourself in the AC mode again.

Some in-depth explanation and other more complicated cases are described here:

星期四, 8月 07, 2014

Lock on suspend & Systemd

Ever since I switched to systemd, I found that the acpi-support LOCK_SCREEN(in /etc/default/acpi-support) setting doesn't work anymore. While acpi_listen still shows that the lid closing event is detected, my screenlock program(i3lock) wasn't getting executed whatsoever.

With a little bit of tracing I found that the lid event and relevant scripts are indeed executed but after invoking the 'CheckPolicy' function in the /etc/acpi/lid.sh the script halted. This is because the script checks the system to see if there are other program being in charge of power management and if there is acpi gets aborted.

So, to enforce screen locking after resume (or before sleep), we'll need to setup a service in systemd that gets executed at the appropriate time. After a bit of searching and playing with the options, I found this ready-to-use unit file by Karsten Gebbert:

to use this, download the .service file to /etc/systemd/system and enable the service with the following command:
(sudo) systemctl enable i3lock@[user].service
Where [user] should be replaced by the username whose password would be used to unlock.

To check if the service is enabled correctly you can either just try to suspend and see if the i3lock is fired up or check the list of currently enabled services:
 systemctl list-unit-files | grep i3lock
if you have successfully enabled it, there should be message like this:
i3lock@.service                            enabled

Note on the file name:
With an @ in the file name means this file is a template and can be enabled with specified instance name if provided. In this case the instance name will be [user] and it will replace the %i variable in the file.

星期五, 5月 17, 2013

installing Paragon NTFS & HFS driver

Recently, I bought a portable HD, which came NTFS-formatted. At first I considered formatting it to XFS or ext4 but it occurred to me that I might have to mount it with windows from time to time (although I don't have many windows PCs and will not have more than one unless necessary.)

Rather than trying to fix/install anything on the stupid Windows to support xfs/ext4, I prefer messing up with my linux which, in some way, is more intuitive for me than dealing with those mysterious bugs in windows.

There's a ntfs driver called ntfs-3g. It is fine, but somehow too slow. I don't know why it has been staying on FUSE all these years, or if staying on FUSE is the reason that makes it so slow. There's a couple of commercial alternatives that come into play: Tuxera(which I suspect is the reason that ntfs-3g being so slow) and Paragon but only the later one offers a free driver for linux, so I gave it a try and it works pretty well so far.

Here's how I do it:

星期二, 3月 19, 2013

cross-compile node.js (0.10.0) for mipsel (Asus RT-N16 with tomatousb)

最近入手了一台 RT-N16, 馬上是刷了 tomatousb, 還算蠻滿意的, 看了那精美的記憶體, 開完機還剩下 100+ MB, 家裡的裝置也很少使用 p2p, 這些記憶體不用好像有點浪費,於是便想把一些本來跑在桌電的 node server 來跑在 rt-n16 上。
記錄一下 cross-compile 的步驟:
先從 tomatousb 抓他們的 toolchain:

$ git clone git://repo.or.cz/tomato.git tomato
$ cd tomato
$ git checkout tomatousb-K26-1.28.9054 
$ sudo ln -s tools/brcm /opt/brcm
這邊用的是 linux 2.6 的版本, 其他版本可以參考 git tag。
然後再抓 node.js 的 source: 我這邊用的是最新的 node-v0.10.0
$ mkdir $HOME/node-src && cd $HOME/node-src
$ wget http://nodejs.org/dist/v0.10.0/node-v0.10.0.tar.gz
$ tar xf node-v0.10.0.tar.gz
$ cd node-v0.10.0
設定的部分,因為是 cross-compiling, 所以把 snapshot 關掉, 因為 compile 出來的 mksnapshot 也沒辦法在 host 上跑:

$ ./configure --prefix=/opt --dest-cpu=mipsel --dest-os=linux --without-snapshot
編譯過程中會有些錯,主要是 linux 版本的問題跟 pthread 有些函數(pthread_barrier_init|destroy|wait)在 uclibc 不支援,所以我做了個 patch, 這會讓有用到 ub_barrier_init|destroy|wait 的 module 無把編譯但 node 本身似乎是沒有用到這些函數,所以暫時可以這樣做:
$ wget -O - http://moon.cse.yzu.edu.tw/~s961449/node-mipsel.patch | patch -p0
$ PREFIX=/opt/brcm/K26/hndtools-mipsel-uclibc-4.2.4/bin/mipsel-linux-
$ export CC=${PREFIX}gcc
$ export CXX=${PREFIX}g++
$ export AR=${PREFIX}ar
$ export RANLIB=${PREFIX}ranlib
$ export LINK=$CXX
$ make -j4 #4 cores
基本上這樣就可以編出能在 tomato 上跑的 node 了, 編完以後 binary 會在 out/Release/node,但是不知道為什麼 tomato 的 firmware 並沒有把一些必要的 library 包進去,所以還要再附上 librt, libstdc++ 才行(optware 用來編譯的 toolchain 不同,所以也無法使用他們的 librt), 並設定 LD_LIBRARY_PATH 才能跑: node.sh:
LD_LIBRARY_PATH="/lib:/usr/lib:/opt/node/lib" /opt/node/bin/node $@
把檔案傳到 ap 上, 我這邊是用 optware 裝了 sftp, 所以直接用 sftp 上傳:
sftp root@your.ap.address
$ cd /opt
$ mkdir node
$ mkdir node/bin
$ mkdir node/lib
$ put out/Release/node node/bin/
$ put node.sh bin/node
$ put /opt/brcm/K26/hndtools-mipsel-uclibc-4.2.4/lib/librt.so node/lib
$ put /opt/brcm/K26/hndtools-mipsel-uclibc-4.2.4/lib/libstdc++.so node/lib/libstdc++.so.6
或是你要打包好在上傳也可以, 各人喜好啦,(因為當初是先上傳了才發現缺 lib)。 這樣應該就可以在 tomato 上跑 node 了! 但是馬上會用掉 30+% 的記憶體,也許可以再 tune 一下,但可以跑已經大喜大賀了, haha.

星期三, 2月 13, 2013

ibus override xmodmap, use xkb options instead

之前寫過一篇關於把 caps lock 重新 map 到 control 的方法,但昨天更新了 ibus 以後突然發現我的 xmodmap 只要切換輸入法引擎的時候就會被覆寫過去,google 了一下,大家似乎是推薦用 xkb 的設定選項來作調整:

Debian 來講的話,就是修改 /etc/default/keyboard
把 XKBOPTIONS 這行加入 ctrl:nocaps (有其他選項的話以逗號分隔)
重新開 X 以後就可以囉!似乎是比 xmodmap 乾淨一些,但缺點就是這樣改到的是整個系統的設定,如果使用者要改就沒辦法了。 若沒有 root 的權限可以改 /etc/default/keyboard, 也可以在 ~/.xsession 加上:
setxkbmap -option "ctrl:nocaps" &
其他的選項可以參考 man xkeyboard-config, /etc/default/keyboard 相關的資訊: man keyboard