Mailing List archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[vdr] Re: VDR pidfile
On Thu, Jun 24, 2004 at 11:11:36AM +0200, Roland Behme wrote:
> Hi Werner
>
> > > It seems like VDR returns a wrong PID or the VDR-process started by
> > > start-stop-daemon terminates after making some children (like all of
> > > us *g*).
> > >
> > > Any ideas?
> >
> > The fix is really simple, nevertheless it was never added to
> > vdr ;^)
> Could you provide a patch or something like that?
Hmmm ... test the patch in the attachment. I've not test this,
it may or may not work ;^)
The setsid() call make a real daemon, in other words: the
VDR gets its own session.
> > OK, one problem could be that vdr has to run as root upto
> > the point where the pid file will be created.
> That's no problem in my setup.
Werner
--
AC3 loop through sound card http://bitstreamout.sourceforge.net/
Howto http://www.vdr-portal.de/board/thread.php?threadid=1958
------------------------------------------------------------------
"Having a smoking section in a restaurant is like having
a peeing section in a swimming pool." -- Edward Burr
--- vdr.c
+++ vdr.c Thu Jun 24 12:14:36 2004
@@ -31,6 +31,8 @@
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
+#include <paths.h>
+#include <errno.h>
#include "audio.h"
#include "channels.h"
#include "config.h"
@@ -53,6 +55,12 @@
#include "tools.h"
#include "videodir.h"
+static const char pidfile[] = _PATH_VARRUN"vdr.pid";
+static void rmfpid(void)
+{
+ unlink(pidfile); // Remove pidfile
+}
+
#define MINCHANNELWAIT 10 // seconds to wait between failed channel switchings
#define ACTIVITYTIMEOUT 60 // seconds before starting housekeeping
#define SHUTDOWNWAIT 300 // seconds to wait in user prompt before automatic shutdown
@@ -314,9 +322,20 @@
}
if (pid != 0)
return 0; // initial program immediately returns
+ if (getuid() == 0) {
+ FILE * fpid;
+ if ((fpid = fopen (pidfile, "w")) == NULL)
+ fprintf(stderr, "vdr: can not open %s: %s\n", pidfile, strerror(errno));
+ else {
+ fprintf(fpid, "%d\n", (int)getpid());
+ fclose(fpid);
+ atexit(rmfpid);
+ }
+ }
fclose(stdin);
fclose(stdout);
fclose(stderr);
+ setsid(void); // Real daemons should do that
#else
fprintf(stderr, "vdr: can't run in daemon mode with DEBUG_OSD on!\n");
return 2;
Home |
Main Index |
Thread Index