[ps-watcher] 46/88: add pidfile patch
Jan Wagner
waja at alioth.debian.org
Fri Nov 8 23:06:39 UTC 2013
This is an automated email from the git hooks/post-receive script.
waja pushed a commit to branch master
in repository ps-watcher.
commit e87dd33c7cf58f95ad1935b3660b55df2f722bec
Author: Jan Wagner <waja at cyconet.org>
Date: Wed Apr 2 21:35:56 2008 +0000
add pidfile patch
---
debian/patches/00list | 1 +
debian/patches/01_add_pidfile_support.dpatch | 108 ++++++++++++++++++++++++++
2 files changed, 109 insertions(+)
diff --git a/debian/patches/00list b/debian/patches/00list
new file mode 100644
index 0000000..4b77285
--- /dev/null
+++ b/debian/patches/00list
@@ -0,0 +1 @@
+01_add_pidfile_support.dpatch
diff --git a/debian/patches/01_add_pidfile_support.dpatch b/debian/patches/01_add_pidfile_support.dpatch
new file mode 100644
index 0000000..7167245
--- /dev/null
+++ b/debian/patches/01_add_pidfile_support.dpatch
@@ -0,0 +1,108 @@
+#!/bin/sh /usr/share/dpatch/dpatch-run
+## 01_add_pidfile_support.dpatch by Jan Wagner <waja at cyconet.org>
+## with hints by Sebastian Harl <sh at tokkee.org> and
+## Alexander Wirt <formorer at formorer.de>
+##
+## DP: add pidfile support to ps-watcher
+
+
+--- ps-watcher-1.06/ps-watcher.in.in 2007-07-04 21:34:23.000000000 +0200
++++ ps-watcher-1.06/ps-watcher.in.in 2008-04-02 18:16:45.000000000 +0200
+@@ -23,8 +23,11 @@
+
+ use vars qw($program $ps_cmd $ps_cmdfull $ps_fullcmd_fmt @ps_vars $ps_dvars
+ $0 $logopened $ps_args_fmt $args
+- $count $pid $command $ps_arg_opts $DEVNULL %opts
++ $count $pid $command $ps_arg_opts $DEVNULL %opts $PIDFILE
+ );
++
++$PIDFILE = "/var/run/ps-watcher.pid";
++
+ use strict;
+ BEGIN { require 5.00503 }
+
+@@ -130,6 +133,7 @@
+ sub read_config($);
+ sub check_config_file($);
+ sub run_trigger($$$);
++sub check_pid();
+
+ init();
+ process_options();
+@@ -147,7 +151,12 @@
+ }
+
+ if ($opts{daemon}) {
+- daemonize();
++ if (! check_pid()) {
++ exit 1;
++ }
++ if (! daemonize()) {
++ exit 1;
++ }
+ }
+
+ install_handlers();
+@@ -584,14 +593,62 @@
+ exit 10;
+ }
+
++sub check_pid() {
++ if (-f $PIDFILE) {
++ if (open(PID,$PIDFILE)) {
++ my $pid = <PID>;
++ if (!close(PID)) {
++ logger("Unable to close file handle PID for file '$PIDFILE': $!");
++ return;
++ }
++ if (-f "/proc/$pid/stat") {
++ if (open(FH,"/proc/$pid/stat")) {
++ my $line = <FH>;
++ if (!close(FH)) {
++ logger("Unable to close file handle FH for file '/proc/$pid/stat': $!");
++ return;
++ }
++ if ($line =~ /\d+[^(]*\((.*)\)\s*/) {
++ my $process = $1;
++ if ($process =~ /^$program$/) {
++ logger("$program already running at PID $pid; exiting.");
++ exit(0);
++ }
++ }
++ } else {
++ logger("Unable to open file handle FH for file '/proc/$pid/stat': $!");
++ return;
++ }
++ } else {
++ logger("Removing stale PID file.");
++ unlink($PIDFILE);
++ }
++ }else{
++ logger("Unable to open file handle PID for file '$PIDFILE': $!");
++ return;
++ }
++ }
++ return 1;
++}
+
+ sub daemonize() {
+ chdir '/' or die "Can't chdir to /: $!";
+ defined(my $pid = fork) or die "Can't fork: $!";
+ exit 0 if $pid;
++ if (open(FH,">$PIDFILE")) {
++ print FH $$;
++ if (!close(FH)) {
++ logger("Unable to close file handle FH for file '$PIDFILE': $!");
++ return;
++ }
++ } else {
++ logger("Unable to open file handle FH for file '$PIDFILE': $!");
++ return;
++ }
+ use POSIX qw(setsid);
+ setsid() or die "Can't start a new session: $!";
+ umask 0;
++ return 1;
+ }
+
+ # Time configuration file was last read.
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/ps-watcher.git
More information about the Pkg-perl-cvs-commits
mailing list