Exemple #1
0
int open(const char *path, int flags, ...)
{
	va_list ap;
	int     fd;
	int     mode;

	typeof(open) *original_open = dlsym(RTLD_NEXT, "open");

	va_start(ap, flags);
	mode = va_arg(ap, int);
	va_end(ap);

	debug(D_DEBUG, "open from %d.\n", getpid());
	fd = original_open(path, flags, mode);

	if(fd > -1)
	{
		struct monitor_msg msg;

		msg.type   = OPEN;
		msg.origin = getpid();
		strcpy(msg.data.s, path);

		send_monitor_msg(&msg);
	}

	return fd;
}
Exemple #2
0
int request_snapshot(struct rmonitor_file_watch_info *f) {
    const char *label = construct_label(f);

    if(!label) {
        //no snapshot to request
        return 0;
    }

    struct rmonitor_msg msg;
    bzero(&msg, sizeof(msg));

    msg.type   = SNAPSHOT;
    msg.error  = 0;
    msg.origin = -1;

    strncpy(msg.data.s, label, sizeof(msg.data.s) - 1);
    int status = send_monitor_msg(&msg);

    return status;
}
Exemple #3
0
pid_t fork()
{
	pid_t pid;
	typeof(fork) *original_fork = dlsym(RTLD_NEXT, "fork");

	debug(D_DEBUG, "fork from %d.\n", getpid());
	pid = original_fork();

	if(!pid)
	{
		struct monitor_msg msg;

		msg.type   = BRANCH;
		msg.origin = getpid();
		msg.data.p = getppid();

		send_monitor_msg(&msg);
	}

	return pid;
}
Exemple #4
0
FILE *fopen(const char *path, const char *mode)
{
	FILE *file;
	typeof(fopen) *original_fopen = dlsym(RTLD_NEXT, "fopen");

	debug(D_DEBUG, "fopen from %d.\n", getpid());
	file = original_fopen(path, mode);

	if(file)
	{
		struct monitor_msg msg;

		msg.type   = OPEN;
		msg.origin = getpid();
		strcpy(msg.data.s, path);

		send_monitor_msg(&msg);
	}

	return file;
}
Exemple #5
0
int fchdir(int fd)
{
	int   status;
	typeof(fchdir) *original_fchdir = dlsym(RTLD_NEXT, "fchdir");

	debug(D_DEBUG, "fchdir from %d.\n", getpid());
	status = original_fchdir(fd);

	if(status == 0)
	{
		struct monitor_msg msg;
		char  *newpath = getcwd(NULL, 0);

		msg.type   = CHDIR;
		msg.origin = getpid();
		strcpy(msg.data.s, newpath);
		free(newpath);

		send_monitor_msg(&msg);
	}

	return status;
}
Exemple #6
0
pid_t waitpid(pid_t pid, int *status, int options)
{
	int status_; //status might be NULL, thus we use status_ to retrive the state.
	pid_t pidb;
	typeof(waitpid) *original_waitpid = dlsym(RTLD_NEXT, "waitpid");

	debug(D_DEBUG, "waiting from %d.\n", getpid());
	pidb = original_waitpid(pid, &status_, options);

	if(WIFEXITED(status_) || WIFSIGNALED(status_))
	{
		struct monitor_msg msg;
		msg.type   = END;
		msg.origin = getpid();
		msg.data.p = pidb;

		send_monitor_msg(&msg);
	}

	if(status)
		*status = status_;

	return pid;
}