Created
June 28, 2018 02:57
-
-
Save lrita/0fcb5750b6cc04f29528c9dfad79066c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# stap -g inject_accept.stp $pid | |
%{ | |
#include <net/sock.h> | |
%} | |
function set_sock_keepalive:long(fd) %{ | |
int err = -1; | |
int keepalive = 1; | |
struct socket *sock = sockfd_lookup(STAP_ARG_fd, &err); | |
if (sock != NULL) { | |
mm_segment_t oldfs; | |
oldfs = get_fs(); | |
set_fs(KERNEL_DS); | |
err = sock_setsockopt(sock, SOL_SOCKET, | |
SO_KEEPALIVE, (char __user*)&keepalive, sizeof(keepalive)); | |
set_fs(oldfs); | |
sockfd_put(sock); | |
} | |
STAP_RETURN(err); | |
%} | |
probe begin { | |
printf("inject begin... \n") | |
} | |
probe syscall.accept.return, syscall.accept4.return { | |
# 当进程号为脚本后第一个参数时,注入keepalive | |
fd = $return | |
if ((pid() == $1) && (fd != -1)) { | |
ok = set_sock_keepalive(fd) | |
if (ok) | |
printf("set_sock_keepalive %d\n", ok) | |
} | |
} | |
probe end { | |
printf("inject end... \n") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment