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
20 * with this program; if not, write the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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 */
33 /* $Id: ltp-bump.c,v 1.1 2009/05/19 09:39:11 subrata_modak Exp $ */
34 #include <stdio.h>
35 #include <errno.h>
36 #include <sys/signal.h>
37 #include <string.h>
38 #include <stdlib.h>
39 #include <unistd.h>
40
41 #include "zoolib.h"
42
43 pid_t read_active(FILE * fp, char *name);
44
main(int argc,char ** argv)45 int main(int argc, char **argv)
46 {
47 int c;
48 char *active = NULL;
49 pid_t nanny;
50 zoo_t zoo;
51 int sig = SIGINT;
52
53 while ((c = getopt(argc, argv, "a:s:12")) != -1) {
54 switch (c) {
55 case 'a':
56 active = 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;
68 }
69 }
70
71 if (active == NULL) {
72 active = zoo_getname();
73 if (active == NULL) {
74 fprintf(stderr,
75 "ltp-bump: Must supply -a or set ZOO env variable\n");
76 exit(1);
77 }
78 }
79
80 if (optind == argc) {
81 fprintf(stderr, "ltp-bump: Must supply names\n");
82 exit(1);
83 }
84
85 /* need r+ here because we're using write-locks */
86 if ((zoo = zoo_open(active)) == NULL) {
87 fprintf(stderr, "ltp-bump: %s\n", zoo_error);
88 exit(1);
89 }
90
91 while (optind < argc) {
92 /*printf("argv[%d] = (%s)\n", optind, argv[optind] ); */
93 nanny = zoo_getpid(zoo, argv[optind]);
94 if (nanny == -1) {
95 fprintf(stderr, "ltp-bump: Did not find tag '%s'\n",
96 argv[optind]);
97 } else {
98 if (kill(nanny, sig) == -1) {
99 if (errno == ESRCH) {
100 fprintf(stderr,
101 "ltp-bump: Tag %s (pid %d) seems to be dead already.\n",
102 argv[optind], nanny);
103 if (zoo_clear(zoo, nanny))
104 fprintf(stderr,
105 "ltp-bump: %s\n",
106 zoo_error);
107 }
108 }
109 }
110 ++optind;
111 }
112 zoo_close(zoo);
113
114 exit(0);
115 }
116