1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

native: set optional path with unix socket option

fixes #1045
This commit is contained in:
Ludwig Ortmann 2014-05-19 19:58:40 +02:00
parent e36590cda7
commit 1e5e19bc23
3 changed files with 16 additions and 2 deletions

View File

@ -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");

View File

@ -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 <sys/select.h>

View File

@ -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 <port>|-u]");
real_printf(" [-t <port>|-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 {