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

Merge pull request #1145 from LudwigOrtmann/native_refactor_getpid

native: refactor getpid calls
parents 76347a85 166b88f1
No related branches found
No related tags found
No related merge requests found
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "nativenet.h" #include "nativenet.h"
#include "nativenet_internal.h" #include "nativenet_internal.h"
#endif #endif
#include "native_internal.h"
#define ENABLE_DEBUG (0) #define ENABLE_DEBUG (0)
#include "debug.h" #include "debug.h"
...@@ -36,12 +37,10 @@ void config_load(void) ...@@ -36,12 +37,10 @@ void config_load(void)
{ {
DEBUG("config_load()\n"); DEBUG("config_load()\n");
int pid = getpid(); sysconfig.id = _native_pid;
sysconfig.id = pid;
#ifdef MODULE_NATIVENET #ifdef MODULE_NATIVENET
_native_net_addr = pid; _native_net_addr = _native_pid;
#endif #endif
return; return;
......
...@@ -148,7 +148,7 @@ int init_unix_socket() ...@@ -148,7 +148,7 @@ int init_unix_socket()
} }
sa.sun_family = AF_UNIX; 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 */ unlink(sa.sun_path); /* remove stale socket */
if (bind(s, (struct sockaddr *)&sa, SUN_LEN(&sa)) == -1) { if (bind(s, (struct sockaddr *)&sa, SUN_LEN(&sa)) == -1) {
err(EXIT_FAILURE, "init_unix_socket: bind"); err(EXIT_FAILURE, "init_unix_socket: bind");
......
...@@ -53,7 +53,7 @@ NORETURN void core_panic(int crash_code, const char *message) ...@@ -53,7 +53,7 @@ NORETURN void core_panic(int crash_code, const char *message)
#if DEVELHELP #if DEVELHELP
/* since we're atop an Unix-like platform, /* since we're atop an Unix-like platform,
just use the (developer-)friendly core-dump feature */ just use the (developer-)friendly core-dump feature */
kill(getpid(), SIGTRAP); kill(_native_pid, SIGTRAP);
#else #else
(void) reboot(RB_AUTOBOOT); (void) reboot(RB_AUTOBOOT);
#endif #endif
......
...@@ -58,6 +58,7 @@ extern void* (*real_malloc)(size_t size); ...@@ -58,6 +58,7 @@ extern void* (*real_malloc)(size_t size);
extern void (*real_free)(void *ptr); extern void (*real_free)(void *ptr);
extern void* (*real_calloc)(size_t nmemb, size_t size); extern void* (*real_calloc)(size_t nmemb, size_t size);
extern void* (*real_realloc)(void *ptr, size_t size); extern void* (*real_realloc)(void *ptr, size_t size);
extern int (*real_getpid)(void);
/** /**
* data structures * data structures
...@@ -77,6 +78,7 @@ extern ucontext_t *_native_cur_ctx, *_native_isr_ctx; ...@@ -77,6 +78,7 @@ extern ucontext_t *_native_cur_ctx, *_native_isr_ctx;
extern const char *_progname; extern const char *_progname;
extern char **_native_argv; extern char **_native_argv;
extern pid_t _native_pid;
#ifdef MODULE_UART0 #ifdef MODULE_UART0
#include <sys/select.h> #include <sys/select.h>
......
...@@ -151,7 +151,7 @@ void _native_handle_tap_input(void) ...@@ -151,7 +151,7 @@ void _native_handle_tap_input(void)
#ifdef __MACH__ #ifdef __MACH__
void sigio_child() void sigio_child()
{ {
pid_t parent = getpid(); pid_t parent = _native_pid;
if ((sigio_child_pid = fork()) == -1) { if ((sigio_child_pid = fork()) == -1) {
err(EXIT_FAILURE, "sigio_child: fork"); err(EXIT_FAILURE, "sigio_child: fork");
...@@ -315,7 +315,7 @@ int tap_init(char *name) ...@@ -315,7 +315,7 @@ int tap_init(char *name)
sigio_child(); sigio_child();
#else #else
/* configure fds to send signals on io */ /* 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)"); err(EXIT_FAILURE, "tap_init(): fcntl(F_SETOWN)");
} }
......
...@@ -38,10 +38,12 @@ ...@@ -38,10 +38,12 @@
#include "tap.h" #include "tap.h"
int (*real_printf)(const char *format, ...); int (*real_printf)(const char *format, ...);
int (*real_getpid)(void);
int _native_null_in_pipe[2]; int _native_null_in_pipe[2];
int _native_null_out_file; int _native_null_out_file;
const char *_progname; const char *_progname;
char **_native_argv; char **_native_argv;
pid_t _native_pid;
/** /**
* initialize _native_null_in_pipe to allow for reading from stdin * initialize _native_null_in_pipe to allow for reading from stdin
...@@ -85,7 +87,7 @@ void _native_log_stdout(char *stdouttype) ...@@ -85,7 +87,7 @@ void _native_log_stdout(char *stdouttype)
} }
else if (strcmp(stdouttype, "file") == 0) { else if (strcmp(stdouttype, "file") == 0) {
char stdout_logname[255]; 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) { if ((stdout_outfile = creat(stdout_logname, 0666)) == -1) {
err(EXIT_FAILURE, "_native_log_stdout: open"); err(EXIT_FAILURE, "_native_log_stdout: open");
} }
...@@ -120,7 +122,7 @@ void _native_log_stderr(char *stderrtype) ...@@ -120,7 +122,7 @@ void _native_log_stderr(char *stderrtype)
} }
else if (strcmp(stderrtype, "file") == 0) { else if (strcmp(stderrtype, "file") == 0) {
char stderr_logname[255]; 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) { if ((stderr_outfile = creat(stderr_logname, 0666)) == -1) {
err(EXIT_FAILURE, "_native_log_stderr: open"); err(EXIT_FAILURE, "_native_log_stderr: open");
} }
...@@ -136,14 +138,12 @@ void _native_log_stderr(char *stderrtype) ...@@ -136,14 +138,12 @@ void _native_log_stderr(char *stderrtype)
void daemonize() void daemonize()
{ {
pid_t pid; if ((_native_pid = fork()) == -1) {
if ((pid = fork()) == -1) {
err(EXIT_FAILURE, "daemonize: fork"); err(EXIT_FAILURE, "daemonize: fork");
} }
if (pid > 0) { if (_native_pid > 0) {
real_printf("RIOT pid: %d\n", pid); real_printf("RIOT pid: %d\n", _native_pid);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
} }
...@@ -191,11 +191,12 @@ __attribute__((constructor)) static void startup(int argc, char **argv) ...@@ -191,11 +191,12 @@ __attribute__((constructor)) static void startup(int argc, char **argv)
*(void **)(&real_malloc) = dlsym(RTLD_NEXT, "malloc"); *(void **)(&real_malloc) = dlsym(RTLD_NEXT, "malloc");
*(void **)(&real_realloc) = dlsym(RTLD_NEXT, "realloc"); *(void **)(&real_realloc) = dlsym(RTLD_NEXT, "realloc");
*(void **)(&real_free) = dlsym(RTLD_NEXT, "free"); *(void **)(&real_free) = dlsym(RTLD_NEXT, "free");
*(void **)(&real_printf) = dlsym(RTLD_NEXT, "printf");
*(void **)(&real_getpid) = dlsym(RTLD_NEXT, "getpid");
*(void **)(&real_printf) = dlsym(RTLD_NEXT, "printf"); _native_argv = argv;
_native_argv = argv;
_progname = argv[0]; _progname = argv[0];
_native_pid = real_getpid();
int argp = 1; int argp = 1;
char *stderrtype = "stdio"; char *stderrtype = "stdio";
......
...@@ -314,6 +314,12 @@ void errx(int eval, const char *fmt, ...) ...@@ -314,6 +314,12 @@ void errx(int eval, const char *fmt, ...)
verrx(eval, fmt, argp); verrx(eval, fmt, argp);
} }
int getpid()
{
warnx("not implemented");
return -1;
}
#ifdef MODULE_VTIMER #ifdef MODULE_VTIMER
int _gettimeofday(struct timeval *tp, void *restrict tzp) { int _gettimeofday(struct timeval *tp, void *restrict tzp) {
(void) tzp; (void) tzp;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment