Final tidies, comments etc.
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
require 'tempfile'
|
||||
|
||||
# LdPreload is a little wrapper for using LD_PRELOAD when testing flexnbd
|
||||
#
|
||||
# LdPreload is a little wrapper for using LD_PRELOAD loggers to pick up system
|
||||
# calls when testing flexnbd.
|
||||
#
|
||||
module LdPreload
|
||||
#
|
||||
# This takes an object name, sets up a temporary log file, whose name is
|
||||
# recorded in the environment as OUTPUT_obj_name, where obj_name is the
|
||||
# name of the preload module to build and load.
|
||||
@@ -34,6 +38,10 @@ module LdPreload
|
||||
lines
|
||||
end
|
||||
|
||||
#
|
||||
# The next to methods assume the log file has one entry per line, and that
|
||||
# each entry is a series of values separated by colons.
|
||||
#
|
||||
def parse_ld_preload_logs(obj_name)
|
||||
read_ld_preload_log(obj_name).map do |l|
|
||||
l.split(':').map { |i| i =~ /^\d+$/ ? i.to_i : i }
|
||||
|
@@ -5,6 +5,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
/*
|
||||
* Noddy LD_PRELOAD wrapper to catch setsockopt calls, and log them to a file.
|
||||
*/
|
||||
|
||||
typedef int (*real_setsockopt_t)(int sockfd, int level, int optname, const void *optval, socklen_t optlen);
|
||||
|
||||
int real_setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen)
|
||||
@@ -12,10 +16,6 @@ int real_setsockopt(int sockfd, int level, int optname, const void *optval, sock
|
||||
return ((real_setsockopt_t)dlsym(RTLD_NEXT, "setsockopt"))(sockfd, level, optname, optval, optlen);
|
||||
}
|
||||
|
||||
/*
|
||||
* Noddy LD_PRELOAD wrapper to catch setsockopt calls, and log them to a file.
|
||||
*/
|
||||
|
||||
int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen)
|
||||
{
|
||||
FILE *fd;
|
||||
@@ -24,9 +24,13 @@ int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t
|
||||
|
||||
retval = real_setsockopt(sockfd, level, optname, optval, optlen);
|
||||
fn = getenv("OUTPUT_setsockopt_logger");
|
||||
|
||||
/*
|
||||
* Only interested in catching non-null 4-byte (integer) values
|
||||
*/
|
||||
if ( fn != NULL && optval != NULL && optlen == 4) {
|
||||
fd = fopen(fn,"a");
|
||||
fprintf(fd,"setsockopt:%d:%d:%d:%i:%d\n", sockfd, level, optname, *(int *)optval, retval);
|
||||
fprintf(fd,"setsockopt:%i:%i:%i:%i:%i\n", sockfd, level, optname, *(int *)optval, retval);
|
||||
fclose(fd);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user