-
Notifications
You must be signed in to change notification settings - Fork 5
/
libnotty.c
63 lines (51 loc) · 1.15 KB
/
libnotty.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdio.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
typedef int (*open_t)(const char *pathname, int flags);
open_t libc_open;
open_t libc_open64;
static void notty_init()
{
void *libc;
char *error;
/* FIXME: Hack for Debian multiarch */
libc = dlopen("/lib/i386-linux-gnu/i686/cmov/libc.so.6", RTLD_LAZY);
if (!libc) {
fputs(dlerror(), stderr);
exit(1);
}
libc_open = dlsym(libc, "open");
if ((error = dlerror()) != NULL) {
fprintf(stderr, "%s\n", error);
exit(1);
}
libc_open64 = dlsym(libc, "open64");
if ((error = dlerror()) != NULL) {
fprintf(stderr, "%s\n", error);
exit(1);
}
}
int open(const char *pathname, int flags)
{
if (!strcmp(pathname, "/dev/tty")) {
fprintf(stderr, "INTERCEPTED open(%s, %#x)\n", pathname, flags);
errno = EINVAL;
return -1;
}
if (!libc_open)
notty_init();
return libc_open(pathname, flags);
}
int open64(const char *pathname, int flags)
{
if (!strcmp(pathname, "/dev/tty")) {
fprintf(stderr, "INTERCEPTED open64(%s, %#x)\n", pathname, flags);
errno = EINVAL;
return -1;
}
if (!libc_open64)
notty_init();
return libc_open64(pathname, flags);
}