[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: KUniqueApp (Re: kdelibs/kio/kded)
From:       Waldo Bastian <bastian () suse ! de>
Date:       1999-11-25 9:39:35
[Download RAW message or body]

On Wed, 24 Nov 1999, Harri Porten wrote:
> On Tue, 23 Nov 1999, David Faure wrote:
> 
> > About KUniqueApp always forking, I was going to object, but after all
> > why not. I don't see a case where it's a problem.
> > Even if, say, KMail becomes a KUniqueApp (for obvious reasons), the
> > fact that it forks on startup is no problem AFAICS.
> 
> Will the forking happen _before_ or _after_ the KApplication is created ? 
> I assume it's after that. Be careful with X then. You may have to close 
> the connection to the display (a file descriptor?) in the parent. 
> Otherwise things might go out of sync.

The parent usually exits without doing very much.

It might be worthwhile to do the forking before we create KApplication
though (I assume that will be slightly faster).

We could add a static method to KUniqueApp which does what the
constructor does now. Something like:

KUniqueApp::s_Started = false;

bool 
KUniqueApp::start(int argc, char *argv[], char *name)
{
   s_Started = true;
   ... fork and send newInstance stuff ...
}

KUniqueApp::KUniqueApp(int argc, char *argv[], char *name)
 : KApplication(argc, argv)
{
  if (!s_Started)
  {
     if (!start(argc, argv, name)) 
        ::exit(0); // Already running
  }
}

An application could still do 

main(int argc, char *argv[])  {
   KUniqueApp(argc, argv, "myName");
   ...
}

but it could also do

main(int argc, char *argv[])  {
   if (!KUniqueApp::start(argc, argv, "myName"))
   { 
       printf("myName is already running.\n");
       exit(0);
   }
   KUniqueApp(argc, argv, "myName");
   ...
}

In this last case, the forking happens before KApplication/QApplication
is created.

Daemons which don't need KApplication could even leave out the
KUniqueApp constructor.

Cheers,
Waldo

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic