linux sigprocmask,sigpending,sigsuspend

1. sigprocmask 设定对信号屏蔽集内的信号的处理方式(阻塞或不阻塞)
SIG_BLOCK
SIG_UNBLOCK
SIG_SETMASK
参考:http://m.bianceng.cn/Programming/C/201212/34842.htm

2. 例子:
sigset_t blockset,oldblockset;
printf(“pid:%ld\n”,(long)getpid());

signal(SIGINT,func); //信号量捕捉函数,捕捉到SIGINT,跳转到函数指针func处执行

sigemptyset(&blockset); //初始化信号量集
sigaddset(&blockset,SIGTSTP); //将SIGTSTP添加到信号量集中
sigaddset(&blockset,SIGINT);//将SIGINT添加到信号量集中

int result = -1;
sigprocmask(SIG_BLOCK,&blockset,NULL);

//将blockset中的SIGINT,SIGTSTP阻塞掉,并保存当前信号屏蔽字
sigprocmask(SIG_SETMASK,&blockset,&oldblockset);

//恢复被屏蔽的信号SIGINT SIGTSTP
sigprocmask(SIG_SETMASK,&oldblockset,NULL);

例子2:
void checkset()
{
sigset_t set;
printf(“checksetstart:\n”);

// 将当前进程被挂起的信号存入new_mask中,并用sigismember查询

if(sigprocmask(0,NULL,&set)<0)
{
printf(“checksetsigprocmask error!!\n”);
exit(0);
}
if(sigismember(&set,SIGINT))
printf(“sigint\n”);

if(sigismember(&set,SIGTSTP))
printf(“sigtstp\n”);

if(sigismember(&set,SIGTERM))
printf(“sigterm\n”);
printf(“checksetend\n”);
}

 

3.sigpending 查询被搁置的信号
参考:http://see.xidian.edu.cn/cpp/html/343.html

4. sigsuspend 
参考: http://blog.chinaunix.net/uid-26885237-id-3206640.html 【这篇文章写的很详细】

使用vsftpd,搭建ftp服务器(五), umask

1. 建立一个新的文件或目录时,它的默认属性,默认权限是umask控制的
2. 每次我将文件通过ftp上传到服务器,看到默认权限是 -rw------
3. 这样使得我要使用下载自动的东西,还要每次ssh去修改文件属性 -rw-rw-rw-,
才能下载
4. $ sudo vim /etc/vsftp.conf
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd’s)
#local_umask=022
local_umask=021

5. umask指定的是“该默认值需要减掉的权限”
参考: http://itlife365.com/blog/read.php/426.htm

使用vsftpd,搭建ftp服务器(四), 卸载 重装

1. ftp服务器想更新一下配置文件,重启的时候发现异常
2. 查看一下状态
$ service vsftpd status
vsftpd stop/waiting
3. google 了一下,还是卸载重装吧
4. vsftpd 不能卸载 ,log如下
root@li653-123:/etc/init.d# apt-get remove vsftpd
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following packages will be REMOVED:
vsftpd
0 upgraded, 0 newly installed, 1 to remove and 49 not upgraded.
After this operation, 342 kB disk space will be freed.
Do you want to continue [Y/n]? y
(Reading database … 31661 files and directories currently installed.)
Removing vsftpd …
dpkg: error processing vsftpd (–remove):
subprocess installed post-removal script returned error exit status 1
Processing triggers for man-db …
Processing triggers for ureadahead …
Errors were encountered while processing:
vsftpd
E: Sub-process /usr/bin/dpkg returned an error code (1)

5.
参考: http://ubuntuforums.org/showthread.php?t=1434911

My fix: Edit the file /var/lib/dpkg/info/vsftp.postrm and comment out the lines which remove the user ‘ftp’ and group ‘ftp’. Edit them as sudo, like this:
sudo vim /var/lib/dpkg/info/vsftpd.postrm
The run apt-get (or your favorite uninstaller) to remove vsftpd:
sudo apt-get remove vsftpd

unix网络编程环境搭建

1. 使用qt搭建编译环境
2. 环境搭建  参考:http://blog.csdn.net/a649518776/article/details/6724121
3.
daytimetcpcli.c:(.text+0x3b): undefined reference to `err_quit’
daytimetcpcli.c:(.text+0x6d): undefined reference to `err_sys’
daytimetcpcli.c:(.text+0xe5): undefined reference to `err_quit’
daytimetcpcli.c:(.text+0x114): undefined reference to `err_sys’
daytimetcpcli.c:(.text+0x155): undefined reference to `err_sys’
daytimetcpcli.c:(.text+0x198): undefined reference to `err_sys’

bug解决参考: http://blog.csdn.net/a45872055555/article/details/26757493

4.

main.c:(.text+0x50b): undefined reference to `Socket’
main.c:(.text+0x556): undefined reference to `Bind’
main.c:(.text+0x565): undefined reference to `Listen’
main.c:(.text+0x581): undefined reference to `Accept’
main.c:(.text+0x589): undefined reference to `Fork’
main.c:(.text+0x59c): undefined reference to `Close’
main.c:(.text+0x5a6): undefined reference to `str_echo’
main.c:(.text+0x5ba): undefined reference to `Close’

解决方法: 导入静态库

Linux更简单了。直接LIBS += -L/lib/path  -l/libname
比如一个静态库名是/usr/local/lib/libaaaa.a
则写成 LIBS += -L/usr/local/lib -laaaa

参考: http://www.qtcn.org/bbs/simple/?t30787.html

 

iptables 配置: 端口转发 (四)

1. 本机端口转发(例子:将80端口转发到81端口)
iptables -t nat -A OUTPUT -d 127.0.0.1 -p tcp –dport 80 -j REDIRECT –to-ports 81

2. 从本机出去的网址,目标端口是80 ,统一转发到预设的81端口上
比如: 想访问www.baidu.com ——-> 81端口(预设的网页)
iptables -t nat -A OUTPUT -p tcp –dport 80 -j REDIRECT –to-ports 81

[待验证]iptables -t nat -A PREROUTING -p tcp –dport 80 -j REDIRECT –to-ports 8080

apache2 配置 : Virtual Hosts使用(二)

1.   /etc/apache2/sites-available/default 增加

<VirtualHost *:81>
ServerAdmin webmaster@localhost

    DocumentRoot /var/www/example.com
<Directory /var/www/example.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>

2. 增加监听81端口

/etc/apache2/ports.conf 增加一行

Listen 81

3. 重启服务

$ sudo /etc/init.d/apache2 restart

4. 查看端口 ,是否正在监听81端口

$ netstat -tunl

5.  检查Virtual Hosts是否配置成功

$ links 127.0.0.1:81

 

 

参考:https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-12-04-lts

iptables block facebook.com (三)

1. 无效

iptables -I OUTPUT -p tcp -d www.facebook.com -j REJECT
iptables -I OUTPUT -p udp -d www.facebook.com -j REJECT

无效

iptables -I OUTPUT  -d www.facebook.com -j REJECT

无效

iptables -I FORWARD -d www.facebook.com -j DROP

无效

iptables -I FORWARD -d www.facebook.com -j DROP

iptables -I OUTPUT  -d www.facebook.com -j REJECT

2. 有效

iptables -I FORWARD -d www.facebook.com -j DROP
iptables -I OUTPUT -p tcp -d www.facebook.com -j REJECT
iptables -I OUTPUT -p udp -d www.facebook.com -j REJECT

3. 有效

iptables -I FORWARD -m string –algo bm –string “facebook.com” -j REJECT #DROP
iptables -I OUTPUT -m string –algo bm –string “facebook.com” -j REJECT # DROP