bozo-prototypes-20090316
[openafs.git] / src / bozo / bnode.p.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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
8  */
9
10 #define BOP_TIMEOUT(bnode)      ((*(bnode)->ops->timeout)((bnode)))
11 #define BOP_GETSTAT(bnode, a)   ((*(bnode)->ops->getstat)((bnode),(a)))
12 #define BOP_SETSTAT(bnode, a)   ((*(bnode)->ops->setstat)((bnode),(a)))
13 #define BOP_DELETE(bnode)       ((*(bnode)->ops->delete)((bnode)))
14 #define BOP_PROCEXIT(bnode, a)  ((*(bnode)->ops->procexit)((bnode),(a)))
15 #define BOP_GETSTRING(bnode, a, b)      ((*(bnode)->ops->getstring)((bnode),(a), (b)))
16 #define BOP_GETPARM(bnode, n, b, l)     ((*(bnode)->ops->getparm)((bnode),(n),(b),(l)))
17 #define BOP_RESTARTP(bnode)     ((*(bnode)->ops->restartp)((bnode)))
18 #define BOP_HASCORE(bnode)      ((*(bnode)->ops->hascore)((bnode)))
19
20 struct bnode_proc;
21
22 struct bnode_ops {
23     struct bnode *(*create) ( char *, char *, char *, char *, char *, char *);
24     int (*timeout) ( struct bnode * );
25     int (*getstat) ( struct bnode *, afs_int32 * );
26     int (*setstat) ( struct bnode *, afs_int32 );
27     int (*delete) ( struct bnode * );
28     int (*procexit) ( struct bnode *, struct bnode_proc * );
29     int (*getstring) ( struct bnode *, char *abuffer, afs_int32 alen );
30     int (*getparm) ( struct bnode *, afs_int32 aindex, char *abuffer, 
31                      afs_int32 alen);
32     int (*restartp) ( struct bnode *);
33     int (*hascore) ( struct bnode *);
34 };
35
36 struct bnode_type {
37     struct bnode_type *next;
38     char *name;
39     struct bnode_ops *ops;
40 };
41
42 struct bnode_token {
43     struct bnode_token *next;
44     char *key;
45 };
46
47 struct bnode {
48     struct bnode *next;         /* next pointer in top-level's list */
49     char *name;                 /* instance name */
50     afs_int32 nextTimeout;      /* next time this guy should be woken */
51     afs_int32 period;           /* period between calls */
52     afs_int32 rsTime;           /* time we started counting restarts */
53     afs_int32 rsCount;          /* count of restarts since rsTime */
54     struct bnode_type *type;    /* type object */
55     struct bnode_ops *ops;      /* functions implementing bnode class */
56     afs_int32 procStartTime;    /* last time a process was started */
57     afs_int32 procStarts;       /* number of process starts */
58     afs_int32 lastAnyExit;      /* last time a process exited, for any reason */
59     afs_int32 lastErrorExit;    /* last time a process exited unexpectedly */
60     afs_int32 errorCode;        /* last exit return code */
61     afs_int32 errorSignal;      /* last proc terminating signal */
62     char *lastErrorName;        /* name of proc that failed last */
63     char *notifier;             /* notifier program to be executed on exits */
64     short refCount;             /* reference count */
65     short flags;                /* random flags */
66     char goal;                  /* 1=running or 0=not running */
67     char fileGoal;              /* same, but to be stored in file */
68 };
69
70 struct bnode_proc {
71     struct bnode_proc *next;    /* next guy in top-level's list */
72     struct bnode *bnode;        /* bnode creating this process */
73     char *comLine;              /* command line used to start this process */
74     char *coreName;             /* optional core file component name */
75     afs_int32 pid;              /* pid if created */
76     afs_int32 lastExit;         /* last termination code */
77     afs_int32 lastSignal;       /* last signal that killed this guy */
78     afs_int32 flags;            /* flags giving process state */
79 };
80
81 struct ezbnode {
82     struct bnode b;
83     afs_int32 zapTime;          /* time we sent a sigterm */
84     char *command;
85     struct bnode_proc *proc;
86     afs_int32 lastStart;        /* time last started process */
87     char waitingForShutdown;    /* have we started any shutdown procedure? */
88     char running;               /* is process running? */
89     char killSent;              /* have we tried sigkill signal? */
90 };
91
92 /* this struct is used to construct a list of dirpaths, along with 
93  * their recommended permissions 
94  */
95 struct bozo_bosEntryStats {
96     const char *path;           /* pathname to check */
97     int dir;                    /* 1=>dir or 0=>file */
98     int rootOwner;              /* 1=>root must own */
99     int reqPerm;                /* required permissions */
100     int proPerm;                /* prohibited permissions */
101 };
102 /* bnode flags */
103 #define BNODE_NEEDTIMEOUT           1   /* timeouts are active */
104 #define BNODE_ACTIVE                2   /* in generic lists */
105 #define BNODE_WAIT                  4   /* someone waiting for status change */
106 #define BNODE_DELETE                8   /* delete this bnode asap */
107 #define BNODE_ERRORSTOP             0x10        /* stopped due to errors */
108
109 /* flags for bnode_proc */
110 #define BPROC_STARTED               1   /* ever started */
111 #define BPROC_EXITED                2   /* exited */
112
113 #define NONOTIFIER                  "__NONOTIFIER__"
114
115 /* status values for bnodes, and goals */
116 #define BSTAT_SHUTDOWN              0   /* shutdown normally */
117 #define BSTAT_NORMAL                1   /* running normally */
118 #define BSTAT_SHUTTINGDOWN          2   /* normal --> shutdown */
119 #define BSTAT_STARTINGUP            3   /* shutdown --> normal */
120
121 /* exit values indicating that NT SCM integrator should restart bosserver */
122 #ifdef AFS_NT40_ENV
123 #define BOSEXIT_RESTART        0xA0
124 #define BOSEXIT_DORESTART(code)  (((code) & ~(0xF)) == BOSEXIT_RESTART)
125 #define BOSEXIT_NOAUTH_FLAG    0x01
126 #define BOSEXIT_LOGGING_FLAG   0x02
127 #endif
128
129 /* max time to wait for fileserver shutdown */
130 #define FSSDTIME        (30 * 60)       /* seconds */
131
132 /* calls back up to the generic bnode layer */
133 extern int bnode_SetTimeout(register struct bnode *abnode, afs_int32 atimeout);
134 extern int bnode_Init(void);
135 extern int bnode_NewProc(struct bnode *abnode, char *aexecString, char *coreName, struct bnode_proc **aproc);
136 extern int bnode_InitBnode(register struct bnode *abnode, struct bnode_ops *abnodeops, char *aname);
137 extern afs_int32 bnode_Create(char *atype, char *ainstance, struct bnode ** abp, char *ap1, char *ap2, char *ap3, char *ap4, char *ap5, char *notifier, int fileGoal, int rewritefile);
138 extern struct bnode *bnode_FindInstance(register char *aname);
139 extern int bnode_WaitStatus(register struct bnode *abnode, int astatus);
140 extern int bnode_SetStat(register struct bnode *abnode, register int agoal);