Skip to content

Commit 3a25662

Browse files
authored
Work on reboot() (#28)
* Add error output for execv() and exit if it fails * Strip --erase on reboot
1 parent 99fdb51 commit 3a25662

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

cores/portduino/main.cpp

+19-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#include <sys/ioctl.h>
99
#include <bluetooth/bluetooth.h>
1010
#include <bluetooth/hci.h>
11+
#include <cerrno>
12+
#include <iostream>
13+
#include <cstring>
1114

1215
#ifdef USE_X11
1316
#include <thread>
@@ -154,11 +157,24 @@ void portduinoAddArguments(const struct argp_child &child,
154157
}
155158

156159
void reboot() {
157-
execv(progArgv[0], progArgv);
160+
int err = execv(progArgv[0], progArgv);
161+
printf("execv() returned %i!\n", err);
162+
std::cout << "error: " << std::strerror(errno) << '\n';
163+
exit(EXIT_FAILURE);
158164
}
159165

160166
int main(int argc, char *argv[]) {
161-
progArgv = argv;
167+
168+
progArgv = (char**) malloc((argc + 1) * sizeof(char*)); // New pointer array, argc + 1 to hold the final null
169+
int j = 0;
170+
for (int i = 0; i < argc; i++) { // iterate through the arguments, stripping out the erase command, to avoid erase on reboot()
171+
if (strcmp(argv[i], "-e") != 0 && strcmp(argv[i], "--erase") != 0 ) {
172+
progArgv[j] = argv[i];
173+
j++;
174+
}
175+
}
176+
progArgv[j] = NULL;
177+
162178
portduinoCustomInit();
163179

164180
auto *args = &portduinoArguments;
@@ -189,6 +205,7 @@ int main(int argc, char *argv[]) {
189205
int status = mkdir(fsRoot.c_str(), 0700);
190206
if (status != 0 && errno == EEXIST && args->erase) {
191207
// Remove contents of existing VFS root directory
208+
std::cout << "Erasing virtual Filesystem!" << std::endl;
192209
rmrf(const_cast<char*>(fsRoot.c_str()));
193210
}
194211

0 commit comments

Comments
 (0)