blob: 5966c2e84f8b9abf5d0d27c85ac197f13088e5ff [file] [log] [blame]
nstrazf307d5f2000-09-14 21:54:44 +00001/*
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 Gaofed96412012-10-24 10:10:29 +080020 * with this program; if not, write the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
nstrazf307d5f2000-09-14 21:54:44 +000022 *
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_modak14390fd2009-05-19 09:39:11 +000033/* $Id: ltp-bump.c,v 1.1 2009/05/19 09:39:11 subrata_modak Exp $ */
nstrazf307d5f2000-09-14 21:54:44 +000034#include <stdio.h>
35#include <errno.h>
36#include <sys/signal.h>
37#include <string.h>
nstrazd5d51ca2001-02-28 17:41:59 +000038#include <stdlib.h>
subrata_modak14390fd2009-05-19 09:39:11 +000039#include <unistd.h>
nstrazf307d5f2000-09-14 21:54:44 +000040
nstrazf307d5f2000-09-14 21:54:44 +000041#include "zoolib.h"
42
Wanlong Gao354ebb42012-12-07 10:10:04 +080043pid_t read_active(FILE * fp, char *name);
nstrazf307d5f2000-09-14 21:54:44 +000044
subrata_modak14390fd2009-05-19 09:39:11 +000045int main(int argc, char **argv)
46{
nstrazf307d5f2000-09-14 21:54:44 +000047 int c;
nstrazf307d5f2000-09-14 21:54:44 +000048 char *active = NULL;
49 pid_t nanny;
nstrazcde46c82001-03-08 19:13:21 +000050 zoo_t zoo;
nstrazf307d5f2000-09-14 21:54:44 +000051 int sig = SIGINT;
52
Garrett Cooper903910d2010-11-23 09:27:44 -080053 while ((c = getopt(argc, argv, "a:s:12")) != -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +080054 switch (c) {
55 case 'a':
56 active = (char *)malloc(strlen(optarg) + 1);
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;
nstrazf307d5f2000-09-14 21:54:44 +000068 }
69 }
70
subrata_modak14390fd2009-05-19 09:39:11 +000071 if (active == NULL) {
nstrazcde46c82001-03-08 19:13:21 +000072 active = zoo_getname();
subrata_modak14390fd2009-05-19 09:39:11 +000073 if (active == NULL) {
Wanlong Gao354ebb42012-12-07 10:10:04 +080074 fprintf(stderr,
75 "ltp-bump: Must supply -a or set ZOO env variable\n");
nstrazf307d5f2000-09-14 21:54:44 +000076 exit(1);
77 }
78 }
subrata_modak14390fd2009-05-19 09:39:11 +000079
80 if (optind == argc) {
81 fprintf(stderr, "ltp-bump: Must supply names\n");
nstrazf307d5f2000-09-14 21:54:44 +000082 exit(1);
83 }
84
85 /* need r+ here because we're using write-locks */
subrata_modak14390fd2009-05-19 09:39:11 +000086 if ((zoo = zoo_open(active)) == NULL) {
87 fprintf(stderr, "ltp-bump: %s\n", zoo_error);
nstrazf307d5f2000-09-14 21:54:44 +000088 exit(1);
89 }
subrata_modak14390fd2009-05-19 09:39:11 +000090
91 while (optind < argc) {
Wanlong Gao354ebb42012-12-07 10:10:04 +080092 /*printf("argv[%d] = (%s)\n", optind, argv[optind] ); */
nstrazcde46c82001-03-08 19:13:21 +000093 nanny = zoo_getpid(zoo, argv[optind]);
subrata_modak14390fd2009-05-19 09:39:11 +000094 if (nanny == -1) {
95 fprintf(stderr, "ltp-bump: Did not find tag '%s'\n",
96 argv[optind]);
97 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +080098 if (kill(nanny, sig) == -1) {
subrata_modak14390fd2009-05-19 09:39:11 +000099 if (errno == ESRCH) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800100 fprintf(stderr,
101 "ltp-bump: Tag %s (pid %d) seems to be dead already.\n",
subrata_modak14390fd2009-05-19 09:39:11 +0000102 argv[optind], nanny);
nstrazcde46c82001-03-08 19:13:21 +0000103 if (zoo_clear(zoo, nanny))
Wanlong Gao354ebb42012-12-07 10:10:04 +0800104 fprintf(stderr,
105 "ltp-bump: %s\n",
106 zoo_error);
nstrazf307d5f2000-09-14 21:54:44 +0000107 }
108 }
109 }
110 ++optind;
111 }
nstrazcde46c82001-03-08 19:13:21 +0000112 zoo_close(zoo);
nstrazf307d5f2000-09-14 21:54:44 +0000113
114 exit(0);
Chris Dearmanec6edca2012-10-17 19:54:01 -0700115}