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>
14 #include <sys/types.h>
26 #include <afs/afsutil.h>
27 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
29 #include "bosprototypes.h"
32 struct bnode *ez_create(char *, char *, char *, char *, char *, char *);
33 static int ez_hascore(struct bnode *bnode);
34 static int ez_restartp(struct bnode *bnode);
35 static int ez_delete(struct bnode *bnode);
36 static int ez_timeout(struct bnode *bnode);
37 static int ez_getstat(struct bnode *bnode, afs_int32 *status);
38 static int ez_setstat(struct bnode *bnode, afs_int32 status);
39 static int ez_procexit(struct bnode *bnode, struct bnode_proc *proc);
40 static int ez_getstring(struct bnode *bnode, char *abuffer, afs_int32 alen);
41 static int ez_getparm(struct bnode *bnode, afs_int32, char *, afs_int32);
43 #define SDTIME 60 /* time in seconds given to a process to evaporate */
45 struct bnode_ops ezbnode_ops = {
59 ez_hascore(struct bnode *abnode)
63 bnode_CoreName(abnode, NULL, tbuffer);
64 if (access(tbuffer, 0) == 0)
71 ez_restartp(struct bnode *bn)
73 struct ezbnode *abnode = (struct ezbnode *)bn;
74 struct bnode_token *tt;
78 code = bnode_ParseLine(abnode->command, &tt);
83 code = stat(tt->key, &tstat);
88 if (tstat.st_ctime > abnode->lastStart)
97 ez_delete(struct bnode *bn)
99 struct ezbnode *abnode = (struct ezbnode *)bn;
101 free(abnode->command);
107 ez_create(char *ainstance, char *acommand, char *unused1, char *unused2,
108 char *unused3, char *unused4)
113 if (ConstructLocalBinPath(acommand, &cmdpath)) {
114 bozo_Log("BNODE: command path invalid '%s'\n", acommand);
118 te = (struct ezbnode *)malloc(sizeof(struct ezbnode));
119 memset(te, 0, sizeof(struct ezbnode));
120 if (bnode_InitBnode((struct bnode *)te, &ezbnode_ops, ainstance) != 0) {
124 te->command = cmdpath;
125 return (struct bnode *)te;
128 /* called to SIGKILL a process if it doesn't terminate normally */
130 ez_timeout(struct bnode *bn)
132 struct ezbnode *abnode = (struct ezbnode *)bn;
134 if (!abnode->waitingForShutdown)
135 return 0; /* spurious */
136 /* send kill and turn off timer */
137 bnode_StopProc(abnode->proc, SIGKILL);
138 abnode->killSent = 1;
139 bnode_SetTimeout((struct bnode *)abnode, 0);
144 ez_getstat(struct bnode *bn, afs_int32 * astatus)
146 struct ezbnode *abnode = (struct ezbnode *)bn;
149 if (abnode->waitingForShutdown)
150 temp = BSTAT_SHUTTINGDOWN;
151 else if (abnode->running)
154 temp = BSTAT_SHUTDOWN;
160 ez_setstat(struct bnode *bn, afs_int32 astatus)
162 struct ezbnode *abnode = (struct ezbnode *)bn;
164 struct bnode_proc *tp;
167 if (abnode->waitingForShutdown)
169 if (astatus == BSTAT_NORMAL && !abnode->running) {
171 abnode->lastStart = FT_ApproxTime();
172 code = bnode_NewProc((struct bnode *)abnode, abnode->command, NULL, &tp);
178 } else if (astatus == BSTAT_SHUTDOWN && abnode->running) {
180 bnode_StopProc(abnode->proc, SIGTERM);
181 abnode->waitingForShutdown = 1;
182 bnode_SetTimeout((struct bnode *)abnode, SDTIME);
189 ez_procexit(struct bnode *bn, struct bnode_proc *aproc)
191 struct ezbnode *abnode = (struct ezbnode *)bn;
193 /* process has exited */
196 abnode->waitingForShutdown = 0;
198 abnode->killSent = 0;
200 bnode_SetTimeout((struct bnode *) abnode, 0); /* clear timer */
202 code = ez_setstat((struct bnode *) abnode, BSTAT_NORMAL);
209 ez_getstring(struct bnode *abnode, char *abuffer, afs_int32 alen)
211 return -1; /* don't have much to add */
215 ez_getparm(struct bnode *bn, afs_int32 aindex, char *abuffer,
218 struct ezbnode *abnode = (struct ezbnode *) bn;
221 strcpy(abuffer, abnode->command);