Category: 黑科技

Pass a Device to a Linux Container

Recently I was trying to make FPGA tools running inside a LinuX Container (LXC). Getting the software tools running is basically about coping with Xilinx’s horrible bash scripts. Making the container see the FPGA hardware seems more challenging and there are very few references on the Internet. The major trick is to pass the correct devices to the LXC. FPGAs (at least those…

Status
Blaok

If you are working with some software which requires you to source some code and messes up with your PATH and other environment variables like Vivado and Merlin compiler, here is a simple and straightforward method to get rid of the mess (to some extent).

#!/bin/bash
VERSION=2016.1
. /space/Xilinx/SDAccel/${VERSION}/settings64.sh
# do something if necessary
if ! test "$0" -ef "$(which $(basename $0))"
then
    exec $(basename $0) "$@"
else
    if test -t 2
    then
        echo "Recursive call detected!" 1&>2
    fi
fi

Some notes:

  • Start with #!/bin/bash if you or your script use bash-specific syntax!
  • Give this file execution permission with chmod +x!
  • Make sure this file itself has the same name as the target program, or is soft-linked to it!
  • Use . instead of source, which improves compatibility!
Status
Blaok

On Linux, if you see

mtr: unable to get raw sockets.

The following might help:

sudo chmod 4755 $(which mtr)

Reference


The reason this happens is that only privileged processes (or processes with proper capabilities(7) on Linux) can create raw sockets, which is needed to send/receive ICMP packets. By chmod(2), the executable will get the S_ISUID mode, which means it can set process effective user ID when execve(2).


A safer solution is

sudo setcap cap_net_raw+ep $(which mtr)

which only gives mtr the cap_net_raw capability.

Reinstalling the mtr package via the package manager should also solve the problem since it will do whatever appropriate to make it work.

 

Status
Blaok

According to cplusplus.com, std::vector<bool> in C++ is specialized and consumes only 1/8 space as you may have expected. However, as 8-bit bytes are usually the shortest available type in most implementations, thread-safety is not guaranteed. This could have caused significant trouble in my current project. How lucky I am to notice this interesting feature before I have actually encountered trouble.

Besides, std::bitset provides a fixed size bit array whose length is fixed at compile-time.

别人家的地图

找签证路线的时候发现谷歌地图有一个打印功能简直贴心(图片可以戳开看原图,会打开新的标签页): 别人家的地图就是好用啊! 相比之下,看看咱自己家(?)地图的打印功能:

Status
Blaok

突然有一天,我的iPad播不出声音了……耳机不行……扬声器也不行……蓝牙都不行……不是静音的问题……重启没有用……所有的播放器都没声了……直到我找到了这篇帖子。其实只要删除

/System/Library/PrivateFrameworks/IAP.framework/Support/iapd

然后重启就行了……