[go: nahoru, domu]

Skip to content

Commit

Permalink
Merge pull request dnschneid#1973 from mkasick/freon
Browse files Browse the repository at this point in the history
freon: Intercept open64 calls; fixes Xorg on Debian stretch-armhf.
  • Loading branch information
dnschneid committed Jul 30, 2015
2 parents aba2c94 + 3477bab commit 34f1b78
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions src/freon.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ static int lockfd = -1;

static int (*orig_ioctl)(int d, int request, void* data);
static int (*orig_open)(const char *pathname, int flags, mode_t mode);
static int (*orig_open64)(const char *pathname, int flags, mode_t mode);
static int (*orig_close)(int fd);

static void preload_init() {
orig_ioctl = dlsym(RTLD_NEXT, "ioctl");
orig_open = dlsym(RTLD_NEXT, "open");
orig_open64 = dlsym(RTLD_NEXT, "open64");
orig_close = dlsym(RTLD_NEXT, "close");
}

Expand Down Expand Up @@ -152,24 +154,19 @@ int ioctl(int fd, unsigned long int request, ...) {
return ret;
}

int open(const char *pathname, int flags, ...) {
if (!orig_open) preload_init();

va_list argp;
va_start(argp, flags);
int mode = va_arg(argp, int);

TRACE("open %s\n", pathname);
static int _open(int (*origfunc)(const char *pathname, int flags, mode_t mode),
const char *origname, const char *pathname, int flags, mode_t mode) {
TRACE("%s %s\n", origname, pathname);
if (!strcmp(pathname, "/dev/tty0")) {
tty0fd = orig_open("/dev/null", flags, mode);
tty0fd = origfunc("/dev/null", flags, mode);
return tty0fd;
} else if (!strcmp(pathname, "/dev/tty7")) {
tty7fd = orig_open("/dev/null", flags, mode);
tty7fd = origfunc("/dev/null", flags, mode);
return tty7fd;
} else {
const char* event = "/dev/input/event";
int fd = orig_open(pathname, flags, mode);
TRACE("open %s %d\n", pathname, fd);
int fd = origfunc(pathname, flags, mode);
TRACE("%s %s %d\n", origname, pathname, fd);
if (!strncmp(pathname, event, strlen(event))) {
TRACE("GRAB\n");
orig_ioctl(fd, EVIOCGRAB, (void *) 1);
Expand All @@ -178,6 +175,28 @@ int open(const char *pathname, int flags, ...) {
}
}

int open(const char *pathname, int flags, ...) {
if (!orig_open) preload_init();

va_list argp;
va_start(argp, flags);
mode_t mode = va_arg(argp, mode_t);
va_end(argp);

return _open(orig_open, "open", pathname, flags, mode);
}

int open64(const char *pathname, int flags, ...) {
if (!orig_open64) preload_init();

va_list argp;
va_start(argp, flags);
mode_t mode = va_arg(argp, mode_t);
va_end(argp);

return _open(orig_open64, "open64", pathname, flags, mode);
}

int close(int fd) {
if (!orig_close) preload_init();

Expand Down

0 comments on commit 34f1b78

Please sign in to comment.