[27125] in Source-Commits
/svn/athena r25961 - in trunk/athena/bin/desync: . debian debian/source man src
daemon@ATHENA.MIT.EDU (Victor Vasiliev)
Sat May 4 19:42:44 2013
Date: Sat, 4 May 2013 19:42:37 -0400
From: Victor Vasiliev <vasilvv@MIT.EDU>
Message-Id: <201305042342.r44NgbTf022127@drugstore.mit.edu>
To: source-commits@MIT.EDU
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Author: vasilvv
Date: 2013-05-04 19:42:36 -0400 (Sat, 04 May 2013)
New Revision: 25961
Added:
trunk/athena/bin/desync/Makefile.am
trunk/athena/bin/desync/configure.ac
trunk/athena/bin/desync/debian/source/
trunk/athena/bin/desync/debian/source/format
trunk/athena/bin/desync/m4/
trunk/athena/bin/desync/man/
trunk/athena/bin/desync/man/Makefile.am
trunk/athena/bin/desync/man/desync.1
trunk/athena/bin/desync/src/
trunk/athena/bin/desync/src/Makefile.am
trunk/athena/bin/desync/src/desync.c
Removed:
trunk/athena/bin/desync/Makefile.in
trunk/athena/bin/desync/configure.in
trunk/athena/bin/desync/desync.1
trunk/athena/bin/desync/desync.c
Modified:
trunk/athena/bin/desync/debian/changelog
trunk/athena/bin/desync/debian/control
trunk/athena/bin/desync/debian/rules
Log:
In desync:
* Use automake
* Bump upstream version
* Switch to debhelper7
* Switch to source format 3.0 (quilt)
Added: trunk/athena/bin/desync/Makefile.am
===================================================================
--- trunk/athena/bin/desync/Makefile.am (rev 0)
+++ trunk/athena/bin/desync/Makefile.am 2013-05-04 23:42:36 UTC (rev 25961)
@@ -0,0 +1,3 @@
+ACLOCAL_AMFLAGS = --install -I m4
+SUBDIRS = src man
+
Added: trunk/athena/bin/desync/configure.ac
===================================================================
--- trunk/athena/bin/desync/configure.ac (rev 0)
+++ trunk/athena/bin/desync/configure.ac 2013-05-04 23:42:36 UTC (rev 25961)
@@ -0,0 +1,35 @@
+# -*- Autoconf -*-
+# Process this file with autoconf to produce a configure script.
+
+AC_PREREQ([2.65])
+AC_INIT([desync], [10.2], [debathena@mit.edu])
+AM_INIT_AUTOMAKE([foreign -Wall])
+AM_MAINTAINER_MODE([enable])
+m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
+AC_CONFIG_MACRO_DIR([m4])
+AC_CONFIG_SRCDIR([src/desync.c])
+AC_CONFIG_HEADERS([config.h])
+
+# Checks for programs.
+AC_PROG_CC
+AC_PROG_INSTALL
+# automake 1.12 seems to require this, but automake 1.11 doesn't recognize it
+m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
+LT_INIT
+
+# Checks for libraries.
+
+# Checks for header files.
+AC_CHECK_HEADERS([fcntl.h limits.h stdlib.h string.h unistd.h])
+
+# Checks for typedefs, structures, and compiler characteristics.
+
+# Checks for library functions.
+AC_CHECK_FUNCS([gethostname strerror strtol])
+
+AC_CONFIG_FILES([Makefile
+ src/Makefile
+ man/Makefile
+])
+AC_OUTPUT
+
Modified: trunk/athena/bin/desync/debian/changelog
===================================================================
--- trunk/athena/bin/desync/debian/changelog 2013-05-03 14:56:20 UTC (rev 25960)
+++ trunk/athena/bin/desync/debian/changelog 2013-05-04 23:42:36 UTC (rev 25961)
@@ -1,9 +1,16 @@
-debathena-desync (10.1-0debathena2) UNRELEASED; urgency=low
+debathena-desync (10.2-0debathena1) UNRELEASED; urgency=low
+ [ Jonathan Reed ]
* Switch from control.in to control (Trac: #561)
* Bump Standards-Version to 3.9.3
* Bump compat level to 7
+ [ Victor Vasiliev ]
+ * Use automake
+ * Bump upstream version
+ * Switch to debhelper7
+ * Switch to source format 3.0 (quilt)
+
-- Jonathan Reed <jdreed@mit.edu> Wed, 03 Apr 2013 13:59:37 -0400
debathena-desync (10.1-0debathena1) unstable; urgency=low
Modified: trunk/athena/bin/desync/debian/control
===================================================================
--- trunk/athena/bin/desync/debian/control 2013-05-03 14:56:20 UTC (rev 25960)
+++ trunk/athena/bin/desync/debian/control 2013-05-04 23:42:36 UTC (rev 25961)
@@ -2,7 +2,7 @@
Section: debathena/text
Priority: extra
Maintainer: Debathena Project <debathena@mit.edu>
-Build-Depends: cdbs, debhelper, dh-buildinfo, autoconf
+Build-Depends: debhelper (>= 7), dh-autoreconf
Standards-Version: 3.9.3
Package: debathena-desync
@@ -13,3 +13,4 @@
The desync program sleeps for a randomly selected period of time
(depending on the machine's hostname) and can be used to
desynchronize periodic tasks which are run on many machines.
+
Modified: trunk/athena/bin/desync/debian/rules
===================================================================
--- trunk/athena/bin/desync/debian/rules 2013-05-03 14:56:20 UTC (rev 25960)
+++ trunk/athena/bin/desync/debian/rules 2013-05-04 23:42:36 UTC (rev 25961)
@@ -1,8 +1,5 @@
#!/usr/bin/make -f
-DEB_AUTO_UPDATE_AUTOCONF = 2.50
-include /usr/share/cdbs/1/rules/debhelper.mk
-include /usr/share/cdbs/1/class/autotools.mk
+%:
+ dh $@ --with autoreconf
-clean::
- rm -f configure
Added: trunk/athena/bin/desync/debian/source/format
===================================================================
--- trunk/athena/bin/desync/debian/source/format (rev 0)
+++ trunk/athena/bin/desync/debian/source/format 2013-05-04 23:42:36 UTC (rev 25961)
@@ -0,0 +1 @@
+3.0 (quilt)
Added: trunk/athena/bin/desync/man/Makefile.am
===================================================================
--- trunk/athena/bin/desync/man/Makefile.am (rev 0)
+++ trunk/athena/bin/desync/man/Makefile.am 2013-05-04 23:42:36 UTC (rev 25961)
@@ -0,0 +1,2 @@
+dist_man1_MANS = desync.1
+
Copied: trunk/athena/bin/desync/man/desync.1 (from rev 25960, trunk/athena/bin/desync/desync.1)
===================================================================
--- trunk/athena/bin/desync/man/desync.1 (rev 0)
+++ trunk/athena/bin/desync/man/desync.1 2013-05-04 23:42:36 UTC (rev 25961)
@@ -0,0 +1,141 @@
+.\" $Id: desync.8,v 1.3 2000-09-30 21:08:29 rbasch Exp $
+.\"
+.\" Copyright 1995, 1996, 1997 by the Massachusetts Institute of Technology.
+.\"
+.\" Permission to use, copy, modify, and distribute this
+.\" software and its documentation for any purpose and without
+.\" fee is hereby granted, provided that the above copyright
+.\" notice appear in all copies and that both that copyright
+.\" notice and this permission notice appear in supporting
+.\" documentation, and that the name of M.I.T. not be used in
+.\" advertising or publicity pertaining to distribution of the
+.\" software without specific, written prior permission.
+.\" M.I.T. makes no representations about the suitability of
+.\" this software for any purpose. It is provided "as is"
+.\" without express or implied warranty.
+.\"
+.TH DESYNC 1 "3 August 2012"
+.SH NAME
+desync \- desynchronize timed jobs on networks
+.SH SYNOPSIS
+.B desync
+[
+.B \-t
+timefile ] [ range ]
+
+.B desync -c
+hours [ range [ other arguments ] ]
+.SH DESCRIPTION
+.I desync
+is a tool which sleeps a random (hostname seeded) period of time (up
+to an hour, by default) in order to skew the network load from several
+machines running
+.I cron
+jobs that would otherwise be synchronized.
+
+An invocation would appear something like
+
+.nf
+ 42 * * * * desync; /usr/lib/sendmail -q
+.fi
+
+in a crontab file.
+.SH OPTIONS
+.TP 8
+.B range
+This optional range specifies, in seconds, the maximum value for the
+randomly selected sleep time. The default value is 3600 (except in
+"crontab" mode, see below).
+.TP 8
+.B \-h name
+Use
+.I name
+to seed the random number generator, instead of using the current host
+name. This option is generally only useful in conjunction with the
+.B \-n
+option.
+.TP 8
+.B \-n
+Instead of sleeping, this option causes
+.I desync
+to write the number of seconds it would sleep to standard output, or,
+if the
+.B \-t
+option is also specified, the number of seconds remaining until the
+timer in
+.I timefile
+expires.
+.TP 8
+.B \-t timefile
+This option changes the behavior of
+.I desync
+to make it useful for desynchronizing jobs when sleeping is not
+appropriate. If
+.I timefile
+does not exist,
+.I desync
+selects a random sleep time using the normal method, adds it to the
+current time value, writes the result into
+.IR timefile ,
+and exits with status 1. If
+.I timefile
+does exist and the current time is less than the time value listed in
+.IR timefile ,
+then
+.I desync
+takes no action and exits with status 1. If
+.I timefile
+exists and the current time is equal to or greater than the time value
+listed in
+.IR timefile ,
+then
+.I desync
+unlinks
+.I timefile
+and exits with status 0. This feature can be used in shell code of
+the following form:
+
+.nf
+ if desync -t /tmp/mytimefile 3600; then
+ echo "Starting the job."
+ else
+ echo "Putting it off until later."
+ fi
+.fi
+
+.TP 8
+.B \-c hours
+This option changes the behavior of
+.I desync
+and causes it to generate output suitable for use in a crontab file. It
+also changes the units of
+.I range
+to minutes (from seconds), changes the default value to 60 and enforces
+a maximum value of 1439. This is useful on modern Linux distributions,
+where sleeping for extended periods inside a cron job can confuse power
+management software or packages such as ConsoleKit, and running a cron
+job every 5 minutes to see if desync thinks it is "time to run" is
+undesirable. Since desync will generate the same value each time on the
+same machine, it is fine to generate crontab files in a package's
+post-install script, for example. In this mode, desync will output the
+crontab fields and then any additional arguments you supply. So to
+generate a crontab with a randomized job, one might do something like
+this:
+
+.nf
+ for i in 2 4 8 14 20; do
+ desync -c $i 120 root /etc/athena/update_ws >> /etc/cron.d/update
+ done
+.fi
+
+
+.SH SEE ALSO
+cron(8)
+.SH AUTHOR
+Craig Fields, MIT Information Systems
+.br
+Greg Hudson, MIT Information Systems
+.br
+Debathena Project
+.br
+Copyright (c) 1995, 1996, 1997, 2012 Massachusetts Institute of Technology
Added: trunk/athena/bin/desync/src/Makefile.am
===================================================================
--- trunk/athena/bin/desync/src/Makefile.am (rev 0)
+++ trunk/athena/bin/desync/src/Makefile.am 2013-05-04 23:42:36 UTC (rev 25961)
@@ -0,0 +1,3 @@
+bin_PROGRAMS = desync
+desync_SOURCES = desync.c
+
Copied: trunk/athena/bin/desync/src/desync.c (from rev 25960, trunk/athena/bin/desync/desync.c)
===================================================================
--- trunk/athena/bin/desync/src/desync.c (rev 0)
+++ trunk/athena/bin/desync/src/desync.c 2013-05-04 23:42:36 UTC (rev 25961)
@@ -0,0 +1,240 @@
+/* Copyright 1996, 1997 by the Massachusetts Institute of Technology.
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ */
+
+static const char rcsid[] = "$Id: desync.c,v 1.9 2000-09-30 21:08:32 rbasch Exp $";
+
+/*
+ * desync - desynchronize cron jobs on networks
+ *
+ * This program is a tool which sleeps an ip-address dependent period
+ * of time in order to skew over the course of a set time cron jobs
+ * that would otherwise be synchronized. It should reside on local disk
+ * so as not to cause a fileserver load at its own invocation.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <ctype.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+#include <time.h>
+#include <limits.h>
+
+extern int optind;
+extern char *optarg;
+
+static char *progname;
+
+static unsigned long get_hash(const char *str);
+
+static void usage(void);
+
+int main(int argc, char **argv)
+{
+ const char *timefile = NULL, *hostname = NULL, *crontabhour = NULL;
+ char buf[128];
+ int range, interval, c, noop = 0;
+ unsigned long tval;
+ time_t timenow;
+ FILE *fp;
+
+ /* Save the program name. */
+ progname = argv[0];
+
+ /* Parse command-line flags. */
+ while ((c = getopt(argc, argv, "h:nc:t:")) != -1)
+ {
+ switch (c) {
+ case 'h':
+ hostname = optarg;
+ break;
+ case 'n':
+ noop = 1;
+ break;
+ case 'c':
+ crontabhour = optarg;
+ break;
+ case 't':
+ timefile = optarg;
+ break;
+ default:
+ usage();
+ return 2;
+ }
+ }
+
+ if (crontabhour && ((timefile != NULL) || (noop == 1))) {
+ usage();
+ return 2;
+ }
+ /* Get the time interval from the remaining argument, if there is one. */
+ argc -= optind;
+ argv += optind;
+ if ((argc > 1) && ! crontabhour) {
+ usage();
+ return 2;
+ }
+ if (argc >= 1) {
+ range = atoi(argv[0]);
+ argc -= 1;
+ argv += 1;
+ } else {
+ range = crontabhour == NULL ? 3600 : 60;
+ }
+ if ((range == 0) ||
+ (crontabhour && (range >= 1440)))
+ {
+ fprintf(stderr, "%s: Invalid range value\n", progname);
+ usage();
+ return 2;
+ }
+
+ /* Get a random number in the given range as the interval. Seed the
+ * random number generator with a hash of the current host name, or
+ * the name given via the -h option.
+ */
+ if (hostname == NULL)
+ {
+ if (gethostname(buf, sizeof(buf)) != 0)
+ {
+ fprintf(stderr, "%s: Unable to obtain hostname: %s\n",
+ progname, strerror(errno));
+ return 2;
+ }
+ buf[sizeof(buf) - 1] = '\0';
+ hostname = buf;
+ }
+ srand(get_hash(hostname));
+ interval = rand() % range;
+
+ if (timefile)
+ {
+ time(&timenow);
+ fp = fopen(timefile, "r");
+ if (fp)
+ {
+ if (fscanf(fp, "%lu", &tval) != 1)
+ {
+ fprintf(stderr, "%s: Invalid time file %s\n", progname,
+ timefile);
+ return 2;
+ }
+ fclose(fp);
+ if (timenow >= tval)
+ {
+ if (noop)
+ puts("0");
+ else
+ unlink(timefile);
+ return 0;
+ }
+ else
+ {
+ if (noop)
+ printf("%lu\n", (unsigned long) (tval - timenow));
+ return 1;
+ }
+ }
+ else if (noop)
+ {
+ fprintf(stderr, "%s: Warning: Cannot open %s (%s)\n", progname,
+ timefile, strerror(errno));
+ printf("%lu\n", (unsigned long) (interval));
+ return (interval == 0 ? 0 : 1);
+ }
+ else
+ {
+ if (interval == 0)
+ return 0;
+ fp = fopen(timefile, "w");
+ if (fp == NULL)
+ {
+ fprintf(stderr, "%s: Couldn't open %s for writing: %s\n",
+ progname, timefile, strerror(errno));
+ return 2;
+ }
+ fprintf(fp, "%lu\n", (unsigned long)(timenow + interval));
+ fclose(fp);
+ return 1;
+ }
+ }
+ else if (crontabhour)
+ {
+ char *endptr;
+ int mins, hours = 0;
+ int j;
+ errno = 0;
+ hours = strtol(crontabhour, &endptr, 10);
+ if ((errno == ERANGE && (hours == LONG_MAX || hours == LONG_MIN))
+ || (errno != 0 && hours == 0)
+ || (endptr == crontabhour))
+ {
+ fprintf(stderr, "%s: Could not convert %s to integer\n", progname,
+ crontabhour);
+ return 1;
+ }
+ if ((hours > 23) || (hours < 0 ))
+ {
+ fprintf(stderr,
+ "%s: in crontab mode, hours must be between 0 and 23\n",
+ progname);
+ return 1;
+ }
+ mins = interval % 60;
+ hours = (hours + (interval / 60)) % 24;
+ printf("%d %d * * *", mins, hours);
+ for (j = 0; j < argc; j++)
+ printf(" %s", argv[j]);
+ printf("\n");
+ }
+ else if (noop)
+ printf("%lu\n", (unsigned long) interval);
+ else
+ sleep(interval);
+
+ return 0;
+}
+
+static unsigned long get_hash(const char *str)
+{
+ const char *p;
+ unsigned long g, hashval = 0;
+
+ for (p = str; *p; p++)
+ {
+ hashval = (hashval << 4) + *p;
+ g = hashval & 0xf0000000;
+ if (g != 0) {
+ hashval ^= g >> 24;
+ hashval ^= g;
+ }
+ }
+
+ if (hashval == 0)
+ hashval = 1;
+
+ return hashval;
+}
+
+static void usage()
+{
+ fprintf(stderr,
+ "Usage: %s [-h name] [-n] [-t timefile] [range]\n %s -c hour [range [crontab arguments]]\n",
+ progname, progname);
+}