<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>autossh/configure.ac</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,4 +1,12 @@
 
+Version 1.4b
+
+- add AUTOSSH_MAXLIFETIME (patch from Steven Clark)
+- include configure.ac in package
+- fix poll flags so not checking for writable when write done (patch
+  from John Grahor)
+- compile time TOUCH_PIDFILE option to touch pid file on connection test.
+
 Version 1.4a
 
 - fix up pid file generation (Xander Hudson)</diff>
      <filename>autossh/CHANGES</filename>
    </modified>
    <modified>
      <diff>@@ -1,8 +1,8 @@
-# $Id: Makefile.in,v 1.3 2006/07/13 14:53:44 harding Exp $
+# $Id: Makefile.in,v 1.4 2007/12/16 06:08:04 harding Exp $
 #
 # @configure_input@
 
-VER=		1.4a
+VER=		1.4b
 
 SSH=		@path_ssh@
 </diff>
      <filename>autossh/Makefile.in</filename>
    </modified>
    <modified>
      <diff>@@ -163,6 +163,8 @@ The following environment variables can be set:
     AUTOSSH_DEBUG	  - sets logging level to LOG_DEBUG, and if
 			    the operating system supports it, sets
 			    syslog to duplicate log entries to stderr.
+    AUTOSSH_FIRST_POLL	  - time to initial poll (default is as 
+			    AUTOSSH_POLL below).
     AUTOSSH_GATETIME      - how long ssh must be up before we consider
 	                    it a successful connection. Default is 30
 			    seconds. If set to 0, then this behaviour
@@ -173,6 +175,9 @@ The following environment variables can be set:
     AUTOSSH_LOGLEVEL	  - log level, they correspond to the levels 
 			    used by syslog; so 0-7 with 7 being the
 			    chattiest.
+    AUTOSSH_MAXLIFETIME   - Sets the maximum number of seconds the process 
+			    should live for before killing off the ssh child 
+			    and exiting.
     AUTOSSH_MAXSTART	  - specifies how many times ssh should be started.
 			    A negative number means no limit on the number 
 			    of times ssh is started. The default value is -1.
@@ -191,7 +196,6 @@ The following environment variables can be set:
 			    network timeouts (default 15 seconds) the 
 			    network timeouts will be adjusted downward 
 			    to 1/2 the poll time.
-    AUTOSSH_FIRST_POLL	  - time to initial poll (default is as above).
     AUTOSSH_PORT	  - set monitor port. Mostly in case ssh
 			    appropriates -M at some time. But because
 			    of this possible use, AUTOSSH_PORT overrides</diff>
      <filename>autossh/README</filename>
    </modified>
    <modified>
      <diff>@@ -17,7 +17,7 @@
 .\&quot; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 .\&quot; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\&quot;
-.\&quot; $Id: autossh.1,v 1.20 2006/05/21 03:33:00 harding Exp $
+.\&quot; $Id: autossh.1,v 1.21 2008/03/28 16:58:21 harding Exp $
 .\&quot;
 .Dd Jul 20, 2004
 .Dt AUTOSSH 1
@@ -211,6 +211,9 @@ way to avoid collisions.
 If this variable is set, the logging level is set to to LOG_DEBUG, and
 if the operating system supports it, syslog is set to duplicate log
 entries to stderr.
+.It Ev AUTOSSH_FIRST_POLL
+Specifies the time to wait before the first connection test. Thereafter
+the general poll time is used (see AUTOSSH_POLL below).
 .It Ev AUTOSSH_GATETIME
 Specifies how long ssh must be up before we consider it a successful
 connection. The default is 30 seconds. Note that if AUTOSSH_GATETIME
@@ -224,6 +227,10 @@ so 0-7 with 7 being the chattiest.
 Specifies that
 .Nm
 should use the named log file, rather than syslog.
+.It Ev AUTOSSH_MAXLIFETIME
+Sets the maximum number of seconds that the program should run. Once
+the number of seconds has been passed, the ssh child will be killed
+and the program will exit.
 .It Ev AUTOSSH_MAXSTART
 Specifies how many times ssh should be started. A negative number
 means no limit on the number of times ssh is started. The default
@@ -245,9 +252,6 @@ Specifies the connection poll time in seconds; default is 600 seconds.
 If the poll time is less than twice the network timeouts (default 15
 seconds) the network timeouts will be adjusted downward to 1/2 the
 poll time.
