aboutsummaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2010-01-15 21:44:48 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2010-01-15 21:44:48 +0000
commita3f6a20e1b1ef2fe3ccfe32e182876a3446d2989 (patch)
tree26cd07db26242b040887d10730f6c56cf508628b /utils
parent1e1bd71bf7b20e94ae600eaaf5931884afee18e3 (diff)
Merged revisions 240499-240500 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk ........ r240499 | tilghman | 2010-01-15 15:40:14 -0600 (Fri, 15 Jan 2010) | 9 lines The previous attempt at using a pipe to guarantee astcanary shutdown did not work. We're revisiting the previous patch, albeit with a method that overcomes the prior criticism that it was not POSIX-compliant. (closes issue #16602) Reported by: frawd Patches: 20100114__issue16602.diff.txt uploaded by tilghman (license 14) Tested by: frawd ........ r240500 | tilghman | 2010-01-15 15:42:36 -0600 (Fri, 15 Jan 2010) | 2 lines Oops, missed an include ........ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.2@240503 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'utils')
-rw-r--r--utils/astcanary.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/utils/astcanary.c b/utils/astcanary.c
index aa13c5656..8cfa3feb7 100644
--- a/utils/astcanary.c
+++ b/utils/astcanary.c
@@ -25,6 +25,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
+#include <stdio.h>
/*!\brief
* At one time, canaries were carried along with coal miners down
@@ -87,9 +88,25 @@ static const char explanation[] =
int main(int argc, char *argv[])
{
int fd;
+ pid_t parent;
+
+ if (argc < 3) {
+ fprintf(stderr, "Usage: %s <monitor-filename> <ppid>\n", argv[0]);
+ exit(1);
+ }
+
/* Run at normal priority */
setpriority(PRIO_PROCESS, 0, 0);
- for (;;) {
+
+ /*!\note
+ * See http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap03.html#tag_03_265
+ * for a justification of this approach. The PPID after the creator dies in Linux and
+ * most other Unix-like systems will be 1, but this is not strictly the case. The POSIX
+ * specification allows it to be an implementation-defined system process. However, it
+ * most certainly will not be the original parent PID, which makes the following code
+ * POSIX-compliant.
+ */
+ for (parent = atoi(argv[2]); parent == getppid() ;) {
/* Update the modification times (checked from Asterisk) */
if (utime(argv[1], NULL)) {
/* Recreate the file if it doesn't exist */
@@ -108,7 +125,7 @@ int main(int argc, char *argv[])
sleep(5);
}
- /* Never reached */
+ /* Exit when the parent dies */
return 0;
}