Inhibit seek failures to force programs to continue when writing to pipes/sockets, LD_PRELOAD-based
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
#define _GNU_SOURCE 1 | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <sys/types.h> | |
#include <dlfcn.h> | |
#include <errno.h> | |
static int (*orig_llseek)( | |
unsigned int fd, unsigned long offset_high, | |
unsigned long offset_low, loff_t *result, | |
unsigned int whence) = NULL; | |
static int (*orig_fseek)( | |
FILE *stream, long offset, int whence | |
) = NULL; | |
int _llseek(unsigned int fd, unsigned long offset_high, | |
unsigned long offset_low, loff_t *result, | |
unsigned int whence) { | |
if(!orig_llseek) { | |
orig_llseek = dlsym(RTLD_NEXT, "_llseek"); | |
} | |
int ret = (*orig_llseek)(fd, offset_high, offset_low, result, whence); | |
if (ret) { | |
fprintf(stderr, "Inhibited seek of %d to %llx\n", fd, | |
(unsigned long long)offset_high * 0x100000000LL + offset_low); | |
} | |
return 0; | |
} | |
int fseek(FILE *stream, long offset, int whence) { | |
if(!orig_fseek) { | |
orig_fseek = dlsym(RTLD_NEXT, "fseek"); | |
} | |
int ret = (*orig_fseek)(stream, offset, whence); | |
if (ret) { | |
fprintf(stderr, "Inhibited fseek of %p to %lx (%d)\n", stream, offset, whence); | |
} | |
errno=0; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment