1*421949a3Ssevan /* $NetBSD: statd.h,v 1.3 2018/01/23 21:06:26 sevan Exp $ */ 224ce527bSscottr 324ce527bSscottr /* 424ce527bSscottr * Copyright (c) 1995 524ce527bSscottr * A.R. Gordon (andrew.gordon@net-tel.co.uk). All rights reserved. 624ce527bSscottr * 724ce527bSscottr * Redistribution and use in source and binary forms, with or without 824ce527bSscottr * modification, are permitted provided that the following conditions 924ce527bSscottr * are met: 1024ce527bSscottr * 1. Redistributions of source code must retain the above copyright 1124ce527bSscottr * notice, this list of conditions and the following disclaimer. 1224ce527bSscottr * 2. Redistributions in binary form must reproduce the above copyright 1324ce527bSscottr * notice, this list of conditions and the following disclaimer in the 1424ce527bSscottr * documentation and/or other materials provided with the distribution. 1524ce527bSscottr * 3. All advertising materials mentioning features or use of this software 1624ce527bSscottr * must display the following acknowledgement: 1724ce527bSscottr * This product includes software developed for the FreeBSD project 1824ce527bSscottr * 4. Neither the name of the author nor the names of any co-contributors 1924ce527bSscottr * may be used to endorse or promote products derived from this software 2024ce527bSscottr * without specific prior written permission. 2124ce527bSscottr * 2224ce527bSscottr * THIS SOFTWARE IS PROVIDED BY ANDREW GORDON AND CONTRIBUTORS ``AS IS'' AND 2324ce527bSscottr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2424ce527bSscottr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2524ce527bSscottr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2624ce527bSscottr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2724ce527bSscottr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2824ce527bSscottr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2924ce527bSscottr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3024ce527bSscottr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3124ce527bSscottr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3224ce527bSscottr * SUCH DAMAGE. 3324ce527bSscottr * 3424ce527bSscottr */ 3524ce527bSscottr 3624ce527bSscottr #include "sm_inter.h" 3724ce527bSscottr 3824ce527bSscottr /* ------------------------------------------------------------------------- */ 3924ce527bSscottr /* 4024ce527bSscottr * Data structures for recording monitored hosts 4124ce527bSscottr * 4224ce527bSscottr * The information held by the status monitor comprises a list of hosts 4324ce527bSscottr * that we have been asked to monitor, and, associated with each monitored 4424ce527bSscottr * host, one or more clients to be called back if the monitored host crashes. 4524ce527bSscottr * 4624ce527bSscottr * The list of monitored hosts must be retained over a crash, so that upon 4724ce527bSscottr * re-boot we can call the SM_NOTIFY procedure in all those hosts so as to 4824ce527bSscottr * cause them to start recovery processing. On the other hand, the client 4924ce527bSscottr * call-backs are not required to be preserved: they are assumed (in the 5024ce527bSscottr * protocol design) to be local processes which will have crashed when 5124ce527bSscottr * we did, and so are discarded on restart. 5224ce527bSscottr * 5324ce527bSscottr * We handle this by keeping the list of monitored hosts in a file 5424ce527bSscottr * (/var/statd.state) which is mmap()ed and whose format is described 551175f55bSchristos * by the typedef Header. The lists of client callbacks are chained 5624ce527bSscottr * off this structure, but are held in normal memory and so will be 5724ce527bSscottr * lost after a re-boot. Hence the actual values of MonList * pointers 5824ce527bSscottr * in the copy on disc have no significance, but their NULL/non-NULL 5924ce527bSscottr * status indicates whether this host is actually being monitored or if it 6024ce527bSscottr * is an empty slot in the file. 6124ce527bSscottr */ 6224ce527bSscottr 6324ce527bSscottr typedef struct MonList_s { 6424ce527bSscottr struct MonList_s *next; /* Next in list or NULL */ 6524ce527bSscottr char notifyHost[SM_MAXSTRLEN + 1]; /* Host to notify */ 6624ce527bSscottr int notifyProg; /* RPC program number to call */ 6724ce527bSscottr int notifyVers; /* version number */ 6824ce527bSscottr int notifyProc; /* procedure number */ 6924ce527bSscottr u_char notifyData[16]; /* Opaque data from caller */ 7024ce527bSscottr } MonList; 7124ce527bSscottr 7224ce527bSscottr typedef struct { 731175f55bSchristos int notifyReqd; /* Time of our next attempt or 0 7424ce527bSscottr informed the monitored host */ 751175f55bSchristos int attempts; /* Number of attempts we tried so far */ 7624ce527bSscottr MonList *monList; /* List of clients to inform if we 7724ce527bSscottr hear that the monitored host has 7824ce527bSscottr crashed, NULL if no longer monitored */ 7924ce527bSscottr } HostInfo; 8024ce527bSscottr 8124ce527bSscottr 8224ce527bSscottr /* Overall file layout. */ 8324ce527bSscottr 8424ce527bSscottr typedef struct { 851175f55bSchristos int magic; /* Zero magic */ 8624ce527bSscottr int ourState; /* State number as defined in statd protocol */ 871175f55bSchristos } Header; 8824ce527bSscottr 8924ce527bSscottr /* ------------------------------------------------------------------------- */ 9024ce527bSscottr 9124ce527bSscottr /* Global variables */ 9224ce527bSscottr 9324ce527bSscottr extern int debug; /* = 1 to enable diagnostics to syslog */ 941175f55bSchristos extern struct sigaction sa; 951175f55bSchristos extern Header status_info; 9624ce527bSscottr 9724ce527bSscottr /* Function prototypes */ 9824ce527bSscottr 991175f55bSchristos /* stat_proc.c */ 100*421949a3Ssevan struct sm_stat_res *sm_stat_1_svc(sm_name *, struct svc_req *); 101*421949a3Ssevan struct sm_stat_res *sm_mon_1_svc(mon *, struct svc_req *); 102*421949a3Ssevan struct sm_stat *sm_unmon_1_svc(mon_id *, struct svc_req *); 103*421949a3Ssevan struct sm_stat *sm_unmon_all_1_svc(my_id *, struct svc_req *); 104*421949a3Ssevan void *sm_simu_crash_1_svc(void *, struct svc_req *); 105*421949a3Ssevan void *sm_notify_1_svc(stat_chge *, struct svc_req *); 106*421949a3Ssevan int do_unmon(char *, HostInfo *, void *); 1071175f55bSchristos 1081175f55bSchristos /* statd.c */ 109*421949a3Ssevan void notify_handler(int); 110*421949a3Ssevan void sync_file(void); 111*421949a3Ssevan void unmon_hosts(void); 112*421949a3Ssevan void change_host(char *, HostInfo *); 113*421949a3Ssevan HostInfo *find_host(char *, HostInfo *); 114*421949a3Ssevan void reset_database(void); 1151175f55bSchristos 116*421949a3Ssevan void sm_prog_1(struct svc_req *, SVCXPRT *); 1171175f55bSchristos 1181175f55bSchristos #define NO_ALARM sa.sa_handler == SIG_DFL ? 0 : (sa.sa_handler = SIG_IGN, sigaction(SIGALRM, &sa, NULL)) 1191175f55bSchristos #define ALARM sa.sa_handler == SIG_DFL ? 0 : (sa.sa_handler = notify_handler, sigaction(SIGALRM, &sa, NULL)) 1201175f55bSchristos #define CLR_ALARM sa.sa_handler == SIG_DFL ? 0 : (sa.sa_handler = SIG_DFL, sigaction(SIGALRM, &sa, NULL)) 121