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>
15 #include <sys/types.h>
22 #include <afs/afsutil.h>
23 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
26 static int ez_timeout(), ez_getstat(), ez_setstat(), ez_delete();
27 static int ez_procexit(), ez_getstring(), ez_getparm(), ez_restartp();
28 static int ez_hascore();
29 struct bnode *ez_create();
31 #define SDTIME 60 /* time in seconds given to a process to evaporate */
33 struct bnode_ops ezbnode_ops = {
46 static int ez_hascore(abnode)
47 register struct ezbnode *abnode; {
50 bnode_CoreName(abnode, (char *) 0, tbuffer);
51 if (access(tbuffer, 0) == 0) return 1;
55 static int ez_restartp (abnode)
56 register struct ezbnode *abnode; {
57 struct bnode_token *tt;
58 register afs_int32 code;
61 code = bnode_ParseLine(abnode->command, &tt);
64 code = stat(tt->key, &tstat);
69 if (tstat.st_ctime > abnode->lastStart) code = 1;
75 static int ez_delete(abnode)
76 struct ezbnode *abnode; {
77 free(abnode->command);
82 struct bnode *ez_create(ainstance, acommand)
88 if (ConstructLocalBinPath(acommand, &cmdpath)) {
89 bozo_Log("BNODE: command path invalid '%s'\n", acommand);
90 return (struct bnode *)0;
93 te = (struct ezbnode *) malloc(sizeof(struct ezbnode));
94 memset(te, 0, sizeof(struct ezbnode));
95 bnode_InitBnode(te, &ezbnode_ops, ainstance);
96 te->command = cmdpath;
97 return (struct bnode *) te;
100 /* called to SIGKILL a process if it doesn't terminate normally */
101 static int ez_timeout(abnode)
102 struct ezbnode *abnode; {
103 if (!abnode->waitingForShutdown) return 0; /* spurious */
104 /* send kill and turn off timer */
105 bnode_StopProc(abnode->proc, SIGKILL);
106 abnode->killSent = 1;
107 bnode_SetTimeout(abnode, 0);
111 static int ez_getstat(abnode, astatus)
112 struct ezbnode *abnode;
113 afs_int32 *astatus; {
114 register afs_int32 temp;
115 if (abnode->waitingForShutdown) temp = BSTAT_SHUTTINGDOWN;
116 else if (abnode->running) temp = BSTAT_NORMAL;
117 else temp = BSTAT_SHUTDOWN;
122 static int ez_setstat(abnode, astatus)
123 register struct ezbnode *abnode;
125 struct bnode_proc *tp;
126 register afs_int32 code;
128 if (abnode->waitingForShutdown) return BZBUSY;
129 if (astatus == BSTAT_NORMAL && !abnode->running) {
131 abnode->lastStart = FT_ApproxTime();
132 code = bnode_NewProc(abnode, abnode->command, (char *) 0, &tp);
133 if (code) return code;
138 else if (astatus == BSTAT_SHUTDOWN && abnode->running) {
140 bnode_StopProc(abnode->proc, SIGTERM);
141 abnode->waitingForShutdown = 1;
142 bnode_SetTimeout(abnode, SDTIME);
148 static int ez_procexit(abnode, aproc)
149 struct ezbnode *abnode;
150 struct bnode_proc *aproc; {
151 /* process has exited */
152 register afs_int32 code;
154 abnode->waitingForShutdown = 0;
156 abnode->killSent = 0;
157 abnode->proc = (struct bnode_proc *) 0;
158 bnode_SetTimeout(abnode, 0); /* clear timer */
160 code = ez_setstat(abnode, BSTAT_NORMAL);
165 static int ez_getstring(abnode, abuffer, alen)
166 struct ezbnode *abnode;
169 return -1; /* don't have much to add */
172 static ez_getparm(abnode, aindex, abuffer, alen)
173 struct ezbnode *abnode;
177 if (aindex > 0) return BZDOM;
178 strcpy(abuffer, abnode->command);