Changeset 1831
- Timestamp:
- 14/09/2007 22:23:23 (4 years ago)
- File:
-
- 1 edited
-
box/chris/general/bin/bbackupd/BackupDaemon.cpp (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
box/chris/general/bin/bbackupd/BackupDaemon.cpp
r1828 r1831 127 127 } 128 128 129 #ifdef WIN32 130 // Create the event object to signal from main thread to worker 131 // when new messages are queued to be sent to the command socket. 132 mhMessageToSendEvent = CreateEvent(NULL, TRUE, FALSE, NULL); 133 if(mhMessageToSendEvent == INVALID_HANDLE_VALUE) 134 { 135 BOX_ERROR("Failed to create event object: error " << 136 GetLastError()); 137 exit(1); 138 } 139 140 // Create the event object to signal from worker to main thread 141 // when a command has been received on the command socket. 142 mhCommandReceivedEvent = CreateEvent(NULL, TRUE, FALSE, NULL); 143 if(mhCommandReceivedEvent == INVALID_HANDLE_VALUE) 144 { 145 BOX_ERROR("Failed to create event object: error " << 146 GetLastError()); 147 exit(1); 148 } 149 150 // Create the critical section to protect the message queue 151 InitializeCriticalSection(&mMessageQueueLock); 152 153 // Create a thread to handle the named pipe 154 HANDLE hThread; 155 unsigned int dwThreadId; 156 157 hThread = (HANDLE) _beginthreadex( 158 NULL, // default security attributes 159 0, // use default stack size 160 HelperThread, // thread function 161 this, // argument to thread function 162 0, // use default creation flags 163 &dwThreadId); // returns the thread identifier 164 #endif 129 #ifdef WIN32 130 // Create the event object to signal from main thread to 131 // worker when new messages are queued to be sent to the 132 // command socket. 133 134 mhMessageToSendEvent = CreateEvent(NULL, TRUE, FALSE, NULL); 135 if(mhMessageToSendEvent == INVALID_HANDLE_VALUE) 136 { 137 BOX_ERROR("Failed to create event object: error " << 138 GetLastError()); 139 exit(1); 140 } 141 142 // Create the event object to signal from worker to main thread 143 // when a command has been received on the command socket. 144 145 mhCommandReceivedEvent = CreateEvent(NULL, TRUE, FALSE, NULL); 146 if(mhCommandReceivedEvent == INVALID_HANDLE_VALUE) 147 { 148 BOX_ERROR("Failed to create event object: error " << 149 GetLastError()); 150 exit(1); 151 } 152 153 // Create the critical section to protect the message queue 154 InitializeCriticalSection(&mMessageQueueLock); 155 #endif 165 156 } 166 157 … … 288 279 void BackupDaemon::RunHelperThread(void) 289 280 { 281 const Configuration &conf(GetConfiguration()); 290 282 mpCommandSocketInfo = new CommandSocketInfo; 291 283 WinNamedPipeStream& rSocket(mpCommandSocketInfo->mListeningSocket); … … 297 289 try 298 290 { 299 rSocket.Accept(BOX_NAMED_PIPE_NAME); 291 std::string socket = conf.GetKeyValue("CommandSocket"); 292 rSocket.Accept(socket); 300 293 } 301 294 catch (BoxException &e) … … 332 325 // Send a header line summarising the configuration 333 326 // and current state 334 const Configuration &conf(GetConfiguration());335 327 char summary[256]; 336 328 size_t summarySize = sprintf(summary, … … 513 505 Timers::Init(); 514 506 515 #ifdef WIN32 516 try 517 { 518 Run2(); 519 } 520 catch(...) 521 { 522 Timers::Cleanup(); 523 throw; 524 } 525 #else // ! WIN32 526 // Ignore SIGPIPE (so that if a command connection is broken, the daemon doesn't terminate) 527 ::signal(SIGPIPE, SIG_IGN); 528 529 // Create a command socket? 530 const Configuration &conf(GetConfiguration()); 531 if(conf.KeyExists("CommandSocket")) 532 { 533 // Yes, create a local UNIX socket 534 mpCommandSocketInfo = new CommandSocketInfo; 535 const char *socketName = conf.GetKeyValue("CommandSocket").c_str(); 536 ::unlink(socketName); 537 mpCommandSocketInfo->mListeningSocket.Listen(Socket::TypeUNIX, socketName); 538 } 507 #ifdef WIN32 508 // Create a thread to handle the named pipe 509 HANDLE hThread; 510 unsigned int dwThreadId; 511 512 hThread = (HANDLE) _beginthreadex( 513 NULL, // default security attributes 514 0, // use default stack size 515 HelperThread, // thread function 516 this, // argument to thread function 517 0, // use default creation flags 518 &dwThreadId); // returns the thread identifier 519 #else 520 // Ignore SIGPIPE so that if a command connection is broken, 521 // the daemon doesn't terminate. 522 ::signal(SIGPIPE, SIG_IGN); 523 524 // Create a command socket? 525 const Configuration &conf(GetConfiguration()); 526 if(conf.KeyExists("CommandSocket")) 527 { 528 // Yes, create a local UNIX socket 529 mpCommandSocketInfo = new CommandSocketInfo; 530 const char *socketName = 531 conf.GetKeyValue("CommandSocket").c_str(); 532 ::unlink(socketName); 533 mpCommandSocketInfo->mListeningSocket.Listen( 534 Socket::TypeUNIX, socketName); 535 } 536 #endif // !WIN32 539 537 540 538 // Handle things nicely on exceptions … … 545 543 catch(...) 546 544 { 545 #ifdef WIN32 546 // Don't delete the socket, as the helper thread 547 // is probably still using it. Let Windows clean 548 // up after us. 549 #else 547 550 if(mpCommandSocketInfo != 0) 548 551 { … … 564 567 mpCommandSocketInfo = 0; 565 568 } 569 #endif // WIN32 566 570 567 571 Timers::Cleanup(); … … 570 574 } 571 575 572 // Clean up 573 if(mpCommandSocketInfo != 0) 574 { 575 delete mpCommandSocketInfo; 576 mpCommandSocketInfo = 0; 577 } 578 #endif 576 #ifndef WIN32 577 // Clean up 578 if(mpCommandSocketInfo != 0) 579 { 580 delete mpCommandSocketInfo; 581 mpCommandSocketInfo = 0; 582 } 583 #endif 579 584 580 585 Timers::Cleanup();
Note: See TracChangeset
for help on using the changeset viewer.
