Final tidies, comments etc.

This commit is contained in:
Patrick J Cherry
2018-02-09 11:42:25 +00:00
parent 195de41d86
commit 9817fd7b0a
2 changed files with 18 additions and 6 deletions

View File

@@ -1,7 +1,11 @@
require 'tempfile' 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 module LdPreload
#
# This takes an object name, sets up a temporary log file, whose name is # 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 # recorded in the environment as OUTPUT_obj_name, where obj_name is the
# name of the preload module to build and load. # name of the preload module to build and load.
@@ -34,6 +38,10 @@ module LdPreload
lines lines
end 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) def parse_ld_preload_logs(obj_name)
read_ld_preload_log(obj_name).map do |l| read_ld_preload_log(obj_name).map do |l|
l.split(':').map { |i| i =~ /^\d+$/ ? i.to_i : i } l.split(':').map { |i| i =~ /^\d+$/ ? i.to_i : i }

View File

@@ -5,6 +5,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <sys/socket.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); 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) 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); 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) int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen)
{ {
FILE *fd; 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); retval = real_setsockopt(sockfd, level, optname, optval, optlen);
fn = getenv("OUTPUT_setsockopt_logger"); fn = getenv("OUTPUT_setsockopt_logger");
/*
* Only interested in catching non-null 4-byte (integer) values
*/
if ( fn != NULL && optval != NULL && optlen == 4) { if ( fn != NULL && optval != NULL && optlen == 4) {
fd = fopen(fn,"a"); 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); fclose(fd);
} }