Changeset 897
- Timestamp:
- 31/08/2006 23:51:29 (5 years ago)
- File:
-
- 1 edited
-
box/chris/merge/lib/server/Daemon.cpp (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
box/chris/merge/lib/server/Daemon.cpp
r710 r897 22 22 #ifdef HAVE_SYSLOG_H 23 23 #include <syslog.h> 24 #endif25 26 #ifdef WIN3227 #include <ws2tcpip.h>28 24 #endif 29 25 … … 147 143 fprintf(stderr, "%s: failed to start: " 148 144 "failed to open configuration file: " 149 "%s \n", DaemonName(),145 "%s", DaemonName(), 150 146 mConfigFileName.c_str()); 151 147 #ifdef WIN32 … … 194 190 THROW_EXCEPTION(ServerException, DaemoniseFailed) 195 191 } 196 #endif // !WIN32197 192 198 193 // Server configuration … … 203 198 pidFileName = serverConfig.GetKeyValue("PidFile"); 204 199 FileHandleGuard<(O_WRONLY | O_CREAT | O_TRUNC), (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)> pidFile(pidFileName.c_str()); 205 206 #ifndef WIN32 200 207 201 // Handle changing to a different user 208 202 if(serverConfig.KeyExists("User")) … … 274 268 // open the log 275 269 ::openlog(DaemonName(), LOG_PID, LOG_LOCAL6); 276 277 270 // Log the start message 278 271 ::syslog(LOG_INFO, "Starting daemon (config: %s) (version " 279 272 BOX_VERSION ")", mConfigFileName.c_str()); 280 273 274 #ifndef WIN32 281 275 // Write PID to file 282 276 char pid[32]; 283 284 #ifdef WIN32285 int pidsize = sprintf(pid, "%d", (int)GetCurrentProcessId());286 #else287 277 int pidsize = sprintf(pid, "%d", (int)getpid()); 288 #endif289 290 278 if(::write(pidFile, pid, pidsize) != pidsize) 291 279 { … … 293 281 THROW_EXCEPTION(ServerException, DaemoniseFailed) 294 282 } 283 #endif 295 284 296 285 // Set up memory leak reporting … … 364 353 return 1; 365 354 } 366 367 #ifdef WIN32368 // Under win32 we must initialise the Winsock library369 // before using sockets370 371 WSADATA info;372 373 if (WSAStartup(0x0101, &info) == SOCKET_ERROR)374 {375 // will not run without sockets376 ::syslog(LOG_ERR, "Failed to initialise Windows Sockets");377 THROW_EXCEPTION(CommonException, Internal)378 }379 #endif380 381 int retcode = 0;382 355 383 356 // Main Daemon running … … 409 382 errors.c_str()); 410 383 // And give up 411 retcode = 1; 412 break; 384 return 1; 413 385 } 414 386 … … 438 410 "(%d/%d)", DaemonName(), e.what(), e.GetType(), 439 411 e.GetSubType()); 440 ret code =1;412 return 1; 441 413 } 442 414 catch(std::exception &e) … … 444 416 ::syslog(LOG_ERR, "%s: terminating due to exception %s", 445 417 DaemonName(), e.what()); 446 ret code =1;418 return 1; 447 419 } 448 420 catch(...) … … 450 422 ::syslog(LOG_ERR, "%s: terminating due to unknown exception", 451 423 DaemonName()); 452 retcode = 1; 453 } 454 455 #ifdef WIN32 456 WSACleanup(); 457 #endif 458 459 return retcode; 424 return 1; 425 } 426 427 return 0; 460 428 } 461 429
Note: See TracChangeset
for help on using the changeset viewer.
