Only when running in Cygwin, auto-wipe shared memory files when the controller does its first boot, but skip on reboots and updates

This commit is contained in:
Thulinma 2024-06-11 16:16:23 +02:00
parent d5aac198df
commit 7a3fd0c280
3 changed files with 33 additions and 0 deletions

View file

@ -175,6 +175,27 @@ static bool checkSerial(const std::string &ser){
#endif
#endif
void Util::Config::wipeShm(){
DIR *d = opendir("/dev/shm");
char fileName[300];
struct dirent *dp;
uint64_t deleted = 0;
if (d){
do{
errno = 0;
if ((dp = readdir(d))){
if (strstr(dp->d_name, "Mst")){
snprintf(fileName, sizeof(fileName), "/dev/shm/%s", dp->d_name);
unlink(fileName);
++deleted;
}
}
}while (dp != NULL);
closedir(d);
}
if (deleted){WARN_MSG("Wiped %" PRIu64 " shared memory file(s)", deleted);}
}
Util::Config::Config(){
// global options here
vals["debug"]["long"] = "debug";

View file

@ -37,6 +37,7 @@ namespace Util{
public:
static void setMutexAborter(void * mutex);
static void wipeShm();
// variables
static bool is_active; ///< Set to true by activate(), set to false by the signal handler.
static bool is_restarting; ///< Set to true when restarting, set to false on boot.

View file

@ -393,6 +393,14 @@ int main_loop(int argc, char **argv){
}
setenv("MIST_CONTROL", "1", 0); // Signal in the environment that the controller handles all children
}
#ifdef __CYGWIN__
// Wipe shared memory, unless NO_WIPE_SHM is set
if (!getenv("NO_WIPE_SHM")){
Util::Config::wipeShm();
setenv("NO_WIPE_SHM", "1", 1);
}
#endif
Controller::readConfigFromDisk();
Controller::writeConfig();
@ -642,6 +650,9 @@ int main(int argc, char **argv){
return main_loop(argc, argv);
}
Util::Procs::fork_complete();
#ifdef __CYGWIN__
setenv("NO_WIPE_SHM", "1", 1);
#endif
if (pid == -1){
FAIL_MSG("Unable to spawn controller process!");
return 2;