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>
33 #include <afs/afsutil.h>
34 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
37 static int ez_timeout(), ez_getstat(), ez_setstat(), ez_delete();
38 static int ez_procexit(), ez_getstring(), ez_getparm(), ez_restartp();
39 static int ez_hascore();
40 struct bnode *ez_create();
42 #define SDTIME 60 /* time in seconds given to a process to evaporate */
44 struct bnode_ops ezbnode_ops = {
58 ez_hascore(register struct ezbnode *abnode)
62 bnode_CoreName(abnode, NULL, tbuffer);
63 if (access(tbuffer, 0) == 0)
70 ez_restartp(register struct ezbnode *abnode)
72 struct bnode_token *tt;
73 register afs_int32 code;
76 code = bnode_ParseLine(abnode->command, &tt);
81 code = stat(tt->key, &tstat);
86 if (tstat.st_ctime > abnode->lastStart)
95 ez_delete(struct ezbnode *abnode)
97 free(abnode->command);
103 ez_create(char *ainstance, char *acommand)
108 if (ConstructLocalBinPath(acommand, &cmdpath)) {
109 bozo_Log("BNODE: command path invalid '%s'\n", acommand);
113 te = (struct ezbnode *)malloc(sizeof(struct ezbnode));
114 memset(te, 0, sizeof(struct ezbnode));
115 if (bnode_InitBnode(te, &ezbnode_ops, ainstance) != 0) {
119 te->command = cmdpath;
120 return (struct bnode *)te;
123 /* called to SIGKILL a process if it doesn't terminate normally */
125 ez_timeout(struct ezbnode *abnode)
127 if (!abnode->waitingForShutdown)
128 return 0; /* spurious */
129 /* send kill and turn off timer */
130 bnode_StopProc(abnode->proc, SIGKILL);
131 abnode->killSent = 1;
132 bnode_SetTimeout(abnode, 0);
137 ez_getstat(struct ezbnode *abnode, afs_int32 * astatus)
139 register afs_int32 temp;
140 if (abnode->waitingForShutdown)
141 temp = BSTAT_SHUTTINGDOWN;
142 else if (abnode->running)
145 temp = BSTAT_SHUTDOWN;
151 ez_setstat(register struct ezbnode *abnode, afs_int32 astatus)
153 struct bnode_proc *tp;
154 register afs_int32 code;
156 if (abnode->waitingForShutdown)
158 if (astatus == BSTAT_NORMAL && !abnode->running) {
160 abnode->lastStart = FT_ApproxTime();
161 code = bnode_NewProc(abnode, abnode->command, NULL, &tp);
167 } else if (astatus == BSTAT_SHUTDOWN && abnode->running) {
169 bnode_StopProc(abnode->proc, SIGTERM);
170 abnode->waitingForShutdown = 1;
171 bnode_SetTimeout(abnode, SDTIME);
178 ez_procexit(struct ezbnode *abnode, struct bnode_proc *aproc)
180 /* process has exited */
181 register afs_int32 code;
183 abnode->waitingForShutdown = 0;
185 abnode->killSent = 0;
186 abnode->proc = (struct bnode_proc *)0;
187 bnode_SetTimeout(abnode, 0); /* clear timer */
189 code = ez_setstat(abnode, BSTAT_NORMAL);
196 ez_getstring(struct ezbnode *abnode, char *abuffer, afs_int32 alen)
198 return -1; /* don't have much to add */
202 ez_getparm(struct ezbnode *abnode, afs_int32 aindex, char *abuffer,
207 strcpy(abuffer, abnode->command);