diff --git a/boards/native/board_config.c b/boards/native/board_config.c index 68d3e9bb425085cd63c80beba31b707a44b49527..512d4eb1724b42f273a4736c279f1d6d27eecf0a 100644 --- a/boards/native/board_config.c +++ b/boards/native/board_config.c @@ -25,6 +25,7 @@ #include "nativenet.h" #include "nativenet_internal.h" #endif +#include "native_internal.h" #define ENABLE_DEBUG (0) #include "debug.h" @@ -36,12 +37,10 @@ void config_load(void) { DEBUG("config_load()\n"); - int pid = getpid(); - - sysconfig.id = pid; + sysconfig.id = _native_pid; #ifdef MODULE_NATIVENET - _native_net_addr = pid; + _native_net_addr = _native_pid; #endif return; diff --git a/boards/native/drivers/native-uart0.c b/boards/native/drivers/native-uart0.c index 1f2fb3c4081a45a04cd612b43acf5208fa9e9a2b..0711c15b8eaf97b5a6a5fc35ce73d0b9e53a16f1 100644 --- a/boards/native/drivers/native-uart0.c +++ b/boards/native/drivers/native-uart0.c @@ -148,7 +148,7 @@ int init_unix_socket() } sa.sun_family = AF_UNIX; - snprintf(sa.sun_path, sizeof(sa.sun_path), "/tmp/riot.tty.%d", getpid()); + snprintf(sa.sun_path, sizeof(sa.sun_path), "/tmp/riot.tty.%d", _native_pid); unlink(sa.sun_path); /* remove stale socket */ if (bind(s, (struct sockaddr *)&sa, SUN_LEN(&sa)) == -1) { err(EXIT_FAILURE, "init_unix_socket: bind"); diff --git a/cpu/native/crash.c b/cpu/native/crash.c index b6f05323524587f2b5757503dc33946d5d250951..08c38621b54a687304dddfa5de486cf0ae7e2772 100644 --- a/cpu/native/crash.c +++ b/cpu/native/crash.c @@ -53,7 +53,7 @@ NORETURN void core_panic(int crash_code, const char *message) #if DEVELHELP /* since we're atop an Unix-like platform, just use the (developer-)friendly core-dump feature */ - kill(getpid(), SIGTRAP); + kill(_native_pid, SIGTRAP); #else (void) reboot(RB_AUTOBOOT); #endif diff --git a/cpu/native/include/native_internal.h b/cpu/native/include/native_internal.h index cf9bf042416fb3c61a9da049f52e49545c34e7c2..5c4ae5caf952fe6e5c51243eeaac41e0aae1af81 100644 --- a/cpu/native/include/native_internal.h +++ b/cpu/native/include/native_internal.h @@ -77,6 +77,7 @@ extern ucontext_t *_native_cur_ctx, *_native_isr_ctx; extern const char *_progname; extern char **_native_argv; +extern pid_t _native_pid; #ifdef MODULE_UART0 #include <sys/select.h> diff --git a/cpu/native/net/tap.c b/cpu/native/net/tap.c index 52ed19da21abc1f1136d179c1166e8f2b484babe..185a975af1f0f1daada2b41b8299bac523823992 100644 --- a/cpu/native/net/tap.c +++ b/cpu/native/net/tap.c @@ -151,7 +151,7 @@ void _native_handle_tap_input(void) #ifdef __MACH__ void sigio_child() { - pid_t parent = getpid(); + pid_t parent = _native_pid; if ((sigio_child_pid = fork()) == -1) { err(EXIT_FAILURE, "sigio_child: fork"); @@ -315,7 +315,7 @@ int tap_init(char *name) sigio_child(); #else /* configure fds to send signals on io */ - if (fcntl(_native_tap_fd, F_SETOWN, getpid()) == -1) { + if (fcntl(_native_tap_fd, F_SETOWN, _native_pid) == -1) { err(EXIT_FAILURE, "tap_init(): fcntl(F_SETOWN)"); } diff --git a/cpu/native/startup.c b/cpu/native/startup.c index 432760dc23aed802087f4ef942eddb87166dcf9a..a45e3688ac23ca59cd172be1fed37a6260ddd72e 100644 --- a/cpu/native/startup.c +++ b/cpu/native/startup.c @@ -42,6 +42,7 @@ int _native_null_in_pipe[2]; int _native_null_out_file; const char *_progname; char **_native_argv; +pid_t _native_pid; /** * initialize _native_null_in_pipe to allow for reading from stdin @@ -85,7 +86,7 @@ void _native_log_stdout(char *stdouttype) } else if (strcmp(stdouttype, "file") == 0) { char stdout_logname[255]; - snprintf(stdout_logname, sizeof(stdout_logname), "/tmp/riot.stdout.%d", getpid()); + snprintf(stdout_logname, sizeof(stdout_logname), "/tmp/riot.stdout.%d", _native_pid); if ((stdout_outfile = creat(stdout_logname, 0666)) == -1) { err(EXIT_FAILURE, "_native_log_stdout: open"); } @@ -120,7 +121,7 @@ void _native_log_stderr(char *stderrtype) } else if (strcmp(stderrtype, "file") == 0) { char stderr_logname[255]; - snprintf(stderr_logname, sizeof(stderr_logname), "/tmp/riot.stderr.%d", getpid()); + snprintf(stderr_logname, sizeof(stderr_logname), "/tmp/riot.stderr.%d", _native_pid); if ((stderr_outfile = creat(stderr_logname, 0666)) == -1) { err(EXIT_FAILURE, "_native_log_stderr: open"); } @@ -136,14 +137,12 @@ void _native_log_stderr(char *stderrtype) void daemonize() { - pid_t pid; - - if ((pid = fork()) == -1) { + if ((_native_pid = fork()) == -1) { err(EXIT_FAILURE, "daemonize: fork"); } - if (pid > 0) { - real_printf("RIOT pid: %d\n", pid); + if (_native_pid > 0) { + real_printf("RIOT pid: %d\n", _native_pid); exit(EXIT_SUCCESS); } } @@ -191,11 +190,11 @@ __attribute__((constructor)) static void startup(int argc, char **argv) *(void **)(&real_malloc) = dlsym(RTLD_NEXT, "malloc"); *(void **)(&real_realloc) = dlsym(RTLD_NEXT, "realloc"); *(void **)(&real_free) = dlsym(RTLD_NEXT, "free"); + *(void **)(&real_printf) = dlsym(RTLD_NEXT, "printf"); - *(void **)(&real_printf) = dlsym(RTLD_NEXT, "printf"); - - _native_argv = argv; + _native_argv = argv; _progname = argv[0]; + _native_pid = getpid(); int argp = 1; char *stderrtype = "stdio";