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:
		
							parent
							
								
									d5aac198df
								
							
						
					
					
						commit
						7a3fd0c280
					
				
					 3 changed files with 33 additions and 0 deletions
				
			
		|  | @ -175,6 +175,27 @@ static bool checkSerial(const std::string &ser){ | ||||||
| #endif | #endif | ||||||
| #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(){ | Util::Config::Config(){ | ||||||
|   // global options here
 |   // global options here
 | ||||||
|   vals["debug"]["long"] = "debug"; |   vals["debug"]["long"] = "debug"; | ||||||
|  |  | ||||||
|  | @ -37,6 +37,7 @@ namespace Util{ | ||||||
| 
 | 
 | ||||||
|   public: |   public: | ||||||
|     static void setMutexAborter(void * mutex); |     static void setMutexAborter(void * mutex); | ||||||
|  |     static void wipeShm(); | ||||||
|     // variables
 |     // variables
 | ||||||
|     static bool is_active;     ///< Set to true by activate(), set to false by the signal handler.
 |     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.
 |     static bool is_restarting; ///< Set to true when restarting, set to false on boot.
 | ||||||
|  |  | ||||||
|  | @ -394,6 +394,14 @@ int main_loop(int argc, char **argv){ | ||||||
|     setenv("MIST_CONTROL", "1", 0); // Signal in the environment that the controller handles all children
 |     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::readConfigFromDisk(); | ||||||
|   Controller::writeConfig(); |   Controller::writeConfig(); | ||||||
|   if (!Controller::conf.is_active){return 0;} |   if (!Controller::conf.is_active){return 0;} | ||||||
|  | @ -642,6 +650,9 @@ int main(int argc, char **argv){ | ||||||
|       return main_loop(argc, argv); |       return main_loop(argc, argv); | ||||||
|     } |     } | ||||||
|     Util::Procs::fork_complete(); |     Util::Procs::fork_complete(); | ||||||
|  | #ifdef __CYGWIN__ | ||||||
|  |     setenv("NO_WIPE_SHM", "1", 1); | ||||||
|  | #endif | ||||||
|     if (pid == -1){ |     if (pid == -1){ | ||||||
|       FAIL_MSG("Unable to spawn controller process!"); |       FAIL_MSG("Unable to spawn controller process!"); | ||||||
|       return 2; |       return 2; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Thulinma
						Thulinma