Imported Upstream version 20090831
[ltp-debian.git] / pan / ltp-bump.c
blob5ab6584db05d0283891e22cfa570a7e6909f9365
1 /*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
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.
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., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
26 * http://www.sgi.com
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
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>
41 #include "zoolib.h"
43 pid_t read_active(FILE *fp, char *name);
45 int main(int argc, char **argv)
47 int c;
48 char *active = NULL;
49 pid_t nanny;
50 zoo_t zoo;
51 int sig = SIGINT;
53 while((c = getopt(argc, argv, "a:s:12")) != -1) {
54 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;
71 if (active == NULL) {
72 active = zoo_getname();
73 if (active == NULL) {
74 fprintf(stderr, "ltp-bump: Must supply -a or set ZOO env variable\n");
75 exit(1);
79 if (optind == argc) {
80 fprintf(stderr, "ltp-bump: Must supply names\n");
81 exit(1);
84 /* need r+ here because we're using write-locks */
85 if ((zoo = zoo_open(active)) == NULL) {
86 fprintf(stderr, "ltp-bump: %s\n", zoo_error);
87 exit(1);
90 while (optind < argc) {
91 /*printf("argv[%d] = (%s)\n", optind, argv[optind] );*/
92 nanny = zoo_getpid(zoo, argv[optind]);
93 if (nanny == -1) {
94 fprintf(stderr, "ltp-bump: Did not find tag '%s'\n",
95 argv[optind]);
96 } else {
97 if (kill( nanny, sig ) == -1) {
98 if (errno == ESRCH) {
99 fprintf(stderr,"ltp-bump: Tag %s (pid %d) seems to be dead already.\n",
100 argv[optind], nanny);
101 if (zoo_clear(zoo, nanny))
102 fprintf(stderr,"ltp-bump: %s\n", zoo_error);
106 ++optind;
108 zoo_close(zoo);
110 exit(0);