Re: New library: libpidfile.
From: Pawel Jakub Dawidek (pjd_at_FreeBSD.org)
Date: 08/24/05
- Previous message: John-Mark Gurney: "Re: New library: libpidfile."
- In reply to: Peter Jeremy: "Re: New library: libpidfile."
- Next in thread: Hajimu UMEMOTO: "Re: New library: libpidfile."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 24 Aug 2005 01:18:48 +0200 To: Peter Jeremy <PeterJeremy@optushome.com.au>
On Tue, Aug 23, 2005 at 07:42:26PM +1000, Peter Jeremy wrote:
+> On Tue, 2005-Aug-23 10:17:58 +0200, Pawel Jakub Dawidek wrote:
+> >In my first concept (when it was part of libutil) I allocated memory
+> >to store needed informations, because I didn't wanted to use preallocated
+> >memory (someone linking libutil doesn't have to use pidfile
+> >functionality).
+>
+> Since there's an initialisation function, why not just malloc whatever
+> memory you need? You can either store the pointer in a local static
+> or have pidfile_open() return it as an opaque pointer that the user
+> has to pass into other pidfile_XXX functions.
I added a handle, so now it goes like this:
struct pidfh *pfh;
pid_t otherpid, childpid;
pfh = pidfile_open("/var/run/daemon.pid", 0644, &otherpid);
if (pfh == NULL) {
if (errno == EEXIST)
errx(EXIT_FAILURE, "Daemon already running, pid: %d.", otherpid);
/* If we cannot create pidfile from other reasons, only warn. */
warn("Cannot open or create pidfile");
}
if (daemon(0, 0) == -1) {
warn("Cannot daemonize");
pidfile_remove(pfh);
exit(EXIT_FAILURE);
}
pidfile_write(pfh);
for (;;) {
/* Do work. */
childpid = fork();
switch (childpid) {
case -1:
syslog(LOG_ERR, "Cannot fork(): %s.", strerror(errno));
break;
case 0:
pidfile_close(pfh);
/* Do child work. */
break;
default:
syslog(LOG_INFO, "Child %d started.", childpid);
break;
}
}
pidfile_remove(pfh);
exit(EXIT_SUCCESS);
I can't use atexit(3) anymore to remove pidfile, but I like it this way
better, anyway.
+> >It also now has 4 functions, which makes it a good candidate of small,
+> >nice, lightweight library:)
+>
+> IMHO, 4 functions is too small. I would prefer to have a smaller
+> number of larger libraries and think this belongs in an existing
+> library - eg libutil. Whilst this may form a nice lightweight
+> library, if everyone wrote small, lightweight libraries, linking
+> an application would require a mile-long command line.
I talked about this with few more guys and they agree it should be a
part of libutil, so I moved it there.
+> Can I suggest two enhancements:
+> 1) Allow NULL to be passed to pidfile_open() to indicate that the
+> pidfile should be in /var/run/PROCESS_NAME.pid (and/or if the
+> name doesn't include any '/' then default to /var/run)
I implemented NULL behaviour, but I'm not sure about the second thing.
I'd like to avoid it.
+> 2) Write a wrapper function that calls pidfile_open() and if it's
+> successful, exec's the rest of the command line.
There is simlar wrapper: lockf(1), so I'll not duplicate functionality,
but I changed daemon(8) to use pidfile(3).
Thanks for all suggestions.
-- Pawel Jakub Dawidek http://www.wheel.pl pjd@FreeBSD.org http://www.FreeBSD.org FreeBSD committer Am I Evil? Yes, I Am!
- application/pgp-signature attachment: stored
- Previous message: John-Mark Gurney: "Re: New library: libpidfile."
- In reply to: Peter Jeremy: "Re: New library: libpidfile."
- Next in thread: Hajimu UMEMOTO: "Re: New library: libpidfile."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
- Re: New library: libpidfile.
... >In my first concept (when it was part of libutil) I allocated memory ...
number of larger libraries and think this belongs in an existing ... library, if everyone
wrote small, lightweight libraries, linking ... (freebsd-arch) - Re: W3WP memory usage
... You may be correct regarding the libraries using the lion's share of memory.
... > I am quite aware that Sharepoint files are stored in the database. ...
>>> public class SPVersion ... (microsoft.public.sharepoint.portalserver.development) - Re: Will a large library cause WMP10 to slow system to a halt?
... 704 Megabytes Installed Memory ... of case likely would slow nearly everything
down - not just the WMP. ... I have 2 250 Gb drives in a RAID 1 ... If you
don't use libraries, how do you play music in WMP? ... (microsoft.public.windowsmedia.player) - Re: [RFC 0/3] Recursive reclaim (on __PF_MEMALLOC)
... Once the memory requirements of a userspace daemon ... Yes, and also inspect
the code to ensure it doesn't violate mlock_all by execing programs, dynamically loading libraries,
etc. ... In nbd-server, there's no dlopen, and I do not currently plan to add ...
Avoiding glib is a good start. ... (Linux-Kernel) - Re: Memory leak when using OleDb
... say 2000 times you'll see that the memory of the ... such a tremendous leak
in the OleDb libraries of .NET nor in the OleDb ... accesses COM objects throught Runtime
Callable Wrappers. ... (microsoft.public.dotnet.framework)