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. */
31 static int ez_timeout(), ez_getstat(), ez_setstat(), ez_delete();
32 static int ez_procexit(), ez_getstring(), ez_getparm(), ez_restartp();
33 static int ez_hascore();
34 struct bnode *ez_create();
36 #define SDTIME 60 /* time in seconds given to a process to evaporate */
38 struct bnode_ops ezbnode_ops = {
52 ez_hascore(register struct ezbnode *abnode)
56 bnode_CoreName(abnode, NULL, tbuffer);
57 if (access(tbuffer, 0) == 0)
64 ez_restartp(register struct ezbnode *abnode)
66 struct bnode_token *tt;
67 register afs_int32 code;
70 code = bnode_ParseLine(abnode->command, &tt);
75 code = stat(tt->key, &tstat);
80 if (tstat.st_ctime > abnode->lastStart)
89 ez_delete(struct ezbnode *abnode)
91 free(abnode->command);
97 ez_create(char *ainstance, char *acommand)
102 if (ConstructLocalBinPath(acommand, &cmdpath)) {
103 bozo_Log("BNODE: command path invalid '%s'\n", acommand);
107 te = (struct ezbnode *)malloc(sizeof(struct ezbnode));
108 memset(te, 0, sizeof(struct ezbnode));
109 if (bnode_InitBnode(te, &ezbnode_ops, ainstance) != 0) {
113 te->command = cmdpath;
114 return (struct bnode *)te;
117 /* called to SIGKILL a process if it doesn't terminate normally */
119 ez_timeout(struct ezbnode *abnode)
121 if (!abnode->waitingForShutdown)
122 return 0; /* spurious */
123 /* send kill and turn off timer */
124 bnode_StopProc(abnode->proc, SIGKILL);
125 abnode->killSent = 1;
126 bnode_SetTimeout(abnode, 0);
131 ez_getstat(struct ezbnode *abnode, afs_int32 * astatus)
133 register afs_int32 temp;
134 if (abnode->waitingForShutdown)
135 temp = BSTAT_SHUTTINGDOWN;
136 else if (abnode->running)
139 temp = BSTAT_SHUTDOWN;
145 ez_setstat(register struct ezbnode *abnode, afs_int32 astatus)
147 struct bnode_proc *tp;
148 register afs_int32 code;
150 if (abnode->waitingForShutdown)
152 if (astatus == BSTAT_NORMAL && !abnode->running) {
154 abnode->lastStart = FT_ApproxTime();
155 code = bnode_NewProc(abnode, abnode->command, NULL, &tp);
161 } else if (astatus == BSTAT_SHUTDOWN && abnode->running) {
163 bnode_StopProc(abnode->proc, SIGTERM);
164 abnode->waitingForShutdown = 1;
165 bnode_SetTimeout(abnode, SDTIME);
172 ez_procexit(struct ezbnode *abnode, struct bnode_proc *aproc)
174 /* process has exited */
175 register afs_int32 code;
177 abnode->waitingForShutdown = 0;
179 abnode->killSent = 0;
180 abnode->proc = (struct bnode_proc *)0;
181 bnode_SetTimeout(abnode, 0); /* clear timer */
183 code = ez_setstat(abnode, BSTAT_NORMAL);
190 ez_getstring(struct ezbnode *abnode, char *abuffer, afs_int32 alen)
192 return -1; /* don't have much to add */
196 ez_getparm(struct ezbnode *abnode, afs_int32 aindex, char *abuffer,
201 strcpy(abuffer, abnode->command);