nstraz | f307d5f | 2000-09-14 21:54:44 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of version 2 of the GNU General Public License as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it would be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 11 | * |
| 12 | * Further, this software is distributed without any warranty that it is |
| 13 | * free of the rightful claim of any third person regarding infringement |
| 14 | * or the like. Any license provided herein, whether implied or |
| 15 | * otherwise, applies only to this software file. Patent licenses, if |
| 16 | * any, provided herein do not apply to combinations of this program with |
| 17 | * other software, or any other product whatsoever. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
Wanlong Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 20 | * with this program; if not, write the Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
nstraz | f307d5f | 2000-09-14 21:54:44 +0000 | [diff] [blame] | 22 | * |
| 23 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 24 | * Mountain View, CA 94043, or: |
| 25 | * |
| 26 | * http://www.sgi.com |
| 27 | * |
| 28 | * For further information regarding this notice, see: |
| 29 | * |
| 30 | * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 31 | * |
| 32 | */ |
subrata_modak | 14390fd | 2009-05-19 09:39:11 +0000 | [diff] [blame] | 33 | /* $Id: ltp-bump.c,v 1.1 2009/05/19 09:39:11 subrata_modak Exp $ */ |
nstraz | f307d5f | 2000-09-14 21:54:44 +0000 | [diff] [blame] | 34 | #include <stdio.h> |
| 35 | #include <errno.h> |
| 36 | #include <sys/signal.h> |
| 37 | #include <string.h> |
nstraz | d5d51ca | 2001-02-28 17:41:59 +0000 | [diff] [blame] | 38 | #include <stdlib.h> |
subrata_modak | 14390fd | 2009-05-19 09:39:11 +0000 | [diff] [blame] | 39 | #include <unistd.h> |
nstraz | f307d5f | 2000-09-14 21:54:44 +0000 | [diff] [blame] | 40 | |
nstraz | f307d5f | 2000-09-14 21:54:44 +0000 | [diff] [blame] | 41 | #include "zoolib.h" |
| 42 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 43 | pid_t read_active(FILE * fp, char *name); |
nstraz | f307d5f | 2000-09-14 21:54:44 +0000 | [diff] [blame] | 44 | |
subrata_modak | 14390fd | 2009-05-19 09:39:11 +0000 | [diff] [blame] | 45 | int main(int argc, char **argv) |
| 46 | { |
nstraz | f307d5f | 2000-09-14 21:54:44 +0000 | [diff] [blame] | 47 | int c; |
nstraz | f307d5f | 2000-09-14 21:54:44 +0000 | [diff] [blame] | 48 | char *active = NULL; |
| 49 | pid_t nanny; |
nstraz | cde46c8 | 2001-03-08 19:13:21 +0000 | [diff] [blame] | 50 | zoo_t zoo; |
nstraz | f307d5f | 2000-09-14 21:54:44 +0000 | [diff] [blame] | 51 | int sig = SIGINT; |
| 52 | |
Garrett Cooper | 903910d | 2010-11-23 09:27:44 -0800 | [diff] [blame] | 53 | while ((c = getopt(argc, argv, "a:s:12")) != -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 54 | switch (c) { |
| 55 | case 'a': |
Maninder Singh | e5c9276 | 2015-06-15 13:24:16 +0000 | [diff] [blame] | 56 | active = malloc(strlen(optarg) + 1); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 57 | strcpy(active, optarg); |
| 58 | break; |
| 59 | case 's': |
| 60 | sig = atoi(optarg); |
| 61 | break; |
| 62 | case '1': |
| 63 | sig = SIGUSR1; |
| 64 | break; |
| 65 | case '2': |
| 66 | sig = SIGUSR2; |
| 67 | break; |
nstraz | f307d5f | 2000-09-14 21:54:44 +0000 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | |
subrata_modak | 14390fd | 2009-05-19 09:39:11 +0000 | [diff] [blame] | 71 | if (active == NULL) { |
nstraz | cde46c8 | 2001-03-08 19:13:21 +0000 | [diff] [blame] | 72 | active = zoo_getname(); |
subrata_modak | 14390fd | 2009-05-19 09:39:11 +0000 | [diff] [blame] | 73 | if (active == NULL) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 74 | fprintf(stderr, |
| 75 | "ltp-bump: Must supply -a or set ZOO env variable\n"); |
nstraz | f307d5f | 2000-09-14 21:54:44 +0000 | [diff] [blame] | 76 | exit(1); |
| 77 | } |
| 78 | } |
subrata_modak | 14390fd | 2009-05-19 09:39:11 +0000 | [diff] [blame] | 79 | |
| 80 | if (optind == argc) { |
| 81 | fprintf(stderr, "ltp-bump: Must supply names\n"); |
nstraz | f307d5f | 2000-09-14 21:54:44 +0000 | [diff] [blame] | 82 | exit(1); |
| 83 | } |
| 84 | |
| 85 | /* need r+ here because we're using write-locks */ |
subrata_modak | 14390fd | 2009-05-19 09:39:11 +0000 | [diff] [blame] | 86 | if ((zoo = zoo_open(active)) == NULL) { |
| 87 | fprintf(stderr, "ltp-bump: %s\n", zoo_error); |
nstraz | f307d5f | 2000-09-14 21:54:44 +0000 | [diff] [blame] | 88 | exit(1); |
| 89 | } |
subrata_modak | 14390fd | 2009-05-19 09:39:11 +0000 | [diff] [blame] | 90 | |
| 91 | while (optind < argc) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 92 | /*printf("argv[%d] = (%s)\n", optind, argv[optind] ); */ |
nstraz | cde46c8 | 2001-03-08 19:13:21 +0000 | [diff] [blame] | 93 | nanny = zoo_getpid(zoo, argv[optind]); |
subrata_modak | 14390fd | 2009-05-19 09:39:11 +0000 | [diff] [blame] | 94 | if (nanny == -1) { |
| 95 | fprintf(stderr, "ltp-bump: Did not find tag '%s'\n", |
| 96 | argv[optind]); |
| 97 | } else { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 98 | if (kill(nanny, sig) == -1) { |
subrata_modak | 14390fd | 2009-05-19 09:39:11 +0000 | [diff] [blame] | 99 | if (errno == ESRCH) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 100 | fprintf(stderr, |
| 101 | "ltp-bump: Tag %s (pid %d) seems to be dead already.\n", |
subrata_modak | 14390fd | 2009-05-19 09:39:11 +0000 | [diff] [blame] | 102 | argv[optind], nanny); |
nstraz | cde46c8 | 2001-03-08 19:13:21 +0000 | [diff] [blame] | 103 | if (zoo_clear(zoo, nanny)) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 104 | fprintf(stderr, |
| 105 | "ltp-bump: %s\n", |
| 106 | zoo_error); |
nstraz | f307d5f | 2000-09-14 21:54:44 +0000 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | } |
| 110 | ++optind; |
| 111 | } |
nstraz | cde46c8 | 2001-03-08 19:13:21 +0000 | [diff] [blame] | 112 | zoo_close(zoo); |
nstraz | f307d5f | 2000-09-14 21:54:44 +0000 | [diff] [blame] | 113 | |
| 114 | exit(0); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 115 | } |