aboutsummaryrefslogtreecommitdiffstats
path: root/pgaas/src/testlock/testlock.c
diff options
context:
space:
mode:
authorHansen, Tony (th1395) <th1395@att.com>2018-03-29 12:57:06 +0000
committerHansen, Tony (th1395) <th1395@att.com>2018-03-29 12:57:23 +0000
commitbd5129dbad044907bd1818b2f8cda3c60da9b3e8 (patch)
treeedc355d63e440a87a1c97ad65357681f279e6ba0 /pgaas/src/testlock/testlock.c
parent4e1b45a2e3e474606965ca3b66bd5f82f526b0ce (diff)
remove most of this code for R2 Beijing
This package is not being used in R2 Beijing because of the move to Kubernetes with OOM. If you need this package, use the R1 Amsterdam release packages. I'm not removing the repo though because it is likely that we will need to add things in R3 Casablanca. Change-Id: I40a46886cfa2f3803f97918ad5cea149f5fcf696 Signed-off-by: Hansen, Tony (th1395) <th1395@att.com> Issue-ID: CCSDK-231
Diffstat (limited to 'pgaas/src/testlock/testlock.c')
-rw-r--r--pgaas/src/testlock/testlock.c110
1 files changed, 0 insertions, 110 deletions
diff --git a/pgaas/src/testlock/testlock.c b/pgaas/src/testlock/testlock.c
deleted file mode 100644
index 41bea59..0000000
--- a/pgaas/src/testlock/testlock.c
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- Usage: testlock [-t timeout] [-s] filename command args ...
-
- Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this code except in compliance
- with the License. You may obtain a copy of the License
- at http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied. See the License for the specific language governing
- permissions and limitations under the License.
-
-*/
-
-#include <sys/file.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <getopt.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <errno.h>
-#include <string.h>
-
-void usage(const char *prog0, const char *msg)
-{
- if (msg) fprintf(stderr, "%s\n", msg);
- fprintf(stderr, "Usage: %s [-v] [-t timeout] [-s] [-r retcode] lock-filename command args ...\n", prog0);
- fprintf(stderr, "-t ##\thow long to wait for a lock to be freed. 0 means exit immediately\n");
- fprintf(stderr, "-s\tsilently ignore errors with locking\n");
- fprintf(stderr, "-r ##\texit with this code when the lock fails\n");
- fprintf(stderr, "-v\tbe verbose\n");
- fprintf(stderr, "Note:\tlock-filename is created (if it does not exist) and truncated before locking.\n");
- fprintf(stderr, "\tlock-filename is not removed after the command finishes\n");
- exit(1);
-}
-
-int main(int argc, char **argv)
-{
- const char *prog0 = argv[0];
-
- int c;
- int timeout = -1;
- bool silent = false;
- bool verbose = false;
- int nolockret = 99;
-
- while ((c = getopt(argc, argv, "t:r:sv?")) != -1) {
- switch (c) {
- case 's': silent = true; break;
- case 't': timeout = atoi(optarg); break;
- case 'r': nolockret = atoi(optarg); break;
- case 'v': verbose = true; break;
- default: usage(prog0, NULL);
- }
- }
-
- argc -= optind;
- argv += optind;
-
- if (argc < 1) {
- usage(prog0, "Missing lock filename");
- } else if (argc < 2) {
- usage(prog0, "Missing command to run");
- }
-
- const char *lockFilename = *argv++;
- if (verbose) printf("lockfilename=%s\n", lockFilename);
-
- int lockfd = creat(lockFilename, 0666);
- if (lockfd < 0) {
- fprintf(stderr, "Cannot open %s: %s\n", lockFilename, strerror(errno));
- exit(2);
- }
-
- if (timeout < 0) {
- /* wait forever */
- lockf(lockfd, F_LOCK, 0);
- } else {
- /* try each second (for up to timeout seconds) to get the lock */
- int lockret = lockf(lockfd, F_TLOCK, 0);
- int count = 0;
- while ((lockret < 0) && (count++ < timeout)) {
- sleep(1);
- lockret = lockf(lockfd, F_TLOCK, 0);
- }
- if (lockret < 0) {
- if (!silent) {
- fprintf(stderr, "Cannot lock %s: %s\n", lockFilename, strerror(errno));
- }
- exit(nolockret);
- }
- }
-
- /* now execute the given command */
- if (verbose) {
- char **a = argv;
- printf("calling program '%s'\n", *a);
- while (*++a) {
- printf("with argument '%s'\n", *a);
- }
- }
- execvp(argv[0], argv);
-}