Project import
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..e99c376
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,139 @@
+#
+#    Copyright (c) 2010-2013 Nest Labs, Inc.
+#    All rights reserved.
+#
+#    This document is the property of Nest. It is considered
+#    confidential and proprietary information.
+#
+#    This document may not be reproduced or transmitted in any form,
+#    in whole or in part, without the express written permission of
+#    Nest.
+#
+#    Description:
+#      This file is the make file for the daemon-monitoring daemon
+#      (DMD), monit.
+#
+
+
+include pre.mak
+
+PackageName		:= monit
+
+PackageExtension	:= tar.gz
+PackageSeparator	:= -
+
+PackagePatchArgs	:= -p1
+
+PackageArchive		:= $(PackageName).$(PackageExtension)
+PackageSourceDir	:= $(PackageName)$(PackageSeparator)$(PackageVersion)
+
+PackageBuildMakefile	= $(call GenerateBuildPaths,Makefile)
+
+PackageBuildConfigure	= $(call GenerateBuildPaths,configure)
+
+LicenseSourceFiles	:= LICENSE COPYING
+LicenseSourcePaths      := $(addprefix $(PackageSourceDir)/,$(LicenseSourceFiles))
+
+CleanPaths		+= $(PackageLicenseFile)
+
+OpenSSLDir		:= sw/tps/openssl
+OpenSSLIncDir		:= $(call GenerateResultPaths,$(OpenSSLDir),usr/include)
+OpenSSLLibDir		:= $(call GenerateResultPaths,$(OpenSSLDir),usr/lib)
+
+ZlibDir			:= sw/tps/zlib
+ZlibIncDir      	:= $(call GenerateResultPaths,$(ZlibDir),usr/include)
+ZlibLibDir      	:= $(call GenerateResultPaths,$(ZlibDir),usr/lib)
+
+SOURCEDIRS                      = $(PackageSourceDir)
+$(PackageSourceDir)_RULE_TARGET = $(BuildDirectory)/configure
+
+all: $(PackageDefaultGoal)
+
+# Generate the package license contents.
+
+$(LicenseSourcePaths): $(BuildDirectory)/source
+
+$(PackageLicenseFile): $(LicenseSourcePaths)
+	$(Verbose)touch $@
+	$(Verbose)for file in $(LicenseSourcePaths); do	\
+		echo "Concatenating \"$${file}\"...";	\
+		cat $${file} >> $@;			\
+	done
+
+# Extract the source from the archive and apply patches, if any.
+
+$(PackageSourceDir): $(PackageArchive) $(PackagePatchPaths)
+	$(expand-and-patch-package)
+
+# Prepare the sources.
+
+$(BuildDirectory)/source: | $(PackageSourceDir)
+	$(Verbose)touch $@
+
+# Patch the sources, if necessary.
+
+$(BuildDirectory)/patch: $(BuildDirectory)/source
+	$(Verbose)touch $@
+
+# Generate the package build configure script by shadowing the source
+# tree as a link farm.
+#
+# This is generally unnecessary for most GNU autoconf-based packages;
+# however, monit completely drops the ball on non-colocated builds.
+
+# Generate the package build makefile.
+
+# Configure the source for building.
+
+$(BuildDirectory)/configure: $(BuildDirectory)/source | $(PackageSourceDir) $(BuildDirectory)
+	$(call create-links,$(CURDIR)/$(PackageSourceDir),$(BuildDirectory))
+	$(Verbose)cd $(BuildDirectory) && \
+	./configure \
+	--config-cache \
+	CC="$(CC)" CXX="$(CXX)" AR=$(AR) RANLIB=$(RANLIB) STRIP=$(STRIP) NM=$(NM) OBJDUMP=$(OBJDUMP) \
+	LDFLAGS="-Wl,-rpath-link -Wl,$(ZlibLibDir)" \
+	INSTALL="$(INSTALL) $(INSTALLFLAGS)" \
+	libmonit_cv_setjmp_available=yes \
+	libmonit_cv_vsnprintf_c99_conformant=yes \
+	ac_cv_ipv6=yes \
+	--build=$(HostTuple) \
+	--host=$(TargetTuple) \
+	--prefix=/usr \
+	--sysconfdir=/etc \
+	--localstatedir=/var \
+	--enable-optimized \
+	--with-ssl-incl-dir=$(OpenSSLIncDir) \
+	--with-ssl-lib-dir=$(OpenSSLLibDir) \
+	--without-pam
+	$(Verbose)touch $@
+
+# Build the source.
+#
+# We have to unset MAKEFLAGS since they confuse the package build otherwise.
+
+$(BuildDirectory)/build: $(BuildDirectory)/configure
+	$(Verbose)unset MAKEFLAGS && \
+	$(MAKE) $(JOBSFLAG) -C $(BuildDirectory) all
+	$(Verbose)touch $@
+
+# Stage the build to a temporary installation area.
+#
+# We have to unset MAKEFLAGS since they confuse the package build otherwise.
+
+$(BuildDirectory)/stage: $(BuildDirectory)/build | $(ResultDirectory)
+	$(Verbose)unset MAKEFLAGS && \
+	$(MAKE) $(JOBSFLAG) -C $(BuildDirectory) \
+	DESTDIR=$(ResultDirectory) \
+	MODE_PROGS=775 \
+	install
+	$(Verbose)touch $@
+
+.PHONY: stage
+stage: $(BuildDirectory)/stage
+
+clean:
+	$(Verbose)$(RM) $(RMFLAGS) -r $(PackageSourceDir)
+	$(Verbose)$(RM) $(RMFLAGS) -r $(BuildDirectory)
+	$(Verbose)$(RM) $(RMFLAGS) -r $(ResultDirectory)
+
+include post.mak
diff --git a/monit.patches/monit-50.description b/monit.patches/monit-50.description
new file mode 100644
index 0000000..16b2b97
--- /dev/null
+++ b/monit.patches/monit-50.description
@@ -0,0 +1 @@
+This patch prints out a human reabable string indicating why the preceding fork call failed.
diff --git a/monit.patches/monit-50.patch b/monit.patches/monit-50.patch
new file mode 100644
index 0000000..8fb8b7c
--- /dev/null
+++ b/monit.patches/monit-50.patch
@@ -0,0 +1,12 @@
+diff -aruN a/src/spawn.c b/src/spawn.c
+--- a/src/spawn.c	2012-05-06 02:40:45.000000000 -0700
++++ b/src/spawn.c	2013-03-16 16:31:41.808861381 -0700
+@@ -157,7 +157,7 @@
+         
+         pid= fork();
+         if(pid < 0) {
+-                LogError("Cannot fork a new process\n");  
++                LogError("Cannot fork a new process: %s\n", strerror(errno));  
+                 exit(1); 
+         }
+         
diff --git a/monit.patches/monit-51.description b/monit.patches/monit-51.description
new file mode 100644
index 0000000..3f5d463
--- /dev/null
+++ b/monit.patches/monit-51.description
@@ -0,0 +1,4 @@
+Forces a linux reboot if monit ever exits from a failure to fork.
+
+Monit can unexpected stop (which is pretty lame for a system monitor) if the
+system runs out of memory. This patch forces a linux reboot if that happens.
diff --git a/monit.patches/monit-51.patch b/monit.patches/monit-51.patch
new file mode 100644
index 0000000..be57788
--- /dev/null
+++ b/monit.patches/monit-51.patch
@@ -0,0 +1,66 @@
+diff -aru monit-5.4/src/daemonize.c monit-edited/src/daemonize.c
+--- monit-5.4/src/daemonize.c	2012-05-06 02:40:45.000000000 -0700
++++ monit-edited/src/daemonize.c	2016-01-07 17:54:13.979175325 -0800
+@@ -61,6 +61,7 @@
+ #include <string.h>
+ #endif
+ 
++#include <sys/reboot.h>
+ #include "monit.h"
+ 
+ 
+@@ -93,8 +94,9 @@
+    */
+   if((pid= fork ()) < 0) {
+     
+-    LogError("Cannot fork of a new process\n");  
+-    exit (1);
++    LogError("Cannot fork of a new process, rebooting\n");
++    sync();
++    reboot(RB_AUTOBOOT);
+     
+   }  
+   else if(pid != 0) {
+@@ -107,8 +109,9 @@
+ 
+   if((pid= fork ()) < 0) {
+     
+-    LogError("Cannot fork of a new process\n");  
+-    exit (1);
++    LogError("Cannot fork of a new process, rebooting\n");
++    sync();
++    reboot(RB_AUTOBOOT);
+     
+   }  
+   else if(pid != 0) {
+Only in monit-edited/src: .daemonize.c.swp
+diff -aru monit-5.4/src/spawn.c monit-edited/src/spawn.c
+--- monit-5.4/src/spawn.c	2016-01-07 14:15:22.132302393 -0800
++++ monit-edited/src/spawn.c	2016-01-07 17:53:54.130841558 -0800
+@@ -64,10 +64,13 @@
+ #include <sys/stat.h>
+ #endif
+ 
++
+ #ifdef HAVE_FCNTL_H
+ #include <fcntl.h>
+ #endif
+ 
++#include <sys/reboot.h>
++
+ #include "event.h"
+ #include "alert.h"
+ #include "monit.h"
+@@ -157,8 +160,9 @@
+         
+         pid= fork();
+         if(pid < 0) {
+-                LogError("Cannot fork a new process: %s\n", strerror(errno));  
+-                exit(1); 
++            LogError("Cannot fork a new process, rebooting: %s\n", strerror(errno));
++            sync();
++            reboot(RB_AUTOBOOT);
+         }
+         
+         if(pid == 0) {
+Only in monit-edited/src: .spawn.c.swp
diff --git a/monit.patches/monit-52.description b/monit.patches/monit-52.description
new file mode 100644
index 0000000..6d46fff
--- /dev/null
+++ b/monit.patches/monit-52.description
@@ -0,0 +1 @@
+This patch removes host name DNS resolution to speed up the start/stop process.
diff --git a/monit.patches/monit-52.patch b/monit.patches/monit-52.patch
new file mode 100644
index 0000000..267c411
--- /dev/null
+++ b/monit.patches/monit-52.patch
@@ -0,0 +1,38 @@
+diff -Naur monit-5.4/src/util.c monit-edited/src/util.c
+--- monit-5.4/src/util.c	2012-05-06 02:40:45.000000000 -0700
++++ monit-edited/src/util.c	2016-03-14 11:48:27.047055577 -0700
+@@ -1886,9 +1886,7 @@
+ 
+ 
+ int Util_getfqdnhostname(char *buf, unsigned len) {
+-        int status;
+         char hostname[STRLEN];
+-        struct addrinfo hints, *info = NULL;
+         
+ 	// Set the base hostname
+         if (gethostname(hostname, sizeof(hostname))) {
+@@ -1896,24 +1894,6 @@
+                 return -1;
+         }
+ 	snprintf(buf, len, "%s", hostname);
+-        
+-	// Try to look for FQDN hostname
+-        memset(&hints, 0, sizeof(hints));
+-        hints.ai_family = AF_UNSPEC;
+-        hints.ai_socktype = SOCK_STREAM;
+-        hints.ai_flags = AI_CANONNAME;
+-        if ((status = getaddrinfo(hostname, NULL, &hints, &info))) {
+-                LogError("%s: Cannot translate '%s' to FQDN name -- %s\n", prog, hostname, status == EAI_SYSTEM ? STRERROR : gai_strerror(status));
+-        } else {
+-		for (struct addrinfo *result = info; result; result = result->ai_next) {
+-			if (Str_startsWith(result->ai_canonname, hostname)) {
+-	                	snprintf(buf, len, "%s", result->ai_canonname);
+-				break;
+-			}
+-		}
+-	}
+-        if (info)
+-                freeaddrinfo(info);
+         return 0;
+ }
+ 
diff --git a/monit.tar.gz b/monit.tar.gz
new file mode 100644
index 0000000..adaafb1
--- /dev/null
+++ b/monit.tar.gz
Binary files differ
diff --git a/monit.url b/monit.url
new file mode 100644
index 0000000..70bfc2f
--- /dev/null
+++ b/monit.url
@@ -0,0 +1 @@
+http://mmonit.com/monit/dist/monit-5.4.tar.gz
diff --git a/monit.version b/monit.version
new file mode 100644
index 0000000..37c2d99
--- /dev/null
+++ b/monit.version
@@ -0,0 +1 @@
+5.4