Skip to content

Commit

Permalink
v3.0.12a Removed custom signal handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
itay-grudev committed Jul 27, 2018
1 parent 46b2204 commit 9357d19
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 77 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

__3.0.12a__
----------

* Removed signal handling.

__3.0.11a__
----------

Expand Down
36 changes: 7 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,36 +252,14 @@ Implementation
The library is implemented with a QSharedMemory block which is thread safe and
guarantees a race condition will not occur. It also uses a QLocalSocket to
notify the main process that a new instance had been spawned and thus invoke the
`instanceStarted()` signal.

To handle an issue on `*nix` systems, where the operating system owns the shared
memory block and if the program crashes the memory remains untouched, the
library binds to the following signals and closes the program with
`error code = 128 + signum` where signum is the number representation of the
signal listed below. Handling the signal is required in order to safely delete
the `QSharedMemory` block. Each of these signals are potentially lethal and will
results in process termination.

* `SIGHUP` - `1`, Hangup.
* `SIGINT` - `2`, Terminal interrupt signal
* `SIGQUIT` - `3`, Terminal quit signal.
* `SIGILL` - `4`, Illegal instruction.
* `SIGABRT` - `6`, Process abort signal.
* `SIGBUS` - `7`, Access to an undefined portion of a memory object.
* `SIGFPE` - `8`, Erroneous arithmetic operation (such as division by zero).
* `SIGSEGV` - `11`, Invalid memory reference.
* `SIGSYS` - `12`, Bad system call.
* `SIGPIPE` - `13`, Write on a pipe with no one to read it.
* `SIGALRM` - `14`, Alarm clock.
* `SIGTERM` - `15`, Termination signal.
* `SIGXCPU` - `24`, CPU time limit exceeded.
* `SIGXFSZ` - `25`, File size limit exceeded.

Additionally the library can recover from being killed with uncatchable signals
and will reset the memory block given that there are no other instances running.
`instanceStarted()` signal and for messaging the primary instance.

Additionally the library can recover from being forcefully killed on *nix
systems and will reset the memory block given that there are no other
instances running.

License
-------
This library and it's supporting documentation are released under
`The MIT License (MIT)` with the exception of some of the examples distributed
under the BSD license.
`The MIT License (MIT)` with the exception of the Qt calculator examples which
is distributed under the BSD license.
43 changes: 0 additions & 43 deletions singleapplication_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@
#include "singleapplication.h"
#include "singleapplication_p.h"

#ifdef Q_OS_UNIX
#include <signal.h>
#include <unistd.h>
#endif

#ifdef Q_OS_WIN
#include <windows.h>
#include <lmcons.h>
Expand Down Expand Up @@ -150,11 +145,6 @@ void SingleApplicationPrivate::startPrimary()
{
Q_Q(SingleApplication);

#ifdef Q_OS_UNIX
// Handle any further termination signals to ensure the
// QSharedMemory block is deleted even if the process crashes
crashHandler();
#endif
// Successful creation means that no main process exists
// So we start a QLocalServer to listen for connections
QLocalServer::removeServer( blockServerName );
Expand Down Expand Up @@ -188,11 +178,6 @@ void SingleApplicationPrivate::startPrimary()

void SingleApplicationPrivate::startSecondary()
{
#ifdef Q_OS_UNIX
// Handle any further termination signals to ensure the
// QSharedMemory block is deleted even if the process crashes
crashHandler();
#endif
}

void SingleApplicationPrivate::connectToPrimary( int msecs, ConnectionType connectionType )
Expand Down Expand Up @@ -263,34 +248,6 @@ qint64 SingleApplicationPrivate::primaryPid()
return pid;
}

#ifdef Q_OS_UNIX
void SingleApplicationPrivate::crashHandler()
{
// Handle any further termination signals to ensure the
// QSharedMemory block is deleted even if the process crashes
signal( SIGHUP, SingleApplicationPrivate::terminate ); // 1
signal( SIGINT, SingleApplicationPrivate::terminate ); // 2
signal( SIGQUIT, SingleApplicationPrivate::terminate ); // 3
signal( SIGILL, SingleApplicationPrivate::terminate ); // 4
signal( SIGABRT, SingleApplicationPrivate::terminate ); // 6
signal( SIGFPE, SingleApplicationPrivate::terminate ); // 8
signal( SIGBUS, SingleApplicationPrivate::terminate ); // 10
signal( SIGSEGV, SingleApplicationPrivate::terminate ); // 11
signal( SIGSYS, SingleApplicationPrivate::terminate ); // 12
signal( SIGPIPE, SingleApplicationPrivate::terminate ); // 13
signal( SIGALRM, SingleApplicationPrivate::terminate ); // 14
signal( SIGTERM, SingleApplicationPrivate::terminate ); // 15
signal( SIGXCPU, SingleApplicationPrivate::terminate ); // 24
signal( SIGXFSZ, SingleApplicationPrivate::terminate ); // 25
}

[[noreturn]] void SingleApplicationPrivate::terminate( int signum )
{
delete (static_cast <SingleApplication*>( QCoreApplication::instance() ))->d_ptr;
::exit( 128 + signum );
}
#endif

/**
* @brief Executed when a connection has been made to the LocalServer
*/
Expand Down
5 changes: 0 additions & 5 deletions singleapplication_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ Q_OBJECT
quint16 blockChecksum();
qint64 primaryPid();

#ifdef Q_OS_UNIX
void crashHandler();
[[noreturn]] static void terminate( int signum );
#endif

SingleApplication *q_ptr;
QSharedMemory *memory;
QLocalSocket *socket;
Expand Down

0 comments on commit 9357d19

Please sign in to comment.