File agent/ninedogs.c changed (mode: 100644) (index daff96b..6d0da9b) |
11 |
11 |
#define __USE_LARGEFILE64 |
#define __USE_LARGEFILE64 |
12 |
12 |
#define __USE_FILE_OFFSET64 |
#define __USE_FILE_OFFSET64 |
13 |
13 |
|
|
|
14 |
|
#include <sys/epoll.h> |
|
15 |
|
#include <sys/eventfd.h> |
|
16 |
|
#include <sys/file.h> |
|
17 |
|
#include <sys/inotify.h> |
14 |
18 |
#include <sys/mman.h> |
#include <sys/mman.h> |
|
19 |
|
#include <sys/mount.h> |
15 |
20 |
#include <sys/random.h> |
#include <sys/random.h> |
|
21 |
|
#include <sys/sem.h> |
|
22 |
|
#include <sys/sendfile.h> |
16 |
23 |
#include <sys/socket.h> |
#include <sys/socket.h> |
17 |
24 |
#include <sys/stat.h> |
#include <sys/stat.h> |
18 |
25 |
#include <sys/time.h> |
#include <sys/time.h> |
|
20 |
27 |
#include <sys/types.h> |
#include <sys/types.h> |
21 |
28 |
#include <sys/un.h> |
#include <sys/un.h> |
22 |
29 |
|
|
|
30 |
|
#include <linux/close_range.h> |
23 |
31 |
#include <signal.h> |
#include <signal.h> |
24 |
32 |
#include <pthread.h> |
#include <pthread.h> |
25 |
33 |
#include <stdarg.h> |
#include <stdarg.h> |
|
... |
... |
__attribute__((constructor)) void ninedogs_init(void) |
2119 |
2127 |
ninedogs_process_core(NINEDOGS_CORE_START, NULL); |
ninedogs_process_core(NINEDOGS_CORE_START, NULL); |
2120 |
2128 |
|
|
2121 |
2129 |
xlog(100, "%s: done; my pid %d\n", __func__, getpid()); |
xlog(100, "%s: done; my pid %d\n", __func__, getpid()); |
|
2130 |
|
|
|
2131 |
|
x = getenv("NINEDOGS_DELAY"); |
|
2132 |
|
if (x != NULL) |
|
2133 |
|
sleep(strtoul(x, NULL, 10)); |
2122 |
2134 |
} |
} |
2123 |
2135 |
|
|
2124 |
2136 |
void *realloc(void *ptr, size_t size) |
void *realloc(void *ptr, size_t size) |
|
... |
... |
int sqlite3_bind_text(void *stmt, int index, const char *value, int len, void *f |
3555 |
3567 |
return ret; |
return ret; |
3556 |
3568 |
} |
} |
3557 |
3569 |
|
|
|
3570 |
|
// TODO: trace |
|
3571 |
|
int chdir(const char *path) |
|
3572 |
|
{ |
|
3573 |
|
static int (*old_chdir)(const char *path) = NULL; |
|
3574 |
|
|
|
3575 |
|
if (!old_chdir) |
|
3576 |
|
old_chdir = ninedogs_dlsym("chdir"); |
|
3577 |
|
|
|
3578 |
|
my_trace(__func__, "", 'c', path); |
|
3579 |
|
int ret = old_chdir(path); |
|
3580 |
|
my_trace(__func__, "", 'r', path, ret); |
|
3581 |
|
|
|
3582 |
|
return ret; |
|
3583 |
|
} |
|
3584 |
|
|
|
3585 |
|
// TODO: trace |
|
3586 |
|
int fchdir(int fd) |
|
3587 |
|
{ |
|
3588 |
|
static int (*old_fchdir)(int fd) = NULL; |
|
3589 |
|
|
|
3590 |
|
if (!old_fchdir) |
|
3591 |
|
old_fchdir = ninedogs_dlsym("fchdir"); |
|
3592 |
|
|
|
3593 |
|
my_trace(__func__, "", 'c', fd); |
|
3594 |
|
int ret = old_fchdir(fd); |
|
3595 |
|
my_trace(__func__, "", 'r', fd, ret); |
|
3596 |
|
|
|
3597 |
|
return ret; |
|
3598 |
|
} |
|
3599 |
|
|
|
3600 |
|
// TODO: trace |
|
3601 |
|
int chmod(const char *path, mode_t mode) |
|
3602 |
|
{ |
|
3603 |
|
static int (*old_chmod)(const char *path, mode_t mode) = NULL; |
|
3604 |
|
|
|
3605 |
|
if (!old_chmod) |
|
3606 |
|
old_chmod = ninedogs_dlsym("chmod"); |
|
3607 |
|
|
|
3608 |
|
my_trace(__func__, "", 'c', path, mode); |
|
3609 |
|
int ret = old_chmod(path, mode); |
|
3610 |
|
my_trace(__func__, "", 'r', path, mode, ret); |
|
3611 |
|
|
|
3612 |
|
return ret; |
|
3613 |
|
} |
|
3614 |
|
|
|
3615 |
|
// TODO: trace |
|
3616 |
|
int fchmod(int fd, mode_t mode) |
|
3617 |
|
{ |
|
3618 |
|
static int (*old_fchmod)(int fd, mode_t mode) = NULL; |
|
3619 |
|
|
|
3620 |
|
if (!old_fchmod) |
|
3621 |
|
old_fchmod = ninedogs_dlsym("fchmod"); |
|
3622 |
|
|
|
3623 |
|
my_trace(__func__, "", 'c', fd, mode); |
|
3624 |
|
int ret = old_fchmod(fd, mode); |
|
3625 |
|
my_trace(__func__, "", 'r', fd, mode, ret); |
|
3626 |
|
|
|
3627 |
|
return ret; |
|
3628 |
|
} |
|
3629 |
|
|
|
3630 |
|
// TODO: fchmodat |
|
3631 |
|
|
|
3632 |
|
// TODO: trace |
|
3633 |
|
int chown(const char *path, uid_t owner, gid_t group) |
|
3634 |
|
{ |
|
3635 |
|
static int (*old_chown)(const char *path, uid_t owner, gid_t group) = NULL; |
|
3636 |
|
|
|
3637 |
|
if (!old_chown) |
|
3638 |
|
old_chown = ninedogs_dlsym("chown"); |
|
3639 |
|
|
|
3640 |
|
my_trace(__func__, "", 'c', path, owner, group); |
|
3641 |
|
int ret = old_chown(path, owner, group); |
|
3642 |
|
my_trace(__func__, "", 'r', path, owner, group, ret); |
|
3643 |
|
|
|
3644 |
|
return ret; |
|
3645 |
|
} |
|
3646 |
|
|
|
3647 |
|
// TODO: trace |
|
3648 |
|
int fchown(int fd, uid_t owner, gid_t group) |
|
3649 |
|
{ |
|
3650 |
|
static int (*old_fchown)(int fd, uid_t owner, gid_t group) = NULL; |
|
3651 |
|
|
|
3652 |
|
if (!old_fchown) |
|
3653 |
|
old_fchown = ninedogs_dlsym("fchown"); |
|
3654 |
|
|
|
3655 |
|
my_trace(__func__, "", 'c', fd, owner, group); |
|
3656 |
|
int ret = old_fchown(fd, owner, group); |
|
3657 |
|
my_trace(__func__, "", 'r', fd, owner, group, ret); |
|
3658 |
|
|
|
3659 |
|
return ret; |
|
3660 |
|
} |
|
3661 |
|
|
|
3662 |
|
// TODO: trace |
|
3663 |
|
int lchown(const char *path, uid_t owner, gid_t group) |
|
3664 |
|
{ |
|
3665 |
|
static int (*old_lchown)(const char *path, uid_t owner, gid_t group) = NULL; |
|
3666 |
|
|
|
3667 |
|
if (!old_lchown) |
|
3668 |
|
old_lchown = ninedogs_dlsym("lchown"); |
|
3669 |
|
|
|
3670 |
|
my_trace(__func__, "", 'c', path, owner, group); |
|
3671 |
|
int ret = old_lchown(path, owner, group); |
|
3672 |
|
my_trace(__func__, "", 'r', path, owner, group, ret); |
|
3673 |
|
|
|
3674 |
|
return ret; |
|
3675 |
|
} |
|
3676 |
|
|
|
3677 |
|
// TODO: fchownat |
|
3678 |
|
|
|
3679 |
|
// TODO: trace |
|
3680 |
|
int chroot(const char *path) |
|
3681 |
|
{ |
|
3682 |
|
static int (*old_chroot)(const char *path) = NULL; |
|
3683 |
|
|
|
3684 |
|
if (!old_chroot) |
|
3685 |
|
old_chroot = ninedogs_dlsym("chroot"); |
|
3686 |
|
|
|
3687 |
|
my_trace(__func__, "", 'c', path); |
|
3688 |
|
int ret = old_chroot(path); |
|
3689 |
|
my_trace(__func__, "", 'r', path, ret); |
|
3690 |
|
|
|
3691 |
|
return ret; |
|
3692 |
|
} |
|
3693 |
|
|
|
3694 |
|
// TODO: trace |
|
3695 |
|
int clock_gettime(clockid_t clockid, struct timespec *tp) |
|
3696 |
|
{ |
|
3697 |
|
static int (*old_clock_gettime)(clockid_t clockid, struct timespec *tp) = NULL; |
|
3698 |
|
|
|
3699 |
|
if (!old_clock_gettime) |
|
3700 |
|
old_clock_gettime = ninedogs_dlsym("clock_gettime"); |
|
3701 |
|
|
|
3702 |
|
int ret = old_clock_gettime(clockid, tp); |
|
3703 |
|
my_trace(__func__, "", 'R', clockid, tp, ret); |
|
3704 |
|
|
|
3705 |
|
return ret; |
|
3706 |
|
} |
|
3707 |
|
|
|
3708 |
|
// TODO: man clock_gettime |
|
3709 |
|
|
|
3710 |
|
// TODO: clock_nanosleep |
|
3711 |
|
|
|
3712 |
|
// TODO: clone |
|
3713 |
|
|
|
3714 |
|
// TODO: trace |
|
3715 |
|
int close_range(unsigned int first, unsigned int last, int flags) |
|
3716 |
|
{ |
|
3717 |
|
static int (*old_close_range)(unsigned int first, unsigned int last, int flags) = NULL; |
|
3718 |
|
|
|
3719 |
|
if (!old_close_range) |
|
3720 |
|
old_close_range = ninedogs_dlsym("close_range"); |
|
3721 |
|
|
|
3722 |
|
my_trace(__func__, "", 'c', first, last, flags); |
|
3723 |
|
int ret = old_close_range(first, last, flags); |
|
3724 |
|
my_trace(__func__, "", 'r', first, last, flags, ret); |
|
3725 |
|
|
|
3726 |
|
return ret; |
|
3727 |
|
} |
|
3728 |
|
|
|
3729 |
|
// TODO: trace |
|
3730 |
|
ssize_t copy_file_range(int fd_in, off64_t *off_in, int fd_out, off64_t *off_out, |
|
3731 |
|
size_t len, unsigned int flags) |
|
3732 |
|
{ |
|
3733 |
|
static int (*old_copy_file_range)(int fd_in, off64_t *off_in, int fd_out, off64_t *off_out, |
|
3734 |
|
size_t len, unsigned int flags) = NULL; |
|
3735 |
|
|
|
3736 |
|
if (!old_copy_file_range) |
|
3737 |
|
old_copy_file_range = ninedogs_dlsym("copy_file_range"); |
|
3738 |
|
|
|
3739 |
|
my_trace(__func__, "", 'c', fd_in, off_in, fd_out, off_out, len, flags); |
|
3740 |
|
ssize_t ret = old_copy_file_range(fd_in, off_in, fd_out, off_out, len, flags); |
|
3741 |
|
my_trace(__func__, "", 'r', fd_in, off_in, fd_out, off_out, len, flags, ret); |
|
3742 |
|
|
|
3743 |
|
return ret; |
|
3744 |
|
} |
|
3745 |
|
|
|
3746 |
|
// TODO: creat |
|
3747 |
|
|
|
3748 |
|
// TODO: trace |
|
3749 |
|
int dup(int oldfd) |
|
3750 |
|
{ |
|
3751 |
|
static int (*old_dup)(int oldfd) = NULL; |
|
3752 |
|
|
|
3753 |
|
if (!old_dup) |
|
3754 |
|
old_dup = ninedogs_dlsym("dup"); |
|
3755 |
|
|
|
3756 |
|
int ret = old_dup(oldfd); |
|
3757 |
|
my_trace(__func__, "", 'R', oldfd, ret); |
|
3758 |
|
|
|
3759 |
|
return ret; |
|
3760 |
|
} |
|
3761 |
|
|
|
3762 |
|
// TODO: trace |
|
3763 |
|
int dup2(int oldfd, int newfd) |
|
3764 |
|
{ |
|
3765 |
|
static int (*old_dup2)(int oldfd, int newfd) = NULL; |
|
3766 |
|
|
|
3767 |
|
if (!old_dup2) |
|
3768 |
|
old_dup2 = ninedogs_dlsym("dup2"); |
|
3769 |
|
|
|
3770 |
|
int ret = old_dup2(oldfd, newfd); |
|
3771 |
|
my_trace(__func__, "", 'R', oldfd, newfd, ret); |
|
3772 |
|
|
|
3773 |
|
return ret; |
|
3774 |
|
} |
|
3775 |
|
|
|
3776 |
|
// TODO: trace |
|
3777 |
|
int dup3(int oldfd, int newfd, int flags) |
|
3778 |
|
{ |
|
3779 |
|
static int (*old_dup3)(int oldfd, int newfd, int flags) = NULL; |
|
3780 |
|
|
|
3781 |
|
if (!old_dup3) |
|
3782 |
|
old_dup3 = ninedogs_dlsym("dup3"); |
|
3783 |
|
|
|
3784 |
|
int ret = old_dup3(oldfd, newfd, flags); |
|
3785 |
|
my_trace(__func__, "", 'R', oldfd, newfd, flags, ret); |
|
3786 |
|
|
|
3787 |
|
return ret; |
|
3788 |
|
} |
|
3789 |
|
|
|
3790 |
|
// TODO: trace |
|
3791 |
|
int epoll_create(int size) |
|
3792 |
|
{ |
|
3793 |
|
static int (*old_epoll_create)(int size) = NULL; |
|
3794 |
|
|
|
3795 |
|
if (!old_epoll_create) |
|
3796 |
|
old_epoll_create = ninedogs_dlsym("epoll_create"); |
|
3797 |
|
|
|
3798 |
|
int ret = old_epoll_create(size); |
|
3799 |
|
my_trace(__func__, "", 'R', size, ret); |
|
3800 |
|
if (ret != -1) |
|
3801 |
|
open_common_post(FD_NODE_EPOLLFD, "", 0, size, ret); |
|
3802 |
|
|
|
3803 |
|
return ret; |
|
3804 |
|
} |
|
3805 |
|
|
|
3806 |
|
// TODO: trace |
|
3807 |
|
int epoll_create1(int flags) |
|
3808 |
|
{ |
|
3809 |
|
static int (*old_epoll_create1)(int flags) = NULL; |
|
3810 |
|
|
|
3811 |
|
if (!old_epoll_create1) |
|
3812 |
|
old_epoll_create1 = ninedogs_dlsym("epoll_create1"); |
|
3813 |
|
|
|
3814 |
|
int ret = old_epoll_create1(flags); |
|
3815 |
|
my_trace(__func__, "", 'R', flags, ret); |
|
3816 |
|
if (ret != -1) |
|
3817 |
|
open_common_post(FD_NODE_EPOLLFD, "", flags, 0, ret); |
|
3818 |
|
|
|
3819 |
|
return ret; |
|
3820 |
|
} |
|
3821 |
|
|
|
3822 |
|
// TODO: trace |
|
3823 |
|
int epoll_ctl(int epfd, int op, int fd, struct epoll_event *ev) |
|
3824 |
|
{ |
|
3825 |
|
static int (*old_epoll_ctl)(int epfd, int op, int fd, struct epoll_event *ev) = NULL; |
|
3826 |
|
|
|
3827 |
|
if (!old_epoll_ctl) |
|
3828 |
|
old_epoll_ctl = ninedogs_dlsym("epoll_ctl"); |
|
3829 |
|
|
|
3830 |
|
int ret = old_epoll_ctl(epfd, op, fd, ev); |
|
3831 |
|
my_trace(__func__, "", 'R', epfd, op, fd, ev, ret); |
|
3832 |
|
|
|
3833 |
|
return ret; |
|
3834 |
|
} |
|
3835 |
|
|
|
3836 |
|
// TODO: epoll_pwait[2] |
|
3837 |
|
|
|
3838 |
|
// TODO: trace |
|
3839 |
|
int epoll_wait(int epfd, struct epoll_event *evs, int maxevents, int timeout) |
|
3840 |
|
{ |
|
3841 |
|
static int (*old_epoll_wait)(int epfd, struct epoll_event *evs, int maxevents, int timeout) = NULL; |
|
3842 |
|
|
|
3843 |
|
if (!old_epoll_wait) |
|
3844 |
|
old_epoll_wait = ninedogs_dlsym("epoll_wait"); |
|
3845 |
|
|
|
3846 |
|
my_trace(__func__, "", 'c', epfd, evs, maxevents, timeout); |
|
3847 |
|
int ret = old_epoll_wait(epfd, evs, maxevents, timeout); |
|
3848 |
|
my_trace(__func__, "", 'r', epfd, evs, maxevents, timeout, ret); |
|
3849 |
|
|
|
3850 |
|
return ret; |
|
3851 |
|
} |
|
3852 |
|
|
|
3853 |
|
// TODO: trace |
|
3854 |
|
int eventfd(unsigned int initval, int flags) |
|
3855 |
|
{ |
|
3856 |
|
static int (*old_eventfd)(unsigned int initval, int flags) = NULL; |
|
3857 |
|
|
|
3858 |
|
if (!old_eventfd) |
|
3859 |
|
old_eventfd = ninedogs_dlsym("eventfd"); |
|
3860 |
|
|
|
3861 |
|
int ret = old_eventfd(initval, flags); |
|
3862 |
|
my_trace(__func__, "", 'R', initval, flags, ret); |
|
3863 |
|
if (ret != -1) |
|
3864 |
|
open_common_post(FD_NODE_EVENTFD, "", flags, initval, ret); |
|
3865 |
|
|
|
3866 |
|
return ret; |
|
3867 |
|
} |
|
3868 |
|
|
|
3869 |
|
// TODO: trace |
|
3870 |
|
int posix_fadvise(int fd, off_t offset, off_t len, int advice) |
|
3871 |
|
{ |
|
3872 |
|
static int (*old_posix_fadvise)(int fd, off_t offset, off_t len, int advice) = NULL; |
|
3873 |
|
|
|
3874 |
|
if (!old_posix_fadvise) |
|
3875 |
|
old_posix_fadvise = ninedogs_dlsym("posix_fadvise"); |
|
3876 |
|
|
|
3877 |
|
int ret = old_posix_fadvise(fd, offset, len, advice); |
|
3878 |
|
my_trace(__func__, "", 'R', fd, offset, len, advice, ret); |
|
3879 |
|
|
|
3880 |
|
return ret; |
|
3881 |
|
} |
|
3882 |
|
|
|
3883 |
|
// TODO: trace |
|
3884 |
|
int fallocate(int fd, int mode, off_t offset, off_t len) |
|
3885 |
|
{ |
|
3886 |
|
static int (*old_fallocate)(int fd, int mode, off_t offset, off_t len) = NULL; |
|
3887 |
|
|
|
3888 |
|
if (!old_fallocate) |
|
3889 |
|
old_fallocate = ninedogs_dlsym("posix_fallocate"); |
|
3890 |
|
|
|
3891 |
|
my_trace(__func__, "", 'c', fd, mode, offset, len); |
|
3892 |
|
int ret = old_fallocate(fd, mode, offset, len); |
|
3893 |
|
my_trace(__func__, "", 'r', fd, mode, offset, len, ret); |
|
3894 |
|
|
|
3895 |
|
return ret; |
|
3896 |
|
} |
|
3897 |
|
|
|
3898 |
|
// TODO: trace |
|
3899 |
|
int flock(int fd, int operation) |
|
3900 |
|
{ |
|
3901 |
|
static int (*old_flock)(int fd, int operation) = NULL; |
|
3902 |
|
|
|
3903 |
|
if (!old_flock) |
|
3904 |
|
old_flock = ninedogs_dlsym("posix_flock"); |
|
3905 |
|
|
|
3906 |
|
my_trace(__func__, "", 'c', fd, operation); |
|
3907 |
|
int ret = old_flock(fd, operation); |
|
3908 |
|
my_trace(__func__, "", 'r', fd, operation, ret); |
|
3909 |
|
|
|
3910 |
|
return ret; |
|
3911 |
|
} |
|
3912 |
|
|
|
3913 |
|
// TODO: trace |
|
3914 |
|
int inotify_init(void) |
|
3915 |
|
{ |
|
3916 |
|
static int (*old_inotify_init)(void) = NULL; |
|
3917 |
|
|
|
3918 |
|
if (!old_inotify_init) |
|
3919 |
|
old_inotify_init = ninedogs_dlsym("inotify_init"); |
|
3920 |
|
|
|
3921 |
|
int ret = old_inotify_init(); |
|
3922 |
|
my_trace(__func__, "", 'R', ret); |
|
3923 |
|
if (ret != -1) |
|
3924 |
|
open_common_post(FD_NODE_INOTIFY, "", 0, 0, ret); |
|
3925 |
|
|
|
3926 |
|
return ret; |
|
3927 |
|
} |
|
3928 |
|
|
|
3929 |
|
// TODO: trace |
|
3930 |
|
int inotify_init1(int flags) |
|
3931 |
|
{ |
|
3932 |
|
static int (*old_inotify_init1)(int flags) = NULL; |
|
3933 |
|
|
|
3934 |
|
if (!old_inotify_init1) |
|
3935 |
|
old_inotify_init1 = ninedogs_dlsym("inotify_init1"); |
|
3936 |
|
|
|
3937 |
|
int ret = old_inotify_init1(flags); |
|
3938 |
|
my_trace(__func__, "", 'R', flags, ret); |
|
3939 |
|
if (ret != -1) |
|
3940 |
|
open_common_post(FD_NODE_INOTIFY, "", flags, 0, ret); |
|
3941 |
|
|
|
3942 |
|
return ret; |
|
3943 |
|
} |
|
3944 |
|
|
|
3945 |
|
// TODO: trace |
|
3946 |
|
int kill(pid_t pid, int sig) |
|
3947 |
|
{ |
|
3948 |
|
static int (*old_kill)(pid_t pid, int sig) = NULL; |
|
3949 |
|
|
|
3950 |
|
if (!old_kill) |
|
3951 |
|
old_kill = ninedogs_dlsym("kill"); |
|
3952 |
|
|
|
3953 |
|
my_trace(__func__, "", 'c', pid, sig); |
|
3954 |
|
int ret = old_kill(pid, sig); |
|
3955 |
|
my_trace(__func__, "", 'r', pid, sig, ret); |
|
3956 |
|
|
|
3957 |
|
return ret; |
|
3958 |
|
} |
|
3959 |
|
|
|
3960 |
|
// TODO: trace |
|
3961 |
|
int link(const char *oldpath, const char *newpath) |
|
3962 |
|
{ |
|
3963 |
|
static int (*old_link)(const char *oldpath, const char *newpath) = NULL; |
|
3964 |
|
|
|
3965 |
|
if (!old_link) |
|
3966 |
|
old_link = ninedogs_dlsym("link"); |
|
3967 |
|
|
|
3968 |
|
my_trace(__func__, "", 'c', oldpath, newpath); |
|
3969 |
|
int ret = old_link(oldpath, newpath); |
|
3970 |
|
my_trace(__func__, "", 'r', oldpath, newpath, ret); |
|
3971 |
|
|
|
3972 |
|
return ret; |
|
3973 |
|
} |
|
3974 |
|
|
|
3975 |
|
// TODO: trace |
|
3976 |
|
int linkat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, |
|
3977 |
|
int flags) |
|
3978 |
|
{ |
|
3979 |
|
static int (*old_linkat)(int olddirfd, const char *oldpath, |
|
3980 |
|
int newdirfd, const char *newpath, int flags) = NULL; |
|
3981 |
|
|
|
3982 |
|
if (!old_linkat) |
|
3983 |
|
old_linkat = ninedogs_dlsym("linkat"); |
|
3984 |
|
|
|
3985 |
|
my_trace(__func__, "", 'c', olddirfd, oldpath, newdirfd, newpath, flags); |
|
3986 |
|
int ret = old_linkat(olddirfd, oldpath, newdirfd, newpath, flags); |
|
3987 |
|
my_trace(__func__, "", 'r', olddirfd, oldpath, newdirfd, newpath, flags, ret); |
|
3988 |
|
|
|
3989 |
|
return ret; |
|
3990 |
|
} |
|
3991 |
|
|
|
3992 |
|
// TODO: trace |
|
3993 |
|
int madvise(void *addr, size_t length, int advice) |
|
3994 |
|
{ |
|
3995 |
|
static int (*old_madvise)(void *addr, size_t length, int advice) = NULL; |
|
3996 |
|
|
|
3997 |
|
if (!old_madvise) |
|
3998 |
|
old_madvise = ninedogs_dlsym("madvise"); |
|
3999 |
|
|
|
4000 |
|
my_trace(__func__, "", 'c', addr, length, advice); |
|
4001 |
|
int ret = old_madvise(addr, length, advice); |
|
4002 |
|
my_trace(__func__, "", 'r', addr, length, advice, ret); |
|
4003 |
|
|
|
4004 |
|
return ret; |
|
4005 |
|
} |
|
4006 |
|
|
|
4007 |
|
// TODO: trace |
|
4008 |
|
int mount(const char *source, const char *target, |
|
4009 |
|
const char *filesystemtype, unsigned long mountflags, const void *data) |
|
4010 |
|
{ |
|
4011 |
|
static int (*old_mount)(const char *source, const char *target, |
|
4012 |
|
const char *filesystemtype, unsigned long mountflags, |
|
4013 |
|
const void *data) = NULL; |
|
4014 |
|
|
|
4015 |
|
if (!old_mount) |
|
4016 |
|
old_mount = ninedogs_dlsym("mount"); |
|
4017 |
|
|
|
4018 |
|
my_trace(__func__, "", 'c', source, target, filesystemtype, mountflags, data); |
|
4019 |
|
int ret = old_mount(source, target, filesystemtype, mountflags, data); |
|
4020 |
|
my_trace(__func__, "", 'r', source, target, filesystemtype, mountflags, data, ret); |
|
4021 |
|
|
|
4022 |
|
return ret; |
|
4023 |
|
} |
|
4024 |
|
|
|
4025 |
|
// TODO: trace |
|
4026 |
|
int nice(int inc) |
|
4027 |
|
{ |
|
4028 |
|
static int (*old_nice)(int inc) = NULL; |
|
4029 |
|
|
|
4030 |
|
if (!old_nice) |
|
4031 |
|
old_nice = ninedogs_dlsym("nice"); |
|
4032 |
|
|
|
4033 |
|
int ret = old_nice(inc); |
|
4034 |
|
my_trace(__func__, "", 'R', inc, ret); |
|
4035 |
|
|
|
4036 |
|
return ret; |
|
4037 |
|
} |
|
4038 |
|
|
|
4039 |
|
// TODO: trace |
|
4040 |
|
int pipe(int pipefd[2]) |
|
4041 |
|
{ |
|
4042 |
|
static int (*old_pipe)(int pipefd[2]) = NULL; |
|
4043 |
|
|
|
4044 |
|
if (!old_pipe) |
|
4045 |
|
old_pipe = ninedogs_dlsym("pipe"); |
|
4046 |
|
|
|
4047 |
|
int ret = old_pipe(pipefd); |
|
4048 |
|
my_trace(__func__, "", 'R', pipefd, ret); |
|
4049 |
|
if (ret == 0) { |
|
4050 |
|
open_common_post(FD_NODE_PIPE, "", 0, 0, pipefd[0]); |
|
4051 |
|
open_common_post(FD_NODE_PIPE, "", 0, 0, pipefd[1]); |
|
4052 |
|
} |
|
4053 |
|
|
|
4054 |
|
return ret; |
|
4055 |
|
} |
|
4056 |
|
|
|
4057 |
|
// TODO: trace |
|
4058 |
|
int pipe2(int pipefd[2], int flags) |
|
4059 |
|
{ |
|
4060 |
|
static int (*old_pipe2)(int pipefd[2], int flags) = NULL; |
|
4061 |
|
|
|
4062 |
|
if (!old_pipe2) |
|
4063 |
|
old_pipe2 = ninedogs_dlsym("pipe2"); |
|
4064 |
|
|
|
4065 |
|
int ret = old_pipe2(pipefd, flags); |
|
4066 |
|
my_trace(__func__, "", 'R', pipefd, flags, ret); |
|
4067 |
|
if (ret == 0) { |
|
4068 |
|
open_common_post(FD_NODE_PIPE, "", flags, 0, pipefd[0]); |
|
4069 |
|
open_common_post(FD_NODE_PIPE, "", flags, 0, pipefd[1]); |
|
4070 |
|
} |
|
4071 |
|
|
|
4072 |
|
return ret; |
|
4073 |
|
} |
|
4074 |
|
|
|
4075 |
|
// TODO: trace |
|
4076 |
|
ssize_t readahead(int fd, off64_t offset, size_t count) |
|
4077 |
|
{ |
|
4078 |
|
static int (*old_readahead)(int fd, off64_t offset, size_t count) = NULL; |
|
4079 |
|
|
|
4080 |
|
if (!old_readahead) |
|
4081 |
|
old_readahead = ninedogs_dlsym("readahead"); |
|
4082 |
|
|
|
4083 |
|
my_trace(__func__, "", 'c', fd, offset, count); |
|
4084 |
|
ssize_t ret = old_readahead(fd, offset, count); |
|
4085 |
|
my_trace(__func__, "", 'r', fd, offset, count, ret); |
|
4086 |
|
|
|
4087 |
|
return ret; |
|
4088 |
|
} |
|
4089 |
|
|
|
4090 |
|
// TODO: trace |
|
4091 |
|
int rename(const char *oldpath, const char *newpath) |
|
4092 |
|
{ |
|
4093 |
|
static int (*old_rename)(const char *oldpath, const char *newpath) = NULL; |
|
4094 |
|
|
|
4095 |
|
if (!old_rename) |
|
4096 |
|
old_rename = ninedogs_dlsym("rename"); |
|
4097 |
|
|
|
4098 |
|
my_trace(__func__, "", 'c', oldpath, newpath); |
|
4099 |
|
int ret = old_rename(oldpath, newpath); |
|
4100 |
|
my_trace(__func__, "", 'r', oldpath, newpath, ret); |
|
4101 |
|
return ret; |
|
4102 |
|
} |
|
4103 |
|
|
|
4104 |
|
// TODO: trace |
|
4105 |
|
int renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath) |
|
4106 |
|
{ |
|
4107 |
|
static int (*old_renameat)(int olddirfd, const char *oldpath, |
|
4108 |
|
int newdirfd, const char *newpath) = NULL; |
|
4109 |
|
|
|
4110 |
|
if (!old_renameat) |
|
4111 |
|
old_renameat = ninedogs_dlsym("renameat"); |
|
4112 |
|
|
|
4113 |
|
my_trace(__func__, "", 'c', olddirfd, oldpath, newdirfd, newpath); |
|
4114 |
|
int ret = old_renameat(olddirfd, oldpath, newdirfd, newpath); |
|
4115 |
|
my_trace(__func__, "", 'r', olddirfd, oldpath, newdirfd, newpath, ret); |
|
4116 |
|
|
|
4117 |
|
return ret; |
|
4118 |
|
} |
|
4119 |
|
|
|
4120 |
|
// TODO: trace |
|
4121 |
|
int renameat2(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, |
|
4122 |
|
unsigned int flags) |
|
4123 |
|
{ |
|
4124 |
|
static int (*old_renameat2)(int olddirfd, const char *oldpath, |
|
4125 |
|
int newdirfd, const char *newpath, unsigned int flags) = NULL; |
|
4126 |
|
|
|
4127 |
|
if (!old_renameat2) |
|
4128 |
|
old_renameat2 = ninedogs_dlsym("renameat2"); |
|
4129 |
|
|
|
4130 |
|
my_trace(__func__, "", 'c', olddirfd, oldpath, newdirfd, newpath, flags); |
|
4131 |
|
int ret = old_renameat2(olddirfd, oldpath, newdirfd, newpath, flags); |
|
4132 |
|
my_trace(__func__, "", 'r', olddirfd, oldpath, newdirfd, newpath, flags, ret); |
|
4133 |
|
|
|
4134 |
|
return ret; |
|
4135 |
|
} |
|
4136 |
|
|
|
4137 |
|
// TODO: trace |
|
4138 |
|
int rmdir(const char *path) |
|
4139 |
|
{ |
|
4140 |
|
static int (*old_rmdir)(const char *path) = NULL; |
|
4141 |
|
|
|
4142 |
|
if (!old_rmdir) |
|
4143 |
|
old_rmdir = ninedogs_dlsym("rmdir"); |
|
4144 |
|
|
|
4145 |
|
my_trace(__func__, "", 'c', path); |
|
4146 |
|
int ret = old_rmdir(path); |
|
4147 |
|
my_trace(__func__, "", 'r', path, ret); |
|
4148 |
|
|
|
4149 |
|
return ret; |
|
4150 |
|
} |
|
4151 |
|
|
|
4152 |
|
// TODO: trace |
|
4153 |
|
int semop(int semid, struct sembuf *sops, size_t nsops) |
|
4154 |
|
{ |
|
4155 |
|
static int (*old_semop)(int semid, struct sembuf *sops, size_t nsops) = NULL; |
|
4156 |
|
|
|
4157 |
|
if (!old_semop) |
|
4158 |
|
old_semop = ninedogs_dlsym("semop"); |
|
4159 |
|
|
|
4160 |
|
my_trace(__func__, "", 'c', semid, sops, nsops); |
|
4161 |
|
int ret = old_semop(semid, sops, nsops); |
|
4162 |
|
my_trace(__func__, "", 'r', semid, sops, nsops, ret); |
|
4163 |
|
|
|
4164 |
|
return ret; |
|
4165 |
|
} |
|
4166 |
|
|
|
4167 |
|
// TODO: trace |
|
4168 |
|
int semtimedop(int semid, struct sembuf *sops, size_t nsops, const struct timespec *timeout) |
|
4169 |
|
{ |
|
4170 |
|
static int (*old_semtimedop)(int semid, struct sembuf *sops, size_t nsops, |
|
4171 |
|
const struct timespec *timeout) = NULL; |
|
4172 |
|
|
|
4173 |
|
if (!old_semtimedop) |
|
4174 |
|
old_semtimedop = ninedogs_dlsym("semtimedop"); |
|
4175 |
|
|
|
4176 |
|
my_trace(__func__, "", 'c', semid, sops, nsops, timeout); |
|
4177 |
|
int ret = old_semtimedop(semid, sops, nsops, timeout); |
|
4178 |
|
my_trace(__func__, "", 'r', semid, sops, nsops, timeout, ret); |
|
4179 |
|
|
|
4180 |
|
return ret; |
|
4181 |
|
} |
|
4182 |
|
|
|
4183 |
|
// TODO: trace |
|
4184 |
|
ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count) |
|
4185 |
|
{ |
|
4186 |
|
static int (*old_sendfile)(int out_fd, int in_fd, off_t *offset, size_t count) = NULL; |
|
4187 |
|
|
|
4188 |
|
if (!old_sendfile) |
|
4189 |
|
old_sendfile = ninedogs_dlsym("sendfile"); |
|
4190 |
|
|
|
4191 |
|
my_trace(__func__, "", 'c', out_fd, in_fd, offset, count); |
|
4192 |
|
ssize_t ret = old_sendfile(out_fd, in_fd, offset, count); |
|
4193 |
|
my_trace(__func__, "", 'r', out_fd, in_fd, offset, count, ret); |
|
4194 |
|
|
|
4195 |
|
return ret; |
|
4196 |
|
} |
|
4197 |
|
|
|
4198 |
|
// TODO: trace |
|
4199 |
|
int setns(int fd, int nstype) |
|
4200 |
|
{ |
|
4201 |
|
static int (*old_setns)(int fd, int nstype) = NULL; |
|
4202 |
|
|
|
4203 |
|
if (!old_setns) |
|
4204 |
|
old_setns = ninedogs_dlsym("setns"); |
|
4205 |
|
|
|
4206 |
|
my_trace(__func__, "", 'c', fd, nstype); |
|
4207 |
|
int ret = old_setns(fd, nstype); |
|
4208 |
|
my_trace(__func__, "", 'r', fd, nstype, ret); |
|
4209 |
|
|
|
4210 |
|
return ret; |
|
4211 |
|
} |
|
4212 |
|
|
|
4213 |
|
// TODO: trace |
|
4214 |
|
int socketpair(int domain, int type, int protocol, int sv[2]) |
|
4215 |
|
{ |
|
4216 |
|
static int (*old_socketpair)(int domain, int type, int protocol, int sv[2]) = NULL; |
|
4217 |
|
|
|
4218 |
|
if (!old_socketpair) |
|
4219 |
|
old_socketpair = ninedogs_dlsym("socketpair"); |
|
4220 |
|
|
|
4221 |
|
int ret = old_socketpair(domain, type, protocol, sv); |
|
4222 |
|
my_trace(__func__, "", 'R', domain, type, protocol, sv, ret); |
|
4223 |
|
if (ret == 0) { |
|
4224 |
|
open_common_post(FD_NODE_SOCKPAIR, "", 0, 0, sv[0]); |
|
4225 |
|
open_common_post(FD_NODE_SOCKPAIR, "", 0, 0, sv[1]); |
|
4226 |
|
} |
|
4227 |
|
|
|
4228 |
|
return ret; |
|
4229 |
|
} |
|
4230 |
|
|
|
4231 |
|
// TODO: trace |
|
4232 |
|
int statx(int dirfd, const char *restrict pathname, int flags, unsigned int mask, |
|
4233 |
|
struct statx *restrict statxbuf) |
|
4234 |
|
{ |
|
4235 |
|
static int (*old_statx)(int dirfd, const char *restrict pathname, int flags, |
|
4236 |
|
unsigned int mask, struct statx *restrict statxbuf) = NULL; |
|
4237 |
|
|
|
4238 |
|
if (!old_statx) |
|
4239 |
|
old_statx = ninedogs_dlsym("statx"); |
|
4240 |
|
|
|
4241 |
|
my_trace(__func__, "", 'c', dirfd, pathname, flags, mask, statxbuf); |
|
4242 |
|
int ret = old_statx(dirfd, pathname, flags, mask, statxbuf); |
|
4243 |
|
my_trace(__func__, "", 'r', dirfd, pathname, flags, mask, statxbuf, ret); |
|
4244 |
|
|
|
4245 |
|
return ret; |
|
4246 |
|
} |
|
4247 |
|
|
|
4248 |
|
// TODO: trace |
|
4249 |
|
int symlink(const char *target, const char *linkpath) |
|
4250 |
|
{ |
|
4251 |
|
static int (*old_symlink)(const char *target, const char *linkpath) = NULL; |
|
4252 |
|
|
|
4253 |
|
if (!old_symlink) |
|
4254 |
|
old_symlink = ninedogs_dlsym("symlink"); |
|
4255 |
|
|
|
4256 |
|
my_trace(__func__, "", 'c', target, linkpath); |
|
4257 |
|
int ret = old_symlink(target, linkpath); |
|
4258 |
|
my_trace(__func__, "", 'r', target, linkpath, ret); |
|
4259 |
|
return ret; |
|
4260 |
|
} |
|
4261 |
|
|
|
4262 |
|
// TODO: trace |
|
4263 |
|
int symlinkat(const char *target, int newdirfd, const char *linkpath) |
|
4264 |
|
{ |
|
4265 |
|
static int (*old_symlinkat)(const char *target, int newdirfd, const char *linkpath) = NULL; |
|
4266 |
|
|
|
4267 |
|
if (!old_symlinkat) |
|
4268 |
|
old_symlinkat = ninedogs_dlsym("symlinkat"); |
|
4269 |
|
|
|
4270 |
|
my_trace(__func__, "", 'c', target, newdirfd, linkpath); |
|
4271 |
|
int ret = old_symlinkat(target, newdirfd, linkpath); |
|
4272 |
|
my_trace(__func__, "", 'r', target, newdirfd, linkpath, ret); |
|
4273 |
|
return ret; |
|
4274 |
|
} |
|
4275 |
|
|
|
4276 |
|
// TODO: trace |
|
4277 |
|
void sync(void) |
|
4278 |
|
{ |
|
4279 |
|
static void (*old_sync)(void) = NULL; |
|
4280 |
|
|
|
4281 |
|
if (!old_sync) |
|
4282 |
|
old_sync = ninedogs_dlsym("sync"); |
|
4283 |
|
|
|
4284 |
|
my_trace(__func__, "", 'c'); |
|
4285 |
|
old_sync(); |
|
4286 |
|
my_trace(__func__, "", 'r'); |
|
4287 |
|
} |
|
4288 |
|
|
|
4289 |
|
// TODO: trace |
|
4290 |
|
int syncfs(int fd) |
|
4291 |
|
{ |
|
4292 |
|
static int (*old_syncfs)(int fd) = NULL; |
|
4293 |
|
|
|
4294 |
|
if (!old_syncfs) |
|
4295 |
|
old_syncfs = ninedogs_dlsym("syncfs"); |
|
4296 |
|
|
|
4297 |
|
my_trace(__func__, "", 'c', fd); |
|
4298 |
|
int ret = old_syncfs(fd); |
|
4299 |
|
my_trace(__func__, "", 'r', fd, ret); |
|
4300 |
|
|
|
4301 |
|
return ret; |
|
4302 |
|
} |
|
4303 |
|
|
|
4304 |
|
// TODO: trace |
|
4305 |
|
mode_t umask(mode_t mask) |
|
4306 |
|
{ |
|
4307 |
|
static mode_t (*old_umask)(mode_t mask) = NULL; |
|
4308 |
|
|
|
4309 |
|
if (!old_umask) |
|
4310 |
|
old_umask = ninedogs_dlsym("umask"); |
|
4311 |
|
|
|
4312 |
|
my_trace(__func__, "", 'c', mask); |
|
4313 |
|
mode_t ret = old_umask(mask); |
|
4314 |
|
my_trace(__func__, "", 'r', mask, ret); |
|
4315 |
|
|
|
4316 |
|
return ret; |
|
4317 |
|
} |
|
4318 |
|
|
|
4319 |
|
// TODO: trace |
|
4320 |
|
int umount(const char *target) |
|
4321 |
|
{ |
|
4322 |
|
static int (*old_umount)(const char *target) = NULL; |
|
4323 |
|
|
|
4324 |
|
if (!old_umount) |
|
4325 |
|
old_umount = ninedogs_dlsym("umount"); |
|
4326 |
|
|
|
4327 |
|
my_trace(__func__, "", 'c', target); |
|
4328 |
|
mode_t ret = old_umount(target); |
|
4329 |
|
my_trace(__func__, "", 'r', target, ret); |
|
4330 |
|
|
|
4331 |
|
return ret; |
|
4332 |
|
} |
|
4333 |
|
|
|
4334 |
|
// TODO: trace |
|
4335 |
|
int umount2(const char *target, int flags) |
|
4336 |
|
{ |
|
4337 |
|
static int (*old_umount2)(const char *target, int flags) = NULL; |
|
4338 |
|
|
|
4339 |
|
if (!old_umount2) |
|
4340 |
|
old_umount2 = ninedogs_dlsym("umount2"); |
|
4341 |
|
|
|
4342 |
|
my_trace(__func__, "", 'c', target, flags); |
|
4343 |
|
mode_t ret = old_umount2(target, flags); |
|
4344 |
|
my_trace(__func__, "", 'r', target, flags, ret); |
|
4345 |
|
|
|
4346 |
|
return ret; |
|
4347 |
|
} |
|
4348 |
|
|
|
4349 |
|
// TODO: trace |
|
4350 |
|
int unshare(int flags) |
|
4351 |
|
{ |
|
4352 |
|
static int (*old_unshare)(int flags) = NULL; |
|
4353 |
|
|
|
4354 |
|
if (!old_unshare) |
|
4355 |
|
old_unshare = ninedogs_dlsym("unshare"); |
|
4356 |
|
|
|
4357 |
|
my_trace(__func__, "", 'c', flags); |
|
4358 |
|
mode_t ret = old_unshare(flags); |
|
4359 |
|
my_trace(__func__, "", 'r', flags, ret); |
|
4360 |
|
|
|
4361 |
|
return ret; |
|
4362 |
|
} |
|
4363 |
|
|