Changeset 897


Ignore:
Timestamp:
31/08/2006 23:51:29 (5 years ago)
Author:
chris
Message:

Revert to trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • box/chris/merge/lib/server/Daemon.cpp

    r710 r897  
    2222#ifdef HAVE_SYSLOG_H 
    2323        #include <syslog.h> 
    24 #endif 
    25  
    26 #ifdef WIN32 
    27         #include <ws2tcpip.h> 
    2824#endif 
    2925 
     
    147143                                fprintf(stderr, "%s: failed to start: " 
    148144                                        "failed to open configuration file: " 
    149                                         "%s\n", DaemonName(),  
     145                                        "%s", DaemonName(),  
    150146                                        mConfigFileName.c_str()); 
    151147#ifdef WIN32 
     
    194190                        THROW_EXCEPTION(ServerException, DaemoniseFailed) 
    195191                } 
    196 #endif // !WIN32 
    197192                 
    198193                // Server configuration 
     
    203198                pidFileName = serverConfig.GetKeyValue("PidFile"); 
    204199                FileHandleGuard<(O_WRONLY | O_CREAT | O_TRUNC), (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)> pidFile(pidFileName.c_str()); 
    205          
    206 #ifndef WIN32    
     200                 
    207201                // Handle changing to a different user 
    208202                if(serverConfig.KeyExists("User")) 
     
    274268                // open the log 
    275269                ::openlog(DaemonName(), LOG_PID, LOG_LOCAL6); 
    276  
    277270                // Log the start message 
    278271                ::syslog(LOG_INFO, "Starting daemon (config: %s) (version "  
    279272                        BOX_VERSION ")", mConfigFileName.c_str()); 
    280273 
     274#ifndef WIN32 
    281275                // Write PID to file 
    282276                char pid[32]; 
    283  
    284 #ifdef WIN32 
    285                 int pidsize = sprintf(pid, "%d", (int)GetCurrentProcessId()); 
    286 #else 
    287277                int pidsize = sprintf(pid, "%d", (int)getpid()); 
    288 #endif 
    289  
    290278                if(::write(pidFile, pid, pidsize) != pidsize) 
    291279                { 
     
    293281                        THROW_EXCEPTION(ServerException, DaemoniseFailed) 
    294282                } 
     283#endif 
    295284                 
    296285                // Set up memory leak reporting 
     
    364353                return 1; 
    365354        } 
    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; 
    382355         
    383356        // Main Daemon running 
     
    409382                                                errors.c_str()); 
    410383                                        // And give up 
    411                                         retcode = 1; 
    412                                         break; 
     384                                        return 1; 
    413385                                } 
    414386                                 
     
    438410                        "(%d/%d)", DaemonName(), e.what(), e.GetType(),  
    439411                        e.GetSubType()); 
    440                 retcode = 1; 
     412                return 1; 
    441413        } 
    442414        catch(std::exception &e) 
     
    444416                ::syslog(LOG_ERR, "%s: terminating due to exception %s",  
    445417                        DaemonName(), e.what()); 
    446                 retcode = 1; 
     418                return 1; 
    447419        } 
    448420        catch(...) 
     
    450422                ::syslog(LOG_ERR, "%s: terminating due to unknown exception", 
    451423                        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; 
    460428} 
    461429 
Note: See TracChangeset for help on using the changeset viewer.