summaryrefslogtreecommitdiff
path: root/utils/astcanary.c
diff options
context:
space:
mode:
authorTilghman Lesher <tilghman@meg.abyt.es>2010-01-15 21:40:14 +0000
committerTilghman Lesher <tilghman@meg.abyt.es>2010-01-15 21:40:14 +0000
commit8037982fa6b3a8e9ebe3a2d11908b8376b39bbef (patch)
tree82cac51b9772a33dc35ead508407977938fb4163 /utils/astcanary.c
parente8a6d2995e95e8b27aba9551c3da025e7b9bfa6d (diff)
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 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@240499 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'utils/astcanary.c')
-rw-r--r--utils/astcanary.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/utils/astcanary.c b/utils/astcanary.c
index aa13c5656..bcf2abb69 100644
--- a/utils/astcanary.c
+++ b/utils/astcanary.c
@@ -87,9 +87,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 +124,7 @@ int main(int argc, char *argv[])
sleep(5);
}
- /* Never reached */
+ /* Exit when the parent dies */
return 0;
}