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 <afs/param.h>
11 #include <sys/types.h>
18 #include <afs/afsutil.h>
19 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
22 static int ez_timeout(), ez_getstat(), ez_setstat(), ez_delete();
23 static int ez_procexit(), ez_getstring(), ez_getparm(), ez_restartp();
24 static int ez_hascore();
25 struct bnode *ez_create();
27 #define SDTIME 60 /* time in seconds given to a process to evaporate */
29 struct bnode_ops ezbnode_ops = {
42 static int ez_hascore(abnode)
43 register struct ezbnode *abnode; {
46 bnode_CoreName(abnode, (char *) 0, tbuffer);
47 if (access(tbuffer, 0) == 0) return 1;
51 static int ez_restartp (abnode)
52 register struct ezbnode *abnode; {
53 struct bnode_token *tt;
54 register afs_int32 code;
57 code = bnode_ParseLine(abnode->command, &tt);
60 code = stat(tt->key, &tstat);
65 if (tstat.st_ctime > abnode->lastStart) code = 1;
71 static int ez_delete(abnode)
72 struct ezbnode *abnode; {
73 free(abnode->command);
78 struct bnode *ez_create(ainstance, acommand)
84 if (ConstructLocalBinPath(acommand, &cmdpath)) {
85 bozo_Log("BNODE: command path invalid '%s'\n", acommand);
86 return (struct bnode *)0;
89 te = (struct ezbnode *) malloc(sizeof(struct ezbnode));
90 bzero(te, sizeof(struct ezbnode));
91 bnode_InitBnode(te, &ezbnode_ops, ainstance);
92 te->command = cmdpath;
93 return (struct bnode *) te;
96 /* called to SIGKILL a process if it doesn't terminate normally */
97 static int ez_timeout(abnode)
98 struct ezbnode *abnode; {
99 if (!abnode->waitingForShutdown) return 0; /* spurious */
100 /* send kill and turn off timer */
101 bnode_StopProc(abnode->proc, SIGKILL);
102 abnode->killSent = 1;
103 bnode_SetTimeout(abnode, 0);
107 static int ez_getstat(abnode, astatus)
108 struct ezbnode *abnode;
109 afs_int32 *astatus; {
110 register afs_int32 temp;
111 if (abnode->waitingForShutdown) temp = BSTAT_SHUTTINGDOWN;
112 else if (abnode->running) temp = BSTAT_NORMAL;
113 else temp = BSTAT_SHUTDOWN;
118 static int ez_setstat(abnode, astatus)
119 register struct ezbnode *abnode;
121 struct bnode_proc *tp;
122 register afs_int32 code;
124 if (abnode->waitingForShutdown) return BZBUSY;
125 if (astatus == BSTAT_NORMAL && !abnode->running) {
127 abnode->lastStart = FT_ApproxTime();
128 code = bnode_NewProc(abnode, abnode->command, (char *) 0, &tp);
129 if (code) return code;
134 else if (astatus == BSTAT_SHUTDOWN && abnode->running) {
136 bnode_StopProc(abnode->proc, SIGTERM);
137 abnode->waitingForShutdown = 1;
138 bnode_SetTimeout(abnode, SDTIME);
144 static int ez_procexit(abnode, aproc)
145 struct ezbnode *abnode;
146 struct bnode_proc *aproc; {
147 /* process has exited */
148 register afs_int32 code;
150 abnode->waitingForShutdown = 0;
152 abnode->killSent = 0;
153 abnode->proc = (struct bnode_proc *) 0;
154 bnode_SetTimeout(abnode, 0); /* clear timer */
156 code = ez_setstat(abnode, BSTAT_NORMAL);
161 static int ez_getstring(abnode, abuffer, alen)
162 struct ezbnode *abnode;
165 return -1; /* don't have much to add */
168 static ez_getparm(abnode, aindex, abuffer, alen)
169 struct ezbnode *abnode;
173 if (aindex > 0) return BZDOM;
174 strcpy(abuffer, abnode->command);