[置顶] Snailium共享新闻
[置顶] Current Project List
来多伦多的空档,在街头拿出电脑打算写点剧本,结果发现自动连上一个无线基站,速度还不错。
打开无线网络管理程序一看,竟然所处的位置上有这么多的AP。看来以后还是要保护好自己的AP,防止盗用。
地点:多伦多 Clarence Squre 北侧
时间:发帖时间
作案工具:Dell Latitude D630 (Wireless 802.11b/g)
貌似那个 One Zone 就是多伦多的城市无线网。
Linux BusyBox 果真是个强大的东西。只要想做,什么都能做出来。正好最近正愁 My Book 的服务总是莫名其妙的挂掉,搞的在单位都无法访问文件。操起简单的 vi,开始制作 Bash Watchdog。(之所以没用 Perl,是考虑到 Perl 在预编译的时候比较耗费系统资源)
经过三个小时的现学现卖,雏形版的 Bash Watchdog - swatchdog 出炉。
- #! /bin/bash
- #
- # Watchdog for system service
- #
- while [ 0 ]
- do
- for PROC
- do
- PID=`ps -aef | grep -v grep | grep -v swatchdog | grep "$PROC"`
- if [ -z "$PID" ] ; then
- TIME=`date "+%Y-%m-%d %H:%M:%S %Z"`
- echo "[$TIME] $PROC is not found, rebooting..." >> /etc/swatchdog/reboot.log
- reboot
- exit 1;
- fi
- done
- sleep 600
- done
- exit 0;
原理很简单,无限循环,检查命令行传入的进程是否存在。如果不存在则重启。
使用也很简单。
- swatchdog cvm transmission amuled
自动侦测 cvm(mionet)、transmission 和 amuled。
Here is HOWTO add nethostfs on Western Digital My Book World Edition. For Chinese version, visit here(中文版).
Prerequisite: Enable SSH on My Book.
Step 1. Download nethostfs v1.5 source code, unpack and compile.
- wget http://www.snailium.net/mbwe/nethostfs15src.tar.gz
- tar -xzvf nethostfs15src.tar.gz
- cd nethostfs15src
- make
- cp nethostfs /usr/sbin
- chmod 755 /usr/sbin/nethostfs
- chown root:root /usr/sbin/nethostfs
Step 2. Create shared folder /PSP/ through My Book Storage Manager.
Step 3. Create service script nethostfs under /etc/init.d/.
- #!/bin/sh
- #
- # Starts or stops the nethostfs for remote PSP access.
- PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
- NAME="nethostfs"
- DESC="Remote PSP access"
- case "$1" in
- start)
- echo -n "Starting $DESC: $NAME"
- nice -n 10 nethostfs /shares/internal/PSP &
- echo "..."
- ;;
- stop)
- echo -n "Stopping $DESC: $NAME"
- killall nethostfs
- echo "."
- ;;
- *)
- N=/etc/init.d/$NAME
- echo "Usage: $N {start|stop}" >&2
- exit 2
- esac
- exit 0
Step 4. Make start/stop link under /etc/init.d/.
- cd /etc/init.d/
- ln -s /etc/init.d/nethostfs S91nethostfs
- ln -s /etc/init.d/nethostfs K09nethostfs
Step 5. Reboot My Book World Edition
Note 1 - nice -n 10 is used in service script to adjust process priorities, in order to avoid nethostfs consumes too much CPU resource.
Note 2 - This works perfect for iRshell, as well as PPA (which uses iRshell's WiFi code)
Western Digital My Book 所使用的 BusyBox 可塑性还是很高的。
想到正好在用 PPA 在 PSP 上通过 WiFi 看电影,干脆把 nethostfs 服务也集成到 My Book 里面好了。(English Version)
前期准备:在 My Book 上加装 SSH 服务。
第一步:按照下面的方法下载 nethostfs v1.5 源代码,解包,编译。
- wget http://www.snailium.net/mbwe/nethostfs15src.tar.gz
- tar -xzvf nethostfs15src.tar.gz
- cd nethostfs15src
- make
- cp nethostfs /usr/sbin
- chmod 755 /usr/sbin/nethostfs
- chown root:root /usr/sbin/nethostfs
第二步:通过 My Book 共享储存管理器建立 PSP 共享文件夹。
第三步:在 /etc/init.d/ 下建立 nethostfs 服务脚本。
- #!/bin/sh
- #
- # Starts or stops the nethostfs for remote PSP access.
- PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
- NAME="nethostfs"
- DESC="Remote PSP access"
- case "$1" in
- start)
- echo -n "Starting $DESC: $NAME"
- nice -n 10 nethostfs /shares/internal/PSP &
- echo "..."
- ;;
- stop)
- echo -n "Stopping $DESC: $NAME"
- killall nethostfs
- echo "."
- ;;
- *)
- N=/etc/init.d/$NAME
- echo "Usage: $N {start|stop}" >&2
- exit 2
- esac
- exit 0
第四步:在 /etc/init.d/ 下建立相关启动/关闭服务链接。
- cd /etc/init.d/
- ln -s /etc/init.d/nethostfs S91nethostfs
- ln -s /etc/init.d/nethostfs K09nethostfs
第五步:重启 My Book。
注意 1:在服务脚本中,使用了 nice -n 10 调整进程的优先级,防止 nethostfs 占用过多资源。
注意 2:此方法也适用于 iRshell。(PPA 的 WiFi 部分使用的是 iRshell 的源代码)
闲来无事,改个PS2游戏玩玩。最近正在玩《无双·远吕智》,就拿它开刀。最终目标是替换全媒体文件。第一回只完成了替换片头。
今天喝酒的时候朋友提到了Facebook的强大,很多朋友都可以在Facebook上找到。后来自己申请了一个帐号研究了一下,发现Facebook不过是美国版的某“白领网”罢了。本文大略分析了一下Facebook是怎样工作的。
本着支持国货的心理,下载了一个银河麒麟2.1,看看最近国产操作系统发展得怎么样。
目前在做的SYSC 3303 Project是关于使用Java编写TFTP服务器/客户端。其中Java的发送数据包要用byte数组。凭着C语言的扎实基础,想当然的认为byte就是8位无符号整数。于是每一个数据包都由String转为byte发送。
但是,问题出现了。在发送ACK和DATA包时,传出的Block #有一部分不正确(例如:65535)。调试的时候显示在创建数据包的时候数据为0xFF_0xFF(65535),但是接收到的数据为0x3F_0x3F(16191)。
看了一下Java Specification,发现在Java中byte和int都是带符号的整数(signed integer),而且唯一的无符号整数(unsigned integer)是char。再往下看,原来char是按照UTF-16编码储存的(16位无符号整数)。郁闷啊。
接下来的工作就是查怎样从byte转换到int。因为带符号整数都是要做带符号扩展(signed extend),也就是说值为0xFF的byte在转成int之后,值为0xFFFFFFFF。终于在网上查到byte与int无符号转换方法,如下:
- int firstByte = 0;
- int secondByte = 0;
- int thirdByte = 0;
- int fourthByte = 0;
- firstByte = (0x000000FF & ((int)buf[index]));
- secondByte = (0x000000FF & ((int)buf[index+1]));
- thirdByte = (0x000000FF & ((int)buf[index+2]));
- fourthByte = (0x000000FF & ((int)buf[index+3]));
- long anUnsignedInt = 0;
- buf[0] = (anUnsignedInt & 0xFF000000L) >> 24;
- buf[1] = (anUnsignedInt & 0x00FF0000L) >> 16;
- buf[2] = (anUnsignedInt & 0x0000FF00L) >> 8;
- buf[3] = (anUnsignedInt & 0x000000FFL);
但是,问题并没有解决。看来不是cast问题。猛然醒悟,原来是从String转成byte的时候出问题了!看来整个Class都要修改了,再次郁闷一下。
总结:Java去掉了无符号的整数,据说本意是为了简化编程,但是事实上在做网络程序时,我们需要应用大量的无符号整数。另外,Java的一些内部机制也会对编程造成困惑,例如从String生成byte数组的算法。但是这些特别的地方一般的教授或者教材并不作介绍。因此,Java特别适合做Top-level程序(最高等级,即应用程序级)。
最后的一点个人总结:我这个智商没办法凌驾于Java之上,最多也就只能用用C语言了……
注:有关Java中unsigned number的详见 http://darksleep.com/player/JavaAndUnsignedTypes.html


![RSS订阅 [电影]拍摄记录 下的文章](templates/blueSky/images/rss.png)