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