2008年07月26日 星期六
iwl3945 on Debian
原来在debian下一直使用ipw3945驱动无线网卡,可是自从升到2.6.24以上内核以后,ipw3945就不能用了,内核提供了iwl3945模块来驱动。可是不知道为什么有好长时间不能从无线路由得到地址,也就是连不上无线网络,由于前段时间太忙,也没把这件事放在心上,使用网线连接凑乎了一段时间。今天实在无聊,就把它折腾出来了。
在折腾过程中,装了linux-wlan-ng,事实证明根本不需要,linux内核本身的东西就基本足够了。
系统版本:Debian testing 2.6.25-2-686
需要安装的软件包:firmware-iwlwifi
配置文件/etc/network/interfaces
iface wlan0 inet dhcp
pre-up ip link set wlan0 up
wireless-essid dlink
wireless-ap any
我用的路由器名称是dlink,根据实际情况可改作其他的。由于我的路由器没有使用加密验证之类的东东,所以没有其他配置,如需要可参考安装wpasupplicant。
ip命令在软件包iproute中。
2007年08月20日 星期一
Kile 和 kdvi之间的正向与反向搜索
正向搜索:在Kile中将闪烁光标放置到相应代码位置后,点击菜单栏上的ForwardDVI图标,可直接跳转到dvi文件的对应位置。
依次点击Kile菜单,Settings->Configure Kile...->Tools+Build,将LaTeX的配置选择为Modern。
反向搜索:在使用kdvi查看dvi时,使用鼠标中键点击dvi文件的某一位置,在Kile中闪烁光标会自动跳转到tex源代码的相应位置。
依次点击kdvi菜单,Settings->Configure KDVI...->DVI Specials,选择编辑器为Kile。
2007年07月20日 星期五
Sierra Wireless AirCard 555 for Debian Linux
这几天在使用联通的掌中宽CDMA无线上网卡,但是只提供了Windows下面的驱动程序。Linux下面的驱动得自己生成。
网卡型号:Sierra Wireless AirCard 555R
我的系统,Debian Linux testing
Kernel,Linux debian 2.6.21-2-686 SMP
创建并编辑下面两个文件:
创建/etc/pcmcia/aircard555.conf:
debian:/etc/pcmcia# more aircard555.conf
card "Sierra Wireless AirCard 555"
manfid 0x0192, 0xa555
cis "cis/aircard555.dat"
bind "serial_cs"
创建/etc/pcmcia/cis/aircard555.cis
debian:/etc/pcmcia/cis# more aircard555.cis
dev_info
no_info
attr_dev_info
EEPROM 250ns, 512b
manfid 0x013f, 0x0710
funcid serial_port
vers_1 7.0, "Sierra Wireless", "AirCard 555", "A555", "Rev 1"
config base 0x0700 mask 0x0073 last_index 0x03
cftable_entry 0x20 [default]
io 0x03f8-0x03ff [lines=3] [8bit] [range]
irq mask 0x3fbc [level]
cftable_entry 0x21
io 0x02f8-0x02ff [lines=3] [8bit] [range]
cftable_entry 0x22
io 0x03e8-0x03ef [lines=3] [8bit] [range]
cftable_entry 0x23
io 0x02e8-0x02ef [lines=3] [8bit] [range]
cftable_entry 0x24
io 0x0000-0x0007 [lines=3] [8bit]
然后应该生成文件aircard555.dat,命令如下:
debian:/etc/pcmcia/cis# pack_cis -o aircard555.dat aircard555.cis
但是,我的系统里面的pack_cis程序有问题,所以我是直接从网上下载的,你可以直接从这里下载aircard555.dat文件,拷贝到相应目录即可。
debian:/etc/pcmcia/cis# dmesg -c
debian:/etc/pcmcia/cis#
这是插入网卡,听到两声beep,
debian:/etc/pcmcia/cis# dmesg
pccard: PCMCIA card inserted into slot 0
pcmcia: registering new device pcmcia0.0
0.0: ttyS0 at I/O 0x3f8 (irq = 3) is a 16550A
可以看到系统已将网卡关联到/dev/ttyS0,在你的系统上有可能设备有所不同。
然后,可以使用pppconfig配置连接。
pppconfig
Main Menu:
Create Create a connection
Provider Name:
aircard
Configure Nameservers (DNS):
(*) Dynamic Use dynamic DNS
Authentication Method for aircard:
CHAP Crypto Handshake Auth Protocol
User Name:
card
Password:
card
Speed:
115200
Pulse or Tone:
(*) Tone
Phone Number:
#777
Choose Modem Config Method
Manually Select Modem Port
/dev/ttyS0
"Properties of aircard"
Please select the property you wish to modify, select "Cancel" to go back
Number #777 Telephone number
User card ISP user name
Password card ISP password
Speed 115200 Port speed
Com /dev/ttyS0 Modem com port
Method CHAP Authentication method
Advanced Advanced Options
Finished Write files and return to main menu.
Previous Return to previous menu
Quit Exit this utility
连接网络:
使用pon或者poff连接或者断开网络。
debian:/etc/pcmcia/cis# pon aircard
debian:/etc/pcmcia/cis# tail /var/log/messages -n 30
Jul 20 17:01:04 debian kernel: 0.0: ttyS0 at I/O 0x3f8 (irq = 3) is a 16550A
Jul 20 17:11:02 debian pppd[17058]: pppd 2.4.4 started by root, uid 0
Jul 20 17:11:03 debian chat[17062]: abort on (BUSY)
Jul 20 17:11:03 debian chat[17062]: abort on (NO CARRIER)
Jul 20 17:11:03 debian chat[17062]: abort on (VOICE)
Jul 20 17:11:03 debian chat[17062]: abort on (NO DIALTONE)
Jul 20 17:11:03 debian chat[17062]: abort on (NO DIAL TONE)
Jul 20 17:11:03 debian chat[17062]: abort on (NO ANSWER)
Jul 20 17:11:03 debian chat[17062]: abort on (DELAYED)
Jul 20 17:11:03 debian chat[17062]: send (ATZ^M)
Jul 20 17:11:03 debian chat[17062]: expect (OK)
Jul 20 17:11:03 debian chat[17062]: ATZ^M^M
Jul 20 17:11:03 debian chat[17062]: OK
Jul 20 17:11:03 debian chat[17062]: -- got it
Jul 20 17:11:03 debian chat[17062]: send (ATDT#777^M)
Jul 20 17:11:03 debian chat[17062]: expect (CONNECT)
Jul 20 17:11:03 debian chat[17062]: ^M
Jul 20 17:11:03 debian chat[17062]: ATDT#777^M^M
Jul 20 17:11:03 debian chat[17062]: CONNECT
Jul 20 17:11:03 debian chat[17062]: -- got it
Jul 20 17:11:03 debian chat[17062]: send (\d)
Jul 20 17:11:04 debian pppd[17058]: Serial connection established.
Jul 20 17:11:04 debian pppd[17058]: Using interface ppp0
Jul 20 17:11:04 debian pppd[17058]: Connect: ppp0 <--> /dev/ttyS0
Jul 20 17:11:09 debian pppd[17058]: CHAP authentication succeeded:
Jul 20 17:11:09 debian pppd[17058]: CHAP authentication succeeded
Jul 20 17:11:10 debian pppd[17058]: local IP address 211.145.37.188
Jul 20 17:11:10 debian pppd[17058]: remote IP address 220.192.0.22
Jul 20 17:11:10 debian pppd[17058]: primary DNS address 220.192.0.130
Jul 20 17:11:10 debian pppd[17058]: secondary DNS address 220.192.8.58
debian:/etc/pcmcia/cis# ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:5363 errors:0 dropped:0 overruns:0 frame:0
TX packets:5363 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1122730 (1.0 MiB) TX bytes:1122730 (1.0 MiB)
ppp0 Link encap:Point-to-Point Protocol
inet addr:211.145.37.188 P-t-P:220.192.0.22 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:3 errors:0 dropped:0 overruns:0 frame:0
TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:72 (72.0 b) TX bytes:87 (87.0 b)
然后就可以上网啦!
debian:/etc/pcmcia/cis# poff aircard
debian:/etc/pcmcia/cis# tail /var/log/messages
Jul 20 17:11:09 debian pppd[17058]: CHAP authentication succeeded
Jul 20 17:11:10 debian pppd[17058]: local IP address 211.145.37.188
Jul 20 17:11:10 debian pppd[17058]: remote IP address 220.192.0.22
Jul 20 17:11:10 debian pppd[17058]: primary DNS address 220.192.0.130
Jul 20 17:11:10 debian pppd[17058]: secondary DNS address 220.192.8.58
Jul 20 17:14:22 debian pppd[17058]: Terminating on signal 15
Jul 20 17:14:22 debian pppd[17058]: Connect time 3.2 minutes.
Jul 20 17:14:22 debian pppd[17058]: Sent 0 bytes, received 122 bytes.
Jul 20 17:14:22 debian pppd[17058]: Connection terminated.
Jul 20 17:14:22 debian pppd[17058]: Exit.
全部文件下载:aircard555.tgz
参考原地址: http://centerclick.org/aircard555/
如果使用pcmciautils,则直接将文件SW_555_SER.cis放到/lib/firmware/下,插入网卡以后,就会自动关联到设备文件/dev/ttyS0。
2007年06月22日 星期五
Debian 升级以后 Acrobat Reader无法打开
在某一次对Debian testing 进行了apt-get upgrade之后,偶然发现自己安装的Acrobat Reader不能正常启动了,报的错误是:
expr:语法错误
经过仔细查验acroread启动脚本,发现是升级Debian的过程中,libgtk2.0-0的版本从2.8.20-7升级到2.10.12-2。
对应的库文件由
/usr/lib/libgdk-x11-2.0.so.0.800.20
变成了
/usr/lib/libgtk-x11-2.0.so.0.1000.12
而acroread启动脚本检查该文件版本时的脚本对应为
get_gtk_file_ver()
{
if [ -f "$1" ]; then
if [ -h "$1" ]; then
ifile=`readlink $1`
if [ $? -eq 1 ]; then
return 1
fi
fi
mfile=`basename $ifile`
echo $mfile | grep -q "libgtk-x11-\([0-9]*\).0.so.0.\([0-9]*\).\([0-9]*\)" 2>/dev/null
if [ $? -ne 0 ]; then
return 1
fi
echo $mfile| sed 's/libgtk-x11-\([0-9]*\).0.so.0.\([0-9]\)00.\([0-9]*\)\|\(.*\)/\1\2\3/g'
return 0
fi
return 1
}
其中,sed行匹配版本号so.0.1000.12中的1000时只给了三位。
修改方法就显然了,将sed行改为
echo $mfile| sed 's/libgtk-x11-\([0-9]*\).0.so.0.\([0-9]\)*00.\([0-9]*\)\|\(.*\)/\1\2\3/g'
即可。
感谢icymoon花费时间调试!
2007年06月05日 星期二
fontconfig问题
新装系统如果执行fc-cache -fv,有时候会出现failed to write cache的情况。
这个问题是由于某些字体所在路径的创建时间要晚于系统当前时间。
逐个修改目录时间,或者干脆等几天就自然好了。
2007年05月01日 星期二
Mplayer打开文件出错
Debian testing
用Mplayer打开媒体文件,有的时候会报下面的错误:
ERROR: Could not open required DirectShow codec drvc.so.
解决方法:apt-get install libstdc++5
2007年04月23日 星期一
Beryl 快捷键
Alt + 鼠标滚轮 上/下使窗口 透明/不透明
Alt + Tab:在当前工作台中切换窗口
Ctrl + Alt + Tab:在所有工作台中切换窗口
Ctrl + Alt + 左/右方向键:立体地切换桌面
Ctrl + Shift + Alt + 左/右方向键:把活动窗口移到左/右工作台
Ctrl + Alt + 鼠标左键并拖曳:手动旋转立方体
Win + 鼠标滚轮 上/下:手动缩放大/小
Alt + 鼠标左键并拖曳:移动窗口
Win + m:屏幕反色
Win + n:当前窗口反色
Ctrl+Win + 鼠标左键并拖曳:将所选区域截图(图片保存在桌面)
鼠标左键点一下窗口标题栏,滑动中键,向上是卷起,向下是展开
Gnome 桌面上不显示已挂载的硬盘图标
使用Gnome桌面,并且在fstab中挂载了很多其他分区,烦人的是,每个挂载的分区都会在桌面上显示一个分区图标,很是烦人。
解决办法是:
1. 应用程序->系统工具->配置编辑器(gconf-editor)
2. 找到 /apps/nautilus/desktop/volumes_visible,去掉勾选即可。
2006年12月12日 星期二
Debian testing on R60e
新近购置了一台IBM(Lenovo) R60e 065877C。花了俺好多银子。心疼啊!
安装Debian Linux的过程更是说起来就是一把泪啊,好在有rmingming牺牲大量时间帮助,终于将其驯服。现在将一些注意的问题记录一下。
选择Debian也是经过很长时间学习才发现其好用之处的,尤其是依赖关系解决的太棒了。原来用过很多其他的发行版,最后发现还是debian适合像我这样的懒人。而且,我们楼里就有安装源,速度可以保证。按下不表,先说正题。
刻一张debian的网络安装盘,安装基本系统,R60e支持USB启动,也可以做成USB安装,具体参考:http://www.debian.org/releases/stable/i386/index.html.zh_CN。
安装基本系统没有问题。重启以后配置完安装源,运行
apt-get update
apt-get dist-upgrade
运行几次apt-get upgrade基本上就可以了。
更新内核:我们这里安装源最新内核是2.6.17-2。apt安装没有问题,但是最后生成的initrd.img不对,需要手动生成
mkinitrd -o /boot/initrd.img-2.6.17-2-686 /lib/modules/2.6.17-2-686/
否则,重启就无法用新内核进入系统。需要注意的是如果initrd-tools的版本不一样的话,也有可能导致生成的initrd.img不一样,会使机器无法启动。
安装图形界面,软件就不说了。我用的是gnome,还有其他一大堆软件。
主要是硬件设备驱动。
网卡:Broadcom NetXtreme BCM5751M Gigabit Ethernet
安装基本系统的时候设置网络,安装程序无法直接认出网卡,在选择的时候选Broadcom的tg3就可以,虽然安装程序自带的驱动可能觉得老了点,但是好像最新的驱动也是一样,没有任何变化。
显卡:集成Intel 945GM
安装xorg配置显卡的时候,使用驱动i810即可,可以直接驱动板载的945GM没有问题。
声卡:板载Intel HDA
安装完linux-sound-base和alsa-base应该就可以了。用gnome的音量控制就可以调出声音来应该。
不过最好安装esound,否则gnome事件的声音好像没法播放。
无线网卡:Intel PRO/Wireless 3945ABG
到http://ipw3945.sourceforge.net/下载驱动,按照说明一步一步来就可以。
首先下载内核代码和头文件,可以直接使用module-assistant这个程序。
我编译了一次内核,然后一切OK。
按照驱动安装说明,需要将内核的ieee80211模块进行替换,然后安装新模块ipw3945,并安装守护进程。
interfaces文件里面iface的写法就依赖于无线网的具体情况了。我的interfaces很简单。
# wireless interface used in my lab
iface eth1 inet dhcp
wireless-essid linksys
wireless-key off
wireless-ap 00:0C:41:9D:3C:A3
加在内核模块ipw3945可以写到/etc/modules里面,守护进程启动可以写到/etc/rc.local里面。
启用无限网络还是等机器以来以后ifup比较好,好像都写到启动脚本里面不怎么管用。
键盘Fn功能键,需要安装tpb。虽然配置tpb可以随X启动,但是由于设备文件nvram放在了,/dev/.static/dev/下面,每次重启系统以后.static的权限都变了。所以直接将设备文件建到了/目录下
mknod /nvram c 10 144
chmod 666 /nvram
然后,修改/etc/tpbrc。修改参数NVRAM就可以了。
当然,tpb默认定义的Fn功能键还差一些,需要进一步研究了,现在能用的有音量、亮度、数字键盘、键盘灯、截屏、挂起。
F*的功能还有几个没有。而且挂起事实上是利用gnome-power-manager实现,不过只是锁屏,休眠还不支持。
投影仪切换是直接在xorg.conf里面设置的
Section "Device"
Identifier "Generic Video Card"
Driver "i810"
BusID "PCI:0:2:0"
Option "MonitorLayout" "NONE,CRT+LFP"
EndSection
这样,是同时向LCD和投影仪显示。另外,虽然BIOS里面设置显示可以是Both,但是事实上,终端状态下,LCD和投影仪只有一个可以显示。
保存gnome的声音设置:
每次虽然调整了声音的设置,但是重启机器以后又会恢复初始状态。
需要安装alsa-utils,调整完以后运行alsactl store,将当前配置存到系统默认配置里,然后每次启动就可以了。
电源管理,直接安装acpi和acpid就可以了。
时间同步:
系统启动时需要从机器硬件时钟读取本地时间,关机的时候也会同步,但是系统默认的读取会报错
select() to /dev/rtc to wait for clock tick timed out
解决方法是,修改/etc/init.d/两个文件hwclock.sh和hwclockfirst.sh,修改其中的HWCLOCKPARS=--directisa就可以了。
2006年11月08日 星期三
tetex+CCT for Ubuntu edgy
装了ubuntu edgy, 写tex用Kile也很方便。平时都是写英文文档,这几天老板要我写份讲义,要求用CCT。所以只好安装CCT。
首先,要安装tetex。
apt-get install tex-common tetex-base tetex-bin tetex-extra
apt-get install cjk-latex dvipdfm-cjk dvipdfmx fontforge
然后,到 ftp://ftp.cc.ac.cn/pub/cct/Linux/下载
cct_0.6180.3a_i386.deb和cct-fonts_1.2.0_i386.deb,并安装
dpkg -i cct_0.6180.3a_i386.deb
dpkg -i cct-fonts_1.2.0_i386.deb
从ftp://ftp.cc.ac.cn/pub/cct/CJK/下载CJK-GBKfonts-0.3-15.i386.rpm
用alien转换为deb包并安装
alien --scripts CJK-GBKfonts-0.3-15.i386.rpm
dpkg -i cjk-gbkfonts_0.3-15_i386.deb
最后,我们需要一些字体, 将windows下的字体直接拷贝到/usr/share/fonts/truetype/下面,其他字体也是一样。
gbkfont-inst /usr/share/fonts/truetype/simsun.ttf song
gbkfont-inst /usr/share/fonts/truetype/simkai.ttf kai
gbkfont-inst /usr/share/fonts/truetype/simhei.ttf hei
gbkfont-inst /usr/share/fonts/truetype/simfang.ttf fang
gbkfont-inst /usr/share/fonts/truetype/simyou.ttf you
gbkfont-inst /usr/share/fonts/truetype/simli.ttf li
OK,可以了。
2006年10月12日 星期四
2006年06月03日 星期六
How to write a Makefile
How to write a Makefile
Introduction
Make is one of the original Unix tools for Software Engineering. By
S.I. Feldman of AT&T Bell Labs circa 1975. But there are public
domain versions (eg. GNU) and versions for other systems
(eg. Vax/VMS).
Related tools are the language compilers (cc, f77, lex, yacc, etc.)
and shell programming tools (eg. awk, sed, cp, rm, etc.). You need to
know how to use these.
Important adjuncts are lint (source code checking for obvious errors)
ctags (locate functions, etc. in source code) and mkdepend. These are
nice, and good programmers use them.
Important, and related tools, are the software revision systems SCCS (Source Code Control System) and RCS (Revision Control System -- the recommended choice)
The idea is to automate and optimize the construction of
programs/files -- ie. to leave enough foot prints so that others can
follow.
Makefile Naming
make is going to look for a file called Makefile, if not found then a
file called makefile. Use the first (so the name stands out in
listings).
You can get away without any Makefile (but shouldn't)! Make has
default rules it knows about.
Makefile Components
- Comments
Comments are any text beginning with the pound (#) sign. A
comment can start anywhere on a line and continue until the end of the
line. For example:
# $Id: slides,v 1.2 1992/02/14 21:00:58 reggers Exp $
- Macros
Make has a simple macro definition and substitution mechanism. Macros are defined in a Makefile as
= pairs. For example:
MACROS= -me
PSROFF= groff -Tps
DITROFF= groff -Tdvi
CFLAGS= -O -systype bsd43
There are lots of default macros -- you should honor the existing naming conventions. To find out what rules/macros make is using type:
% make -p
NOTE: That your environment variables are exported into the make as macros. They will override the defaults.
You can set macros on the make command line:
% make "CFLAGS= -O" "LDFLAGS=-s" printenv
cc -O printenv.c -s -o printenv
- Targets
You make a particular target (eg. make all), in none specified then the first target found:
paper.dvi: $(SRCS)
$(DITROFF) $(MACROS) $(SRCS) >paper.dvi
NOTE: The the line beginning with $(DITROFF) begins with TAB not spaces.
The target is made if any of the dependent files have changed. The dependent files in this case are represented by the $(SRCS) statement. - Continuation of Lines
Use a back slash (\). This is important for long macros and/or rules.
- Conventional Macros
There are lots of default macros (type "make -p" to print out the defaults). Most are pretty obvious from the rules in which they are used:
AR = ar
GFLAGS =
GET = get
ASFLAGS =
MAS = mas
AS = as
FC = f77
CFLAGS =
CC = cc
LDFLAGS =
LD = ld
LFLAGS =
LEX = lex
YFLAGS =
YACC = yacc
LOADLIBS =
MAKE = make
MAKEARGS = 'SHELL=/bin/sh'
SHELL = /bin/sh
MAKEFLAGS = b
- Special Macros
Before issuing any command in a target rule set there are certain special macros predefined.
- $@ is the name of the file to be made.
- $? is the names of the changed dependents.
So, for example, we could use a rule
printenv: printenv.c
$(CC) $(CFLAGS) $? $(LDFLAGS) -o $@
alternatively:
printenv: printenv.c
$(CC) $(CFLAGS) $@.c $(LDFLAGS) -o $@
There are two more special macros used in implicit rules. They are:
- $< the name of the related file that caused the action.
- $* the prefix shared by target and dependent files.
- $@ is the name of the file to be made.
- Makefile Target Rules
The general syntax of a Makefile Target Rule is
target [target...] : [dependent ....]
[command ...]
Items in brackets are optional, ellipsis means one or more.
Note the tab to preface each command is required.
The semantics is pretty simple. When you say "make target"
make finds the target rule that applies and, if any of the
dependents are newer than the target, make executes the com-
mands one at a time (after macro substitution). If any
dependents have to be made, that happens first (so you have
a recursion).
A make will terminate if any command returns a failure sta-
tus. That's why you see rules like:
clean:
-rm *.o *~ core paper
Make ignores the returned status on command lines that begin
with a dash. eg. who cares if there is no core file?
Make will echo the commands, after macro substition to show
you what's happening as it happens. Sometimes you might want
to turn that off. For example:
install:
@echo You must be root to install
- Example Target Rules
For example, to manage sources stored within RCS (sometimes
you'll need to "check out" a source file):
SRCS=x.c y.c z.c$(SRCS):
co $@
To manage sources stored within SCCS (sometimes you'll need
to "get" a source file):
$(SRCS):
sccs get $@
Alternativley, to manage sources stored within SCCS or RCS
let's generalize with a macro that we can set as required.
SRCS=x.c y.c z.c
# GET= sccs get
GET= co$(SRCS):
$(GET) $@
For example, to construct a library of object files
lib.a: x.o y.o z.o
ar rvu lib.a x.o y.o z.o
ranlib lib.a
Alternatively, to be a bit more fancy you could use:
OBJ=x.o y.o z.o
AR=arlib.a: $(OBJ)
$(AR) rvu $@ $(OBJ)
ranlib $@
Since AR is a default macro already assigned to "ar" you can
get away without defining it (but shouldn't).
If you get used to using macros you'll be able to make a few
rules that you can use over and over again.
For example, to construct a library in some other directory
INC=../misc
OTHERS=../misc/lib.a$(OTHERS):
cd $(INC); make lib.a
Beware:, the following will not work (but you'd think it
should)
INC=../misc
OTHERS=../misc/lib.a$(OTHERS):
cd $(INC)
make lib.a
Each command in the target rule is executed in a separate
shell. This makes for some interesting constructs and long
continuation lines.
To generate a tags file
SRCS=x.c y.c z.c
CTAGS=ctags -x >tagstags: $(SRCS)
${CTAGS} $(SRCS)
On large projects a tags file, that lists all functions and
their invocations is a handy tool.
To generate a listing of likely bugs in your problems
lint:
lint $(CFLAGS) $(SRCS)
Lint is a really good tool for finding those obvious
bugs that slip into programs -- eg. type classes, bad argu-
ment list, etc.
- Some Basic Make Rule
People have come to expect certain targets in Makefiles. You
should always browse first, but it's reasonable to expect
that the targets all (or just make), install, and clean will
be found.
- make all -- should compile everything so that you can do local testing before installing things.
- make install -- should install things in the right places. But watch out that things are installed in the right place for your system.
- make clean -- should clean things up. Get rid of the executables, any temporary files, object files, etc.
You may encounter other common targets, some have been
already mentioned (tags and lint).
- make all -- should compile everything so that you can do local testing before installing things.
- An Example Makefile for printenv
# make the printenv command
#
OWNER=bin
GROUP=bin
CTAGS= ctags -x >tags
CFLAGS= -O
LDFLAGS= -s
CC=cc
GET=co
SRCS=printenv.c
OBJS=printenv.o
SHAR=shar
MANDIR=/usr/man/manl/printenv.l
BINDIR=/usr/local/bin
DEPEND= makedepend $(CFLAGS)
all: printenv# To get things out of the revision control system
$(SRCS):
$(GET) $@
# To make an object from source
$(CC) $(CFLAGS) -c $*.c# To make an executable
printenv: $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS)# To install things in the right place
install: printenv printenv.man
$(INSTALL) -c -o $(OWNER) -g $(GROUP) -m 755 printenv $(BINDIR)
$(INSTALL) -c -o $(OWNER) -g $(GROUP) -m 644 printenv.man $(MANDIR)# where are functions/procedures?
tags: $(SRCS)
$(CTAGS) $(SRCS)# what have I done wrong?
lint: $(SRCS)
lint $(CFLAGS) $(SRCS)# what are the source dependencies
depend: $(SRCS)
$(DEPEND) $(SRCS)# to make a shar distribution
shar: clean
$(SHAR) README Makefile printenv.man $(SRCS) >shar# clean out the dross
clean:
-rm printenv *~ *.o *.bak core tags shar# DO NOT DELETE THIS LINE -- make depend depends on it.
printenv.o: /usr/include/stdio.h
- Makefile Implicit Rules
Consider the rule we used for printenv
printenv: printenv.c
$(CC) $(CFLAGS) printenv.c $(LDFLAGS) -o printenv
We generalized a bit to get
printenv: printenv.c
$(CC) $(CFLAGS) $@.c $(LDFLAGS) -o $@
The command is one that ought to work in all cases where we
build an executable x out of the source code x.c This can be
stated as an implicit rule:
.c:
$(CC) $(CFLAGS) $@.c $(LDFLAGS) -o $@
This Implicit rule says how to make x out of x.c -- run cc
on x.c and call the output x. The rule is implicit because
no particular target is mentioned. It can be used in all
cases.
Another common implicit rule is for the construction of .o
(object) files out of .c (source files).
.o.c:
$(CC) $(CFLAGS) -c $<
alternatively
.o.c:
$(CC) $(CFLAGS) -c $*.c
- Make Dependencies
It's pretty common to have source code that uses include
files. For example:
% cat program.c#include
#include "defs.h"
#include "glob.h"
etc....
main(argc,argv)
etc...
The implicit rule only covers part of the source code depen-
dency (it only knows that program.o depends on program.c).
The usual method for handling this is to list the dependen-
cies separately;
etc...
$(CC) $(CFLAGS) -c $*.c
etc...
program.o: program.c defs.h glob.h
Usually an implicit rule and a separate list of dependencies
is all you need. And it ought to be easy enough to figure
out what the dependencies are.
However, there are a number of nice tools around that will
automatically generate dependency lists for you. For example
(trivial):
DEPEND= makedepend $(CFLAGS)
etc...
# what are the source dependenciesdepend: $(SRCS)
$(DEPEND) $(SRCS)etc....
# DO NOT DELETE THIS LINE -- ....printenv.o: /usr/include/stdio.h
These tools (mkdepend, mkmkf, etc.) are very common these
days and aren't too difficult to use or understand. They're
just shell scripts that run cpp (or cc -M, or etc.) to find
out what all the include dependencies are. They then just
tack the dependency list onto the end of the Makefile.
2006年06月02日 星期五
SuSE10.1的Xgl
按照http://www.novell.com/coolsolutions/feature/17174.html
的说明直接可以安装成功。
只是在安装完Xgl和compiz,并且做完设置以后还需要重启gnome才能打开gnome-session-properties继续进行设置。
最后的效果截图:

2006年05月26日 星期五
硬盘安装SUSE10.1
新版SUSE终于发布了,历经了几天的下载,中间还有两张iso的md5sum出错,终于把五张SUSE-Linux-10.1-GM-i386-CD*.iso下载了下来。本来琢磨这刻出盘来安装的,无奈手头白盘没有了,于是就有了这篇从硬盘安装的笔记。
看了网上一些关于从硬盘安装Linux的帖子以后,开始了自己的实践。
我的机器现装了Windows 2003 Server, 硬盘80G,分成了c,d,e三个分区,预留15G给linux.
1。从以下地址
http://grub4dos.sourceforge.net/
下载grub for dos。
解压后将文件grldr拷贝到C盘根目录,并修改C盘根目录下面的boot.ini文件,添加grub启动项,具体形式如下:
[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Windows Server 2003, Enterprise" /noexecute=optout /fastdetect
C:\grldr="GRUB"
2. 我的五张ISO都下载到了E:\suse目录下,将SUSE-Linux-10.1-GM-i386-CD1.iso解压到D:\cd1下面,
(我这里很奇怪,原本解压在E盘下面的,可是grub启动之后死活找不到E盘,所以放到了D盘下面)
将D:\cd1\boot\i386\loader\下面的linux和initrd两个文件拷贝到D盘根目录下,(这里也可以放到E盘根目录下)。
OK,下面就可以重启机器了。
3。重启机器,选择Grub引导。进入grub命令提示符之后,需要执行以下命令
grub> find /linux
返回 (hd0,4)
grub> kernel (hd0,4)/linux root=/dev/ram
(返回忽略)
grub> initrd (hd0,4)/initrd
(返回忽略)
grub> boot
就可以看到启动了机器
4。此时启动的系统只需要做几项设置,包括语言、键盘布局、还有就是安装源了
我的安装源是hda5,然后设置路径为cd1.
这是系统就自动读取安装信息进入Suse的安装程序了。
5。其他忽略不表,正常选择和设定,安装第一张光盘完成后会自动重启计算机。
在重启以后,由于找不到第二张光盘的解压路径,会报错,一般错误会是类似这样的信息:
hd:///cd1?device=/dev/hda5???filetype=auto(差不多吧,如果记得不差的话)
因为我们只解压了一张ISO,如果把所有ISO都依次解压为cd1,cd2,cd3,cd4,cd5五个文件夹的话,这个问题就不会有了,关键问题就是这样太浪费空间了。
这时,需要Ctrl+Alt+F2(F3-F6也可)切换到控制台方式下面,这时是有root shell的
我们需要手动挂载没有解压的几个ISO文件
cd /media
mkdir win-e
mount /dev/hda6 /media/win-e
mkdir cd2
mkdir cd3
mkdir cd4
mkdir cd5
mount -o loop /media/win-e/suse/SUSE-Linux-10.1-GM-i386-CD2.iso /media/cd2
mount -o loop /media/win-e/suse/SUSE-Linux-10.1-GM-i386-CD3.iso /media/cd3
mount -o loop /media/win-e/suse/SUSE-Linux-10.1-GM-i386-CD4.iso /media/cd4
mount -o loop /media/win-e/suse/SUSE-Linux-10.1-GM-i386-CD5.iso /media/cd5
OK,按键Alt+F7回到图形界面,报错窗口中选中“显示细节”,将URL(依次)修改为
dir:///media/cd2
即可继续安装系统了。
2006年04月10日 星期一
Suse10安装 QtiPlot - Data analysis and scientific plotting
Linux下面的Origin
安装源文件都位于/software下
1.安装QwtPlot3D
下载地址:http://qwtplot3d.sourceforge.net/web/navigation/download_frame.html
解压qwtplot3d-0.2.6.tgz
mkdir /usr/include/qwtplot3d
将/software/qwtplot3d/include目录下所有文件拷贝至/usr/include/qwtplot3d
在/software/qwtplot3d/运行
/usr/lib/qt3/bin/qmake(我的Suse把qt3装在此目录)
这时make时会报错误,说-lXmu找不到库文件,Suse10下libXmu装的路径是/usr/X11R6/lib/
修改Makefile,将
LIBS = $(SUBLIBS) -L/usr/lib/ -L$(QTDIR)/lib/ -L/usr/lib/ -lz -lqt-mt -lGLU -lGL -lXmu -lpthread
改为
LIBS = $(SUBLIBS) -L/usr/lib/ -L$(QTDIR)/lib/ -L/usr/lib/ -L/usr/X11R6/lib/ -lz -lqt-mt -lGLU -lGL -lXmu -lpthread
然后make就可以了
把/software/qwtplot3d/lib/下所有文件拷贝至/usr/lib/下
2. 安装GSL库
下载地址:http://www.gnu.org/software/gsl/
beat@huang:/software> tar -zxvf gsl-1.7.tar.gz
beat@huang:/software> cd gsl-1.7/
beat@huang:/software/gsl-1.7> ./configure --prefix=/usr/
beat@huang:/software/gsl-1.7> make
beat@huang:/software/gsl-1.7> su
huang:/software/gsl-1.7 # make install
3. 安装qtiplot
下载地址:http://soft.proindependent.com/qtiplot.html
beat@huang:/software> tar -xf qtiplot-0.8.2.tar
beat@huang:/software> cd qtiplot-0.8.2/
beat@huang:/software/qtiplot-0.8.2> export PATH=$PATH:/usr/lib/qt3/bin/
beat@huang:/software/qtiplot-0.8.2> qmake
beat@huang:/software/qtiplot-0.8.2> make
beat@huang:/software/qtiplot-0.8.2> su
huang:/software/qtiplot-0.8.2 # make install
好啦,装完拉
2006年04月09日 星期日
Gaim使用Google Talk
系统Suse 10
Gaim 版本 1.5.0-3
启动Gaim,选择帐户,添加;
协议选Jabber,用户名是gmail帐号(不含@gmail.com),服务器写:gmail.com;
密码是gmail邮箱密码;别名可任意取。
点下面的”显示全部选项“,只勾选“若可用则使用TLS”,端口:5222,连接服务器:talk.google.com。
然后确定,就可以登录使用Google Talk了。
2006年04月04日 星期二
Richard Stallman ”未来的自由软件”
会议: 意大利都灵GPLv3会议
时间: 2006-03-18 9:30到13:30
演讲人: Richard Stallman
主题: 未来的自由软件
演讲文稿
Richard Stallman:
Before I get into the main subject, which is the plans for version three of the GPL, I want to mention a very important fundamental issue.
[1h 27m 06s]
There is a term that some people use, which causes terrible confusion and should never be used, and that is the term "intellectual property". Now, I heard someone mention that term. I don't think he was explaining why that term should not be used.
It is devastatingly harmful to use the term "intellectual property" because that term implies the existence of something which does not exist.
Copyright law exists. Patent law exists. They have almost nothing in common in terms of the requirements that they put on the public. Trademark law also exists. It has nothing in common with copyright law or patent law about what it requires of the public. So, the idea that there is some general thing which these are instances of already gets people so confused that they cannot understand these issues. There is no such thing. These are three separate unrelated issues, and any attempt to generalise about them guarantees confusion. Everyone who uses the term "intellectual property" is either confused himself or trying to confuse you.
[applause]
[1h 29m 12s]
I came to this conclusion a few years ago and since then I have decided that I will never use that term. No exceptions. I will talk about why the term is confusing, because that's a useful thing to do, but I will never use that term. I never use it. I hope you will join me in making this firm policy of never using it. And if someone else says something about "intellectual property", I will not respond directly to what he said without first explaining the confusion buried in it, because you see, the confusion buried in a statement is usually more harmful than whatever may be false that he actually tried to say.
The false premises, the false presuppositions are the most important problem. So, if someone makes a statement about intellectual property and some part of it is the specific point, which I might disagree with, the first thing I will say is why it's a mistake to talk about intellectual property at all, and then I will try to translate what he said into clearer terms, and then I might say if I agree with it or not. But that's secondary, and explaining to people the confusion in the term intellectual property itself is the most important thing to do.
There is a tendency to, we all have it, to follow other people in their choice of terminology. If someone says an outrageous thing and he uses the term intellectual property, you will feel drawn into responding in the same terms. So, learn to resist that temptation.
[1h 31m 20s]
The most important mistake, the most important falsehood in that statement is its use of the term "intellectual property" in the first place. And the most important thing about it to respond to, if you could only choose one thing, is that one. And you can say: "and since your whole picture of the situation is totally confused, clearly the specifics of what you said need to be rethought".
That's all you need to do to deal with the specific thing he said.
And, by the way, when the term "intellectual property" is used in the name of a law or a committee, that is an example of the confusion. It's almost a certainty that any law named "intellectual property" is a harmful, an unjust law. Of course, you have to check the details to be sure of that, but you can be almost certain just from hearing the name. And the reason is that you can tell from the name that unjust premises and confusions went into the design of the law so what could you expect except harmfulness.
[1h 33m 00s]
So, at this point, I should go to the intended topic, which is version three of the GPL.
I designed GPL version one in 1989, and GPL version two in 1991. I thought of making a version three something like five or six years ago. We didn't intend to wait fifteen years. It was due to the fact that I was busy, and there were some things that were hard to figure out.
The idea that there would be changes in the GPL was planned from the beginning. That is, version one already included a plan for transition to future versions. We suggested that people release their programs under "version one or any later version of the GPL", and the idea was that when version two came out, it would automatically be usable for all those programs and in the time since version two, we've been suggesting that people release their software under "version two or any later version" and I believe most GPL covered programs do say that, with the result that when GPL version three comes out, a lot of software will be usable under GPL version three.
The older versions of the GPL also promise that future versions would be "similar in spirit". In other words, the changes will not be radical. Any radical change would be false to the spirit and would be wrong.
[1h 35m 17s]
The changes that we've proposed in version three are all in small sub-issues. Some of them are very important, but in the overall framework, they're small changes. And the overall effect of GPL version three will be basically the same as version two, protecting the same four freedoms, but doing it somewhat better, dealing with some problems which we've encountered and adapting better to various different laws around the world.
One thing that we've done is that we've restructured some of the concepts, for instance, we make it clear that many other activities that have the effect of providing copies to other people are treated the same as distribution. Anything that's covered by copyright law which has the effect that it enables other people to get copies is effectively equivalent to distribution, and this insulates GPL version three from certain differences between laws in various countries about just what constitutes distribution. So it has the effect of making the GPL work more the same in all countries, despite precisely how they have formulated their copyright laws.
There are many changes in GPL version three which do something like that, they actually just make it more uniform and more reliably doing the same thing we expected it already did.
[1h 37m 20s]
But there are some places where we actually have changed the policies in small ways. One of these concerns software patents. GPL version two is based on an implicit grant of a patent licence. The idea is that if somebody says "here is a thing and you can use it", implicitly he's promising he's not going to sue you for patent infringement if you go ahead and do what he said; however, since in the past eight years or so some other free software licences have included explicit statements of patent licenses, patent licence grants by people distributing the software, and so we decided to do the same thing, and we've included an explicit statement that the distributors of the software all promise not to sue anybody who is using any version of that software for patent infringement based on the versions that they distributed. Basically, whatever their versions do, they're promising not to sue you for.
However, there's a subtlety that came up in this. What if somebody doesn't have a patent but he has got a licence for that patent, and he distributes the code to you. Well, does that licence he got include your exercise of the four freedoms? Including your freedom to redistribute copies yourself, with changes? Maybe not, but if it doesn't, it creates a dangerous and unfair situation. Unfair to you because he is distributing the software, or distributing his version of the software, and he is not going to get sued for patent infringement because he got a licence. He distributes it to you under the GPL and the GPL says you are free to redistribute it too, but if you do that you might get sued because his patent license might not cover you.
[1h 40m 04s]
Well, this is unfair, this is something that's not supposed to happen. He received this program under the GPL and the GPL says when he distributes a version of it, he must really give you the freedom to do the same. If he can count on safely doing it, and he knows you will get sued if you do it, by a third party, he's cheating. So, GPL version three, along with the explicit patent licence grant, says that if he is knowingly relying on a patent licence for distributing his version, he must take some effective step to protect you as well if you distribute.
Now, the reason it talks about "knowingly relying" is that there are companies that have signed blanket cross licences with other companies, so the company distributing the program, might have some blanket cross licence with some company, and that blanket cross licence might cover a thousand patents, and they don't even know what those thousand patents say. So, if they don't even know that they have a patent licence, they're not required to pay attention, but if they know about a specific patent that would cover this program, that means they are knowingly relying on a patent licence and that means they have to keep you safe as well. This is a very controversial decision. It may seem like a subtle point, it covers a peculiar scenario, but it's not an impossible scenario. It could be a very important scenario. In this scenario, this point is essential to ensure that the GPL really does what it intends to do, which is, make sure that you do get the freedom to redistribute the software that you got. And this is typical of the ways that we are changing GPL version three. They apply to complicated scenarios but those scenarios may happen frequently, and in those scenarios we are trying to make sure that you really get the four fundamental freedoms which that free software.
Did someone earlier already describe the four freedoms?
Then I better do so.
[1h 42m 43s]
Freedom zero is the freedom to run the program as you wish for any purpose.
Freedom one is the freedom to study the source code and change it to do what you wish.
Freedom two is the freedom to help your neighbour, that's the freedom to make copies and distribute them to others when you wish.
Freedom three is the freedom to help your community, that's the freedom to publish or distribute modified versions when you wish.
So here we're talking about what is necessary to ensure that freedom two really exist for you in a certain special scenario, freedom two being the freedom to redistribute copies and also freedom three, it applies to that too.
[1h 43m 35s]
Another area where we have made changes concerns Digital Restrictions Management. Now, freedom zero says you are free to run the program as you wish for any purpose. We are not limiting freedom zero. If someone wants to run a program to encrypt something, that's fine. If someone wants to run a program to decrypt something, that's fine. If somebody wants to run a program to produce an encrypted medium that's difficult to access, that's fine. If somebody has some other GPL covered program to access that media and he wants to run it to access the encrypted data, that's fine too. And distributing software that could be used for those purposes is also entirely permitted, and will be permitted by GPL version 3.
[1h 44m 58s]
However, freedom zero does not include imposing your purposes on someone else who is going to run the program, because his freedom zero is the freedom to run the program for any purpose of his. So, there is no such thing as the freedom to use any software to impose your purpose on someone else. In fact, that should be illegal. I'm serious. And that's what DRM is.
When somebody distributes a player, that has DRM in it, what he's doing is trying to restrict your running of your computer for his purposes, which is directly in conflict with the four freedoms that you should have.
And that's what GPLv3 is in certain ways trying to stop and it does this simply by assuring you all four of the freedoms when you use the software. You see, because DRM - Digital Restrictions Management - is a plan to restrict the public, anyone distributing a version of a GPL-covered program as a player for DRM media always does something to stop the public from modifying the player, because his purpose in distributing a DRM player is to restrict you, he has to make sure you can't escape from his restrictions, from his power. That means he is always going to try to deny you freedom one. Freedom one is the freedom to study the source code of the program and change it to do what you want. What you want, might be, to escape from his restrictions, and if you have freedom one, you can escape from his restrictions. So his goal is somehow or other, for practical purposes, to deny you freedom number one.
[1h 47m 26s]
Now, what he might do is, use non-free software, and then completely deny you freedom number one. In fact, that's what they usually do. We can't change that with the GPL because they're not including any GPL-covered code. They don't have to pay attention to the GPL. There should just be a law against it. It should be illegal. DRM should be illegal, but we can't change laws by modifying the GPL.
However, there are those that want to use GPL-covered software for this purpose, and they want to do so by turning freedom number one into a sham, a facade. So they plan to do something like, make a modified version of the GPL-covered program, which contains code to restrict you, and distribute that to you and somehow arrange that you can't really modify it, or if you modify it it won't run, or if you modify it and operate it, it won't operate on the same data.
[1h 48m 42s]
They do this in various ways. This is known as Tivo-isation because this is what the Tivo does. The Tivo includes some GPL-covered software. It includes a GNU+Linux system, a small one, but it does, and you can get the source code for that, as required by the GPL because many parts of GNU+Linux are under the GPL, and once you get the source code, you can modify it, and there are ways to install the modified software in your Tivo and if you do that, it won't run, period. Because, it does a check sum of the software and it verifies that it's a version from them and if it's your version, it won't run at all. So this is what we are forbidding, with the text we have written for GPL version three. It says that the source code they must give you includes whatever signature keys, or codes that are necessary to make your modified version run.
In other words, it ensures that freedom number one is real. That you really can modify the source code, install it, and then it will run and not only that, we say, they must give you enough to make the modified version operate on the same range of data. Because, you see, Microsoft's plan, which they call Palladium, and then they change the name - they change these names frequently so as to evade criticism, to make criticism difficult, to make any kind of comment on their plans difficult. You talk about their plan and they say "Oh, we've dropped that, we have a different plan now". And probably it is different in some details, but the point is that they generate encryption and decryption keys using a check sum of the program which means that a different program can't possibly access the same data. Although, that's just the base level, and then on top of that they implement other facilities where the program simply has to be signed by the authorised signer in order to be able to access the data.
[1h 51m 29s]
Well, GPL version three says that if they distribute a GPL-covered program in this way, they must provide you with the key necessary so that you can sign your version and make it access the same data. Otherwise, they would say "Yes, you can run your modified version, but it will have a different check sum, so your version will only operate on data files made for your version, just as our version only operates on data made for our version". And what that means is that all the available files will only work with their version and your changed version will not be able to access them. That's exactly, in fact, how Treacherous Computing is designed to work. The plan is that they will publish files that are encrypted and it will be impossible to access those files with any other program, so GPL version three is designed to ensure that you really, effectively, get the freedom to take the program you were given, modify it, and run the modified version to do a different thing on the same data on the same machine.
But, there's one other way that we're trying to thwart DRM. You see, one thing they do is, some countries, including, I'm sad to say, this one, have adopted unjust laws that support DRM. The exact opposite of what they ought to do, which is prohibit DRM, and what they say is: when media have been encoded for DRM, then writing another program to access that media is illegal, and the way they do this is they say that DRM constitutes an effective, they call it "protection" I call it "restriction", measure. So, what we say is, by releasing a program under GPL version three, you agree that it is not an effective restriction measure. In other words, you authorise others to develop on their own software to read the output of your program.
This also is a matter of recognising and respecting their freedom to develop software and use their computers. And this, what I've described so far, is all that GPL version three says about DRM.
[1h 54m 36s]
Another area in which we've made large changes has to do with compatibility with a wide range of other free software licences.
We've always understood GPL version two, and version one, as being compatible with some other free software licences. Namely, those that don't require anything except what the GPL requires. So, for instance, there is the X11 licence, all it requires is that you keep the licence there. This doesn't actually demand anything that conflicts with the GPL, so we've always interpreted it as being compatible with the GPL, and what it means to say that two free software licences are compatible is that you can take code from a program under licence A and code from a program under licence B and put them together in one program and you have not violated either licence.
If both licences permit the combining of the code, then you can combine the code, and that's what it means to say the licences are compatible. Now, it's very useful to be able to combine the code, so compatibility of the licences is a convenient thing. Now, it's impossible for all free software licences to be compatible. You see, the GPL makes certain requirements and we are not willing to have them taken off, and so another licence, such as GPL version one, that doesn't have those requirements, cannot be compatible with GPL version two or three. That's impossible.
A licence like the Mozilla Public License has its own specific requirements, but it requires things the GPL doesn't require. It can't be compatible, I believe. So we can't be compatible with all of them, but we went through other free software licences and we identified certain kinds of requirements that are pretty harmless and we wouldn't mind if people could attach those kinds of requirements to GPL-covered programs, and we made an explicit list of those kinds of requirements. Section seven of the draft of GPL version three says you can put your own terms and conditions on code that you add to the GPL covered program, and your terms and conditions can include these kinds of requirements. You can also give additional permission. Any kind of additional permission you like. So your terms on your code can be more permissive than the GPL itself. And section seven makes it completely explicit that this is compatible with the GPL.
[1h 58m 22s]
Now, these, the added kinds of requirements that you can make, include different requirements as regards credit and notices and how to identify changes on your code. That's harmless, that only really is relevant when people change your code, and when they do that they will see your terms at the beginning of your code and they will know what to do. And it can include a requirement that they not use certain of your trademarks in ways that trademark law forbids. And this would just be a way of reinforcing trademark law using the copyright on your code. And that's harmless because you could actually do that with trademark law in the first place. So this doesn't actually restrict people in any way that they wouldn't be restricted otherwise.
[1h 59m 28s]
You can put on requirements that -- and this is a non-trivial kind of requirement that we've decided to let people put on -- requirements that if people run your code, on a publicly accessible server, then it must have a command that the user can use to download the source code of the version that is running. Which means that if someone makes changes and puts the changes in his version, on his server, he has to make his source code changes available to the users who talk to his server.
This requirement is known as the Affero clause because it's used in the Affero GPL. The Affero GPL is like GNU GPL version two except it has this requirement as well.
We were thinking of including some kind of requirement like that in GNU GPL version three. We didn't want to make it apply to everything automatically. That would be a drastic change, so we would have to make it something that people could activate explicitly for their programs, and then I realised people could activate it explicitly for their programs by putting the Affero GPL on their programs and as long as the GNU GPL says it's compatible with that, that's a way you could activate that requirement for your code and it means we don't have to put any specific thing about that in the GNU GPL, we only have to make the GNU GPL compatible with it and we did.
[2h 01m 33s]
There's another kind of requirement that we've decided to permit, and this is patent retaliation clauses. Now, the reason is that there are several other free software licences that have patent retaliation clauses.
Patent retaliation means, if you sue somebody for patent infringement, then you lose the right to use this code.
Of course there are many ways to do that because every patent retaliation clause puts on some specifics, if you sue him or him for patent infringement in certain circumstances, then you lose the right to use this code, and the question is, what are those circumstances, what are the conditions under which the retaliation operates.
Now, we saw that there are some very broad and nasty patent retaliation clauses. Some of them say, "if you sue me for patent retaliation, for any reason about anything, you lose the right to use this code". Now that's bad because it means, suppose I sue you for patent infringement and you have a patent so you counter sue me, and then my free software licence retaliates against you and you lose the right to use that code, now that's not fair because in that case you are defending yourself, you're not the aggressor, so we decided to accept only patent retaliation clauses that are limited enough that they do not retaliate against defense, that they only retaliate against aggression, so there are two kinds of clauses that we identified that do this. One is, if the clause itself, makes a distinction between defense and aggression, so it says, if you sue somebody for patent infringement and it's aggression, then you lose the right to use this code, but if you are suing in retaliation for aggression, then what you are doing is defensive and then we do not retaliate against you.
This is one kind of patent retaliation clause that we accept.
[2h 04m 21s]
The other kind is, if you sue, alleging that some free software, relating to this code is patent infringement, then you lose the right to use this code. In the broad space of possible kinds of patent retaliation clauses, we picked two kinds, each of which is limited enough that it will not retaliate against people for practicing defense with patents. It will only retaliate against aggressors. And we've said these two kinds of clauses are OK to add to your code in a GNU GPL covered program. This is a conceptually complicated thing. There's no way to make it any simpler, I hope, at least, that I've explained it clearly.
The GPL itself does contain one very limited kind of patent retaliation, but it's a different kind. It says if make changes in a GPL-covered program and then somebody else makes similar changes and you sue him for patent infringement then you lose the right to continue making changes and copying the program to your own machines.
This is a very limited situation and it's meant to protect against one particular kind of abuse on the part of server operators where they make an improvement, which they're free to do, and run it on their servers and they don't release their source code and if the code does not have the Affero clause on it then they don't have to release the source code, and then you decide that you are going to implement a similar improvement and then they sue you for patent infringement.
So, once again, we're making a change that keeps people honest and makes sure that the four standard freedoms that the four standard freedoms that the GPL has always tried to ensure, really apply in all cases.
This is pretty much it, but there is also one interesting change in the section that deals with modified versions. There has always been a requirement that if you get a program that prints some kind of notice about the licence when it starts up, you can't take that out. We've generalised that so that it applies to various kinds of user interfaces in various ways.
So, for instance, if the program is graphical and it has an "about" box, the about box has to say "this is free software under the GPL". And if it starts up interactively and asks for commands, then it has to print the notice at the beginning, and the requirements are a little bit different depending on how obtrusive this would be. For example, the about box is simply a menu item sitting in a menu, well that doesn't bother anybody, so we just say that always has to be there.
On the other hand, printing a notice at start up can be annoying, there are certain programs which shouldn't print notices at start up. So what we say is that if the program that you got doesn't print a notice and you change it, then your program doesn't have to print a notice either. You know, if you change Bash, well Bash isn't supposed to print a notice when it starts up and we don't require you make it print a notice, but if you gave it a GUI, with menus, you would have to put in an about box because the about box doesn't do any harm.
[2h 10m 02s]
I've covered all the issues I can think of that are worth discussing, and I am willing to ask for questions however you can discuss a question with me but if you think you see a problem, you should go to the site gplv3.fsf.org and report this problem and get it considered through our discussion committees and they'll either publish an answer eventually, or they will pass the issue on to me and I'll think about whether a change is needed.
So, I'm ready for questions.
[2h 10m 55s]
[applause]
Q1: I would like to ask, what is the position of Stallman, and to clarify a bit about the different position of the Linux community about Digital Rights Management.
Stallman: I can't speak for them, and I don't want to try. All I can point out is that Linux is one of thousands of programs in the GNU+Linux operating system. These programs already have various different licences. If some of those programs continue to be distributed under GPL version two while others move to GPL version three or to "GPL version three or later", that won't be any disaster. The developers of Linux are the ones who will decide which licence to use on their program, but I'm confident that most of the GNU+Linux system will be under the GPL version three, regardless of what the Linux developers decide about their program.
I hope that they will move to GPL version three because I want to see Linux resisting Tivo-isation. Linux, after all, is one of the programs that has already been Tivo-ised.
[applause]
Q2: (Question asked in Italian, something about linking and dynamic languages)
Stallman: Actually, there are changes making it clearer that it doesn't matter which kind of linking is being used. If there are two modules that are designed to be run linked together and it's clear from the design from one or the other that they are meant to be linked together then we say they are treated as one program and so I hope that will make it a little bit clearer although that's not really a change, it's a clarification. That's what we believe GPL version two means already.
Q3a: I have two different questions. The first is what happens if anyone released code under GPL version two maybe ten years ago and now isn't happy with version three and says you're changing the spirit, when I said I would release it under version two and subsequent version, I didn't think of these. Do you imagine he would be bound to version three, or...
Stallman: Yes. Because we're not changing the spirit. These are small changes.
Q3a2: OK, so basically, you're the one who judges...
Stallman: Well, maybe a court might, but I can't believe that anyone not strongly prejudiced would conclude that this is a change in the spirit. A change in the spirit certainly permits change in the details of the requirements and anyone who released it under version two or later should have seen the changes that were made from version one, which were not as big but they were the same kinds of things. So yeh, if he released it under GPL "two or later" you'll be able to use it now under version three.
Q3b1: OK, the second question is that, as you know, I'm involved in these United Nation processes on the Internet governance, so I'm interested to know, do you think the fight against Digital Rights Managements and Trusted Comp[interrupted]
Stallman: Digital Restrictions Management, and Treacherous Computing. Don't use the enemy's propaganda terms, every time you use those terms you are supporting the enemy.
[applause]
Q3b2: OK, so the correct term is Treacherous Computing right? So on the fight against these new mechanisms, do you think it can only be won by writing free software, releasing free software?
Stallman: I don't know.
Q3b3: Do you imagine that there should be need for intervention or lobbying at the legal level?
Stallman: I think Treacherous Computing should be illegal. But I don't know how we're going to convince governments to actually do that because governments mostly are not very democratic anymore. They mostly are the pro-consuls of the mega corporations, their job is to keep us in line under the rule of the empire. That's why they run for office, they get into office, they do what the emperor -- the emperor being the mega corporations -- tells them to do, and their job is explaining to us why they can't do what we want them to do. It's very very sad and once in a while somebody has enough courage to refuse to obey, somebody like [sounds like Hugo Chavez].
Q3b4: So do you think it's not even worth trying?
Stallman: Oh, it's worth trying. It's just going to be hard, the point is you have to keep putting the pressure on these politicians. In France, there is a battle going on and we still might win it about the legalisation of peer-to-peer copying on the Internet. This shows that when enough people get energised, the empire can lose a battle.
It's very important.
[applause]
[2h 19m 53s]
Stallman: Another thing that people should do is refuse to buy anything that's based on DRM. Don't buy corrupt disks, that is the fake CDs that have music set up so that you're blocked from copying it. Don't buy DVDs unless you have DeCSS and you can copy it.
If you can't copy it - don't buy it!
[applause]
[2h 20m 23s]
Q4: (Question in Italian, mentions Eben Moglen)
Stallman: Well, first, I'm the one who decides what goes into GPL version three, and, of course, whenever I think of language I'm usually working with Eben Moglen since he's a lawyer and he's the only one that can tell me if the language will really do what I hope it will do. Meanwhile, a lot of other people are involved. For instance, you can go to the gplv3.fsf.org site and study it and if you think you see something that's not good or whatever kind of problem you might think there is, you can report it and your comment will go to a discussion committee and, there are four discussion committees, it will go to one of those committees which will then group your comment with other comments that raise that same issue and then they will study each issue and post the issue and their response to it and your comment will be connected to the issue which they grouped it into so it will be connected to the response as well.
And thus, there are probably hundreds of people participating in checking the draft and trying to make sure it does the right thing.
Q5: In the end of the process of deciding what modifications of the licence will be done there's one single person, that is you. Can you explain why this decision and you have not chosen to make some group?
Stallman: I don't know other people who can do this.
I hope that the process that's going on now will help develop people who can be part of some group activity but at the moment, I don't know anyone that I could delegate this to. Obviously I can't always forever be the person doing this, barring unforeseen advances in medical technology or AI and nanotechnology, which I certainly hope will come soon but they're not likely, but at this point, I think this is the right thing to do.
Q5.2: Maybe it will change in the future.
Stallman: I hope. We're going to have to replace me somehow, sooner or later.
[applause]
[2h 24m 30s]
Q6: You told us about what GPLv3 will be, but what about the issues that are included, the suggestions that you refused. Can you give us some samples?
Stallman: Well, when I decided that we had to do something to resist Digital Restrictions Management, the obvious way to do this would be restrictions on what kinds of jobs the program can be made to do, but I decided that that would be the wrong way to do it and so I thought hard and I came up with a way to achieve the job by directly protecting the freedom of each user without any restrictions about what technical job a version of the program can do.
Another example of what we decided not to do was putting the Affero clause into the GNU GPL in some way.
Another example of something we decided not to do, we decided not to put in very much in the way of patent retaliation clause and the reason is we have doubts about how effective those clauses really can be. We have doubts about whether our community actually has enough power that the threat of our retaliation would scare anyone.
So, these are some examples of changes we decided not to do. Some for reasons of principle and some for practical reasons.
So, thank you for your attention, and happy hacking.
[applause]
2006年04月01日 星期六
pdflatex使用中文字体
首先,还是使用gbkfonts程序自动生成所有的字体文件和map。
将生成的所有文件按目录结构放到系统目录下面。
将cjk.map拷贝到texmf/fonts/map/
修改texmf/web2c/updmap.cfg
最后面加上Map cjk.map
运行mktexlsr,运行updmap即可。
2006年03月25日 星期六
SuSE10安装Mplayer
近几天来访问此篇文章的多数是要解决Mplayer编译时gcc4版本的问题,其实只需要下载CVS版本安装就不存在这个问题了。打patch的只限于MPlayer v1.0pre7的版本。大家大可不必如此费神。
0. 首先需要安装两个开发包:gtk-1.2.10-888和glib-devel-1.2.10-595
1. 预备工作
到http://www.mplayerhq.hu/design7/dload.html下载以下安装文件:
主程序:MPlayer v1.0pre7try2 源码
解码器:all-20050412.tar.bz2
字体:font-arial-cp1250.tar.bz2,font-arial-iso-8859-1.tar.bz2,font-arial-iso-8859-2.tar.bz2,font-arial-iso-8859-7.tar.bz2
皮肤:PowerPlayer-1.1.tar.bz2(以此为例)
到http://www.chinalinuxpub.com/bbs/attachment.php?attachmentid=4380下载mplayer-1.0_pre7-gcc4-fix.patch.zip
因为suse10上的gcc版本太高,所以必须要给mplayer打补丁才能安装。
2. 安装解码器
huang:/software/mplayer # tar xvf all-20050412.tar.bz2
huang:/software/mplayer # mv all-20050412/ /usr/local/lib/codecs
huang:/software/mplayer # ln -s /usr/local/lib/codecs /usr/lib/win32
3. 安装主程序
huang:/software/mplayer # tar xvf MPlayer-1.0pre7try2
打补丁,只有 gcc-4.0 的时候才需要打补丁。
huang:/software/mplayer # unzip mplayer-1.0_pre7-gcc4-fix.patch.zip
huang:/software/mplayer # cd MPlayer-1.0pre7try2/
huang:/software/mplayer/MPlayer-1.0pre7try2 # patch -p1 < ../mplayer-1.0_pre7-gcc4-fix.patch
为了是mplayer的GUI支持UTF8中文,需要改变一个文件的编码
huang:/software/mplayer/MPlayer-1.0pre7try2 # cd help/
huang:/software/mplayer/MPlayer-1.0pre7try2/help # mv help_mp-zh_CN.h help_mp-zh_CN.h.bak
huang:/software/mplayer/MPlayer-1.0pre7try2/help # iconv -f GB2312 -t UTF-8 help_mp-zh_CN.h.bak -o help_mp-zh_CN.h
配置
huang:/software/mplayer/MPlayer-1.0pre7try2 # ./configure --enable-gui --language=zh_CN --prefix=/usr/local/mplayer/
huang:/software/mplayer/MPlayer-1.0pre7try2 # make
huang:/software/mplayer/MPlayer-1.0pre7try2 # make install
4. 安装字体
huang:/software/mplayer/MPlayer-1.0pre7try2 # cd ..
huang:/software/mplayer # tar xvf font-arial-cp1250.tar.bz2
huang:/software/mplayer # tar xvf font-arial-iso-8859-1.tar.bz2
huang:/software/mplayer # tar xvf font-arial-iso-8859-2.tar.bz2
huang:/software/mplayer # tar xvf font-arial-iso-8859-7.tar.bz2
huang:/software/mplayer # mv font-arial-cp1250/ /usr/local/mplayer/share/mplayer/font/
huang:/software/mplayer # mv font-arial-iso-8859-1/ /usr/local/mplayer/share/mplayer/font/
huang:/software/mplayer # mv font-arial-iso-8859-2/ /usr/local/mplayer/share/mplayer/font/
huang:/software/mplayer # mv font-arial-iso-8859-7/ /usr/local/mplayer/share/mplayer/font/
5. 安装皮肤
huang:/software/mplayer # tar xvf PowerPlayer-1.1.tar.bz2
huang:/software/mplayer # mv PowerPlayer default
huang:/software/mplayer # mv default/ /usr/local/mplayer/share/mplayer/Skin/
最后,字幕字体
找一个ttf字体文件,放到~/.mplayer/下面,并改名为subfont.ttf即可。
huang:/software/mplayer # ln -s /usr/local/mplayer/bin/mplayer /usr/local/bin/mplayer
huang:/software/mplayer # ln -s /usr/local/mplayer/bin/mplayer /usr/local/bin/gmplayer
使用gui则用gmplayer启动,否则使用mplayer即可
启动选项,-sub 跟字幕文件 -subcp cp936,也可以 -font 跟字体文件改变字幕字体。
2006年03月24日 星期五
最简单的中文latex配置
安装了SuSE 10系统自带的tex系统,可以在CJK环境下使用某些特定的字体类型,但是很多字体还是不能使用。
以下是一个非常简单的解决办法:
1.到王垠主页
http://learn.tsinghua.edu.cn:8080/2001315450/programs.html
下载了gbkfonts的可执行文件,只要gbkfonts的那个静态链接文件就可以了。
cp gbkfonts /usr/local/bin
chmod +x /usr/local/bin/gbkfonts
2. 建立texmf-local
不要直接放在/usr/share/texmf 下面,这样以后升级不方便。
因为~/texmf 目录默认是mktexlsr搜索的路径
mkdir ~/texmf
cd ~/texmf
gbkfonts /windows/C/windows/Fonts/simkai.ttf kai
gbkfonts /windows/C/windows/Fonts/simhei.ttf hei
...
其他字体用同样的方法生成。
3.
mv cjk.map dvips/config/ 这里会报没有dvips/config目录,新建一个就可以了。
cp /usr/share/texmf/dvips/config/config.ps dvips/config/
echo "p +cjk.map" >> dvips/config/config.ps
mv pdftex.cfg pdftex/config/
mktexlsr 最好用root执行一下
4. 测试代码
beat@huang:~/tex> cat testcjk.tex
\documentclass{article}
\usepackage{CJK}
\begin{document}
\begin{CJK*}{GBK}{hei}
这是黑体。
\end{CJK*}
\end{document}
然后latex testcjk.tex,dvipdfm testcjk.dvi就生成了相应的dvi和pdf文档。
2006年03月10日 星期五
Adobe Acrobat Reader 亚洲字体包 for Adobe Reader 7.0 under Linux
Adobe Acrobat Reader 亚洲字体包 for Adobe Reader 7.0 under Linux
下载地址:
http://download.adobe.com/pub/adobe/reader/unix/7x/7.0.5/misc/FontPack705_chs_i386-linux.tar.gz
2006年03月01日 星期三
2005年11月15日 星期二
Linux下常用压缩格式的压缩与解压
.tar
解包:tar xvf FileName.tar
打包:tar cvf FileName.tar DirName
(注:tar是打包,不是压缩!)
---------------------------------------------
.gz
解压1:gunzip FileName.gz
解压2:gzip -d FileName.gz
压缩:gzip FileName
.tar.gz 和 .tgz
解压:tar zxvf FileName.tar.gz
压缩:tar zcvf FileName.tar.gz DirName
---------------------------------------------
.bz2
解压1:bzip2 -d FileName.bz2
解压2:bunzip2 FileName.bz2
压缩: bzip2 -z FileName
.tar.bz2
解压:tar jxvf FileName.tar.bz2
压缩:tar jcvf FileName.tar.bz2 DirName
---------------------------------------------
.bz
解压1:bzip2 -d FileName.bz
解压2:bunzip2 FileName.bz
压缩:未知
.tar.bz
解压:tar jxvf FileName.tar.bz
压缩:未知
---------------------------------------------
.Z
解压:uncompress FileName.Z
压缩:compress FileName
.tar.Z
解压:tar Zxvf FileName.tar.Z
压缩:tar Zcvf FileName.tar.Z DirName
---------------------------------------------
.zip
解压:unzip FileName.zip
压缩:zip FileName.zip DirName
---------------------------------------------
.rar
解压:rar x FileName.rar
压缩:rar a FileName.rar DirName
rar请到:http://www.rarsoft.com/download.htm 下载!
解压后请将rar_static拷贝到/usr/bin目录(其他由$PATH环境变量指定的目录也可以):
[root@www2 tmp]# cp rar_static /usr/bin/rar
---------------------------------------------
.lha
解压:lha -e FileName.lha
压缩:lha -a FileName.lha FileName
lha请到:http://www.infor.kanazawa-it.ac.jp/~ishii/lhaunix/下载!
>解压后请将lha拷贝到/usr/bin目录(其他由$PATH环境变量指定的目录也可以):
[root@www2 tmp]# cp lha /usr/bin/
---------------------------------------------
.rpm
解包:rpm2cpio FileName.rpm | cpio -div
---------------------------------------------
.deb
解包:ar p FileName.deb data.tar.gz | tar zxf -
---------------------------------------------
.tar .tgz .tar.gz .tar.Z .tar.bz .tar.bz2 .zip .cpio .rpm .deb .slp
.arj .rar .ace .lha .lzh .lzx .lzs .arc .sda .sfx .lnx .zoo .cab .kar .cpt .pit .sit .sea
解压:sEx x FileName.*
压缩:sEx a FileName.* FileName
sEx只是调用相关程序,本身并无压缩、解压功能,请注意!
sEx请到: http://sourceforge.net/projects/sex下载!
解压后请将sEx拷贝到/usr/bin目录(其他由$PATH环境变量指定的目录也可以):
[root@www2 tmp]# cp sEx /usr/bin/
2005年11月13日 星期日
编写Linux下的Daemon程序
编写Linux下的Daemon程序 作者: dagger 无崖阁 xyg.ods.org
版本: 1.0 2003-04-08 初始版本
一、引言 Daemon程序是一直运行的服务端程序,又称为守护进程。
本文介绍了在Linux下编写Daemon程序的步骤,并给出了例子程序。
二、Daemon程序简介 Daemon是长时间运行的进程,通常在系统启动后就运行,
在系统关闭时才结束。一般说Daemon程序在后台运行,是因为它没有控制终端,
无法和前台的用户交互。Daemon程序一般都作为服务程序使用,等待客户端程序
与它通信。我们也把运行的Daemon程序称作守护进程。
三、Daemon程序编写规则
编写Daemon程序有一些基本的规则,以避免不必要的麻烦。
1、首先是程序运行后调用fork,并让父进程退出。子进程获得一个新的进程ID,
但继承了父进程的进程组ID。
2、调用setsid创建一个新的session,使自己成为新session和新进程组的
leader,并使进程没有控制终端(tty)。
3、改变当前工作目录至根目录,以免影响可加载文件系统。或者也可以改变到
某些特定的目录。
4、设置文件创建mask为0,避免创建文件时权限的影响。
5、关闭不需要的打开文件描述符。因为Daemon程序在后台执行,不需要于终端
交互,通常就关闭STDIN、STDOUT和STDERR。其它根据实际情况处理。
另一个问题是Daemon程序不能和终端交互,也就无法使用printf方法输出信息
了。我们可以使用syslog机制来实现信息的输出,方便程序的调试。在使用
syslog前需要首先启动syslogd程序,关于syslogd程序的使用请参考它
的man page,或相关文档,我们就不在这里讨论了。
四、一个Daemon程序的例子 编译运行环境为Redhat Linux 8.0。
我们新建一个daemontest.c程序,文件内容如下:
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
#include <syslog.h>
#include <signal.h>
int daemon_init(void)
{ pid_t pid;
if((pid = fork()) < 0) return(-1);
else if(pid != 0) exit(0); /* parent exit */
/* child continues */
setsid(); /* become session leader */
chdir("/"); /* change working directory */
umask(0); /* clear file mode creation mask */
close(0); /* close stdin */
close(1); /* close stdout */
close(2); /* close stderr */
return(0); }
void sig_term(int signo)
{ if(signo == SIGTERM)
/* catched signal sent by kill(1) command */
{ syslog(LOG_INFO, "program terminated.");
closelog(); exit(0); }
}
int main(void)
{ if(daemon_init() == -1)
{ printf("can't fork self\n"); exit(0); }
openlog("daemontest", LOG_PID, LOG_USER);
syslog(LOG_INFO, "program started.");
signal(SIGTERM, sig_term); /* arrange to catch the signal */
while(1) { sleep(1); /* put your main program here */ }
return(0); }
使用如下命令编译该程序: gcc -Wall -o daemontest daemontest.c
编译完成后生成名为daemontest的程序,执行./daemontest来测试程序的运行。
使用ps axj命令可以显示系统中已运行的daemon程序的信息,包括进程ID、
session ID、控制终端等内容。
部分显示内容:
PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
1098 1101 1101 1074 pts/1 1101 S 0 0:00 -bash 1 1581 777 777 ? -1 S 500 0:13 gedit 1 1650 1650 1650 ? -1 S 500 0:00 ./daemontest 794 1654 1654 794 pts/0 1654 R 500 0:00
ps axj 从中可以看到daemontest程序运行的进程号为1650。
我们再来看看/var/log/messages文件中的信息: Apr 7 22:00:32 localhost
daemontest[1650]: program started.
显示了我们在程序中希望输出的信息。
我们再使用kill 1650命令来杀死这个进程,
/var/log/messages文件中就会有如下的信息:
Apr 7 22:11:10 localhost daemontest[1650]: program terminated.
使用ps axj命令检查,发现系统中daemontest进程已经没有了。
五、参考资料
Advanced Programming in the UNIX Environment W.Richard Stevens
Daemon是怎样练成的
守护进程
守护进程是生存期长的一种进程。它们独立于控制终端并且周期性的执行某种任务或等待处理某些发生的事件。他们常常在系统引导装入时启动,在系统关闭时终止。unix系统有很多守护进程,大多数服务器都是用守护进程实现的。比如,网络服务inetd、Web服务http等。同时,守护进程完成许多系统任务。比如,作业规划进程crond、打印进程lqd等。
这里主要说明守护进程的进程结构,以及如何编写守护进程程序。因为守护进程没有控制终端,所以我们还要介绍在守护进程运行时错误输出的方法。
守护进程及其特性
守护进程最重要的特性是后台运行。在这一点上,DOS下的常驻内存程序TSR与之相似。
其次,守护进程必须与其运行前的环境隔离开来。这些环境包括未关闭的文件描述符、控制终端、会话和进程组、工作目录以及文件创建掩码等。这些环境通常是守护进程从执行它的父进程(特别是shell)中继承下来的。
最后,守护进程的启动方式有其特殊之处。它可以在系统启动时从启动脚本/etc/rc.d中启动,可以由inetd守护进程启动,可以有作业规划进程crond启动,还可以由用户终端(通常是shell)执行。
总之,除开这些特殊性以外,守护进程与普通进程基本上没有什么区别。因此,编写守护进程实际上是把一个普通进程按照上述的守护进程的特性改造成为守护进程。如果大家对进程的认识比较深入,就对守护进程容易理解和编程了。
首先我们来察看一些常用的系统守护进程,看一下他们和几个概念:进程组、控制终端和对话期有什么联系。p s命令打印系统中各个进程的状态。该命令有多个选择项,有关细节请参考系统手册。为了察看所需的信息,执行:
ps -axj
PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
0 1 0 0 ? -1 S 0 0:04 init
1 2 1 1 ? -1 SW 0 0:00 [keventd]
1 3 1 1 ? -1 SW 0 0:00 [kapm-idled]
0 4 1 1 ? -1 SWN 0 0:00 [ksoftirqd_CPU0]
0 5 1 1 ? -1 SW 0 0:00 [kswapd]
0 6 1 1 ? -1 SW 0 0:00 [kreclaimd]
0 7 1 1 ? -1 SW 0 0:00 [bdflush]
0 8 1 1 ? -1 SW 0 0:00 [kupdated]
1 9 1 1 ? -1 SW< 0 0:00 [mdrecoveryd]
1 17 1 1 ? -1 SW 0 0:02 [kjournald]
1 92 1 1 ? -1 SW 0 0:00 [khubd]
1 573 573 573 ? -1 S 0 0:03 syslogd -r -x
1 578 578 578 ? -1 S 0 0:00 klogd -2
1 598 598 598 ? -1 S 32 0:00 portmap
进程号为1、2的这些进程非常特殊,存在于系统的整个生命期中。它们没有父进程ID ,没有组进程ID ,也没有对话期ID 。syslogd 守护进程可用于任何为操作人员记录系统消息的程序中。可以在一台实际的控制台上打印这些消息,也可将它们写到一个文件中。sendmail 是标准邮递守护进程。update 程序定期将内核缓存中的内容写到硬盘上(通常是每隔30 秒)。为了做到这一点,该程序每隔30 秒调用sync(2 )函数一次。cron 守护进程在指定的日期和时间执行指定的命令。许多系统管理任务是由cron 定期地使相关程序执行而得以实现的。inetd进程监听系统的网络界面,以输入对各种网络服务器的请求。最后一个守护进程,lpd 处理对系统提出的各个打印请求。
注意,所有守护进程都以超级用户(用户ID为0)的优先权运行。没有一个守护进程具有控制终端,终端名称设置为问号(?)、终端前台进程组ID设置为-1。缺少控制终端是守护进程调用了setsid的结果。除update以外的所有守护进程都是进程组的首进程,对话期的首进程,而且是这些进程组和对话期中的唯一进程。最后,应当引起注意的是所有这些守护进程的父进程都是init进程。
在接触实际编程前,我们来看看编写守护进程要碰到的概念:进程组合会话期。
进程组
每个进程除了有一进程ID之外,还属于一个进程组(在讨论信号时就会涉及进程组)进程组是一个或多个进程的集合。每个进程有一个唯一的进程组ID。进程组ID类似于进程ID——它是一个正整数,并可存放在pid_t数据类型中。
每个进程组有一个组长进程。组长进程的标识是,其进程组ID等于其进程ID,进程组组长可以创建一个进程组,创建该组中的进程,然后终止,只要在某个进程组中有一个进程存在,则该进程就存在,这与其组长进程是否终止无关。从进程组创建开始到其中最后一个进程离开为止的时间区间称为进程组的生命期。某个进程组中的最后一个进程可以终止,也可以参加另一进程组。
前面已经提到进程调用setgid可以参加一个现存的组或者创建一个新进程组(setsid也可以创建一个新的进程组,后面将用到)
会话期
会话期(session)是一个或多个进程组的集合。其中,在一个会话期中有3个进程组,通常是有shell的管道线将几个进程编成一组的。
下面说明有关会话期和进程组的一些特性:
一个会话期可以有一个单独的控制终端(controlling terminal),这一般是我们在其上登录的终端设备(终端登录)或伪终端设备(网络登录),但这个控制终端并不是必需的。
建立与控制终端连接的会话期首进程,被称之为控制进程(contronlling process)。以及一个会话期中的几个进程组可被分为一个前台进程组(foreground process group)以及一个或几个后台进程组(background process group)
如果一个会话期有一个控制终端,则它有一个前台进程组,其他进程组为后台进程组。无论何时键入中断键(常常是delete或ctrl-c)或退出键(通常是ctrl-\),就会造成将中断信号或退出信号送至前途进程组的所有进程。
守护进程的编程规则
在不同Unix环境下,守护进程的具体编程细节并不一致。但所幸的是,守护进程的编程原则其实都一样,区别仅在于具体的实现细节不同,这个原则就是要满足守护进程的特性。编程规则如下:
1、在后台运行
为避免挂起控制终端,要将daemon放入后台执行,其方法是,在进程中调用fork使父进程终止,让daemon在子进程中后台执行。具体就是调用f o r k ,然后使父进程e x i t 。这样做实现了下面几点:
第一,如果该精灵进程是由一条简单s h e l l 命令起动的,那么使父进程终止使得s h e l l 认为这条命令已经执行完成。
第二,子进程继承了父进程的进程组I D ,但具有一个新的进程I D ,这就保证了子进程不是一个进程组的首进程。这对于下面就要做的s e t s i d 调用是必要的前提条件。
2、脱离控制终端,登录会话和进程组
登录会话可以包含多个进程组,这些进程组共享一个控制终端,这个控制终端通常是创建进程的登录终端、控制终端,登录会话和进程组通常是从父进程继承下来的。我们的目的就是要摆脱它们,使之不受它们的影响。
其方法是在第一点的基础上,调用setsid()使进程成为会话组长:
需要说明的是,当进程是会话组长时,setsid()调用会失败,但第一点已经保证进程不是会话组长。setsid()调用成功后,进程成为新的会话组长和新的进程组长,并与原来的登录会话和进程组脱离,由于会话过程对控制终端的独占性,进程同时与控制终端脱离。
具体是操作就是:
(a )成为新对话期的首进程
(b )成为一个新进程组的首进程
(c )没有控制终端。
3、禁止进程重新打开控制终端
现在,进程已经成为无终端的会话组长,但它可以重新申请打开一个控制终端。可以通过使进程不再成为会话组长来禁止进程重新打开控制终端:
4、关闭打开的文件描述符
进程从创建它的父进程那里继承了打开的文件描述符。如不关闭,将会浪费系统资源,造成进程所在地文件系统无法卸下以及无法预料的错误。一般来说,必要的是关闭0、1、2三个文件描述符,即标准输入、标准输出、标准错误。因为我们一般希望守护进程自己有一套信息输出、输入的体系,而不是把所有的东西都发送到终端屏幕上。调用fclose();
5、改变当前工作目录
将当前工作目录更改为根目录。从父进程继承过来的当前工作目录可能在一个装配的文件系统中。因为精灵进程通常在系统再引导之前是一直存在的,所以如果精灵进程的当前工作目录在一个装配文件系统中,那么该文件系统就不能被拆卸。
另外,某些精灵进程可能会把当前工作目录更改到某个指定位置,在此位置做它们的工作。例如,行式打印机假脱机精灵进程常常将其工作目录更改到它们的s p o o l 目录上。
可以调用chdir(“目录”);
6、重设文件创建掩码
将文件方式创建屏蔽字设置为0 。由继承得来的文件方式创建屏蔽字可能会拒绝设置某些许可权。例如,若精灵进程要创建一个组可读、写的文件,而继承的文件方式创建屏蔽字,屏蔽了这两种许可权,则所要求的组可读、写就不能起作用。
7、处理SIGCHLD 信号
处理SIGCHLD信号并不是必需的。但对于某些进程,特别是服务器进程往往在请求到来时生产子进程出来请求。如果父进程不等待子进程结束,子进程将成为僵尸进程,(zombie)而仍占用系统资源。如果父进程等待子进程结束,将增加父进程的负担,影响服务器进程的并发性能。在系统V下可以简单的将SIGCHLD信号的操作设为SIG-IGN:
signal(SIGCHLD,SIG_IGN);
这样,内核在子进程结束时不会产生僵尸进程,这一点与BSD4不同,在BSD4下必须显示等 待子进程结束才能释放僵尸进程。
守护进程实例
守护进程实例包括两部分:主程序test.c和初始化程序init.c。主程序每隔一分钟向/tmp
目录中的日志test.log 报告运行状态。初始化程序中的init_daemon 函数负责生成守护进程
void make_daemon(void)
{
pid_t pid;
FILE * lockfd;
sigset_t sighup;
int i;
extern pid_t getsid(pid_t);
pid = fork();//第一个子进程生成
if (pid < 0) {
printinfo(”fork error!”,INFOERROR);
exit(FAILEXIT);
}else if (pid > 0) {
printinfo(”fork 1 ok! “, INFOSCREEN);
exit(OKEXIT);//退出父进程,摆脱shell的控制
}
pid = getpid();//获得子进程自身的id
lockfd = fopen(PIDFILE, “w”);//以下是将pid写入文件
if (lockfd != NULL) {
fprintf(lockfd, “%d\n”, pid);
fclose(lockfd);
}//写入pid
if (getsid(0) != pid) {//创建新的会话期
if (setsid() < 0) {
printinfo(”backupdaemon setsid error!”,INFOERROR);
perror(”setsid”);
}
}
if(pid=fork()){//再次生成子进程,这时候是孙子进程
exit(0);//退出上一代进程
}else if(pid<0){
exit(1);
}
close(1);//关闭文件
close(2);
chdir(rundir);//改变运行的目录
umask(022);//改变文件权限
}
守护进程的错误输出
守护进程不属于任何终端,所以当需要输出某些信息时,它无法像一般程序那样将信息直接输出到标准输出和标准错误输出中。我们很大时候也不希望每个守护进程将它自己的出错消息写到一个单独的文件中。因为对于系统管理人员而言,要记住哪一个守护进程写到哪一个记录文件中,并定期的检查这些文件,他一定会为此感到头疼的。所以,我们需要有一个集中的守护进程出错记录机制。目前很多系统都引入了syslog记录进程来实现这一目的。
自伯克利开发了BSD syslog并广泛应用以来,BSD syslog 机制被大多数守护进程所使用。我们下面介绍BSD syslog 的用法。有三种方法产生记录消息:
1 内核例程可以调用log函数。任何一个用户进程通过打开和读/dev/klog设备就可以读取这些消息。因为我们无意编写内核中的例程,所以不再进一步说明此函数。
2 大多数用户进程(守护进程)调用syslog函数以产生记录消息。我们将在下面说明其调用序列。这使消息发送至Unix域数据报套接口/dev/log。
3 在此主机上,或通过TCP/IP网络连接到此主机的某一其他主机上的一个用户进程可将记录消息发向UDP端口514。
注意:syslog 函数并不产生这些UDP数据报——它们要求产生此记录消息的进程具有显式的网络编程。
通常,syslog守护进程读取三种格式的记录消息。此守护进程在启动时读一个配置文件。一般来说,其文件名为/etc/syslog.conf,该文件决定了不同种类的消息应送向何处。例如,紧急消息可被送向系统管理员(若已登录),并在控制台上显示,而警告消息则可记录到一个文件中。该机制提供了syslog函数,其调用格式如下
#include <syslog.h>
void openlog (char*ident,int option ,int facility);
void syslog(int priority,char*format,……)
void closelog();
调用openlog是可选择的。如果不调用openlog,则在第一次调用syslog时,自动调用openlog。调用closelog也是可选择的,它只是关闭被用于与syslog守护进程通信的描述符。调用openlog 使我们可以指定一个ident,以后, 此ident 将被加至每则记录消息中。ident 一般是程序的名称(例如 ,cron ,inetd 等)。option 有4种可能:
LOG_CONS 若日志消息不能通过Unix域数据报发送至syslog,则将该消息写至控制台。
LOG_NDELAY1 立即打开Unix域数据报套接口至syslog守护进程,而不要等到记录第一消息。通常,在记录第一条消息之前,该套接口不打开。
LOG_PERROR 除将日志消息发送给syslog 外,还将它至标准出错。此选项仅由4.3BSDReno及以后版本支持。
LOG_PID 每条消息都包含进程ID。此选项可供对每个请求都fork一个子进程的守护进程使用。
在openlog中设置facility参数的目的是让配置文件可以说明,来自不同设施的消息以不同的方式进行处理。如果不调用openlog,或者以facility 为0来调用它,那么在调用syslog 时,可将facility作为priority参数的一个部分进行说明。调用syslog产生一个记录消息。其priority参数是facility和level的组合,它们可选取的值分别列于下面。level值按优先级从高级到最低按序排列。
2005年10月23日 星期日
SuSE Linux安装chm文件阅读软件
Linux默认安装不支持阅读chm格式的文件,但是有许多文档以chm格式发布,是个很头疼的问题。
经过google搜索发现可以安装几个类似的软件,比如chmsee,chmviewer,xchm等等。网上介绍认为xchm是个不错的选择。以下是我安装的过程:
从sourceforge上下载xchm1.2源代码,下载地址:
http://sourceforge.net/project/showfiles.php?group_id=87007
安装xchm需要两个包支持,一个是 wxGTK,另一个是 chmlib。
下载wxGTK的地址是:http://www.wxwidgets.org/
下载chmlib的地址是:http://66.93.236.84/%7Ejedwin/projects/chmlib/
分别是:wxWidgets-2.6.2.tar.gz和chmlib-0.36.tgz。
安装wxGTK的过程没有问题,只需要tar configure make make install就可以了
安装chmlib-0.36.tgz时配置编译均没有问题,但是make install的时候不能把库文件拷到/usr/lib或/usr/local/lib下面。需要手动把src/.libs生成的库文件拷到相应目录下面。
然后ldconfig
然后解压 xchm-1.2.tar.gz并按正常过程安装。
之后可以查看chm文件了。不过不幸的是xchm只能看英文文档,中文文档无法正确显示。
然后我选择继续安装chmsee-0.9.5,源码下载地址:http://linuxfire.dhis.org/~zhong/
chmsee需要安装libgtkhtml,我已事先安装了 gtkhtml3.8_3.8.1。
tar -xvf chmsee-0.9.5.tar.bz2
./configure
配置过程中报找不到gtkhtml-3.1
解决方案:
ln -s /usr/local/lib/pkgconfig/libgtkhtml-3.8.pc /usr/local/lib/pkgconfig/libgtkhtml-3.1.pc
然后./configure
make
make install
一切ok。可以正常阅读chm文件了,只需要在chmsee启动时选择编码就可以了。
2005年10月21日 星期五
Acrobat Reader7 中文支持
SuSE Linux 10.0 默认安装了Adobe Reader 7.0.1-4,但是不能支持中文pdf文档阅读。目前Adobe官方网站并没有给出Adobe Reader 7.x for Linux的亚洲语言字体包。
我的解决方案是:从Adobe官方网站下载Adobe Reader 5.x for Unix的亚洲语言字体包,chsfont.tar.gz,
下载地址:ftp://ftp.adobe.com/pub/adobe/acrobatreader/unix/5.x/chsfont.tar.gz
tar -zxvf chsfont.tar.gz
cd CHSKIT/
tar -xvf LANGCHS.TAR
tar -xvf LANGCOM.TAR
把所有解压后的所有文件拷贝到 /usr/X11R6/lib/Acrobat7/Resource/CMap/即可。
安装prozilla,多线程下载加速软件
源码下载地址http://prozilla.genesys.ro/downloads/prozilla/tarballs/,我下载的版本是prozilla-2.0.0-r1.tar.gz
tar -zxvf prozilla-2.0.0-r1.tar.gz
cd prozilla-2.0.0-r1/libprozilla/src/
vi Makefile.in //此发行版的makefle有个小问题
删除第114行
includedir = $(prefix)/include行末的一个空格
cd ../..
./configure --prefix=/usr/apps/prozilla/
make
make install
ln -s /usr/apps/prozilla/bin/proz /usr/bin/proz
使用方法:
Usage: proz [OPTIONS] file_url
Ex: proz http://gnu.org/gnu.jpg
Options:
-h, --help Give this help
-r, --resume Resume an interrupted download
-f, --force Never prompt the user when overwriting files
-1 Force a single connection only
-n, --no-netrc Don't use .netrc, get the user/password
from the command line,otherwise use the
anonymous login for FTP sessions
--no-getch Instead of waiting for the user pressing a key,
print the error to stdout and quit
--debug Log debugging info to a file (default is debug.log)
-v,--verbose Increase the amount of information sent to stdout
--no-curses Don't use Curses, plain text to stdout
Directories:
-P, --directory-prefix=DIR save the generated file to DIR/
FTP Options:
--use-port Force usage of PORT insted of PASV (default)
for ftp transactions
Download Options:
-s, --ftpsearch Do a ftpsearch for faster mirrors
--no-search Do a direct download (no ftpsearch)
-k=n Use n connections instead of the default(4)
--timeout=n Set the timeout for connections to n seconds
(default 180)
-t, --tries=n Set number of attempts to n (default(200), 0=unlimited)
--retry-delay=n Set the time between retrys to n seconds
(default 15 seconds)
--max-bps=n Limit bandwith consumed to n bps (0=unlimited)
FTP Search Options:
--pt=n Wait 2*n seconds for a server response (default 2*4)
--pao=n Ping n servers at once(default 5 servers at once)
--max-ftps-servers=n Request a max of n servers from ftpsearch (default 40)
--min-size=n If a file is smaller than 'n'Kb, don't search, just download it
--ftpsid=n The ftpsearch server to use
(0=filesearching.com
1=ftpsearch.elmundo.es
Information Options:
-L, --license Display software license
-V, --version Display version number
ProZilla homepage: http://prozilla.genesys.ro
Please report bugs to <prozilla@genesys.ro>
2005年10月14日 星期五
SuSE10调整屏幕偏移和分辨率
在我的机器上装SuSE10以后,进入gnome桌面环境后,屏幕是偏向右侧的。如果这时用显示器下面的自动调整的话,可以调整到合适的状态,但是回到console模式下面就向左偏移了。修改方法是:
1.在console模式下自动调整到最佳位置;
2.startx进入X环境,命令行xvidtune进行调整(这时,可以用显示器的自动调整键),调整好以后,点xvidtune的show按钮,在终端中会显示以下类似信息:
[18:13:28 @Huang ~]#xvidtune
Vendor: --> VESA, Model: 1024X768@60HZ
Num hsync: 1, Num vsync: 1
hsync range 0: 31.00 - 48.00
vsync range 0: 50.00 - 60.00
"1024x768" 65.00 1024 1064 1200 1344 768 771 777 806 -hsync -vsync
3.修改文件/etc/X11/xorg.conf
找到Section "Modes"的位置,添加或修改一行Modeline 为上面得到的数字,并将其他Modeline行注释或删掉,得到类似下面的结果:
Section "Modes"
Identifier "Modes[0]"
Modeline "1024x768" 65.0 1024 1064 1200 1344 768 771 777 806 -hsync -vsync
#Modeline "1024x768" 61.89 1024 1080 1184 1344 768 769 772 794
EndSection
保存,退出。
退出X环境重新进入就可以了。
2005年10月13日 星期四
提示符
\u - 当前用户的用户名(=$LOGNAME)
\h - 运行shell 的计算机名(hostname)
\H - 完整的计算机名
\W - 当前工作目录名
\w - 当前工作命令全路径名
\$ - 对于普通用户显示$ ,对于超级用户显示#
\! - 当前命令的历史编号
\# - 当前命令编号(在当前的shell 下运行的命令)
\d - 当前日期
\t - 当前时间(24 小时制)
\T - 当前时间(12 小时制),bash 2.0 有效
\@ - 当前时间(AM/PM 格式),bash 2.0 有效
\s - shell 的类型
\a - 告警声音
\j - 用户的任务数
\n - 新行
\\ - 反斜杠
\[ - 不可打印字符开始标志
\] - 不可打印字符结束标志
\nnn - ASCII 字符对应的八进制数值
$(date) - date (输出当前日期)命令输出或者其他的命令
2005年10月10日 星期一
SSH权威指南
第一章 SSH简介
ssh(secure shell)是一种通用,功能强大的基于软件的网络安全解决方案,计算机每次向网络
发送数据时,SSH都会自动对其进行加密。数据到达目的地时,SSH自动对加密数据进行
解密。整个过程都是透明的。它使用了现代的安全加密算法,足以胜任大型公司的任务繁重
的应用程序的要求。
SSH协议内容涉及认证AUTHENTICATION,加密ENCRYPTION,和网络上传输数据的完整
性INTEGRITY。
SSH特性概述
1、远程登录
$ ssh -l root host.example.com
2、安全文件传输
$ scp myfile metoo@secondacount.com
3、安全执行远程命令,能确保传输的数据安全。
4、密钥和代理
基于密钥的认证方法不用记住多个帐号密码。
5、访问控制,能授权别人访问自已帐号。
6、端口转发
$ ssh -L 3002:localhost:119 xxx.xxx.com
相关安全技术
rsh命令族,rsh,rlogin and rcp。连接不加密,认证模型十分脆弱。
PGP加密程序。它是基于文件的。
Kerberos认证系统,用于网络可能被监视,


