diff options
author | V3n3RiX <venerix@redcorelinux.org> | 2017-10-09 18:53:29 +0100 |
---|---|---|
committer | V3n3RiX <venerix@redcorelinux.org> | 2017-10-09 18:53:29 +0100 |
commit | 4f2d7949f03e1c198bc888f2d05f421d35c57e21 (patch) | |
tree | ba5f07bf3f9d22d82e54a462313f5d244036c768 /dev-util/lockrun |
reinit the tree, so we can have metadata
Diffstat (limited to 'dev-util/lockrun')
-rw-r--r-- | dev-util/lockrun/Manifest | 6 | ||||
-rw-r--r-- | dev-util/lockrun/files/lockrun.c-20120508 | 294 | ||||
-rw-r--r-- | dev-util/lockrun/lockrun-20120508-r1.ebuild | 30 | ||||
-rw-r--r-- | dev-util/lockrun/lockrun-20120508.ebuild | 30 | ||||
-rw-r--r-- | dev-util/lockrun/metadata.xml | 5 |
5 files changed, 365 insertions, 0 deletions
diff --git a/dev-util/lockrun/Manifest b/dev-util/lockrun/Manifest new file mode 100644 index 000000000000..bea1e131878e --- /dev/null +++ b/dev-util/lockrun/Manifest @@ -0,0 +1,6 @@ +AUX lockrun.c-20120508 7025 SHA256 b44a2458a7a2357a321078f7f5a321f488580c2dbf11a704cb63397fc47acd65 SHA512 f800e96d41d11c9b6f7e28c5bd1f2b59b824ccba5f093574d8f4df8e737f2df47c3f8e89a08eee81b9c3fb46377e62be9c5ddf83df253fd0ab3a25a85a8bee0b WHIRLPOOL 75cf819092caaa9d83a06f258b305e01e16cb3b047eb17ad05363df67b1095c4bf65d01403ba3d0e85069be3ad437086fee2cdf92f5f9e979c299d21e8baf8ad +EBUILD lockrun-20120508-r1.ebuild 601 SHA256 51e07d760e23137f3b32901b34def356d1cba0ba761510999fb207e58aaf8031 SHA512 695fd4aa9e9488763d9e4b58544894f0a965e2dedd096e1811bc208b58ee883e8aa26f912cf779a2058e8e1f0d2e154d789b4c88f4d0048d9fad96bf71f6c0e7 WHIRLPOOL 17c267c6269bea2d45cf06263ba2753a128d38d93023ad75d52d1090490e2f0138f355b4eddc81dd4ad0b19d9094f6e40306a8e54ecef8eaa78d8572fd482372 +EBUILD lockrun-20120508.ebuild 599 SHA256 b8c48166edfc40dba74351c4c7e35bff8e3f31d388b9a008e2b4f66d4e9c2847 SHA512 a39be47b2381380580eb9edc1387591ac7b36372cb6b27f41a4d1f83b177682ab5f0352a234a1c55db3575cbd31dc0994f44f4f9dbbb9618ea88c7550986ec73 WHIRLPOOL 0e482fc764ffa1fb3a26cd1513711aea5cf1da009af90ef32862cc40b19c091c40fc728b43cb3ee1a2182cf997f9137d11b8a2a48490104f8830aeea249d0efd +MISC ChangeLog 2555 SHA256 2ab902210c30d7949bc309d3c32cee7d2e1205badbbc5e86e4709aeab6500548 SHA512 10c91b570a145beb8146fbe72e5fcaa77b3c18cd2548e6d4fe6ba39040ebcbefb8606cbcfacd3f7b8b20b6215ec1a7ca5722810026b41c53bda4a3df02be1885 WHIRLPOOL e30a66459d2638f7dac4a250a7c6da1a22ad0c0200948948d2920787c8f663583701c4f0f964c964caa7369910e4a24a2328caeb695318326dffdca79502c788 +MISC ChangeLog-2015 1806 SHA256 9f4fc194618cb2adc547ab90fc283426f4d2dc57d1ec41f03f19f38cff8dcf25 SHA512 d58392101eedfc6593daa3938534e0ff42fd43f60d384d3cbba7464de6364aab9802232bcd0f2b62479eb051de5ca47c8a9d74049e32f18c95af36e0abe38d2d WHIRLPOOL 28e49ba6424cb80560afd7c145312379a4de056007b1696052f08f7e37a08a3bdb0bfefba6065a11bd6556f760fe99906f1ad6b9e472ac2a3edb098ddfe2e1a5 +MISC metadata.xml 166 SHA256 2caff447f5bd2701d8456ada5cc633c41ef4373fa4bfeabeb73599d40bcc941b SHA512 a56648c974a1d14dd4c18237532773c72057a13ab90c58b5da04f185e3c12a8bd8d5c21fb06053507f31766291a82dc7d87b34cd65fd94cfe2af7295c813ef84 WHIRLPOOL 1ff70497eca6531f0e0614c72a19f4b8e5ff486a58d369f4f0b36308d1d6b01168f9da887740e3b9f536236be251d3fe05f904d27a9233a7cf613416ba882968 diff --git a/dev-util/lockrun/files/lockrun.c-20120508 b/dev-util/lockrun/files/lockrun.c-20120508 new file mode 100644 index 000000000000..51da6c71fa4a --- /dev/null +++ b/dev-util/lockrun/files/lockrun.c-20120508 @@ -0,0 +1,294 @@ +/* + * $Id: //websites/unixwiz/unixwiz.net/webroot/tools/lockrun.c#5 $ + * + * 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-r1.ebuild b/dev-util/lockrun/lockrun-20120508-r1.ebuild new file mode 100644 index 000000000000..1a0c8c9f4992 --- /dev/null +++ b/dev-util/lockrun/lockrun-20120508-r1.ebuild @@ -0,0 +1,30 @@ +# Copyright 1999-2017 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +EAPI=6 + +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" + +S="${WORKDIR}" + +src_unpack() { + cp -v "${FILESDIR}"/${PN}.c-${PV} "${S}"/${PN}.c || die + cp -v "${FILESDIR}"/${PN}.c-${PV} "${S}"/README || die +} + +src_compile() { + emake CC=$(tc-getCC) ${PN} + sed -i README -e '60q;s|^ \*||g' || die +} + +src_install () { + dobin ${PN} + einstalldocs +} diff --git a/dev-util/lockrun/lockrun-20120508.ebuild b/dev-util/lockrun/lockrun-20120508.ebuild new file mode 100644 index 000000000000..70d5bafe59d6 --- /dev/null +++ b/dev-util/lockrun/lockrun-20120508.ebuild @@ -0,0 +1,30 @@ +# Copyright 1999-2012 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +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 || die + cp "${FILESDIR}"/${PN}.c-${PV} "${S}"/README || die +} + +src_compile() { + emake CC=$(tc-getCC) ${PN} + sed -i README -e '60q;s|^ \*||g' || die +} + +src_install () { + dobin ${PN} + dodoc README +} diff --git a/dev-util/lockrun/metadata.xml b/dev-util/lockrun/metadata.xml new file mode 100644 index 000000000000..6f49eba8f496 --- /dev/null +++ b/dev-util/lockrun/metadata.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd"> +<pkgmetadata> +<!-- maintainer-needed --> +</pkgmetadata> |