mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-22 04:11:16 -05:00
Close orphaned jt9 sub-process before restarting
This commit is contained in:
parent
81da36d681
commit
fe28f48cce
41
main.cpp
41
main.cpp
@ -353,14 +353,41 @@ int main(int argc, char *argv[])
|
||||
// Multiple instances: use rig_name as shared memory key
|
||||
mem_jt9.setKey(a.applicationName ());
|
||||
|
||||
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"};
|
||||
// try and shut down any orphaned jt9 process
|
||||
for (int i = 3; i; --i) // three tries to close old jt9
|
||||
{
|
||||
if (mem_jt9.attach ()) // shared memory presence implies
|
||||
// orphaned jt9 sub-process
|
||||
{
|
||||
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 ();
|
||||
memset(mem_jt9.data(),0,sizeof(struct dec_data)); //Zero all decoding params in shared memory
|
||||
mem_jt9.unlock ();
|
||||
|
Loading…
Reference in New Issue
Block a user