Skip to content
Snippets Groups Projects
Commit 4c961bfb authored by Ludwig Knüpfer's avatar Ludwig Knüpfer
Browse files

native: refactor getpid calls

parent 76347a85
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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");
......
......@@ -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
......
......@@ -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>
......
......@@ -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)");
}
......
......@@ -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";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment