diff --git a/boards/native/drivers/native-uart0.c b/boards/native/drivers/native-uart0.c index 7e26a4f16a..ff4c1c1441 100644 --- a/boards/native/drivers/native-uart0.c +++ b/boards/native/drivers/native-uart0.c @@ -149,7 +149,13 @@ int init_unix_socket(void) } sa.sun_family = AF_UNIX; - snprintf(sa.sun_path, sizeof(sa.sun_path), "/tmp/riot.tty.%d", _native_pid); + + if (_native_unix_socket_path != NULL) { + snprintf(sa.sun_path, sizeof(sa.sun_path), "%s", _native_unix_socket_path); + } + else { + 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/include/native_internal.h b/cpu/native/include/native_internal.h index 4261a3f78c..043a463f52 100644 --- a/cpu/native/include/native_internal.h +++ b/cpu/native/include/native_internal.h @@ -79,6 +79,7 @@ extern ucontext_t *_native_cur_ctx, *_native_isr_ctx; extern const char *_progname; extern char **_native_argv; extern pid_t _native_pid; +extern const char *_native_unix_socket_path; #ifdef MODULE_UART0 #include diff --git a/cpu/native/startup.c b/cpu/native/startup.c index 559e012511..933922492f 100644 --- a/cpu/native/startup.c +++ b/cpu/native/startup.c @@ -44,6 +44,7 @@ int _native_null_out_file; const char *_progname; char **_native_argv; pid_t _native_pid; +const char *_native_unix_socket_path = NULL; /** * initialize _native_null_in_pipe to allow for reading from stdin @@ -160,7 +161,7 @@ void usage_exit(void) #endif #ifdef MODULE_UART0 - real_printf(" [-t |-u]"); + real_printf(" [-t |-u [path]]"); #endif real_printf(" [-d] [-e|-E] [-o]\n"); @@ -177,6 +178,7 @@ void usage_exit(void) #ifdef MODULE_UART0 real_printf("\ -u redirect stdio to UNIX socket\n\ + if no path is given /tmp/riot.tty.PID is used\n\ -t redirect stdio to TCP socket\n"); #endif @@ -272,6 +274,11 @@ __attribute__((constructor)) static void startup(int argc, char **argv) if (strcmp(stderrtype, "stdio") == 0) { stderrtype = "null"; } + + /* parse optional path */ + if ((argp + 1 < argc) && (argv[argp + 1][0] != '-')) { + _native_unix_socket_path = argv[++argp]; + } } #endif else {