Browse Source

fix: log perror format

master
Dnomd343 2 years ago
parent
commit
54562d696a
  1. 12
      src/utils/network.c
  2. 12
      src/utils/process.c

12
src/utils/network.c

@ -152,7 +152,7 @@ int create_ipv4_udp_sock(char *address, int port) { // 创建并绑定IPv4 UDP
ipv4_udp_addr.sin_addr.s_addr = inet_addr(address); // 监听地址 ipv4_udp_addr.sin_addr.s_addr = inet_addr(address); // 监听地址
} }
if (bind(ipv4_udp_sock, (struct sockaddr*)&ipv4_udp_addr, sizeof(ipv4_udp_addr)) < 0) { // 绑定接口 if (bind(ipv4_udp_sock, (struct sockaddr*)&ipv4_udp_addr, sizeof(ipv4_udp_addr)) < 0) { // 绑定接口
log_perror("IPv4 UDP Sock bind error"); log_perror("IPv4 UDP Sock bind error -> ");
return -1; // 端口被占用 return -1; // 端口被占用
} }
return ipv4_udp_sock; return ipv4_udp_sock;
@ -170,7 +170,7 @@ int create_ipv6_udp_sock(char *address, int port) { // 创建并绑定IPv6 UDP
inet_pton(AF_INET6, address, &ipv6_udp_addr.sin6_addr); // 监听地址 inet_pton(AF_INET6, address, &ipv6_udp_addr.sin6_addr); // 监听地址
} }
if (bind(ipv6_udp_sock, (struct sockaddr*)&ipv6_udp_addr, sizeof(ipv6_udp_addr)) < 0) { // 绑定接口 if (bind(ipv6_udp_sock, (struct sockaddr*)&ipv6_udp_addr, sizeof(ipv6_udp_addr)) < 0) { // 绑定接口
log_perror("IPv6 UDP Sock bind error"); log_perror("IPv6 UDP Sock bind error -> ");
return -1; // 端口被占用 return -1; // 端口被占用
} }
return ipv6_udp_sock; return ipv6_udp_sock;
@ -220,7 +220,7 @@ long ipv4_send_and_receive(char *ipv4_server_ip, int ipv4_server_port, char *sen
ipv4_server_addr.sin_port = htons(ipv4_server_port); // 目标端口 ipv4_server_addr.sin_port = htons(ipv4_server_port); // 目标端口
ipv4_server_addr.sin_addr.s_addr = inet_addr(ipv4_server_ip); // 目标IP ipv4_server_addr.sin_addr.s_addr = inet_addr(ipv4_server_ip); // 目标IP
if (sendto(ipv4_server_fd, send_buffer, send_len, 0, (struct sockaddr*)&ipv4_server_addr, sizeof(ipv4_server_addr)) < 0) { // 发送缓冲区数据 if (sendto(ipv4_server_fd, send_buffer, send_len, 0, (struct sockaddr*)&ipv4_server_addr, sizeof(ipv4_server_addr)) < 0) { // 发送缓冲区数据
log_perror("IPv4 UDP send failed"); log_perror("IPv4 UDP send failed -> ");
} }
long recv_len = ipv4_receive(ipv4_server_fd, recv_buffer, BUFFER_SIZE, TIMEOUT, ipv4_server_addr); // 接收数据到缓冲区 long recv_len = ipv4_receive(ipv4_server_fd, recv_buffer, BUFFER_SIZE, TIMEOUT, ipv4_server_addr); // 接收数据到缓冲区
close(ipv4_server_fd); // 关闭描述符 close(ipv4_server_fd); // 关闭描述符
@ -235,7 +235,7 @@ long ipv6_send_and_receive(char *ipv6_server_ip, int ipv6_server_port, char *sen
ipv6_server_addr.sin6_port = htons(ipv6_server_port); // 目标端口 ipv6_server_addr.sin6_port = htons(ipv6_server_port); // 目标端口
inet_pton(AF_INET6, ipv6_server_ip, &ipv6_server_addr.sin6_addr); // 目标IP inet_pton(AF_INET6, ipv6_server_ip, &ipv6_server_addr.sin6_addr); // 目标IP
if (sendto(ipv6_server_fd, send_buffer, send_len, 0, (struct sockaddr*)&ipv6_server_addr, sizeof(ipv6_server_addr)) < 0) { // 发送缓冲区数据 if (sendto(ipv6_server_fd, send_buffer, send_len, 0, (struct sockaddr*)&ipv6_server_addr, sizeof(ipv6_server_addr)) < 0) { // 发送缓冲区数据
log_perror("IPv6 UDP send failed"); log_perror("IPv6 UDP send failed -> ");
} }
long recv_len = ipv6_receive(ipv6_server_fd, recv_buffer, BUFFER_SIZE, TIMEOUT, ipv6_server_addr); // 接收数据到缓冲区 long recv_len = ipv6_receive(ipv6_server_fd, recv_buffer, BUFFER_SIZE, TIMEOUT, ipv6_server_addr); // 接收数据到缓冲区
close(ipv6_server_fd); // 关闭描述符 close(ipv6_server_fd); // 关闭描述符
@ -258,7 +258,7 @@ void ipv4_proxy(void *ipv4_info) { // 代理IPv4客户端
log_warn("UDP Proxy: server return timeout"); log_warn("UDP Proxy: server return timeout");
} else { } else {
if (sendto(info->ipv4_client_fd, recv_buffer, recv_len, 0, (struct sockaddr*)&(info->ipv4_client_addr), sizeof(info->ipv4_client_addr)) < 0) { // 服务端数据返回给客户端 if (sendto(info->ipv4_client_fd, recv_buffer, recv_len, 0, (struct sockaddr*)&(info->ipv4_client_addr), sizeof(info->ipv4_client_addr)) < 0) { // 服务端数据返回给客户端
log_perror("IPv4 UDP return failed"); log_perror("IPv4 UDP return failed -> ");
} else { } else {
log_info("UDP Proxy: ↑ %ld bytes ↓ %ld bytes", info->len, recv_len); log_info("UDP Proxy: ↑ %ld bytes ↓ %ld bytes", info->len, recv_len);
} }
@ -276,7 +276,7 @@ void ipv6_proxy(void *ipv6_info) { // 代理IPv6客户端
log_warn("UDP Proxy: Server return timeout"); log_warn("UDP Proxy: Server return timeout");
} else { } else {
if (sendto(info->ipv6_client_fd, recv_buffer, recv_len, 0, (struct sockaddr*)&(info->ipv6_client_addr), sizeof(info->ipv6_client_addr)) < 0) { // 服务端数据返回给客户端 if (sendto(info->ipv6_client_fd, recv_buffer, recv_len, 0, (struct sockaddr*)&(info->ipv6_client_addr), sizeof(info->ipv6_client_addr)) < 0) { // 服务端数据返回给客户端
log_perror("IPv6 UDP return failed"); log_perror("IPv6 UDP return failed -> ");
} else { } else {
log_info("UDP Proxy: ↑ %ld bytes ↓ %ld bytes", info->len, recv_len); log_info("UDP Proxy: ↑ %ld bytes ↓ %ld bytes", info->len, recv_len);
} }

