simpleipc

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

simpleipc

Brad Campbell
G'day all,

I've been having a play with simpleipc.pp for trying to do cross-platform single instance detection.

Ordinarily it behaves perfectly, but I just noticed on Linux that it all comes crashing down if the
server application crashes without removing the pipe.

I then have to manually remove the pipe to be able to start the server again.

Has anyone come up against this, or similar previously?
I'm somewhat stumped as to how to go about solving this as I can't find a reliable way of detecting
a listener on the end of the pipe.

I figure the best way to go about it is to move from pipes to unix sockets, but this then starts to
get considerably more complex.

Brad
--
Dolphins are so intelligent that within a few weeks they can
train Americans to stand at the edge of the pool and throw them
fish.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: simpleipc

Michael Van Canneyt


On Thu, 16 Oct 2008, Brad Campbell wrote:

> G'day all,
>
> I've been having a play with simpleipc.pp for trying to do cross-platform
> single instance detection.
>
> Ordinarily it behaves perfectly, but I just noticed on Linux that it all comes
> crashing down if the server application crashes without removing the pipe.
>
> I then have to manually remove the pipe to be able to start the server again.
>
> Has anyone come up against this, or similar previously?
> I'm somewhat stumped as to how to go about solving this as I can't find a
> reliable way of detecting a listener on the end of the pipe.

You could write the server process id to a file, and detect whether the process
is still alive.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: simpleipc

Brad Campbell
Michael Van Canneyt wrote:

>
> On Thu, 16 Oct 2008, Brad Campbell wrote:
>
>> G'day all,
>>
>> I've been having a play with simpleipc.pp for trying to do cross-platform
>> single instance detection.
>>
>> Ordinarily it behaves perfectly, but I just noticed on Linux that it all comes
>> crashing down if the server application crashes without removing the pipe.
>>
>> I then have to manually remove the pipe to be able to start the server again.
>>
>> Has anyone come up against this, or similar previously?
>> I'm somewhat stumped as to how to go about solving this as I can't find a
>> reliable way of detecting a listener on the end of the pipe.
>
> You could write the server process id to a file, and detect whether the process
> is still alive.

What I ended up doing was creating a lockfile and having the server hold an exclusive lock on it.
If the server starts and can get an exclusive lock then it know's it is the first process running,
and to delete the ipc pipe if it hangs over from a crash. That is now working perfectly. (Except
that simpleipc crashes on OSX when it tries to create the fifo, but that's another issue and not
related to simpleipc).

I'm really quite impressed with simpleipc, it's made going cross platform very easy.

..actually, the whole freepascal/lazarus thing has made going cross platform very easy.

Regards,
Brad
--
Dolphins are so intelligent that within a few weeks they can
train Americans to stand at the edge of the pool and throw them
fish.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: simpleipc

Luca Olivetti-2
En/na Brad Campbell ha escrit:

> What I ended up doing was creating a lockfile and having the server hold
> an exclusive lock on it.
> If the server starts and can get an exclusive lock then it know's it is
> the first process running, and to delete the ipc pipe if it hangs over
> from a crash.

Well, if you detected that's the first (and only) instance running, then
you  don't need the ipc server anymore, do you? (as long as it was used
only to detect multiple invocations).
There's a component/unit named uniqueinstance/uniqueinstanceraw to do
that, but since I had problems with it (the process starting more than
once), I modified as you say to use a lockfile.
Somehow someone managed to start two copies of the same server, I still
don't know how since I cannot reproduce it.

Bye
--
Luca

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: simpleipc

Brad Campbell
Luca Olivetti wrote:

> En/na Brad Campbell ha escrit:
>
>> What I ended up doing was creating a lockfile and having the server
>> hold an exclusive lock on it.
>> If the server starts and can get an exclusive lock then it know's it
>> is the first process running, and to delete the ipc pipe if it hangs
>> over from a crash.
>
> Well, if you detected that's the first (and only) instance running, then
> you  don't need the ipc server anymore, do you? (as long as it was used
> only to detect multiple invocations).

Which it's not. I also use it to open windows in the main instance from extra instances opened.

> There's a component/unit named uniqueinstance/uniqueinstanceraw to do
> that, but since I had problems with it (the process starting more than
> once), I modified as you say to use a lockfile.

Which is precisely the component I am using, and precisely the problem I came up against. It works
brilliantly until your main app crashes or is killed or, or, or.. then it just refuses to work until
you manually clean up after it.

I also have problems with the component itself causing all sorts of segfaults if it aborts an
application loading when it detects a previous instance. I worked around it, but it's still ugly in
parts. If I manage to get it cleaned up and de-uglified I'll submit it back.

> Somehow someone managed to start two copies of the same server, I still
> don't know how since I cannot reproduce it.

Since I made my modifications I've managed to avoid that nicely.

Brad
--
Dolphins are so intelligent that within a few weeks they can
train Americans to stand at the edge of the pool and throw them
fish.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: simpleipc

Luiz Americo Pereira Camara-2
In reply to this post by Brad Campbell
Brad Campbell wrote:

> G'day all,
>
> I've been having a play with simpleipc.pp for trying to do
> cross-platform single instance detection.
>
> Ordinarily it behaves perfectly, but I just noticed on Linux that it
> all comes crashing down if the server application crashes without
> removing the pipe.
>
> I then have to manually remove the pipe to be able to start the server
> again.
>
> Has anyone come up against this, or similar previously?

I already noticed that in the component i wrote to launch a single
instance. No good solution found.

Luiz
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal