diff options
author | Jeroen Roovers <jer@gentoo.org> | 2012-05-08 15:58:57 +0000 |
---|---|---|
committer | Jeroen Roovers <jer@gentoo.org> | 2012-05-08 15:58:57 +0000 |
commit | 94fca30e50995fd1f22c7affe93226ce43ff3ebc (patch) | |
tree | c8ab749908eaad59a51b426e7de495d3d9e0197a /dev-util | |
parent | Marking PAR-Dist-0.480.0 ppc64 for bug 414937 (diff) | |
download | historical-94fca30e50995fd1f22c7affe93226ce43ff3ebc.tar.gz historical-94fca30e50995fd1f22c7affe93226ce43ff3ebc.tar.bz2 historical-94fca30e50995fd1f22c7affe93226ce43ff3ebc.zip |
Version bump by Marcin Mirosław (bug #415147).
Package-Manager: portage-2.2.0_alpha101/cvs/Linux x86_64
Diffstat (limited to 'dev-util')
-rw-r--r-- | dev-util/lockrun/ChangeLog | 10 | ||||
-rw-r--r-- | dev-util/lockrun/Manifest | 16 | ||||
-rw-r--r-- | dev-util/lockrun/files/lockrun.c-20120508 | 294 | ||||
-rw-r--r-- | dev-util/lockrun/lockrun-20120508.ebuild | 31 |
4 files changed, 341 insertions, 10 deletions
diff --git a/dev-util/lockrun/ChangeLog b/dev-util/lockrun/ChangeLog index 04cd6e6ac486..83c346098920 100644 --- a/dev-util/lockrun/ChangeLog +++ b/dev-util/lockrun/ChangeLog @@ -1,6 +1,12 @@ # ChangeLog for dev-util/lockrun -# Copyright 1999-2010 Gentoo Foundation; Distributed under the GPL v2 -# $Header: /var/cvsroot/gentoo-x86/dev-util/lockrun/ChangeLog,v 1.8 2010/08/11 01:00:23 jer Exp $ +# Copyright 1999-2012 Gentoo Foundation; Distributed under the GPL v2 +# $Header: /var/cvsroot/gentoo-x86/dev-util/lockrun/ChangeLog,v 1.9 2012/05/08 15:58:57 jer Exp $ + +*lockrun-20120508 (08 May 2012) + + 08 May 2012; Jeroen Roovers <jer@gentoo.org> +files/lockrun.c-20120508, + +lockrun-20120508.ebuild: + Version bump by Marcin Mirosław (bug #415147). 11 Aug 2010; Jeroen Roovers <jer@gentoo.org> lockrun-2.ebuild: Use dobin. Use emake, respect CC, and respect LDFLAGS (bug #331839). diff --git a/dev-util/lockrun/Manifest b/dev-util/lockrun/Manifest index 09d1325b9ff1..62aff1a15b21 100644 --- a/dev-util/lockrun/Manifest +++ b/dev-util/lockrun/Manifest @@ -1,16 +1,16 @@ -----BEGIN PGP SIGNED MESSAGE----- -Hash: SHA256 +Hash: SHA1 AUX lockrun.c 6575 RMD160 91c6820a87669de5d240df0b58ebcb41bc5f9d54 SHA1 d50a9b5f3c22683c47bbe3173355cd6f0cbc2090 SHA256 a334776691c0e0c7ceea0ea78bac9124ab9df176797cd77cda95a1307065e715 +AUX lockrun.c-20120508 7021 RMD160 cd061c88f1bbe5370fdadfd0cd5bd139a0dcdfcd SHA1 456716dcbb6d1816e3633440462126a65c58439e SHA256 e9e60ae24c52875332d775a94f1fe188f7cf0d95b2de9e728f83dec693aba44d EBUILD lockrun-2.ebuild 649 RMD160 38d7fa2e79d0bde1116fb51412ab7b8c59f88735 SHA1 d497417fe219547c59f1866103ad1eebf5545372 SHA256 853cbedcc882d9cdb5d743890ebe531413d15f17ce1fac7214c7cc05c1171600 -MISC ChangeLog 1044 RMD160 696eb2859ff30813139f2344c5905c65a3df1284 SHA1 ab527642a6a0bef6e07ce228ce71a597b04d6784 SHA256 3981334d5fc82adbff898f4e87ca7c9d4458d55716222305524a795da225a439 +EBUILD lockrun-20120508.ebuild 700 RMD160 c8e8ed0a7f7d5b3295ad4a2bb14ce249914219af SHA1 201fff647680e19f952456c5877af5ec8f9c4260 SHA256 e7bbb4037937116976e958b7af63eb8499943d73faeabd88496273ec08626464 +MISC ChangeLog 1230 RMD160 5a9c7d22e925c8886334e66e2c143b338194aed8 SHA1 6d1c732e7f4db5c96fbab39e7519570b3dc5da38 SHA256 ed147063b04a969aa6e5a011ea9a0e7affe37e73fe716e2251fe9cb56c26c4d1 MISC metadata.xml 211 RMD160 f0c4ad6ccb0152d62a300bc77956ea3bf7c170a2 SHA1 6f46be7ecc51754f0679bc5a779c151e1b701016 SHA256 84ff2341253cdd21a6782e14ebc076a8bcae11428aacfe2454f4b32165504727 -----BEGIN PGP SIGNATURE----- -Version: GnuPG v2.0.18 (GNU/Linux) +Version: GnuPG v2.0.17 (GNU/Linux) -iJwEAQEIAAYFAk59m4sACgkQfXuS5UK5QB2GBQP/TgP4zmUr816uHg7eJMNpLCea -FA35TdCFkHYxlAyzYpJXmc93aSzJXO1VV0d296SStcv2tvvY9/T+wWD4+idiCETE -eh7IR0qtCvaI4ZzBSQFXq7Yw1pl9boH/eZ2zXz0FKSL65+urXFNkQFZZP2sogKzT -FSgkq/nrdr5lTA56JpA= -=72go +iEYEARECAAYFAk+pQssACgkQVWmRsqeSphPsggCfWstgwBn/I6RK8AxFh7XWrtY6 +mMUAnjWQpELrDJXoRD41C/3GiChWqn+J +=/Nr8 -----END PGP SIGNATURE----- diff --git a/dev-util/lockrun/files/lockrun.c-20120508 b/dev-util/lockrun/files/lockrun.c-20120508 new file mode 100644 index 000000000000..67ff22f0e622 --- /dev/null +++ b/dev-util/lockrun/files/lockrun.c-20120508 @@ -0,0 +1,294 @@ +/* + * $Id: lockrun.c-20120508,v 1.1 2012/05/08 15:58:57 jer Exp $ + * + * written by : Stephen J. Friedl + * Software Consultant + * steve@unixwiz.net + * http://www.unixwiz.net/tools/ + * + * =================================================================== + * ======== This software is in the public domain, and can be ======== + * ======== used by anybody for any purpose ======== + * =================================================================== + * + * Lockrun: This program is used to launch a program out with a lockout + * so that only one can run at a time. It's mainly intended for use out + * of cron so that our five-minute running jobs which run long don't get + * walked on. We find this a *lot* with Cacti jobs which just get hung + * up: it's better to miss a polling period than to stack them up and + * slow each other down. + * + * So we use a file which is used for locking: this program attempts to + * lock the file, and if the lock exists, we have to either exit with + * an error, or wait for it to release. + * + * lockrun --lockfile=FILE -- my command here + * + * COMMAND LINE + * ------------ + * + * --lockfile=F + * + * Specify the name of a file which is used for locking. The file is + * created if necessary (with mode 0666), and no I/O of any kind is + * done. The file is never removed. + * + * --maxtime=N + * + * The script being controlled should run for no more than <N> seconds, + * and if it's beyond that time, we should report it to the standard + * error (which probably gets routed to the user via cron's email). + * + * --wait + * + * When a lock is hit, we normally exit with error, but --wait causes + * it to loop until the lock is released. + * + * --verbose + * + * Show a bit more runtime debugging. + * + * --quiet + * + * Don't show "run is locked" error if things are busy; keeps cron from + * overwhelming you with messages if lockrun overlap is not uncommon. + * + * -- + * + * Mark the end of the options: the command to run follows. + * + */ + +#include <stdio.h> +#include <stdarg.h> +#include <errno.h> +#include <stdlib.h> +#include <string.h> +#include <fcntl.h> +#include <unistd.h> +#include <time.h> +#include <sys/types.h> +#include <sys/wait.h> +#include <sys/file.h> + +#ifndef __GNUC__ +# define __attribute__(x) /* nothing */ +#endif + + +#define STRMATCH(a,b) (strcmp((a),(b)) == 0) + +#define UNUSED_PARAMETER(v) ((void)(v)) + +#define TRUE 1 +#define FALSE 0 + +static const char *lockfile = 0; +static int wait_for_lock = FALSE; +static mode_t openmode = 0666; +static int sleeptime = 10; /* seconds */ +static int Verbose = FALSE; +static int Maxtime = 0; +static int Quiet = FALSE; + +static char *getarg(char *opt, char ***pargv); + +static void die(const char *format, ...) + __attribute__((noreturn)) + __attribute__((format(printf, 1, 2))); + +#ifdef __sun +# define WAIT_AND_LOCK(fd) lockf(fd, F_TLOCK,0) +#else +# define WAIT_AND_LOCK(fd) flock(fd, LOCK_EX | LOCK_NB) +#endif + +int main(int argc, char **argv) +{ + char *Argv0 = *argv; + int rc; + int lfd; + pid_t childpid; + time_t starttime; + + UNUSED_PARAMETER(argc); + + time(&starttime); + + for ( argv++ ; *argv ; argv++ ) + { + char *arg = *argv; + char *opt = strchr(arg, '='); + + /* the -- token marks the end of the list */ + + if ( strcmp(*argv, "--") == 0 ) + { + argv++; + break; + } + + if (opt) *opt++ = '\0'; /* pick off the =VALUE part */ + + if ( STRMATCH(arg, "-L") || STRMATCH(arg, "--lockfile")) + { + lockfile = getarg(opt, &argv); + } + + else if ( STRMATCH(arg, "-W") || STRMATCH(arg, "--wait")) + { + wait_for_lock = TRUE; + } + + else if ( STRMATCH(arg, "-S") || STRMATCH(arg, "--sleep")) + { + sleeptime = atoi(getarg(opt, &argv)); + } + + else if ( STRMATCH(arg, "-T") || STRMATCH(arg, "--maxtime")) + { + Maxtime = atoi(getarg(opt, &argv)); + } + + else if ( STRMATCH(arg, "-V") || STRMATCH(arg, "--verbose")) + { + Verbose++; + } + + else if ( STRMATCH(arg, "-q") || STRMATCH(arg, "--quiet")) + { + Quiet = TRUE; + } + + else + { + die("ERROR: \"%s\" is an invalid cmdline param", arg); + } + } + + /*---------------------------------------------------------------- + * SANITY CHECKING + * + * Make sure that we have all the parameters we require + */ + if (*argv == 0) + die("ERROR: missing command to %s (must follow \"--\" marker) ", Argv0); + + if (lockfile == 0) + die("ERROR: missing --lockfile=F parameter"); + + /*---------------------------------------------------------------- + * Open or create the lockfile, then try to acquire the lock. If + * the lock is acquired immediately (==0), then we're done, but + * if the lock is not available, we have to wait for it. + * + * We can either loop trying for the lock (for --wait), or exit + * with error. + */ + + if ( (lfd = open(lockfile, O_RDWR|O_CREAT, openmode)) < 0) + die("ERROR: cannot open(%s) [err=%s]", lockfile, strerror(errno)); + + while ( WAIT_AND_LOCK(lfd) != 0 ) + { + if ( ! wait_for_lock ) + { + if ( Quiet) + exit(EXIT_SUCCESS); + else + die("ERROR: cannot launch %s - run is locked", argv[0]); + } + + /* waiting */ + if ( Verbose ) printf("(locked: sleeping %d secs)\n", sleeptime); + + sleep(sleeptime); + } + + fflush(stdout); + + /* run the child */ + + + if ( (childpid = fork()) == 0 ) + { + close(lfd); // don't need the lock file + + execvp(argv[0], argv); + } + else if ( childpid > 0 ) + { + time_t endtime; + pid_t pid; + + if ( Verbose ) + printf("Waiting for process %ld\n", (long) childpid); + + pid = waitpid(childpid, &rc, 0); + + time(&endtime); + + endtime -= starttime; + + if ( Verbose || (Maxtime > 0 && endtime > Maxtime) ) + printf("pid %d exited with status %d (time=%ld sec)\n", pid, rc, endtime); + } + else + { + die("ERROR: cannot fork [%s]", strerror(errno)); + } + + exit(rc); +} + + +/*! \fn static char *getarg(char *opt, char ***pargv) + * \brief A function to parse calling parameters + * + * This is a helper for the main arg-processing loop: we work with + * options which are either of the form "-X=FOO" or "-X FOO"; we + * want an easy way to handle either one. + * + * The idea is that if the parameter has an = sign, we use the rest + * of that same argv[X] string, otherwise we have to get the *next* + * argv[X] string. But it's an error if an option-requiring param + * is at the end of the list with no argument to follow. + * + * The option name could be of the form "-C" or "--conf", but we + * grab it from the existing argv[] so we can report it well. + * + * \return character pointer to the argument + * + */ +static char *getarg(char *opt, char ***pargv) +{ + const char *const optname = **pargv; + + /* option already set? */ + if (opt) return opt; + + /* advance to next argv[] and try that one */ + if ((opt = *++(*pargv)) == 0) + die("ERROR: option %s requires a parameter", optname); + + return opt; +} + +/* + * die() + * + * Given a printf-style argument list, format it to the standard error, + * append a newline, then exit with error status. + */ + +static void die(const char *format, ...) +{ +va_list args; + + va_start(args, format); + vfprintf(stderr, format, args); + putc('\n', stderr); + va_end(args); + + exit(EXIT_FAILURE); +} diff --git a/dev-util/lockrun/lockrun-20120508.ebuild b/dev-util/lockrun/lockrun-20120508.ebuild new file mode 100644 index 000000000000..a2fad569424e --- /dev/null +++ b/dev-util/lockrun/lockrun-20120508.ebuild @@ -0,0 +1,31 @@ +# Copyright 1999-2012 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: /var/cvsroot/gentoo-x86/dev-util/lockrun/lockrun-20120508.ebuild,v 1.1 2012/05/08 15:58:57 jer Exp $ + +EAPI=4 +inherit toolchain-funcs + +DESCRIPTION="Lockrun - runs cronjobs with overrun protection" +HOMEPAGE="http://www.unixwiz.net/tools/lockrun.html" + +LICENSE="public-domain" +SLOT="0" +KEYWORDS="~amd64 ~hppa ~x86" +IUSE="" + +S="${WORKDIR}" + +src_unpack() { + cp "${FILESDIR}"/${PN}.c-${PV} "${S}"/${PN}.c + cp "${FILESDIR}"/${PN}.c-${PV} "${S}"/README +} + +src_compile() { + emake CC=$(tc-getCC) ${PN} + sed -i README -e '60q;s|^ \*||g' || die +} + +src_install () { + dobin ${PN} + dodoc README +} |