2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
13 #include <afs/procmgmt.h>
16 #include <sys/types.h>
28 #include <afs/afsutil.h>
29 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
31 #include "bosprototypes.h"
34 struct bnode *ez_create(char *, char *, char *, char *, char *, char *);
35 static int ez_hascore(struct bnode *bnode);
36 static int ez_restartp(struct bnode *bnode);
37 static int ez_delete(struct bnode *bnode);
38 static int ez_timeout(struct bnode *bnode);
39 static int ez_getstat(struct bnode *bnode, afs_int32 *status);
40 static int ez_setstat(struct bnode *bnode, afs_int32 status);
41 static int ez_procexit(struct bnode *bnode, struct bnode_proc *proc);
42 static int ez_getstring(struct bnode *bnode, char *abuffer, afs_int32 alen);
43 static int ez_getparm(struct bnode *bnode, afs_int32, char *, afs_int32);
45 #define SDTIME 60 /* time in seconds given to a process to evaporate */
47 struct bnode_ops ezbnode_ops = {
61 ez_hascore(struct bnode *abnode)
65 bnode_CoreName(abnode, NULL, tbuffer);
66 if (access(tbuffer, 0) == 0)
73 ez_restartp(struct bnode *bn)
75 struct ezbnode *abnode = (struct ezbnode *)bn;
76 struct bnode_token *tt;
80 code = bnode_ParseLine(abnode->command, &tt);
85 code = stat(tt->key, &tstat);
90 if (tstat.st_ctime > abnode->lastStart)
99 ez_delete(struct bnode *bn)
101 struct ezbnode *abnode = (struct ezbnode *)bn;
103 free(abnode->command);
109 ez_create(char *ainstance, char *acommand, char *unused1, char *unused2,
110 char *unused3, char *unused4)
115 if (ConstructLocalBinPath(acommand, &cmdpath)) {
116 bozo_Log("BNODE: command path invalid '%s'\n", acommand);
120 te = (struct ezbnode *)malloc(sizeof(struct ezbnode));
121 memset(te, 0, sizeof(struct ezbnode));
122 if (bnode_InitBnode((struct bnode *)te, &ezbnode_ops, ainstance) != 0) {
126 te->command = cmdpath;
127 return (struct bnode *)te;
130 /* called to SIGKILL a process if it doesn't terminate normally */
132 ez_timeout(struct bnode *bn)
134 struct ezbnode *abnode = (struct ezbnode *)bn;
136 if (!abnode->waitingForShutdown)
137 return 0; /* spurious */
138 /* send kill and turn off timer */
139 bnode_StopProc(abnode->proc, SIGKILL);
140 abnode->killSent = 1;
141 bnode_SetTimeout((struct bnode *)abnode, 0);
146 ez_getstat(struct bnode *bn, afs_int32 * astatus)
148 struct ezbnode *abnode = (struct ezbnode *)bn;
151 if (abnode->waitingForShutdown)
152 temp = BSTAT_SHUTTINGDOWN;
153 else if (abnode->running)
156 temp = BSTAT_SHUTDOWN;
162 ez_setstat(struct bnode *bn, afs_int32 astatus)
164 struct ezbnode *abnode = (struct ezbnode *)bn;
166 struct bnode_proc *tp;
169 if (abnode->waitingForShutdown)
171 if (astatus == BSTAT_NORMAL && !abnode->running) {
173 abnode->lastStart = FT_ApproxTime();
174 code = bnode_NewProc((struct bnode *)abnode, abnode->command, NULL, &tp);
180 } else if (astatus == BSTAT_SHUTDOWN && abnode->running) {
182 bnode_StopProc(abnode->proc, SIGTERM);
183 abnode->waitingForShutdown = 1;
184 bnode_SetTimeout((struct bnode *)abnode, SDTIME);
191 ez_procexit(struct bnode *bn, struct bnode_proc *aproc)
193 struct ezbnode *abnode = (struct ezbnode *)bn;
195 /* process has exited */
198 abnode->waitingForShutdown = 0;
200 abnode->killSent = 0;
202 bnode_SetTimeout((struct bnode *) abnode, 0); /* clear timer */
204 code = ez_setstat((struct bnode *) abnode, BSTAT_NORMAL);
211 ez_getstring(struct bnode *abnode, char *abuffer, afs_int32 alen)
213 return -1; /* don't have much to add */
217 ez_getparm(struct bnode *bn, afs_int32 aindex, char *abuffer,
220 struct ezbnode *abnode = (struct ezbnode *) bn;
223 strcpy(abuffer, abnode->command);