Home

hellwolf

Recent Entries

Journal Info

Name
hellwolf_misty

View

Advertisement

February 14th, 2007

Net::OICQ有新版本了

Add to Memories Tell a Friend
在sourceforge,咱们把badboy搬过去吧~:D
Tags: ,

February 12th, 2007

perl中的setgroups

Add to Memories Tell a Friend
在用root运行程序时进行权限降级的时候光setuid(2)和setgid(2)是不够的,因为还有一个系统supplementary group IDs。修改这个列表的接口就是setgroups(2)。
在perl中调用setgroups的方法是通过操作$)变量:
# perl -e 'print $),"\n"; $)="1000 1000";print $),"\n"'
0 10 6 4 3 2 1 0
1000 1000
这里包含一个技巧,那就是重复1000两次,否则你会得到:
# perl -e 'print $),"\n"; $)="1000";print $),"\n"'
0 10 6 4 3 2 1 0
1000 10 6 4 3 2 1 0
Tags:

December 3rd, 2006

今天用ftpsync同步git repository发现郁闷的问题,ftpsync似乎无法处理远程的点文件,后来发现是Net::FTP的问题,要用LIST -a命令替代LIST的命令,hack一下就OK拉:

--- ftpsync.pl  2006-07-31 12:01:47.000000000 +0800
+++ ftpsync.pl  2006-12-03 15:22:27.000000000 +0800
@@ -39,6 +39,9 @@
 use File::Find;
 use File::Listing;
 use Net::FTP;
+sub Net::FTP::dir {
+    shift->_list_cmd("LIST","-a",@_);
+}
 use strict;
 # flushing ...
 use IO::Handle;


其实还有郁闷问题,git无法直接读取ftp上的git repos,可现在fedora-cn只有ftp服务:(
Tags:

October 25th, 2006

some notes on ybuild 0.3

Add to Memories Tell a Friend
1. Ybuild::Exception, 统一异常模块
use Ybuild::Exception;
my $e = new Ybuild::Exception Bug => "Bug #123456";
print $e->get_report;
#new a Exception object and throw it, or die it as a perl jargon
throw Ybuild::Exception Error => "Failed";


比干巴巴的die好那么一点点

2. Ybuild::Specin, 可选的spec模板功能
Ybuld::Specin::get_spec_from_file根据后缀名决定行为方式。

# 一般的spec的仅仅做如下处理:
a.在头部加上ypkgopt部分,例如:
## this section was generated by ybuild system ###
#begin ypkgopts
%define ypkgopt__spec_type normal
#end ypkgopts
b.修改Release tag,后面补上:
%{?ybuildnum:.%{ybuildnum_prefix}%{ybuildnum}}

#如果是specin文件,则首先调用specin_to_specbody解析specin,解析规则类似php。对由<?specin ?>包括的字符中间部分为perl代码,代码的标准输出就作为spec文件的一部分。例
<?specin print "hello, world"?>

specin嵌入代码中可以使用的资源是:
$yrepos, Ybuild::Repos对象。可访问很多Ybuild Repos信息。
$ypkg, Yuild::YPackage对象。本Ybuild Packages的一些信息。
$ypkgopts, Ybuild::YPkgopts对象。本包的opt信息
$specin,字符串。Specin文件内容。

转换完毕后执行于spec文件相同的步骤得到最终的spec。

在嵌入的specin中,可以使用Ybuild::Specin::*模块
计划中的常用模块为:
Common,常用routines
Binarypacakge, 直接打包二进制的包,如acrobatreader,flashplayer等
Autopacakge, 打包由autotools生成的package
Perlpacakge


3. Ybuild::YPkgopts
Package的参数功能。参数结构
{
default_value =>
readonly =>
tiphelp =>
value =>
value_check
}
内部参数由变量 %Ybuild::YPkgopts::global_ypkgopt 定义。
外部参数可以在$REPOSDIR/opt.d/*中定义——仓库全局变量
$PACKAGEDIR/opt.d/*中定义——包变量。

4. Ybuild::Config
在Ybuild::Config(3)中有详细叙述。
Tags: ,

August 15th, 2006

use strict;
use Stardict;

my %dicts = (
    ec => 'XDICT英汉辞典',
    ce => 'XDICT汉英辞典',
    fr_en => 'dictd_www.freedict.de_fra-eng',
    en_fr => 'dictd_www.freedict.de_eng-fra',
);

for my $k (keys %dicts){
    my $d = Stardict->new(
        dicts => [$dicts{$k}],
    );
    die "init dict $k -> $dicts{$k} failed" unless defined $d;
    my $dicname = $dicts{$k};
    $dicts{$k} = [$d, $dicname];
}

Xchat::register ("Stardict v0.01 by Daniel Miao", "0.01", "", "");
Xchat::hook_command('dict', \&do_lookup_word);
Xchat::print("Stardict init successfully");

sub do_lookup_word {
    my $dic = $_[0][1];
    my $st = $_[1][2];
    if(defined $dicts{$dic}){
        my $dicname = $dicts{$dic}[1];
        my ($wd) = $dicts{$dic}[0]->getword($st);
        if(!defined $wd){
            Xchat::print("no such word \"$st\" in dictionary $dicname"); 
        }else{
            my $s = $wd->{data};
            $s =~ s:\n: :mg;
            $s =~ s:^\s*(.*)\s*$:$1:mg;
            Xchat::command "say $dicname: $s";
        }
    }else{
        Xchat::print("no such dic alias $dic"); 
    }
    return 1;
}

Tags: ,
Powered by LiveJournal.com