2015年1月16日星期五

2014年10月9日星期四

推送的博文

测试一下

2011年3月11日星期五

修正编译驱动模块时遇到的unknown field ‘ioctl’ specified in initializer错误

/!\ 没兴趣看我罗嗦废话的直接按照下文中蓝字部分执行应该就行了。

----------------------
今天心血来潮编译安装了 2.6.37.3的内核,结果发现原来好好的 vbox 虚拟机打不开了,错误提示: 让重新安装  virtualbox-ose-dkms 然后用 root 执行 modprobe vboxdrv 。

看来是新内核和现有的vbox驱动不兼容了。

按照提示执行:

sudo apt-get install virtualbox-ose-dkms

结果提示已经安装了最新版本的 。。也是啊,我以前都有的啊。

尝试执行 sudo dpkg-reconfigure virtualbox-ose-dkms 

就爆出一个错误。察看 /var/lib/dkms/virtualbox-ose/3.1.6/build/make.log 发现,问题出在 /var/lib/dkms/virtualbox-ose/3.1.6/build/vboxnetadp/linux/VBoxNetAdp-linux.c 文件的 第 92行,
 /var/lib/dkms/virtualbox-ose/3.1.6/build/vboxnetadp/linux/VBoxNetAdp-linux.c:92: error: unknown field ‘ioctl’ specified in initializer

vi +92 /var/lib/dkms/virtualbox-ose/3.1.6/build/vboxnetadp/linux/VBoxNetAdp-linux.c 看到那一行的内容是:
ioctl:      VBoxNetAdpLinuxIOCtl,

不知所以。上google。。。

结果发现这是个普遍的问题,这位仁兄说到了关键,
http://linux.chinaunix.net/bbs/redirect.php?goto=findpost&ptid=1174031&pid=7323551

但是俺不知道怎么改。。。继续google,在某外国友人的论坛上发现了修改方法,一位好心的老兄给出了patch(代码):

 --- VBoxNetAdp-linux.c~ 2010-08-05 14:52:24.000000000 +0100
+++ VBoxNetAdp-linux.c  2010-09-17 13:34:23.000000000 +0100
@@ -60,7 +60,7 @@

 static int VBoxNetAdpLinuxOpen(struct inode *pInode, struct file *pFilp);
 static int VBoxNetAdpLinuxClose(struct inode *pInode, struct file *pFilp);
-static int VBoxNetAdpLinuxIOCtl(struct inode *pInode, struct file *pFilp, unsigned int uCmd, unsigned long ulArg);
+static long VBoxNetAdpLinuxIOCtl(struct inode *pInode, struct file *pFilp, unsigned int uCmd, unsigned long ulArg);

 /*****************************************************************************
 *   Global Variables                                                         *
@@ -83,7 +83,7 @@
     owner:      THIS_MODULE,
     open:       VBoxNetAdpLinuxOpen,
     release:    VBoxNetAdpLinuxClose,
-    ioctl:      VBoxNetAdpLinuxIOCtl,
+    unlocked_ioctl:      VBoxNetAdpLinuxIOCtl,
 };

 /** The miscdevice structure. */
@@ -246,7 +246,7 @@
  * @param   uCmd        The function specified to ioctl().
  * @param   ulArg       The argument specified to ioctl().
  */
