Close orphaned jt9 sub-process before restarting

This commit is contained in:
Bill Somerville 2020-07-18 12:17:21 +01:00
parent 81da36d681
commit fe28f48cce
No known key found for this signature in database
GPG Key ID: D864B06D1E81618F

View File

@ -353,14 +353,41 @@ int main(int argc, char *argv[])
// Multiple instances: use rig_name as shared memory key // Multiple instances: use rig_name as shared memory key
mem_jt9.setKey(a.applicationName ()); mem_jt9.setKey(a.applicationName ());
if(!mem_jt9.attach()) { // try and shut down any orphaned jt9 process
if (!mem_jt9.create(sizeof(struct dec_data))) { for (int i = 3; i; --i) // three tries to close old jt9
splash.hide (); {
MessageBox::critical_message (nullptr, a.translate ("main", "Shared memory error"), if (mem_jt9.attach ()) // shared memory presence implies
a.translate ("main", "Unable to create shared memory segment")); // orphaned jt9 sub-process
throw std::runtime_error {"Shared memory error"}; {
dec_data_t * dd = reinterpret_cast<dec_data_t *> (mem_jt9.data());
mem_jt9.lock ();
dd->ipc[1] = 999; // tell jt9 to shut down
mem_jt9.unlock ();
mem_jt9.detach (); // start again
}
else
{
break; // good to go
}
QThread::sleep (1); // wait for jt9 to end
}
if (!mem_jt9.attach ())
{
if (!mem_jt9.create (sizeof (struct dec_data)))
{
splash.hide ();
MessageBox::critical_message (nullptr, a.translate ("main", "Shared memory error"),
a.translate ("main", "Unable to create shared memory segment"));
throw std::runtime_error {"Shared memory error"};
}
}
else
{
splash.hide ();
MessageBox::critical_message (nullptr, a.translate ("main", "Sub-process error"),
a.translate ("main", "Failed to close orphaned jt9 process"));
throw std::runtime_error {"Sub-process error"};
} }
}
mem_jt9.lock (); mem_jt9.lock ();
memset(mem_jt9.data(),0,sizeof(struct dec_data)); //Zero all decoding params in shared memory memset(mem_jt9.data(),0,sizeof(struct dec_data)); //Zero all decoding params in shared memory
mem_jt9.unlock (); mem_jt9.unlock ();