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