-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
native: allow for native to be resetable via SIGUSR1 #12517
Conversation
40129dc
to
943fd68
Compare
Test, works as advertised.
|
on FreeBSD I get:
|
cpu/native/startup.c
Outdated
@@ -577,6 +586,10 @@ __attribute__((constructor)) static void startup(int argc, char **argv, char **e | |||
periph_init(); | |||
board_init(); | |||
|
|||
/* should not error as SIGUSR is a valid error code and EINVAL is the only | |||
* specified error code => don't check return value */ | |||
signal(SIGUSR1, reset_handler); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to (should) use: https://github.com/RIOT-OS/RIOT/blob/master/cpu/native/irq_cpu.c#L412 instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or additionally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be.
cpu/native/startup.c
Outdated
@@ -390,6 +392,13 @@ extern init_func_t __init_array_start; | |||
extern init_func_t __init_array_end; | |||
#endif | |||
|
|||
static void reset_handler(int signo) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this to
static void _reset_handler(void)
{
pm_reboot();
}
and added:
register_interrupt(SIGUSR1, _reset_handler);
below and it works on FreeBSD, the signal(...)
is not needed
with the proposed changes it looks good:
|
I will apply the changes @smlng proposed and retest on Linux. |
cpu/native/include/native_internal.h
Outdated
* | ||
* @see e.g. https://www.freebsd.org/cgi/man.cgi?query=signal§ion=3 | ||
*/ | ||
typedef void (*real_sig_t) (int); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed anymore, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, sorry.... still on my first coffee ^^"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enjoy that first ☕️
cpu/native/include/native_internal.h
Outdated
@@ -121,6 +128,7 @@ extern int (*real_setitimer)(int which, const struct itimerval | |||
*__restrict value, struct itimerval *__restrict ovalue); | |||
extern int (*real_setsid)(void); | |||
extern int (*real_setsockopt)(int socket, ...); | |||
extern real_sig_t (*real_signal)(int sig, real_sig_t handler); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here?
cpu/native/syscalls.c
Outdated
@@ -87,6 +87,7 @@ int (*real_setitimer)(int which, const struct itimerval | |||
*restrict value, struct itimerval *restrict ovalue); | |||
int (*real_setsid)(void); | |||
int (*real_setsockopt)(int socket, ...); | |||
real_sig_t (*real_signal)(int sig, real_sig_t handler); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also not needed anymore?
when done, please squash and trigger Murdock please |
Cleaned out now unnecessary changes and squashed. |
a2ce01d
to
d670f77
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tested ACK: Linux and FreeBSD
I guess FreeBSD implies OSX? |
RIOT does not work on latest macOS, bc the latter is 64bit only now - so no macOS right now |
@x3ro are you still working on a 64-bit native port? (: |
There is I think twenty years of divergence between FreeBSD and Darwin ^^, but okay :-) |
Contribution description
Based on the discussion sparked by this comment #12448 (comment) I decided to provide a simple PoC of how to make
native
resetable.Testing procedure
Start a
native
instance in one terminal (application is arbitrary), find out its PID in another terminal, and then use the PID to reset e.g.:The
native
instance should then reboot (noticeable by a big fat!! REBOOT !!
printed)Issues/PRs references
#12448 (comment)