信号在android源码/external/pppd 源码项目中的应用解读分析
来源:互联网 发布:java 读取apk版本号 编辑:程序博客网 时间:2024/06/06 01:25
pppoe里面也有信号的处理的方式,
直接上源码:
static voidsetup_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 voidhup(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 voidterm(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 voidchld(sig) int sig;{ got_sigchld = 1; if (waiting)siglongjmp(sigjmp, 1);}
加一个标志位,表示子进程已经退出,需要主进程做相应的动作。
阅读全文
0 0
- 信号在android源码/external/pppd 源码项目中的应用解读分析
- 信号在android源码/external/dhcpcd 源码项目中的应用解读分析
- 信号在android源码/external/dnsmasq 源码项目中的应用解读分析
- [PPPOE]PPPD源码分析
- pppoe协议和pppd源码分析
- pppoe协议和pppd源码分析
- 【Android应用源码分析】HandlerThread 源码分析
- 【Android应用源码分析】IntentService 源码分析
- Android VSync信号产生过程源码分析
- 谈谈23种设计模式在Android源码及项目中的应用
- Flasky搞起来---源码解读,项目中的包解读
- pppd源码详解
- pppd 源码修改1
- 源码分析及反向在金融核心系统中的应用
- 项目源码解读 absControl
- 项目源码解读 baseControl
- 项目源码解读dimensionControl
- Android开源项目和应用源码分析
- POJ 1625 Censored!(AC自动机+DP)
- 腾讯云海量社交网络业务下的DevOps架构应用实践
- PHP实现 记录网站访问量
- maven安装插件的配置
- 开源ESB-ServiceMix服务总线
- 信号在android源码/external/pppd 源码项目中的应用解读分析
- <c:forEach>详解
- 微信公众号中信息推送出现中文乱码的问题的思考
- android开发中常见的问题
- 【Redis源码剖析】
- Week5 Lasso Regression
- leetcode 637. Average of Levels in Binary Tree
- Spring (三)注入依赖对象、注入集合类型的属性
- 用户特征分析的应用