mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-24 05:53:49 +01:00
Merge pull request #1145 from LudwigOrtmann/native_refactor_getpid
native: refactor getpid calls
This commit is contained in:
commit
1e96570722
@ -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
|
||||
|
||||
@ -58,6 +58,7 @@ extern void* (*real_malloc)(size_t size);
|
||||
extern void (*real_free)(void *ptr);
|
||||
extern void* (*real_calloc)(size_t nmemb, size_t size);
|
||||
extern void* (*real_realloc)(void *ptr, size_t size);
|
||||
extern int (*real_getpid)(void);
|
||||
|
||||
/**
|
||||
* data structures
|
||||
@ -77,6 +78,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)");
|
||||
}
|
||||
|
||||
|
||||
@ -38,10 +38,12 @@
|
||||
#include "tap.h"
|
||||
|
||||
int (*real_printf)(const char *format, ...);
|
||||
int (*real_getpid)(void);
|
||||
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 +87,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 +122,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 +138,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 +191,12 @@ __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_getpid) = dlsym(RTLD_NEXT, "getpid");
|
||||
|
||||
*(void **)(&real_printf) = dlsym(RTLD_NEXT, "printf");
|
||||
|
||||
_native_argv = argv;
|
||||
_native_argv = argv;
|
||||
_progname = argv[0];
|
||||
_native_pid = real_getpid();
|
||||
|
||||
int argp = 1;
|
||||
char *stderrtype = "stdio";
|
||||
|
||||
@ -314,6 +314,12 @@ void errx(int eval, const char *fmt, ...)
|
||||
verrx(eval, fmt, argp);
|
||||
}
|
||||
|
||||
int getpid()
|
||||
{
|
||||
warnx("not implemented");
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef MODULE_VTIMER
|
||||
int _gettimeofday(struct timeval *tp, void *restrict tzp) {
|
||||
(void) tzp;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user