信号在android源码/external/pppd 源码项目中的应用解读分析
2017-09-02 11:55
483 查看
pppoe里面也有信号的处理的方式,
直接上源码:
static void
setup_signals()
{
struct sigaction sa;
/*
* Compute mask of all interesting signals and install signal handlers
* for each. Only one signal handler may be active at a time. Therefore,
* all other signals should be masked when any handler is executing.
*/
sigemptyset(&signals_handled);
sigaddset(&signals_handled, SIGHUP);
sigaddset(&signals_handled, SIGINT);
sigaddset(&signals_handled, SIGTERM);
sigaddset(&signals_handled, SIGCHLD);
sigaddset(&signals_handled, SIGUSR2);
#define SIGNAL(s, handler) do { \
sa.sa_handler = handler; \
if (sigaction(s, &sa, NULL) < 0) \
fatal("Couldn't establish signal handler (%d): %m", s); \
} while (0)
sa.sa_mask = signals_handled;
sa.sa_flags = 0;
SIGNAL(SIGHUP, hup); /* Hangup */
SIGNAL(SIGINT, term); /* Interrupt */
SIGNAL(SIGTERM, term); /* Terminate */
SIGNAL(SIGCHLD, chld);
SIGNAL(SIGUSR1, toggle_debug); /* Toggle debug flag */
SIGNAL(SIGUSR2, open_ccp); /* Reopen CCP */
/*
* Install a handler for other signals which would otherwise
* cause pppd to exit without cleaning up.
*/
SIGNAL(SIGABRT, bad_signal);
SIGNAL(SIGALRM, bad_signal);
SIGNAL(SIGFPE, bad_signal);
SIGNAL(SIGILL, bad_signal);
SIGNAL(SIGPIPE, bad_signal);
SIGNAL(SIGQUIT, bad_signal);
SIGNAL(SIGSEGV, bad_signal);
/*
* Apparently we can get a SIGPIPE when we call syslog, if
* syslogd has died and been restarted. Ignoring it seems
* be sufficient.
*/
signal(SIGPIPE, SIG_IGN);
}
这里面和之前的dhcp以及dnsmasq不一样,单纯信号函数接口和对应的hangler处理
上面对每一种有单独的处理方式,分别来看。
/*
* hup - Catch SIGHUP signal.
*
* Indicates that the physical layer has been disconnected.
* We don't rely on this indication; if the user has sent this
* signal, we just take the link down.
*/
static void
hup(sig)
int sig;
{
/* can't log a message here, it can deadlock */
got_sighup = 1;
if (conn_running)
/* Send the signal to the [dis]connector process(es) also */
kill_my_pg(sig);
notify(sigreceived, sig);
if (waiting)
siglongjmp(sigjmp, 1);
}这里面由一个重要的知识点,siglongjump,需要后面补充下!
着重讨论下面的case:用户主动关闭这个进程的操作,和前面是一样的。
/*
* term - Catch SIGTERM signal and SIGINT signal (^C/del).
*
* Indicates that we should initiate a graceful disconnect and exit.
*/
/*ARGSUSED*/
static void
term(sig)
int sig;
{
/* can't log a message here, it can deadlock */
got_sigterm = sig;
if (conn_running)
/* Send the signal to the [dis]connector process(es) also */
kill_my_pg(sig);
notify(sigreceived, sig);
if (waiting)
siglongjmp(sigjmp, 1);
}下面主要为了保持同步而接收的信号,
/*
* chld - Catch SIGCHLD signal.
* Sets a flag so we will call reap_kids in the mainline.
*/
static void
chld(sig)
int sig;
{
got_sigchld = 1;
if (waiting)
siglongjmp(sigjmp, 1);
}
加一个标志位,表示子进程已经退出,需要主进程做相应的动作。
直接上源码:
static void
setup_signals()
{
struct sigaction sa;
/*
* Compute mask of all interesting signals and install signal handlers
* for each. Only one signal handler may be active at a time. Therefore,
* all other signals should be masked when any handler is executing.
*/
sigemptyset(&signals_handled);
sigaddset(&signals_handled, SIGHUP);
sigaddset(&signals_handled, SIGINT);
sigaddset(&signals_handled, SIGTERM);
sigaddset(&signals_handled, SIGCHLD);
sigaddset(&signals_handled, SIGUSR2);
#define SIGNAL(s, handler) do { \
sa.sa_handler = handler; \
if (sigaction(s, &sa, NULL) < 0) \
fatal("Couldn't establish signal handler (%d): %m", s); \
} while (0)
sa.sa_mask = signals_handled;
sa.sa_flags = 0;
SIGNAL(SIGHUP, hup); /* Hangup */
SIGNAL(SIGINT, term); /* Interrupt */
SIGNAL(SIGTERM, term); /* Terminate */
SIGNAL(SIGCHLD, chld);
SIGNAL(SIGUSR1, toggle_debug); /* Toggle debug flag */
SIGNAL(SIGUSR2, open_ccp); /* Reopen CCP */
/*
* Install a handler for other signals which would otherwise
* cause pppd to exit without cleaning up.
*/
SIGNAL(SIGABRT, bad_signal);
SIGNAL(SIGALRM, bad_signal);
SIGNAL(SIGFPE, bad_signal);
SIGNAL(SIGILL, bad_signal);
SIGNAL(SIGPIPE, bad_signal);
SIGNAL(SIGQUIT, bad_signal);
SIGNAL(SIGSEGV, bad_signal);
/*
* Apparently we can get a SIGPIPE when we call syslog, if
* syslogd has died and been restarted. Ignoring it seems
* be sufficient.
*/
signal(SIGPIPE, SIG_IGN);
}
这里面和之前的dhcp以及dnsmasq不一样,单纯信号函数接口和对应的hangler处理
上面对每一种有单独的处理方式,分别来看。
/*
* hup - Catch SIGHUP signal.
*
* Indicates that the physical layer has been disconnected.
* We don't rely on this indication; if the user has sent this
* signal, we just take the link down.
*/
static void
hup(sig)
int sig;
{
/* can't log a message here, it can deadlock */
got_sighup = 1;
if (conn_running)
/* Send the signal to the [dis]connector process(es) also */
kill_my_pg(sig);
notify(sigreceived, sig);
if (waiting)
siglongjmp(sigjmp, 1);
}这里面由一个重要的知识点,siglongjump,需要后面补充下!
着重讨论下面的case:用户主动关闭这个进程的操作,和前面是一样的。
/*
* term - Catch SIGTERM signal and SIGINT signal (^C/del).
*
* Indicates that we should initiate a graceful disconnect and exit.
*/
/*ARGSUSED*/
static void
term(sig)
int sig;
{
/* can't log a message here, it can deadlock */
got_sigterm = sig;
if (conn_running)
/* Send the signal to the [dis]connector process(es) also */
kill_my_pg(sig);
notify(sigreceived, sig);
if (waiting)
siglongjmp(sigjmp, 1);
}下面主要为了保持同步而接收的信号,
/*
* chld - Catch SIGCHLD signal.
* Sets a flag so we will call reap_kids in the mainline.
*/
static void
chld(sig)
int sig;
{
got_sigchld = 1;
if (waiting)
siglongjmp(sigjmp, 1);
}
加一个标志位,表示子进程已经退出,需要主进程做相应的动作。
相关文章推荐
- 信号在android源码/external/dnsmasq 源码项目中的应用解读分析
- 信号在android源码/external/dhcpcd 源码项目中的应用解读分析
- Android开源项目和应用源码分析
- Android开源项目和应用源码分析
- Android部分开源项目源码分析之--ListView 图片顶部模糊的高斯处理
- Android应用源码安卓局域网飞鸽传输项目
- 【基于zxing的编解码实战】zxing项目源码解读(2.3.0版本,Android部分)
- 项目清单文件分析与第一个ANDROID应用的启动过程
- 项目源码--Android高清壁纸应用
- Android应用源码找美食看电影本地服务综合项目
- Android应用源码专业设计师网站客户端项目
- 在不修改源码的情况下分析Android应用的操作日志
- 开源项目源码解析-Android Universal Image Loader 源码分析
- Android应用源码带定位和密码找回的锁屏项目
- [Android]Volley源码分析(肆)应用
- 【基于zxing的编解码实战】zxing项目源码解读(2.3.0版本,Android部分)
- Android部分开源项目源码分析之--图片滑动的效果
- 和我一起开发Android应用(二)——“悦词-i背单词”项目功能分析
- Android VSync信号产生过程源码分析
- Android部分开源项目源码分析之---Volley源码分析(一)