diff --git a/boards/native/drivers/native-uart0.c b/boards/native/drivers/native-uart0.c index ff4c1c1441..d58139aa7a 100644 --- a/boards/native/drivers/native-uart0.c +++ b/boards/native/drivers/native-uart0.c @@ -156,7 +156,7 @@ int init_unix_socket(void) else { snprintf(sa.sun_path, sizeof(sa.sun_path), "/tmp/riot.tty.%d", _native_pid); } - unlink(sa.sun_path); /* remove stale socket */ + real_unlink(sa.sun_path); /* remove stale socket */ if (bind(s, (struct sockaddr *)&sa, SUN_LEN(&sa)) == -1) { err(EXIT_FAILURE, "init_unix_socket: bind"); } @@ -183,11 +183,11 @@ void handle_uart_in(void) /* end of file / socket closed */ if (_native_uart_conn != 0) { if (_native_null_out_file != -1) { - if (dup2(_native_null_out_file, STDOUT_FILENO) == -1) { + if (real_dup2(_native_null_out_file, STDOUT_FILENO) == -1) { err(EXIT_FAILURE, "handle_uart_in: dup2(STDOUT_FILENO)"); } } - if (dup2(_native_null_in_pipe[0], STDIN_FILENO) == -1) { + if (real_dup2(_native_null_in_pipe[0], STDIN_FILENO) == -1) { err(EXIT_FAILURE, "handle_uart_in: dup2(STDIN_FILENO)"); } _native_uart_conn = 0; @@ -221,10 +221,10 @@ void handle_uart_sock(void) warnx("handle_uart_sock: successfully accepted socket"); } - if (dup2(s, STDOUT_FILENO) == -1) { + if (real_dup2(s, STDOUT_FILENO) == -1) { err(EXIT_FAILURE, "handle_uart_sock: dup2()"); } - if (dup2(s, STDIN_FILENO) == -1) { + if (real_dup2(s, STDIN_FILENO) == -1) { err(EXIT_FAILURE, "handle_uart_sock: dup2()"); } _native_syscall_leave(); diff --git a/cpu/native/include/native_internal.h b/cpu/native/include/native_internal.h index 27befb3e7c..902d9e1fd6 100644 --- a/cpu/native/include/native_internal.h +++ b/cpu/native/include/native_internal.h @@ -61,6 +61,10 @@ extern void* (*real_realloc)(void *ptr, size_t size); extern int (*real_getpid)(void); extern int (*real_pipe)(int[2]); extern int (*real_close)(int); +extern int (*real_fork)(void); +extern int (*real_dup2)(int, int); +extern int (*real_unlink)(const char *); +extern int (*real_execve)(const char *, char *const[], char *const[]); /** * data structures diff --git a/cpu/native/native_cpu.c b/cpu/native/native_cpu.c index d9874ec9fa..b146c7606f 100644 --- a/cpu/native/native_cpu.c +++ b/cpu/native/native_cpu.c @@ -69,7 +69,7 @@ int reboot_arch(int mode) printf("\n\n\t\t!! REBOOT !!\n\n"); - if (execve(_native_argv[0], _native_argv, NULL) == -1) { + if (real_execve(_native_argv[0], _native_argv, NULL) == -1) { err(EXIT_FAILURE, "reboot: execve"); } diff --git a/cpu/native/net/tap.c b/cpu/native/net/tap.c index 22a514f677..6acc0db076 100644 --- a/cpu/native/net/tap.c +++ b/cpu/native/net/tap.c @@ -153,7 +153,7 @@ void sigio_child() { pid_t parent = _native_pid; - if ((sigio_child_pid = fork()) == -1) { + if ((sigio_child_pid = real_fork()) == -1) { err(EXIT_FAILURE, "sigio_child: fork"); } diff --git a/cpu/native/startup.c b/cpu/native/startup.c index 51c88bb3f1..e7cb1eb921 100644 --- a/cpu/native/startup.c +++ b/cpu/native/startup.c @@ -62,7 +62,7 @@ void _native_null_in(char *stdiotype) return; } - if (dup2(_native_null_in_pipe[0], STDIN_FILENO) == -1) { + if (real_dup2(_native_null_in_pipe[0], STDIN_FILENO) == -1) { err(EXIT_FAILURE, "_native_null_in: dup2(STDIN_FILENO)"); } } @@ -97,7 +97,7 @@ void _native_log_stdout(char *stdouttype) errx(EXIT_FAILURE, "_native_log_stdout: unknown log type"); } - if (dup2(stdout_outfile, STDOUT_FILENO) == -1) { + if (real_dup2(stdout_outfile, STDOUT_FILENO) == -1) { err(EXIT_FAILURE, "_native_log_stdout: dup2(STDOUT_FILENO)"); } _native_null_out_file = stdout_outfile; @@ -132,14 +132,14 @@ void _native_log_stderr(char *stderrtype) errx(EXIT_FAILURE, "_native_log_stderr: unknown log type"); } - if (dup2(stderr_outfile, STDERR_FILENO) == -1) { + if (real_dup2(stderr_outfile, STDERR_FILENO) == -1) { err(EXIT_FAILURE, "_native_log_stderr: dup2(STDERR_FILENO)"); } } void daemonize(void) { - if ((_native_pid = fork()) == -1) { + if ((_native_pid = real_fork()) == -1) { err(EXIT_FAILURE, "daemonize: fork"); } @@ -201,6 +201,10 @@ __attribute__((constructor)) static void startup(int argc, char **argv) *(void **)(&real_getpid) = dlsym(RTLD_NEXT, "getpid"); *(void **)(&real_pipe) = dlsym(RTLD_NEXT, "pipe"); *(void **)(&real_close) = dlsym(RTLD_NEXT, "close"); + *(void **)(&real_fork) = dlsym(RTLD_NEXT, "fork"); + *(void **)(&real_dup2) = dlsym(RTLD_NEXT, "dup2"); + *(void **)(&real_unlink) = dlsym(RTLD_NEXT, "unlink"); + *(void **)(&real_execve) = dlsym(RTLD_NEXT, "execve"); _native_argv = argv; _progname = argv[0]; diff --git a/cpu/native/syscalls.c b/cpu/native/syscalls.c index fffca56a95..d784b8b2b9 100644 --- a/cpu/native/syscalls.c +++ b/cpu/native/syscalls.c @@ -56,6 +56,10 @@ void* (*real_calloc)(size_t nmemb, size_t size); void* (*real_realloc)(void *ptr, size_t size); int (*real_pipe)(int[2]); int (*real_close)(int); +int (*real_fork)(void); +int (*real_dup2)(int, int); +int (*real_unlink)(const char *); +int (*real_execve)(const char *, char *const[], char *const[]); void _native_syscall_enter(void) {