-
Notifications
You must be signed in to change notification settings - Fork 8.2k
boards: native_sim: add reboot for native sim #87987
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
Merged
kartben
merged 1 commit into
zephyrproject-rtos:main
from
husqvarnagroup:af/native-sim-reboot
Apr 29, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| /* | ||
| * Copyright (c) 2025 GARDENA GmbH | ||
| * Copyright (c) 2025 Nordic Semiconductor ASA | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include "reboot_bottom.h" | ||
| #include "posix_board_if.h" | ||
|
|
||
| void sys_arch_reboot(int type) | ||
| { | ||
| (void)type; | ||
| native_set_reboot_on_exit(); | ||
| posix_exit(0); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* | ||
| * Copyright (c) 2025 GARDENA GmbH | ||
| * Copyright (c) 2025 Nordic Semiconductor ASA | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include <stdbool.h> | ||
| #include <errno.h> | ||
| #include <string.h> | ||
| #include <unistd.h> | ||
| #include <nsi_main.h> | ||
| #include <nsi_tasks.h> | ||
| #include <nsi_tracing.h> | ||
| #include <nsi_cmdline.h> | ||
|
|
||
| static const char module[] = "native_sim_reboot"; | ||
|
|
||
| static long close_open_fds(void) | ||
| { | ||
| /* close all open file descriptors except 0-2 */ | ||
| errno = 0; | ||
|
|
||
| long max_fd = sysconf(_SC_OPEN_MAX); | ||
|
|
||
| if (max_fd < 0) { | ||
| if (errno != 0) { | ||
| nsi_print_error_and_exit("%s: %s\n", module, strerror(errno)); | ||
| } else { | ||
| nsi_print_warning("%s: Cannot determine maximum number of file descriptors" | ||
| "\n", | ||
| module); | ||
| } | ||
| return max_fd; | ||
| } | ||
| for (int fd = 3; fd < max_fd; fd++) { | ||
| (void)close(fd); | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| static bool reboot_on_exit; | ||
|
|
||
| void native_set_reboot_on_exit(void) | ||
| { | ||
| reboot_on_exit = true; | ||
| } | ||
|
|
||
| void maybe_reboot(void) | ||
| { | ||
| char **argv; | ||
| int argc; | ||
|
|
||
| if (!reboot_on_exit) { | ||
| return; | ||
| } | ||
|
|
||
| reboot_on_exit = false; /* If we reenter it means we failed to reboot */ | ||
|
|
||
| nsi_get_cmd_line_args(&argc, &argv); | ||
|
|
||
| if (close_open_fds() < 0) { | ||
| nsi_exit(1); | ||
| } | ||
|
|
||
| nsi_print_warning("%s: Restarting process.\n", module); | ||
|
|
||
| (void)execv("/proc/self/exe", argv); | ||
|
|
||
| nsi_print_error_and_exit("%s: Failed to restart process, exiting (%s)\n", module, | ||
| strerror(errno)); | ||
| } | ||
|
|
||
| NSI_TASK(maybe_reboot, ON_EXIT_POST, 999); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * Copyright (c) 2025 GARDENA GmbH | ||
| * Copyright (c) 2025 Nordic Semiconductor ASA | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #ifndef BOARDS_NATIVE_NATIVE_SIM_REBOOT_BOTTOM_H | ||
| #define BOARDS_NATIVE_NATIVE_SIM_REBOOT_BOTTOM_H | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| void native_set_reboot_on_exit(void); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* BOARDS_NATIVE_NATIVE_SIM_REBOOT_BOTTOM_H */ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.