-static int VBoxNetAdpLinuxIOCtl(struct inode *pInode, struct file *pFilp, unsned int uCmd, unsigned long ulArg)
+static long VBoxNetAdpLinuxIOCtl(struct inode *pInode, struct file *pFilp, ungned int uCmd, unsigned long ulArg)
 {
     VBOXNETADPREQ Req;
     PVBOXNETADP pAdp;


但是别高兴的太早。这个补丁俺打上去的时候被拒绝了,还好补丁的内容不多,俺手动改!!!,

首先将 /var/lib/dkms/virtualbox-ose/3.1.6/build/vboxnetadp/linux/VBoxNetAdp-linux.c 的第92行:
ioctl:      VBoxNetAdpLinuxIOCtl,
改为:
 unlocked_ioctl:      VBoxNetAdpLinuxIOCtl,

然后搜索: int VBoxNetAdpLinuxIOCtl , 找到函数定义代码,将 int 改为 long.

现在为止,已经成功一半。

现在 进入 /usr/src/virtualbox-ose-3.1.6/vboxdrv 目录执行,sudo make install && sudo modprobe vboxdrv, ok ,如果不出错的话,vbox现在已经修复了。

为什么这么简单的一句命令我称之为一半呢?因为我当时天真的认为,直接执行下 sudo dpkg --configure virtualbox-ose-dkms 就可以了。谁知道它们竟然聪明的将我改的代码覆盖了。。。


--
yaoms

2011年1月6日星期四

Binder invocation to an incorrect interface 错误

#Android
在使用 aidl 开发程序时遇到了一个错误:
Binder invocation to an incorrect interface
搞了半天才明白,原来是因为我改动了aidl 的包路径,在服务器端和客户端必须保证一致的包路径,系统才认为这是一个正确的接口。

--
yaoms

2010年12月16日星期四

使用正则表达式查找源码包中包含中文字符的文件, grep perl regex sources chinese characters

列出所有包含中文的行(含文件名):
grep --color=auto -Pr '[^\x00-\x7f]+' src/

只列出文件名,去除重复项:
grep --color=auto -Pr '[^\x00-\x7f]+' src/ | awk -F: '{print $1}' | sort | uniq | sort

事实上,正则表达式(Perl) [^\x00-\x7f]+ 可以匹配任何非 ASCII 字符,不止中文字符,日文,韩文等非 ASCII 字符一样可以匹配。
--
yaoms

2010年11月8日星期一

xsel + libnotify-bin + google translate 自定义一个桌面取词翻译小工具

应用平台: linux X11 gnome
依赖的软件: xsel, libnotify-bin, python(simplejson,urllib,urllib2)

两个脚本:

~/bin/translate.py

#!/usr/bin/env python
from urllib2 import urlopen
from urllib import urlencode
import simplejson
import sys

# The google translate API can be found here:
# http://code.google.com/apis/ajaxlanguage/documentation/#Examples

target=sys.argv[1]

text=' '.join(sys.argv[2:])

base_url='https://www.googleapis.com/language/translate/v2?'

params=urlencode( (('key',    'AIzaSyCTMQYOQUQdWSAJ478lI-peSVelazL_iCQ'),
       ('target', target),
       ('q',      text), ) )

url=base_url+params

response=urlopen(url)

jsonObject = simplejson.load(response)

print "from:%s; %s" % (jsonObject['data']['translations'][0]['detectedSourceLanguage'],jsonObject['data']['translations'][0]['translatedText'].encode('utf-8'))


~/bin/trans-xsel

#!/bin/bash

# depend on xsel, libnotify-bin, translate.py
WORD=`/usr/bin/xsel -o`
TEXT=`translate.py zh """$WORD"""`
DISPLAY=:0.0 notify-send -i /usr/share/pixmaps/gdict.xpm -u normal -t 8000  来自谷歌翻译: """$TEXT"""

给这两个脚本添加执行权限,并把 ~/bin 加入 PATH 变量。

使用 gconf-editor 命令,启动 gnome 配置工具。

在 /apps/metacity/keybinding_commands/ 中 设置一个空闲的 command 键的值为  trans-xsel
在 /apps/metacity/global_keybindings/run_command_1 中设置 自己的快捷键: 例如 <Control><Alt>z

设置完成之后关闭配置工具。

使用方法:

在桌面上的任意窗口中(比如浏览器)选中要翻译的文本,按快捷键 Ctrl+Alt+z 系统提示框将会弹出提示框显示翻译结果。

--
yaoms