discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What is needed to run a tool like a daemon?


From: Saso Kiselkov
Subject: Re: What is needed to run a tool like a daemon?
Date: Thu, 03 Dec 2009 09:04:48 +0100
User-agent: Thunderbird 2.0.0.23 (X11/20090817)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Sure it's unportable, which is why I always include a custom
implementation of daemon() with my code which works on most *nixes :-).
After reading the message though I realize I misunderstood it.

What's most likely screwing up is that the process doesn't de-register
from the name server. Maybe a simple atexit() or signal() handler would
do the trick.

German: you do try this as a test whether the name is being unregistered:

void
dereg_name (void)
{
  // deregistration code here
  ...

  // to make sure we know that deregistration succeeded
  // even when we have no controlling terminal
  FILE *fp = fopen ("/tmp/test_dereg", "wb");
  fprintf (fp, "Deregistered name\n");
  fclose (fp);
}

void
handle_sig (int signum)
{
  exit (EXIT_SUCCESS);
}

int
main (int argc, char *argv[])
{
  ...
  signal (SIGINT, handle_sig);
  signal (SIGTERM, handle_sig);
  atexit (dereg_name);
  ...
}

I hope I'm not completely missing the point again...

BR,
- --
Saso

Richard Frith-Macdonald wrote:
> On 3 Dec 2009, at 07:34, Saso Kiselkov wrote:
> 
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> And what's stopping you from simply forking into the background? Like
>> with the following:
>>
>> if (daemon (0, 0) == -1)
>>  {
>>    NSLog (@"Error daemonizing: %s", strerror (errno));
>>    exit (EXIT_FAILURE);
>>  }
> 
> I don't think that addresses the issue of registering a name.
> 
> Perhaps more importantly though, the code above has the problem of 'daemon()' 
> being severely unportable.
> 
> In GNUstep you should use NSTask to portably create a subprocess.
> 
> The gdnc tool (base/Tools/gdnc.m) provides an example of a process which 
> makes itsself be a daemon in a portable manner.
> 
> 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAksXcSAACgkQRO8UcfzpOHD8MwCeMSjpTYs2gCCTMaAvB2OlJlha
vPAAoL3mHpd/LnAHFyqmrKX0BEReKxmo
=7c/V
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]