@@ -94,13 +94,16 @@ static void interposer_log(const char *level, const char *msg, ...)
94
94
}
95
95
96
96
// Function that takes the address of a function pointer and uses dlsym to load the system function into it
97
- static void load_real_func (void (* * target )(void ), const char * name )
97
+ static int load_real_func (void (* * target )(void ), const char * name )
98
98
{
99
+ if (* target != NULL ) return 0 ;
99
100
* target = dlsym (RTLD_NEXT , name );
100
101
if (target == NULL )
101
102
{
102
103
interposer_log (LOG_ERROR , "Error getting original '%s' function: %s" , name , dlerror ());
104
+ return -1 ;
103
105
}
106
+ return 0 ;
104
107
}
105
108
106
109
// Function pointers to original calls
@@ -313,6 +316,7 @@ int interposer_open_socket(js_interposer_t *interposer)
313
316
// Interpose epoll_ctl to make joystck socket fd non-blocking.
314
317
int epoll_ctl (int epfd , int op , int fd , struct epoll_event * event )
315
318
{
319
+ if (load_real_func ((void * )& real_epoll_ctl , "epoll_ctl" ) < 0 ) return -1 ;
316
320
if (op == EPOLL_CTL_ADD )
317
321
{
318
322
// Find matching device in interposer list
@@ -336,6 +340,7 @@ int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event)
336
340
// Interposer function for open syscall
337
341
int open (const char * pathname , int flags , ...)
338
342
{
343
+ if (load_real_func ((void * )& real_open , "open" ) < 0 ) return -1 ;
339
344
// Find matching device in interposer list
340
345
js_interposer_t * interposer = NULL ;
341
346
for (size_t i = 0 ; i < NUM_INTERPOSERS (); i ++ )
@@ -369,6 +374,7 @@ int open(const char *pathname, int flags, ...)
369
374
// Interposer function for open64
370
375
int open64 (const char * pathname , int flags , ...)
371
376
{
377
+ if (load_real_func ((void * )& real_open64 , "open64" ) < 0 ) return -1 ;
372
378
// Find matching device in interposer list
373
379
js_interposer_t * interposer = NULL ;
374
380
for (size_t i = 0 ; i < NUM_INTERPOSERS (); i ++ )
@@ -618,6 +624,7 @@ int intercept_ev_ioctl(js_interposer_t *interposer, int fd, unsigned long reques
618
624
// Interposer function for ioctl syscall
619
625
int ioctl (int fd , unsigned long request , ...)
620
626
{
627
+ if (load_real_func ((void * )& real_ioctl , "ioctl" ) < 0 ) return -1 ;
621
628
va_list args ;
622
629
va_start (args , request );
623
630
void * arg = va_arg (args , void * );
0 commit comments