27 Nov, 2012, Kline wrote in the 1st comment:
Votes: 0
I understand that shared objects can be effectively "reloaded" by calling dlclose() and just re-opening them, but can this be applied by an object to itself?
Line 16 removes the old copy of object. However, if run on itself, it justifiably segfaults as I've told it to self-destruct with further code left to process. If I move the deletion to line 24 though, the object never seems to actually reload itself.

I can certainly add a check to prevent calling reload() on itself and move the deletion to line 24 and things work perfectly. Except that I'd like to be able to call reload() on itself if I can. Is there a way I'm overlooking? Or would a different set of dlopen() flags let me do this? Currently I open objects with RTLD_LAZY and RTLD_GLOBAL.

if ( client )
{
if ( arg.empty() )
{
client->Send( "Reload -which- command?" CRLF );
return;
}

if ( ( oldcmd = client->gServer()->FindCommand( arg ) ) != NULL )
{
security = client->gSecurity();

if ( oldcmd->Authorized( security ) )
{
file = oldcmd->gFile();
oldcmd->Delete();

newcmd = new Command();
if ( !newcmd->New( file ) )
{
LOGFMT( flags, "AdmReload::Run()->Command::New()-> command %s returned false", CSTR( file ) );
delete newcmd;
}

client->Send( "Command successfully reloaded." CRLF );
}
}
else
client->Send( "That command doesn't exist." CRLF );
}
28 Nov, 2012, plamzi wrote in the 2nd comment:
Votes: 0
Have reload() schedule the task, then have a static function perform the task a bit later.
28 Nov, 2012, Kline wrote in the 3rd comment:
Votes: 0
plamzi said:
Have reload() schedule the task, then have a static function perform the task a bit later.

Thanks, that never even crossed my mind actually. Sounds perfect!
0.0/3