-.It Ev AUTOSSH_FIRST_POLL
-Specifies the time to wait before the first connection test. Thereafter
-the general poll time is used (see AUTOSSH_POLL above).
 .It Ev AUTOSSH_PORT
 Sets the connection monitoring port. Mostly in case ssh appropriates
 -M at some time. But because of this possible use, AUTOSSH_PORT</diff>
      <filename>autossh/autossh.1</filename>
    </modified>
    <modified>
      <diff>@@ -4,7 +4,7 @@
  *
  * 	From the example of rstunnel.
  *
- * Copyright (c) Carson Harding, 2002-2006.
+ * Copyright (c) Carson Harding, 2002-2008.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -81,7 +81,7 @@ extern char *__progname;
 char *__progname;
 #endif
 
-const char *rcsid = &quot;$Id: autossh.c,v 1.75 2006/07/13 14:49:53 harding Exp $&quot;;
+const char *rcsid = &quot;$Id: autossh.c,v 1.81 2008/04/04 22:29:58 harding Exp $&quot;;
 
 #ifndef SSH_PATH
 #  define SSH_PATH &quot;/usr/bin/ssh&quot;
@@ -89,6 +89,7 @@ const char *rcsid = &quot;$Id: autossh.c,v 1.75 2006/07/13 14:49:53 harding Exp $&quot;;
 
 #define POLL_TIME	600	/* 10 minutes default */
 #define GATE_TIME	30	/* 30 seconds default */
+#define MAX_LIFETIME	0	/* default max lifetime of forever */
 #define TIMEO_NET	15000	/* poll on accept() and io (msecs) */
 #define MAX_CONN_TRIES	3	/* how many attempts */
 #define MAX_START	(-1)	/* max # of runs; &lt;0 == forever */
@@ -118,10 +119,12 @@ char	*env_port;		/* port spec'd in environment */
 char	*echo_message = &quot;&quot;;	/* message to append to echo string */
 char	*pid_file_name;		/* path to pid file */
 int	pid_file_created;	/* we have created pid file */
+time_t	pid_start_time;		/* time autossh process started */
 int	poll_time = POLL_TIME;	/* default connection poll time */
 int	first_poll_time = POLL_TIME; /* initial connection poll time */
 double	gate_time = GATE_TIME;	/* time to &quot;make it out of the gate&quot; */
 int	max_start = MAX_START;  /* how many times to run (default no limit) */
+double 	max_lifetime = MAX_LIFETIME; /* how long can the process/daemon live */
 int	net_timeout = TIMEO_NET; /* timeout on network data */
 char	*ssh_path = SSH_PATH;	/* default path to ssh */
 int	start_count;		/* # of times exec()d ssh */
@@ -169,6 +172,7 @@ void	xerrlog(int level, char *fmt, ...)
 void	doerrlog(int level, char *fmt, va_list ap);
 char	*timestr(void);
 void	sig_catch(int sig);
+int	exceeded_lifetime(void);
 
 void
 usage(int code)
