Skip to content

Commit 7a3fd0c

Browse files
committed
Only when running in Cygwin, auto-wipe shared memory files when the controller does its first boot, but skip on reboots and updates
1 parent d5aac19 commit 7a3fd0c

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

lib/config.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,27 @@ static bool checkSerial(const std::string &ser){
175175
#endif
176176
#endif
177177

178+
void Util::Config::wipeShm(){
179+
DIR *d = opendir("/dev/shm");
180+
char fileName[300];
181+
struct dirent *dp;
182+
uint64_t deleted = 0;
183+
if (d){
184+
do{
185+
errno = 0;
186+
if ((dp = readdir(d))){
187+
if (strstr(dp->d_name, "Mst")){
188+
snprintf(fileName, sizeof(fileName), "/dev/shm/%s", dp->d_name);
189+
unlink(fileName);
190+
++deleted;
191+
}
192+
}
193+
}while (dp != NULL);
194+
closedir(d);
195+
}
196+
if (deleted){WARN_MSG("Wiped %" PRIu64 " shared memory file(s)", deleted);}
197+
}
198+
178199
Util::Config::Config(){
179200
// global options here
180201
vals["debug"]["long"] = "debug";

lib/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ namespace Util{
3737

3838
public:
3939
static void setMutexAborter(void * mutex);
40+
static void wipeShm();
4041
// variables
4142
static bool is_active; ///< Set to true by activate(), set to false by the signal handler.
4243
static bool is_restarting; ///< Set to true when restarting, set to false on boot.

src/controller/controller.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,14 @@ int main_loop(int argc, char **argv){
393393
}
394394
setenv("MIST_CONTROL", "1", 0); // Signal in the environment that the controller handles all children
395395
}
396+
397+
#ifdef __CYGWIN__
398+
// Wipe shared memory, unless NO_WIPE_SHM is set
399+
if (!getenv("NO_WIPE_SHM")){
400+
Util::Config::wipeShm();
401+
setenv("NO_WIPE_SHM", "1", 1);
402+
}
403+
#endif
396404

397405
Controller::readConfigFromDisk();
398406
Controller::writeConfig();
@@ -642,6 +650,9 @@ int main(int argc, char **argv){
642650
return main_loop(argc, argv);
643651
}
644652
Util::Procs::fork_complete();
653+
#ifdef __CYGWIN__
654+
setenv("NO_WIPE_SHM", "1", 1);
655+
#endif
645656
if (pid == -1){
646657
FAIL_MSG("Unable to spawn controller process!");
647658
return 2;

0 commit comments

Comments
 (0)