162 #ifdef HAVE_SYS_TYPES_H
163 # include <sys/types.h>
166 #ifdef HAVE_SYS_STAT_H
167 # include <sys/stat.h>
174 #if defined(__VMS) && __CRTL_VER < 70000000
175 # include <omniVMS/unlink.hxx>
180 # include <winbase.h>
181 # define stat(x,y) _stat(x,y)
182 # define unlink(x) _unlink(x)
183 # define STRUCT_STAT struct _stat
185 # define STRUCT_STAT struct stat
196 #ifdef HAVE_SYS_PARAM_H
197 # include <sys/param.h>
213 #if defined(HAVE_FSTREAM_OPEN)
214 # define FLAG_TRUNCATE ios::trunc
215 # define FLAG_APPEND ios::app
217 #elif defined(HAVE_FSTREAM_ATTACH)
218 # if defined(__WIN32__)
220 # elif defined(O_SYNC)
221 # define FLAG_SYNC O_SYNC
223 # define FLAG_SYNC O_FSYNC
225 # define FLAG_TRUNCATE O_CREAT|O_TRUNC
226 # define FLAG_APPEND O_APPEND
228 # error "Can't open a file without ofstream::open() or ofstream::attach()"
236 # define VMS_SEMICOLON ";"
238 # define VMS_SEMICOLON
263 time_t
t =time(NULL);
265 if(strncmp(p, &
str[1], 24) == 0)
267 strncpy(&
str[1], p, 24);
285 _activeFilename(NULL),
286 _backupFilename(NULL),
287 _checkpointFilename(NULL),
290 _checkpointNeeded(true),
300 DB(20,
"omniEventsLog::~omniEventsLog()");
320 return(::stat(filename,&sb) == 0);
331 if(endPointNoListen && endPointNoListen[0])
332 ecf->
addattr(
string(
"endPointNoListen=")+endPointNoListen);
344 cerr <<
"Error: cannot read database file '"
351 " to recover the server's state, or delete it to create a new\n"
352 " database file." << endl;
357 persiststream.close();
361 const char* errorStr =NULL;
364 errorStr=
"Can't find EventChannelFactory.";
365 else if(ecf->
attrLong(
"port",-1)<=0)
366 errorStr=
"EventChannelFactory is not assigned a valid port.";
371 <<errorStr<<
" Try deleting the file (and any backup)."<<endl;
381 assert(initialState!=NULL);
391 cerr <<
"Error: cannot "
394 <<
"': " << strerror(errno) << endl;
395 cerr <<
"\nUse option '-l' or set the environment variable "
397 <<
"\nto specify the directory where the files are kept.\n"
409 CORBA::Object_var obj;
410 assert(!CORBA::is_nil(obj =
_factory->_this()));
421 omni_thread::PRIORITY_NORMAL
435 int idle_time_btw_chkpt;
436 static int firstCheckPoint = 1;
437 char *itbc = getenv(
"OMNIEVENTS_ITBC");
438 if (itbc == NULL || sscanf(itbc,
"%d",&idle_time_btw_chkpt) != 1)
444 omni_condition cond(&
mutex);
453 if (! firstCheckPoint)
456 omni_thread::get_time(&s, &n, idle_time_btw_chkpt);
472 DB(1,
ts.
t() <<
"Checkpointing Phase 1: Prepare.")
485 DB(0,
ts.
t() <<
"Error: cannot open checkpoint file '"
497 #if defined(__sunos__) && defined(__SUNPRO_CC) && __SUNPRO_CC < 0x500
505 DB(0,
ts.
t()<<
"I/O error writing checkpoint file: "<<strerror(errno)
506 <<
"\nAbandoning checkpoint")
509 #if defined(__sunos__) && defined(__SUNPRO_CC) && __SUNPRO_CC < 0x500
521 DB(1,
ts.
t() <<
"Checkpointing Phase 2: Commit.")
524 #if defined(__sunos__) && defined(__SUNPRO_CC) && __SUNPRO_CC < 0x500
532 #if defined(__WIN32__)
541 DB(0,
ts.
t() <<
"Error: failed to link backup file '"
547 #if !defined( __VMS) && !defined(__WIN32__)
551 DB(0,
ts.
t() <<
"Error: failed to unlink old log file '"
557 #if defined(__WIN32__)
571 #if !defined( __VMS) && !defined(__WIN32__)
575 DB(0,
ts.
t() <<
"Error: failed to unlink checkpoint file '"
592 DB(1,
ts.
t() <<
"Checkpointing completed.")
618 const char* logname =
"omnievents-";
622 cerr <<
"Error: cannot get the name of this host." << endl;
627 #if defined(__WIN32__)
630 char last( logdir[strlen(logdir)-1] );
631 if (last !=
':' && last !=
']')
634 <<
") is not a directory name." << endl;
638 if (logdir[0] !=
'/')
641 <<
") is not an absolute path name." << endl;
644 if (logdir[strlen(logdir)-1] !=
'/')
662 char*& filename,
const char* logdir,
const char* sep,
663 const char* logname,
const char* hostname,
const char* ext)
666 strlen(logdir)+strlen(sep)+strlen(logname)+strlen(hostname)+strlen(ext);
667 filename=
new char[len];
668 sprintf(filename,
"%s%s%s%s%s",logdir,sep,logname,hostname,ext);
686 ofstream& s,
const char* filename,
int flags,
int* fd)
688 #if defined(HAVE_FSTREAM_OPEN)
689 # ifdef HAVE_STD_IOSTREAM
690 ios::openmode openmodeflags =ios::out|ios::openmode(flags);
692 int openmodeflags =ios::out|flags;
695 # ifdef FSTREAM_OPEN_PROT
696 s.open(filename,openmodeflags,0644);
698 s.open(filename,openmodeflags);
703 #elif defined(HAVE_FSTREAM_ATTACH)
705 int localFd = _open(filename, O_WRONLY | flags, _S_IWRITE);
707 int localFd = open(filename, O_WRONLY | flags, 0644);
725 ):omni_thread(NULL,priority)
727 DB(15,
"omniEventsLogWorker::omniEventsLogWorker()");
739 DB(15,
"omniEventsLogWorker : run_undetached Start");
741 DB(15,
"omniEventsLogWorker : run_undetached End");
743 catch (CORBA::SystemException& ex) {
744 DB(0,
"omniEventsLogWorker killed by CORBA system exception"
747 catch (CORBA::Exception& ex) {
748 DB(0,
"omniEventsLogWorker killed by CORBA exception"
752 DB(0,
"omniEventsLogWorker killed by unknown exception.")
759 DB(20,
"omniEventsLogWorker::~omniEventsLogWorker()");
#define OMNIEVENTS_LOG_CHECKPOINT_PERIOD
Define OMNIEVENTS_LOG_CHECKPOINT_PERIOD to specify the number of seconds the omniEvents server execut...
#define OMNIEVENTS_LOG_DEFAULT_LOCATION
Define OMNIEVENTS_LOG_DEFAULT_LOCATION to specify the default location where the omniEvents server ex...
#define OMNIEVENTS_LOGDIR_ENV_VAR
Define OMNIEVENTS_LOGDIR_ENV_VAR to specify the environment variable that users may set to override t...
int gethostname(char *hostname, size_t len)
#define MAXHOSTNAMELEN
Provides the function ‘int gethostname(char* hostname, size_t len)’ in a platform independent manner.
#define IF_OMNIORB4(omniORB4_code)
#define NP_MINORSTRING(systemException)
This class can be used to generate timestamps.
static omniEventsLog * theLog
void setFilename(char *&filename, const char *logdir, const char *sep, const char *logname, const char *hostname, const char *ext)
Helper function that sets the value of the first parameter to the concatenation of all the subsequent...
PersistNode * bootstrap(int port, const char *endPointNoListen)
Creates an initialState from its arguments.
void incarnateFactory(PersistNode *initialState)
Constructs the EventChannelFactory from the information in the initialState parameter.
EventChannelFactory_i * _factory
virtual void openOfstream(ofstream &s, const char *filename, int flags=0, int *fd=NULL)
Helper method that opens an output file stream using whatever method is available.
char * _checkpointFilename
virtual PersistNode * parse()
Creates an initialState from the logfile.
bool fileExists(const char *filename) const
virtual void initializeFileNames(const char *logdir)
Sets the values of 'active', 'backup' and 'checkpoint' file names.
virtual void runWorker()
Kicks off the worker thread that periodically checkpoints the persistency logfile.
omniEventsLog(const char *logdir=NULL)
omni_thread * _workerThread
In charge of checkpoints.
virtual void output(ostream &os)
void checkpoint(void)
Entry point used by the omniEventsLogWorker to perform checkpointing.
omniEventsLogWorker()
No default construction allowed.
void * run_undetached(void *)
PersistNode * addnode(const string &name)
long attrLong(const string &key, long fallback=0) const
PersistNode * child(const string &key) const
void addattr(const string &keyvalue)