@@ -195,50 +199,53 @@ usage(int code)
 		fprintf(stderr, &quot;\n&quot;);
 		fprintf(stderr, &quot;Environment variables are:\n&quot;);
 		fprintf(stderr, 
-		    &quot;    AUTOSSH_GATETIME   &quot;
+		    &quot;    AUTOSSH_GATETIME    &quot;
 		    &quot;- how long must an ssh session be established\n&quot;
-		    &quot;                       &quot;
+		    &quot;                        &quot;
 		    &quot;  before we decide it really was established\n&quot;
-		    &quot;                       &quot;
+		    &quot;                        &quot;
 		    &quot;  (in seconds)\n&quot;);
 		fprintf(stderr, 
-		    &quot;    AUTOSSH_LOGFILE    &quot;
+		    &quot;    AUTOSSH_LOGFILE     &quot;
 		    &quot;- file to log to (default is to use the syslog\n&quot;
-		    &quot;                       &quot;
+		    &quot;                        &quot;
 		    &quot;  facility)\n&quot;);
 		fprintf(stderr, 
-		    &quot;    AUTOSSH_LOGLEVEL   &quot;
+		    &quot;    AUTOSSH_LOGLEVEL    &quot;
 		    &quot;- level of log verbosity\n&quot;);
 		fprintf(stderr, 
-		    &quot;    AUTOSSH_MAXSTART   &quot;
+		    &quot;    AUTOSSH_MAXLIFETIME &quot;
+		    &quot;- set the maximum time to live (seconds)\n&quot;);
+		fprintf(stderr, 
+		    &quot;    AUTOSSH_MAXSTART    &quot;
 		    &quot;- max times to restart (default is no limit)\n&quot;);
 		fprintf(stderr, 
-		    &quot;    AUTOSSH_MESSAGE    &quot;
+		    &quot;    AUTOSSH_MESSAGE     &quot;
 		    &quot;- message to append to echo string (max 64 bytes)\n&quot;);
 #if defined(__CYGWIN__)
 		fprintf(stderr, 
-		    &quot;    AUTOSSH_NTSERVICE  &quot;
+		    &quot;    AUTOSSH_NTSERVICE   &quot;
 		    &quot;- tweak some things for running under cygrunsrv\n&quot;);
 #endif
 		fprintf(stderr, 
-		    &quot;    AUTOSSH_PATH       &quot;
+		    &quot;    AUTOSSH_PATH        &quot;
 		    &quot;- path to ssh if not default\n&quot;);
 		fprintf(stderr, 
-		    &quot;    AUTOSSH_PIDFILE    &quot;
+		    &quot;    AUTOSSH_PIDFILE     &quot;
 		    &quot;- write pid to this file\n&quot;);
 		fprintf(stderr, 
-		    &quot;    AUTOSSH_POLL       &quot;
+		    &quot;    AUTOSSH_POLL        &quot;
 		    &quot;- how often to check the connection (seconds)\n&quot;);
 		fprintf(stderr, 
-		    &quot;    AUTOSSH_FIRST_POLL &quot;
+		    &quot;    AUTOSSH_FIRST_POLL  &quot;
 		    &quot;- time before first connection check (seconds)\n&quot;);
 		fprintf(stderr, 
-		    &quot;    AUTOSSH_PORT       &quot;
+		    &quot;    AUTOSSH_PORT        &quot;
 		    &quot;- port to use for monitor connection\n&quot;);
 		fprintf(stderr, 
-		    &quot;    AUTOSSH_DEBUG      &quot;
+		    &quot;    AUTOSSH_DEBUG       &quot;
 		    &quot;- turn logging to maximum verbosity and log to\n&quot;
-		    &quot;                       &quot;
+		    &quot;                        &quot;
 		    &quot;  stderr\n&quot;);
 		fprintf(stderr, &quot;\n&quot;);
 	}
@@ -603,7 +610,7 @@ get_env_args(void)
 
 	if ((s = getenv(&quot;AUTOSSH_MAXSTART&quot;)) != NULL) {
 		max_start = (int)strtol(s, &amp;t, 0);
-		if (*s == '\0' || *t != '\0' )
+		if (*s == '\0' || max_start &lt; 0 || *t != '\0')
 			xerrlog(LOG_ERR, &quot;invalid max start number \&quot;%s\&quot;&quot;, s);
 	}
 
@@ -620,6 +627,33 @@ get_env_args(void)
 		if (*s != '\0')
 			env_port = s;
 
+	if ((s = getenv(&quot;AUTOSSH_MAXLIFETIME&quot;)) != NULL) {
+		max_lifetime = (double)strtoul(s, &amp;t, 0);
+		if (*s == '\0' || *t != '\0' )
+			xerrlog(LOG_ERR,
+				&quot;invalid max lifetime \&quot;%s\&quot;&quot;, s);
+		/* can't really be &lt; 0, as converted as unsigned long */
+		if (max_lifetime &lt;= 0 )
+			max_lifetime = MAX_LIFETIME;
+		else {
+			if (poll_time &gt; max_lifetime) {
+				errlog( LOG_INFO, 
+					&quot;poll time is greater then lifetime,&quot;
+					&quot; dropping poll time to %.0f&quot;, max_lifetime );
+				poll_time = max_lifetime;
+			}
+
+			if (first_poll_time &gt; max_lifetime) {
+				errlog( LOG_INFO, 
+					&quot;first poll time is greater then lifetime,&quot;
+					&quot; dropping first poll time to %.0f&quot;, max_lifetime );
+				first_poll_time = max_lifetime;
+			}
+
+			time(&amp;pid_start_time);
+		}
+	}
+
 	if ((s = getenv(&quot;AUTOSSH_PIDFILE&quot;)) != NULL)
 		if (*s != '\0')
 			pid_file_name = s;
