[26731] in Source-Commits

home help back first fref pref prev next nref lref last post

Re: /svn/athena r25710 - trunk/athena/bin/desync

daemon@ATHENA.MIT.EDU (Benjamin Kaduk)
Wed Aug 8 14:03:21 2012

Date: Wed, 8 Aug 2012 14:03:16 -0400 (EDT)
From: Benjamin Kaduk <kaduk@MIT.EDU>
To: Jonathan D Reed <jdreed@MIT.EDU>
cc: source-commits@MIT.EDU
In-Reply-To: <201208072357.q77Nv6lK001807@drugstore.mit.edu>
Message-ID: <alpine.GSO.1.10.1208081401370.22690@multics.mit.edu>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed

On Tue, 7 Aug 2012, Jonathan D Reed wrote:

> Author: jdreed
> Date: 2012-08-07 19:57:06 -0400 (Tue, 07 Aug 2012)
> New Revision: 25710
>
> Modified:
>   trunk/athena/bin/desync/desync.1
>   trunk/athena/bin/desync/desync.c
> Log:
> Update usage and enforce limits in crontab mode
>
> Modified: trunk/athena/bin/desync/desync.1
> ===================================================================
> --- trunk/athena/bin/desync/desync.1	2012-08-07 19:58:58 UTC (rev 25709)
> +++ trunk/athena/bin/desync/desync.1	2012-08-07 23:57:06 UTC (rev 25710)
> @@ -24,7 +24,7 @@
> timefile ] [ range ]
>
> .B desync -c
> -hours [ range ] [ other arguments ]
> +hours [ range [ other arguments ] ]
> .SH DESCRIPTION
> .I desync
> is a tool which sleeps a random (hostname seeded) period of time (up
> @@ -44,7 +44,8 @@
> .TP 8
> .B range
> This optional range specifies, in seconds, the maximum value for the
> -randomly selected sleep time.  The default value is 3600.
> +randomly selected sleep time.  The default value is 3600 (except in
> +"crontab" mode, see below).
> .TP 8
> .B \-h name
> Use
> @@ -106,16 +107,20 @@
> .B \-c hours
> This option changes the behavior of
> .I desync
> -and causes it to generate output suitable for use in a crontab file.
> -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:
> +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
>
> Modified: trunk/athena/bin/desync/desync.c
> ===================================================================
> --- trunk/athena/bin/desync/desync.c	2012-08-07 19:58:58 UTC (rev 25709)
> +++ trunk/athena/bin/desync/desync.c	2012-08-07 23:57:06 UTC (rev 25710)
> @@ -95,9 +95,10 @@
>     argc -= 1;
>     argv += 1;
>   } else {
> -    range = 3600;
> +    range = crontabhour == NULL ? 3600 : 60;

The bare ternary looks odd to me there; I would normally use parentheses 
in a construction like that.  Though I don't remember whether it would be 
around the whole thing or just the logic comparison...
Anyway, ACK, and thanks.

-Ben

>   }
> -  if (range == 0)
> +  if ((range == 0) ||
> +      (crontabhour && (range >= 1440)))
>     {
>       fprintf(stderr, "%s: Invalid range value\n", progname);
>       usage();
> @@ -234,6 +235,6 @@
> static void usage()
> {
>   fprintf(stderr,
> -	  "Usage: %s [-h name] [-n] [-t timefile] [range]\n       %s -c hour [range] [crontab arguments]\n",
> +	  "Usage: %s [-h name] [-n] [-t timefile] [range]\n       %s -c hour [range [crontab arguments]]\n",
> 	  progname, progname);
> }
>
>

home help back first fref pref prev next nref lref last post