syscall-dump: add more wrappers (fopen..)
This commit is contained in:
parent
1ba0f93d81
commit
9e28ab7f0b
5
Makefile
5
Makefile
@ -167,7 +167,12 @@ s2i_dump: tools/syscall-dump.so
|
||||
firmware/initramfs/usr/lib/libcrypto.so.1.0.0 \
|
||||
firmware/initramfs/usr/lib/libxml2.so.2 \
|
||||
root@$(SATIP_HOST):/usr/lib
|
||||
scp firmware/initramfs/root/default_sl.json \
|
||||
firmware/initramfs/root/*.txt \
|
||||
firmware/initramfs/root/*.m3u \
|
||||
root@$(SATIP_HOST):/root
|
||||
scp firmware/initramfs/usr/local/bin/mdnsd root@$(SATIP_HOST):/usr/bin
|
||||
scp $(TOOLCHAIN)/target/bin/netstat root@$(SATIP_HOST):/bin
|
||||
|
||||
#
|
||||
# minisatip
|
||||
|
@ -4,7 +4,12 @@ if ! test -d /mnt/s2i-log; then
|
||||
mkdir -p /mnt/s2i-log
|
||||
mount -t tmpfs -o size=300M,mode=0755 tmpfs /mnt/s2i-log
|
||||
fi
|
||||
if ! test -d /mnt/ramdisk; then
|
||||
mkdir -p /mnt/ramdisk
|
||||
mount -t tmpfs -o size=1024k,mode=0755 tmpfs /mnt/ramdisk
|
||||
fi
|
||||
mkdir -p /usr/local/bin
|
||||
mkdir -p /var/run
|
||||
ln -sf /usr/bin/mdnsd /usr/local/bin/mdnsd
|
||||
rm -f /mnt/s2i-log/s2i.log
|
||||
LD_PRELOAD=/usr/lib/syscall-dump.so \
|
||||
|
@ -45,6 +45,7 @@ static inline int gettid(void)
|
||||
static int dlog_fd = -1;
|
||||
static int (*real_open)(const char *pathname, int flags, ...);
|
||||
static int (*real_open64)(const char *pathname, int flags, ...);
|
||||
static int (*real___open64)(const char *pathname, int flags, ...);
|
||||
static int (*real_socket)(int domain, int type, int protocol);
|
||||
static int (*real_ioctl)(int fd, unsigned long request, ...);
|
||||
static ssize_t (*real_write)(int fd, const void *buf, size_t len);
|
||||
@ -54,6 +55,13 @@ static off64_t (*real_lseek64)(int fd, off64_t offset, int whence);
|
||||
static int (*real_close)(int fd);
|
||||
static int (*real_dup)(int oldfd);
|
||||
static int (*real_dup2)(int oldfd, int newfd);
|
||||
static int (*real_eventfd)(unsigned int initval, int flags);
|
||||
static int (*real_system)(const char *command);
|
||||
static FILE *(*real_fopen)(const char *pathname, const char *mode);
|
||||
static FILE *(*real_freopen)(const char *pathname, const char *mode, FILE *stream);
|
||||
static int (*real_fclose)(FILE *fp);
|
||||
static size_t (*real_fread)(void *ptr, size_t size, size_t nmemb, FILE *stream);
|
||||
static size_t (*real_fwrite)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
|
||||
|
||||
#define REDIR(realptr, symname) do { \
|
||||
if ((realptr) == NULL) { \
|
||||
@ -70,14 +78,33 @@ static void dlog(const char *fmt, ...)
|
||||
char buf[2048], *b;
|
||||
va_list ap;
|
||||
size_t len;
|
||||
ssize_t r;
|
||||
int keep_errno = errno;
|
||||
ssize_t r, j;
|
||||
int keep_errno = errno, fd;
|
||||
|
||||
if (dlog_fd < 0) {
|
||||
const char *f = getenv("SYSCALL_DUMP_LOG");
|
||||
REDIR(real_open, "open");
|
||||
REDIR(real_read, "read");
|
||||
REDIR(real_close, "close");
|
||||
sprintf(buf, "/proc/%d/cmdline", gettid());
|
||||
fd = real_open(buf, O_RDONLY);
|
||||
if (fd >= 0) {
|
||||
r = real_read(fd, buf, sizeof(buf)-1);
|
||||
real_close(fd);
|
||||
if (r > 0) {
|
||||
if (buf[r-1] == '\0')
|
||||
r--;
|
||||
for (j = 0; j < r; j++)
|
||||
if (buf[j] == '\0')
|
||||
buf[j] = '|';
|
||||
buf[r] = '\0';
|
||||
}
|
||||
} else {
|
||||
buf[0] = '\0';
|
||||
}
|
||||
dlog_fd = f ? real_open(f, O_CREAT|O_APPEND|O_WRONLY, 0600) : 2 /* stderr */;
|
||||
if (dlog_fd < 0) exit(1002);
|
||||
dlog("syscall dump init for executable '%s', log fd %d\n", buf, dlog_fd);
|
||||
}
|
||||
sprintf(buf, "[%5d]", gettid());
|
||||
va_start(ap, fmt);
|
||||
@ -144,7 +171,7 @@ int open64(const char *pathname, int flags, ...)
|
||||
va_list ap;
|
||||
mode_t mode;
|
||||
int r;
|
||||
|
||||
|
||||
REDIR(real_open64, "open64");
|
||||
|
||||
if (flags & O_CREAT) {
|
||||
@ -162,6 +189,62 @@ int open64(const char *pathname, int flags, ...)
|
||||
return r;
|
||||
}
|
||||
|
||||
/* __open64() wrapper */
|
||||
int __open64(const char *pathname, int flags, ...)
|
||||
{
|
||||
va_list ap;
|
||||
mode_t mode;
|
||||
int r;
|
||||
|
||||
REDIR(real___open64, "__open64");
|
||||
|
||||
if (flags & O_CREAT) {
|
||||
/* Get argument */
|
||||
va_start(ap, flags);
|
||||
mode = va_arg(ap, mode_t);
|
||||
va_end(ap);
|
||||
|
||||
r = real_open64(pathname, flags, mode);
|
||||
dlog("__open64('%s', 0x%x, 0x%lx) = %d (%d)\n", pathname, flags, (long)mode, r, E(r));
|
||||
} else {
|
||||
r = real_open64(pathname, flags);
|
||||
dlog("__open64('%s', 0x%x) = %d (%d)\n", pathname, flags, r, E(r));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/* fopen() wrapper */
|
||||
FILE *fopen(const char *pathname, const char *mode)
|
||||
{
|
||||
FILE *r;
|
||||
int keep_errno;
|
||||
|
||||
REDIR(real_fopen, "fopen");
|
||||
|
||||
r = real_fopen(pathname, mode);
|
||||
keep_errno = errno;
|
||||
dlog("fopen('%s', '%s') = %p (%d) (fileno %d)\n", pathname, mode,
|
||||
r, r == NULL ? errno : 0, r != NULL ? fileno(r) : -1);
|
||||
errno = keep_errno;
|
||||
return r;
|
||||
}
|
||||
|
||||
/* freopen() wrapper */
|
||||
FILE *freopen(const char *pathname, const char *mode, FILE *stream)
|
||||
{
|
||||
FILE *r;
|
||||
int keep_errno;
|
||||
|
||||
REDIR(real_freopen, "freopen");
|
||||
|
||||
r = real_freopen(pathname, mode, stream);
|
||||
keep_errno = errno;
|
||||
dlog("freopen('%s', '%s', %p) = %p (%d) (fileno %d)\n", pathname, mode, stream,
|
||||
r, r == NULL ? errno : 0, r != NULL ? fileno(r) : -1);
|
||||
errno = keep_errno;
|
||||
return r;
|
||||
}
|
||||
|
||||
/* socket() wrapper */
|
||||
int socket(int domain, int type, int protocol)
|
||||
{
|
||||
@ -186,6 +269,18 @@ int close(int fd)
|
||||
return r;
|
||||
}
|
||||
|
||||
/* fclose() wrapper */
|
||||
int fclose(FILE *fp)
|
||||
{
|
||||
int r;
|
||||
|
||||
REDIR(real_fclose, "fclose");
|
||||
|
||||
r = real_fclose(fp);
|
||||
dlog("fclose(%p) = %d (%d)\n", fp, r, r == EOF ? errno : 0);
|
||||
return r;
|
||||
}
|
||||
|
||||
/* write() wrapper */
|
||||
ssize_t write(int fd, const void *buf, size_t len)
|
||||
{
|
||||
@ -241,6 +336,29 @@ off64_t lseek64(int fd, off64_t offset, int whence)
|
||||
return r;
|
||||
}
|
||||
|
||||
/* fread () wrapper */
|
||||
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
|
||||
{
|
||||
size_t r;
|
||||
|
||||
REDIR(real_fread, "fread");
|
||||
|
||||
r = real_fread(ptr, size, nmemb, stream);
|
||||
dlog("fread(%p, %zu, %zu, %p) = %zu\n", ptr, size, nmemb, stream, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
|
||||
{
|
||||
size_t r;
|
||||
|
||||
REDIR(real_fwrite, "fwrite");
|
||||
|
||||
r = real_fwrite(ptr, size, nmemb, stream);
|
||||
dlog("fwrite(%p, %zu, %zu, %p) = %zu\n", ptr, size, nmemb, stream, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
/* dup() wrapper */
|
||||
int dup(int oldfd)
|
||||
{
|
||||
@ -265,6 +383,30 @@ int dup2(int oldfd, int newfd)
|
||||
return r;
|
||||
}
|
||||
|
||||
/* eventfd() wrapper */
|
||||
int eventfd(unsigned int initval, int flags)
|
||||
{
|
||||
int r;
|
||||
|
||||
REDIR(real_eventfd, "eventfd");
|
||||
|
||||
r = real_eventfd(initval, flags);
|
||||
dlog("eventfd(%u, %d) = %d (%d)\n", initval, flags, r, E(r));
|
||||
return r;
|
||||
}
|
||||
|
||||
/* system() wrapper */
|
||||
int system(const char *command)
|
||||
{
|
||||
int r;
|
||||
|
||||
REDIR(real_system, "system");
|
||||
|
||||
r = real_system(command);
|
||||
dlog("system('%s') = %d (%d)\n", command, r, E(r));
|
||||
return r;
|
||||
}
|
||||
|
||||
/* ioctl() wrapper */
|
||||
int ioctl(int fd, unsigned long request, ...)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user