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>
16 #include <sys/types.h>
27 #include <afs/afsutil.h>
28 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
30 #include "bosprototypes.h"
32 static int ez_timeout(), ez_getstat(), ez_setstat(), ez_delete();
33 static int ez_procexit(), ez_getstring(), ez_getparm(), ez_restartp();
34 static int ez_hascore();
35 struct bnode *ez_create();
37 #define SDTIME 60 /* time in seconds given to a process to evaporate */
39 struct bnode_ops ezbnode_ops = {
53 ez_hascore(register struct ezbnode *abnode)
57 bnode_CoreName(abnode, NULL, tbuffer);
58 if (access(tbuffer, 0) == 0)
65 ez_restartp(register struct ezbnode *abnode)
67 struct bnode_token *tt;
68 register afs_int32 code;
71 code = bnode_ParseLine(abnode->command, &tt);
76 code = stat(tt->key, &tstat);
81 if (tstat.st_ctime > abnode->lastStart)
90 ez_delete(struct ezbnode *abnode)
92 free(abnode->command);
98 ez_create(char *ainstance, char *acommand)
103 if (ConstructLocalBinPath(acommand, &cmdpath)) {
104 bozo_Log("BNODE: command path invalid '%s'\n", acommand);
108 te = (struct ezbnode *)malloc(sizeof(struct ezbnode));
109 memset(te, 0, sizeof(struct ezbnode));
110 if (bnode_InitBnode(te, &ezbnode_ops, ainstance) != 0) {
114 te->command = cmdpath;
115 return (struct bnode *)te;
118 /* called to SIGKILL a process if it doesn't terminate normally */
120 ez_timeout(struct ezbnode *abnode)
122 if (!abnode->waitingForShutdown)
123 return 0; /* spurious */
124 /* send kill and turn off timer */
125 bnode_StopProc(abnode->proc, SIGKILL);
126 abnode->killSent = 1;
127 bnode_SetTimeout(abnode, 0);
132 ez_getstat(struct ezbnode *abnode, afs_int32 * astatus)
134 register afs_int32 temp;
135 if (abnode->waitingForShutdown)
136 temp = BSTAT_SHUTTINGDOWN;
137 else if (abnode->running)
140 temp = BSTAT_SHUTDOWN;
146 ez_setstat(register struct ezbnode *abnode, afs_int32 astatus)
148 struct bnode_proc *tp;
149 register afs_int32 code;
151 if (abnode->waitingForShutdown)
153 if (astatus == BSTAT_NORMAL && !abnode->running) {
155 abnode->lastStart = FT_ApproxTime();
156 code = bnode_NewProc(abnode, abnode->command, NULL, &tp);
162 } else if (astatus == BSTAT_SHUTDOWN && abnode->running) {
164 bnode_StopProc(abnode->proc, SIGTERM);
165 abnode->waitingForShutdown = 1;
166 bnode_SetTimeout(abnode, SDTIME);
173 ez_procexit(struct ezbnode *abnode, struct bnode_proc *aproc)
175 /* process has exited */
176 register afs_int32 code;
178 abnode->waitingForShutdown = 0;
180 abnode->killSent = 0;
181 abnode->proc = (struct bnode_proc *)0;
182 bnode_SetTimeout(abnode, 0); /* clear timer */
184 code = ez_setstat(abnode, BSTAT_NORMAL);
191 ez_getstring(struct ezbnode *abnode, char *abuffer, afs_int32 alen)
193 return -1; /* don't have much to add */
197 ez_getparm(struct ezbnode *abnode, afs_int32 aindex, char *abuffer,
202 strcpy(abuffer, abnode->command);