[omniORB] Proper way for orderly server process shutdown?
Sai-Lai Lo
S.Lo@uk.research.att.com
09 Jul 1999 11:49:51 +0100
Wil,
>>>>> Wil Evers writes:
> Does anyone have some simple example code performing an orderly shutdown?
> Platform details: I'm running Linux kernel 2.0.36 with glibc2 and
> egcs-1.1.2.
The code bit below is what I used for testing, you can see I'm calling
impl_shutdown inside a oneway call so what you are doing is correct.
With regard to the the program core dump on linux, I've also seen this on
machines running glibc-2.0. It happens about once out of 20 invocations.
I cannot figure out what is causing this. However if you look at where it
SEGV under gdb, its always inside the pthread library. Since I cannot find
any wrong with the shutdown code, I've classified this one as a bug in
glibc-2.0.
I've also tested the same program on a Redhat 6.0 machine that comes with
glibc-2.1. So far I've not seen one core dump. This may be an indication
that the problem has been fixed in glibc-2.1.
On a related issue, if one do a Ctrl-C on a running linux multi-threaded
program, occasionally one gets a core dump. I still cannot figure out how
signals are handled in linux threads and whether the core dump is caused by
a bug in the thread package or I've done something silly.
-------------------
// Usage: server2 [<echo object name> <shutdown object name>]
// names are COSNaming compound names (e.g. x/y/echo.obj)>]
//
// IDL
// interface Shutdown {
// oneway void off();
// };
//
#include <iostream.h>
#include <common/common.h>
#include <echo.hh>
#include <shutdown.hh>
CORBA::BOA_ptr boa;
class Echo_i : public virtual _sk_Echo {
public:
Echo_i() {}
virtual ~Echo_i() { cerr << "Echo_i::~Echo_i" << endl; }
virtual char * echoString(const char *mesg);
};
char *
Echo_i::echoString(const char *mesg) {
char *p = CORBA::string_dup(mesg);
return p;
}
class Shutdown_i : public virtual _sk_Shutdown {
public:
Shutdown_i() {}
~Shutdown_i() { cerr << "Shutdown_i::~Shutdow_i" << endl; }
void off() { boa->impl_shutdown(); }
};
int
main(int argc, char **argv)
{
CORBA::ORB_ptr orb = CORBA::ORB_init(argc,argv,"omniORB2");
boa = orb->BOA_init(argc,argv,"omniORB2_BOA");
CosNaming::Name use_echo_name;
CosNaming::Name use_shutdown_name;
if (argc > 1) {
if (argc != 3) {
cerr << "Usage: server2 [<echo object name> <shutdown object name>]\n"
<< " names are COSNaming compound names (e.g. x/y/echo.obj)>]"
<< endl;
return 1;
}
try {
use_echo_name = string_to_name(argv[1]);
use_shutdown_name = string_to_name(argv[2]);
}
catch (...) {
cerr << argv[1] << " or " << argv[2]
<< " is not a valid COS Naming compound name." << endl;
return 1;
}
}
omniORB::idleConnectionScanPeriod(omniORB::idleIncoming,15);
Echo_i *myobj = new Echo_i;
myobj->_obj_is_ready(boa);
{
Echo_var myobjRef = myobj->_this();
if (use_echo_name.length()) {
if (!bindObjectToName(orb,myobjRef,use_echo_name)) {
return 1;
}
}
else {
CORBA::String_var p = orb->object_to_string(myobjRef);
cerr << "Echo object: " << (char*)p << endl;
}
}
Shutdown_i *myswitch = new Shutdown_i;
myswitch->_obj_is_ready(boa);
{
CORBA::Object_var myobjRef = myswitch->_this();
if (use_shutdown_name.length()) {
if (!bindObjectToName(orb,myobjRef,use_shutdown_name)) {
return 1;
}
}
else {
CORBA::String_var p = orb->object_to_string(myobjRef);
cerr << "Offswitch object: " << (char*)p << endl;
}
}
cerr << "Main thread calling BOA is ready..." << endl;
boa->impl_is_ready();
cerr << "Main thread returns from BOA is ready..." << endl;
myobj->_dispose();
myswitch->_dispose();
cerr << "Removing BOA..." << endl;
boa->destroy();
cerr << "BOA has been removed.." << endl;
return 0;
}
--
Sai-Lai Lo S.Lo@uk.research.att.com
AT&T Laboratories Cambridge WWW: http://www.uk.research.att.com
24a Trumpington Street Tel: +44 1223 343000
Cambridge CB2 1QA Fax: +44 1223 313542
ENGLAND