8 Star 1 Fork 22

src-openEuler/dhcp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
bugfix-dhcp-4.2.5-check-dhclient-pid.patch 1.81 KB
一键复制 编辑 原始数据 按行查看 历史
eaglegai 提交于 2020-07-22 11:38 . update dhcp version to 4.4.2
--- a/client/dhclient.c 2019-01-25 14:34:46.996000000 +0800
+++ b/client/dhclient.c 2019-01-25 14:34:16.382000000 +0800
@@ -114,6 +114,8 @@
int bootp_broadcast_always = 0;
+int buf_size = 128;
+
extern struct option *default_requested_options[];
void run_stateless(int exit_mode, u_int16_t port);
@@ -143,6 +143,7 @@ static void dhclient_ddns_cb_free(dhcp_ddns_cb_t *ddns_cb,
char* file, int line);
#endif /* defined NSUPDATE */
+static int check_dhclient_pid(pid_t pid);
/*!
*
@@ -682,7 +686,8 @@
e = fscanf(pidfd, "%ld\n", &temp);
oldpid = (pid_t)temp;
- if (e != 0 && e != EOF && oldpid) {
+ if (e != 0 && e != EOF) {
+ if (oldpid && check_dhclient_pid(oldpid)) {
if (kill(oldpid, SIGTERM) == 0) {
log_info("Killed old client process");
(void) unlink(path_dhclient_pid);
@@ -698,6 +703,7 @@
log_info("Removed stale PID file");
(void) unlink(path_dhclient_pid);
}
+ }
}
fclose(pidfd);
} else {
@@ -738,7 +744,7 @@
oldpid = (pid_t)temp;
if (e != 0 && e != EOF) {
- if (oldpid) {
+ if (oldpid && check_dhclient_pid(oldpid)) {
if (kill(oldpid, SIGTERM) == 0)
unlink(path_dhclient_pid);
}
@@ -6045,3 +6051,27 @@
log_error("dhcp4o6_stop: send(): %m");
}
#endif /* DHCPv6 && DHCP4o6 */
+
+static int check_dhclient_pid(pid_t pid) {
+ char proc_pid_path[buf_size];
+ char task_name[buf_size];
+
+ memset(proc_pid_path, 0, buf_size);
+ memset(task_name, 0, buf_size);
+
+ snprintf(proc_pid_path, buf_size - 1, "/proc/%d/comm", pid);
+
+ FILE* fp = fopen(proc_pid_path, "r");
+ if(fp != NULL) {
+ if( fgets(task_name, buf_size, fp) == NULL ) {
+ fclose(fp);
+ return 0;
+ }
+ fclose(fp);
+ if(strncmp(task_name, "dhclient", 8) == 0) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-openeuler/dhcp.git
[email protected]:src-openeuler/dhcp.git
src-openeuler
dhcp
dhcp
master

搜索帮助