12
src/utils/process.c

@ -93,7 +93,7 @@ void get_sub_exit() { // catch child process die
if (ss_pid != 0) { if (ss_pid != 0) {
ss_ret = waitpid(ss_pid, &ss_status, WNOHANG); // non-blocking ss_ret = waitpid(ss_pid, &ss_status, WNOHANG); // non-blocking
if (ss_ret == -1) { if (ss_ret == -1) {
log_perror("Shadowsocks waitpid error"); log_perror("Shadowsocks waitpid error -> ");
error_exit(); error_exit();
} else if (ss_ret) { // ss exit } else if (ss_ret) { // ss exit
sub_exit_info = get_exit_info(ss_status, ss_pid); sub_exit_info = get_exit_info(ss_status, ss_pid);
@ -104,7 +104,7 @@ void get_sub_exit() { // catch child process die
if (plugin != NULL && plugin_pid != 0) { // with plugin if (plugin != NULL && plugin_pid != 0) { // with plugin
plugin_ret = waitpid(plugin_pid, &plugin_status, WNOHANG); // non-blocking plugin_ret = waitpid(plugin_pid, &plugin_status, WNOHANG); // non-blocking
if (plugin_ret == -1) { if (plugin_ret == -1) {
log_perror("Plugin waitpid error"); log_perror("Plugin waitpid error -> ");
error_exit(); error_exit();
} else if (plugin_ret) { // plugin exit } else if (plugin_ret) { // plugin exit
sub_exit_info = get_exit_info(plugin_status, plugin_pid); sub_exit_info = get_exit_info(plugin_status, plugin_pid);
@ -142,12 +142,12 @@ char** load_plugin_env(sip003 *service) { // load plugin's environment variable
void process_exec(sip003 *service) { // run shadowsocks main process and plugin void process_exec(sip003 *service) { // run shadowsocks main process and plugin
if ((ss_pid = fork()) < 0) { if ((ss_pid = fork()) < 0) {
log_perror("Shadowsocks fork error"); log_perror("Shadowsocks fork error -> ");
error_exit(); error_exit();
} else if (ss_pid == 0) { // child process } else if (ss_pid == 0) { // child process
prctl(PR_SET_PDEATHSIG, SIGKILL); // child die with his father prctl(PR_SET_PDEATHSIG, SIGKILL); // child die with his father
if (execvp(service->shadowsocks_cmd[0], service->shadowsocks_cmd) < 0) { if (execvp(service->shadowsocks_cmd[0], service->shadowsocks_cmd) < 0) {
log_perror("Shadowsocks exec error"); log_perror("Shadowsocks exec error -> ");
exit(2); exit(2);
} }
} }
@ -160,14 +160,14 @@ void process_exec(sip003 *service) { // run shadowsocks main process and plugin
return; return;
} }
if ((plugin_pid = fork()) < 0) { if ((plugin_pid = fork()) < 0) {
log_perror("Plugin fork error"); log_perror("Plugin fork error -> ");
error_exit(); error_exit();
} else if (plugin_pid == 0) { // child process } else if (plugin_pid == 0) { // child process
prctl(PR_SET_PDEATHSIG, SIGKILL); // child die with his father prctl(PR_SET_PDEATHSIG, SIGKILL); // child die with his father
char **plugin_env = load_plugin_env(service); char **plugin_env = load_plugin_env(service);
char *plugin_arg[] = { plugin, NULL }; char *plugin_arg[] = { plugin, NULL };
if (execvpe(plugin, plugin_arg, plugin_env) < 0) { if (execvpe(plugin, plugin_arg, plugin_env) < 0) {
log_perror("Plugin exec error"); log_perror("Plugin exec error -> ");
exit(2); exit(2);
} }
} }

Loading…
Cancel
Save