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>
22 #include <afs/afsutil.h>
24 #include "bosprototypes.h"
26 extern char *DoPidFiles;
28 struct bnode *ez_create(char *, char *, char *, char *, char *, char *);
29 static int ez_hascore(struct bnode *bnode);
30 static int ez_restartp(struct bnode *bnode);
31 static int ez_delete(struct bnode *bnode);
32 static int ez_timeout(struct bnode *bnode);
33 static int ez_getstat(struct bnode *bnode, afs_int32 *status);
34 static int ez_setstat(struct bnode *bnode, afs_int32 status);
35 static int ez_procexit(struct bnode *bnode, struct bnode_proc *proc);
36 static int ez_getstring(struct bnode *bnode, char *abuffer, afs_int32 alen);
37 static int ez_getparm(struct bnode *bnode, afs_int32, char *, afs_int32);
38 static int ez_procstarted(struct bnode *bnode, struct bnode_proc *proc);
40 #define SDTIME 60 /* time in seconds given to a process to evaporate */
42 struct bnode_ops ezbnode_ops = {
57 ez_hascore(struct bnode *abnode)
61 bnode_CoreName(abnode, NULL, tbuffer);
62 if (access(tbuffer, 0) == 0)
69 ez_restartp(struct bnode *bn)
71 struct ezbnode *abnode = (struct ezbnode *)bn;
72 struct bnode_token *tt;
76 code = bnode_ParseLine(abnode->command, &tt);
81 code = stat(tt->key, &tstat);
86 if (tstat.st_ctime > abnode->lastStart)
95 ez_delete(struct bnode *bn)
97 struct ezbnode *abnode = (struct ezbnode *)bn;
99 free(abnode->command);
105 ez_create(char *ainstance, char *acommand, char *unused1, char *unused2,
106 char *unused3, char *unused4)
111 if (ConstructLocalBinPath(acommand, &cmdpath)) {
112 bozo_Log("BNODE: command path invalid '%s'\n", acommand);
116 te = (struct ezbnode *)malloc(sizeof(struct ezbnode));
117 memset(te, 0, sizeof(struct ezbnode));
118 if (bnode_InitBnode((struct bnode *)te, &ezbnode_ops, ainstance) != 0) {
122 te->command = cmdpath;
123 return (struct bnode *)te;
126 /* called to SIGKILL a process if it doesn't terminate normally */
128 ez_timeout(struct bnode *bn)
130 struct ezbnode *abnode = (struct ezbnode *)bn;
132 if (!abnode->waitingForShutdown)
133 return 0; /* spurious */
134 /* send kill and turn off timer */
135 bnode_StopProc(abnode->proc, SIGKILL);
136 abnode->killSent = 1;
137 bnode_SetTimeout((struct bnode *)abnode, 0);
142 ez_getstat(struct bnode *bn, afs_int32 * astatus)
144 struct ezbnode *abnode = (struct ezbnode *)bn;
147 if (abnode->waitingForShutdown)
148 temp = BSTAT_SHUTTINGDOWN;
149 else if (abnode->running)
152 temp = BSTAT_SHUTDOWN;
158 ez_setstat(struct bnode *bn, afs_int32 astatus)
160 struct ezbnode *abnode = (struct ezbnode *)bn;
162 struct bnode_proc *tp;
165 if (abnode->waitingForShutdown)
167 if (astatus == BSTAT_NORMAL && !abnode->running) {
169 abnode->lastStart = FT_ApproxTime();
170 code = bnode_NewProc((struct bnode *)abnode, abnode->command, NULL, &tp);
176 } else if (astatus == BSTAT_SHUTDOWN && abnode->running) {
178 bnode_StopProc(abnode->proc, SIGTERM);
179 abnode->waitingForShutdown = 1;
180 bnode_SetTimeout((struct bnode *)abnode, SDTIME);
187 ez_procstarted(struct bnode *bn, struct bnode_proc *aproc)
192 code = bozo_CreatePidFile(bn->name, NULL, aproc->pid);
198 ez_procexit(struct bnode *bn, struct bnode_proc *aproc)
200 struct ezbnode *abnode = (struct ezbnode *)bn;
202 /* process has exited */
206 bozo_DeletePidFile(bn->name, NULL);
209 abnode->waitingForShutdown = 0;
211 abnode->killSent = 0;
213 bnode_SetTimeout((struct bnode *) abnode, 0); /* clear timer */
215 code = ez_setstat((struct bnode *) abnode, BSTAT_NORMAL);
222 ez_getstring(struct bnode *abnode, char *abuffer, afs_int32 alen)
224 return -1; /* don't have much to add */
228 ez_getparm(struct bnode *bn, afs_int32 aindex, char *abuffer,
231 struct ezbnode *abnode = (struct ezbnode *) bn;
234 strcpy(abuffer, abnode->command);