(file) Return to ServerProcessUnix.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Service

  1 karl  1.8 //%2006////////////////////////////////////////////////////////////////////////
  2 h.sterling 1.1 //
  3                // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4                // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5                // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6                // IBM Corp.; EMC Corporation, The Open Group.
  7                // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8                // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9                // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10                // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl       1.8 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12                // EMC Corporation; Symantec Corporation; The Open Group.
 13 h.sterling 1.1 //
 14                // Permission is hereby granted, free of charge, to any person obtaining a copy
 15                // of this software and associated documentation files (the "Software"), to
 16                // deal in the Software without restriction, including without limitation the
 17                // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 18                // sell copies of the Software, and to permit persons to whom the Software is
 19                // furnished to do so, subject to the following conditions:
 20                // 
 21                // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22                // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 23                // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 24                // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 25                // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 26                // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 27                // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 28                // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 29                //
 30                //==============================================================================
 31                //
 32                //%/////////////////////////////////////////////////////////////////////////////
 33 kumpf      1.14 
 34 h.sterling 1.1  #include <fcntl.h>
 35                 #include <unistd.h>
 36 kumpf      1.14 
 37 h.sterling 1.1  #include <Pegasus/Common/Signal.h>
 38 kumpf      1.14 
 39 w.otsuka   1.4  #define MAX_WAIT_TIME 240
 40 h.sterling 1.1  
 41                 PEGASUS_USING_PEGASUS;
 42                 PEGASUS_USING_STD;
 43                 
 44                 Boolean handleSigUsr1 = false;
 45                 Boolean graveError = false;
 46                 
 47                 void sigUsr1Handler(int s_n, PEGASUS_SIGINFO_T * s_info, void * sig)
 48                 {
 49                     handleSigUsr1 = true;
 50                 }
 51                 
 52                 void sigTermHandler(int s_n, PEGASUS_SIGINFO_T * s_info, void * sig)
 53                 {
 54                     graveError= handleSigUsr1=true;
 55                 } 
 56                 
 57                 
 58                 //constructor
 59                 ServerProcess::ServerProcess() {}
 60                 
 61 h.sterling 1.1  //destructor
 62                 ServerProcess::~ServerProcess() {}
 63                 
 64                 // no-ops
 65                 void ServerProcess::cimserver_set_process(void* p) {}
 66                 void ServerProcess::cimserver_exitRC(int rc) {}
 67                 int ServerProcess::cimserver_initialize(void) { return 1; }
 68 marek      1.10 
 69                 // for all OSes supporting signals provide a cimserver_wait function
 70                 // that waits to be awakened by signal PEGASUS_SIGTERM or PEGASUS_SIGHUP
 71                 #ifdef PEGASUS_HAS_SIGNALS
 72                 int ServerProcess::cimserver_wait(void)
 73                 {
 74                     int sig = -1;
 75                     sigset_t set;
 76                     sigemptyset(&set);
 77                     sigaddset(&set, PEGASUS_SIGTERM);
 78                     sigaddset(&set, PEGASUS_SIGHUP);
 79                     errno = 0;
 80                     do
 81                     {
 82                 #if defined(PEGASUS_OS_ZOS) || defined(PEGASUS_OS_SOLARIS)
 83                         sig = sigwait(&set);
 84                 #else // else for platforms = LINUX, HPUX, AIX
 85                         sigwait(&set, &sig);
 86                 #endif
 87                     } while (errno == EINTR);
 88                     return sig;
 89 marek      1.10 }
 90                 #else
 91 h.sterling 1.1  int ServerProcess::cimserver_wait(void) { return 1; }
 92 marek      1.10 #endif
 93                 
 94 h.sterling 1.1  String ServerProcess::getHome(void) { return String::EMPTY; }
 95                 
 96                 // daemon_init , RW Stevens, "Advance UNIX Programming"
 97                 
 98                 int ServerProcess::cimserver_fork(void) 
 99                 { 
100 kumpf      1.14.2.1 #if defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION)
101                     
102                         getSigHandle()->registerHandler(SIGTERM, sigTermHandler);
103                         getSigHandle()->activate(SIGTERM);
104                         server_pid = getpid();
105                         umask(S_IRWXG | S_IRWXO);
106                     
107                         return 0;
108                     
109                     #else /* !defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) */
110                     
111 h.sterling 1.1          getSigHandle()->registerHandler(PEGASUS_SIGUSR1, sigUsr1Handler);
112                         getSigHandle()->activate(PEGASUS_SIGUSR1);
113                         getSigHandle()->registerHandler(SIGTERM, sigTermHandler);
114                         getSigHandle()->activate(SIGTERM);
115                      
116                       pid_t pid;
117                       if( (pid = fork() ) < 0) 
118                       {
119                           getSigHandle()->deactivate(PEGASUS_SIGUSR1);
120                           getSigHandle()->deactivate(SIGTERM);
121                           return(-1);
122                       }
123                       else if (pid != 0)
124                       {
125                           //
126                           // parent wait for child
127                           // if there is a problem with signal, parent process terminates
128                           // when waitTime expires
129                           //
130                           Uint32 waitTime = MAX_WAIT_TIME;
131                     
132 h.sterling 1.1            while(!handleSigUsr1 && waitTime > 0)
133                           {
134                             sleep(1);
135                             waitTime--;
136                           }
137 w.otsuka   1.4            if( !handleSigUsr1 )
138                             {
139                             MessageLoaderParms parms("src.Service.ServerProcessUnix.CIMSERVER_START_TIMEOUT",
140                               "The cimserver command timed out waiting for the CIM server to start.");
141                             PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
142                           }
143 h.sterling 1.1            exit(graveError);
144                       }
145                       
146                       setsid();
147 marek      1.10       umask(S_IRWXG | S_IRWXO );
148                     
149                       // spawned daemon process doesn't need the old signal handlers of its parent
150                       getSigHandle()->deactivate(PEGASUS_SIGUSR1);
151                       getSigHandle()->deactivate(SIGTERM);
152 h.sterling 1.1      
153                       return(0);
154 kumpf      1.14.2.1 
155                     #endif /* !defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) */
156 h.sterling 1.1      }
157                     
158                     
159                     // notify parent process to terminate so user knows that cimserver
160                     // is ready to serve CIM requests.
161                     void ServerProcess::notify_parent(int id)
162                     {
163                       pid_t ppid = getppid();
164                       if (id)
165                        kill(ppid, SIGTERM);
166                       else
167                        kill(ppid, PEGASUS_SIGUSR1); 
168                     }
169                     
170                     
171                     // Platform specific run
172 kumpf      1.7      int ServerProcess::platform_run(
173                         int argc,
174                         char** argv,
175                         Boolean shutdownOption,
176                         Boolean debugOutputOption)
177 h.sterling 1.1      {
178 kumpf      1.7          return cimserver_run(argc, argv, shutdownOption, debugOutputOption);
179 h.sterling 1.1      }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2