@@ -679,6 +713,8 @@ ssh_run(int sock, char **av)
 	srandom(getpid() ^ tv.tv_usec ^ tv.tv_sec);
 
 	while (max_start &lt; 0 || start_count &lt; max_start) {
+		if (exceeded_lifetime())
+			return;
 		restart_ssh = 0;
 		start_count++;
 		grace_time(start_time);
@@ -726,6 +762,8 @@ ssh_watch(int sock)
 	int	val;
 	static	int	secs_left;
 	int	my_poll_time = first_poll_time;
+	time_t	now;
+	double	secs_to_shutdown;
 
 #if defined(HAVE_SETPROCTITLE)
 	setproctitle(&quot;parent of %d (%d)&quot;, 
@@ -753,8 +791,16 @@ ssh_watch(int sock)
 			secs_left = alarm(0);
 			if (secs_left == 0)
 				secs_left = my_poll_time;
+
 			my_poll_time = poll_time;
 
+			if (max_lifetime != 0) {
+				time(&amp;now);
+				secs_to_shutdown = max_lifetime - difftime(now,pid_start_time);
+				if (secs_to_shutdown &lt; poll_time)
+					secs_left = secs_to_shutdown;
+			}
+
 			errlog(LOG_DEBUG, 
 			    &quot;set alarm for %d secs&quot;, secs_left);
 
@@ -775,6 +821,11 @@ ssh_watch(int sock)
 				return P_EXIT;
 				break;
 			case SIGALRM:
+				if (exceeded_lifetime()) {
+					ssh_kill();
+					return P_EXIT;
+				}
+
 				if (writep &amp;&amp; sock != -1 &amp;&amp;
 				    !conn_test(sock, mhost, writep)) {
 					errlog(LOG_INFO, 
@@ -782,6 +833,19 @@ ssh_watch(int sock)
 					ssh_kill();
 					return P_RESTART;
 				}
+#ifdef TOUCH_PIDFILE
+				/*
+				 * utimes() with a NULL time argument sets
+				 * file access and modification times to
+				 * the current time
+				 */
+				if (pid_file_name &amp;&amp; 
+				    utimes(pid_file_name, NULL) != 0) {
+					errlog(LOG_ERR,
+					    &quot;could not touch pid file: %s&quot;,
+					    strerror(errno));
+				}
+#endif
 				break;
 			default:
 				break;
@@ -791,6 +855,27 @@ ssh_watch(int sock)
 }
 
 /*
+ * Checks to see if we have exceeded our time to live
+ * Returns 1 if we have, 0 if we haven't
+ */
+int
+exceeded_lifetime(void)
+{
+	time_t	now;
+
+	if (max_lifetime &gt; 0 ) {
+		time(&amp;now);
+		if (difftime(now, pid_start_time) &gt;= max_lifetime ) {
+			errlog(LOG_INFO, 
+				&quot;exceeded maximum time to live, shutting down&quot;);
+			return 1;
+		}
+	}
+
+	return 0;
+}
+
+/*
  * Wait on child: with options == WNOHANG, poll for
  * dead child, else if options == 0, then wait for
  * known dead child.
@@ -1258,8 +1343,16 @@ conn_send_and_receive(char *rp, char *wp, size_t len,
 				wp    += nwrite;
 			}
 			/* if complete, turn off polling for write */
-			if (wleft == 0)
+			if (wleft == 0) {
 				ntopoll = 1;
+				/* 
+				 * if we are reading and writing to the 
+				 * same fd then we must clear the write bit 
+				 * so that poll doesn't loop tight.
+				 */
+				if (iwr == ird)
+				    pfd[ird].events = POLLIN;
+			}
 		}
 
 		if (pfd[ird].revents &amp; POLLIN || pfd[ird].revents &amp; POLLHUP) {</diff>
      <filename>autossh/autossh.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 Summary:	Automatically restart SSH sessions and tunnels
 Name:		autossh
-Version:	1.4
+Version:	1.4b
 Release:	1
 License:	Distributable
 Group:		Applications/Networking
@@ -38,6 +38,9 @@ rm -rf $RPM_BUILD_ROOT
 %{_mandir}/man1/*
 
 %changelog
+* Fri Mar 28 2008 Carson Harding &lt;harding@motd.ca&gt;
+- update to 1.4b
+
 * Sat May 20 2006 Carson Harding &lt;harding@motd.ca&gt;
 - update to 1.4 and use autoconf
 </diff>
      <filename>autossh/autossh.spec</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>e5a68b00d9e2816a402e14f2cf39ec24f4236310</id>
    </parent>
  </parents>
  <author>
    <name>Ryan Tomayko</name>
    <email>rtomayko@gmail.com</email>
  </author>
  <url>http://github.com/rtomayko/hem/commit/7d8e2057bc3697af467ba7fb03f178c13ad71083</url>
  <id>7d8e2057bc3697af467ba7fb03f178c13ad71083</id>
  <committed-date>2009-02-26T02:33:16-08:00</committed-date>
  <authored-date>2009-02-26T02:33:16-08:00</authored-date>
  <message>bring in autossh-1.4b</message>
  <tree>7fbdbd3ae2dacc8fa54e9fc52703f355e59e805f</tree>
  <committer>
    <name>Ryan Tomayko</name>
    <email>rtomayko@gmail.com</email>
  </committer>
</commit>
