1 1.3 sevan /* $NetBSD: statd.h,v 1.3 2018/01/23 21:06:26 sevan Exp $ */ 2 1.1 scottr 3 1.1 scottr /* 4 1.1 scottr * Copyright (c) 1995 5 1.1 scottr * A.R. Gordon (andrew.gordon (at) net-tel.co.uk). All rights reserved. 6 1.1 scottr * 7 1.1 scottr * Redistribution and use in source and binary forms, with or without 8 1.1 scottr * modification, are permitted provided that the following conditions 9 1.1 scottr * are met: 10 1.1 scottr * 1. Redistributions of source code must retain the above copyright 11 1.1 scottr * notice, this list of conditions and the following disclaimer. 12 1.1 scottr * 2. Redistributions in binary form must reproduce the above copyright 13 1.1 scottr * notice, this list of conditions and the following disclaimer in the 14 1.1 scottr * documentation and/or other materials provided with the distribution. 15 1.1 scottr * 3. All advertising materials mentioning features or use of this software 16 1.1 scottr * must display the following acknowledgement: 17 1.1 scottr * This product includes software developed for the FreeBSD project 18 1.1 scottr * 4. Neither the name of the author nor the names of any co-contributors 19 1.1 scottr * may be used to endorse or promote products derived from this software 20 1.1 scottr * without specific prior written permission. 21 1.1 scottr * 22 1.1 scottr * THIS SOFTWARE IS PROVIDED BY ANDREW GORDON AND CONTRIBUTORS ``AS IS'' AND 23 1.1 scottr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 1.1 scottr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 1.1 scottr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 26 1.1 scottr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 1.1 scottr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 1.1 scottr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 1.1 scottr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 1.1 scottr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 1.1 scottr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 1.1 scottr * SUCH DAMAGE. 33 1.1 scottr * 34 1.1 scottr */ 35 1.1 scottr 36 1.1 scottr #include "sm_inter.h" 37 1.1 scottr 38 1.1 scottr /* ------------------------------------------------------------------------- */ 39 1.1 scottr /* 40 1.1 scottr * Data structures for recording monitored hosts 41 1.1 scottr * 42 1.1 scottr * The information held by the status monitor comprises a list of hosts 43 1.1 scottr * that we have been asked to monitor, and, associated with each monitored 44 1.1 scottr * host, one or more clients to be called back if the monitored host crashes. 45 1.1 scottr * 46 1.1 scottr * The list of monitored hosts must be retained over a crash, so that upon 47 1.1 scottr * re-boot we can call the SM_NOTIFY procedure in all those hosts so as to 48 1.1 scottr * cause them to start recovery processing. On the other hand, the client 49 1.1 scottr * call-backs are not required to be preserved: they are assumed (in the 50 1.1 scottr * protocol design) to be local processes which will have crashed when 51 1.1 scottr * we did, and so are discarded on restart. 52 1.1 scottr * 53 1.1 scottr * We handle this by keeping the list of monitored hosts in a file 54 1.1 scottr * (/var/statd.state) which is mmap()ed and whose format is described 55 1.2 christos * by the typedef Header. The lists of client callbacks are chained 56 1.1 scottr * off this structure, but are held in normal memory and so will be 57 1.1 scottr * lost after a re-boot. Hence the actual values of MonList * pointers 58 1.1 scottr * in the copy on disc have no significance, but their NULL/non-NULL 59 1.1 scottr * status indicates whether this host is actually being monitored or if it 60 1.1 scottr * is an empty slot in the file. 61 1.1 scottr */ 62 1.1 scottr 63 1.1 scottr typedef struct MonList_s { 64 1.1 scottr struct MonList_s *next; /* Next in list or NULL */ 65 1.1 scottr char notifyHost[SM_MAXSTRLEN + 1]; /* Host to notify */ 66 1.1 scottr int notifyProg; /* RPC program number to call */ 67 1.1 scottr int notifyVers; /* version number */ 68 1.1 scottr int notifyProc; /* procedure number */ 69 1.1 scottr u_char notifyData[16]; /* Opaque data from caller */ 70 1.1 scottr } MonList; 71 1.1 scottr 72 1.1 scottr typedef struct { 73 1.2 christos int notifyReqd; /* Time of our next attempt or 0 74 1.1 scottr informed the monitored host */ 75 1.2 christos int attempts; /* Number of attempts we tried so far */ 76 1.1 scottr MonList *monList; /* List of clients to inform if we 77 1.1 scottr hear that the monitored host has 78 1.1 scottr crashed, NULL if no longer monitored */ 79 1.1 scottr } HostInfo; 80 1.1 scottr 81 1.1 scottr 82 1.1 scottr /* Overall file layout. */ 83 1.1 scottr 84 1.1 scottr typedef struct { 85 1.2 christos int magic; /* Zero magic */ 86 1.1 scottr int ourState; /* State number as defined in statd protocol */ 87 1.2 christos } Header; 88 1.1 scottr 89 1.1 scottr /* ------------------------------------------------------------------------- */ 90 1.1 scottr 91 1.1 scottr /* Global variables */ 92 1.1 scottr 93 1.1 scottr extern int debug; /* = 1 to enable diagnostics to syslog */ 94 1.2 christos extern struct sigaction sa; 95 1.2 christos extern Header status_info; 96 1.1 scottr 97 1.1 scottr /* Function prototypes */ 98 1.1 scottr 99 1.2 christos /* stat_proc.c */ 100 1.3 sevan struct sm_stat_res *sm_stat_1_svc(sm_name *, struct svc_req *); 101 1.3 sevan struct sm_stat_res *sm_mon_1_svc(mon *, struct svc_req *); 102 1.3 sevan struct sm_stat *sm_unmon_1_svc(mon_id *, struct svc_req *); 103 1.3 sevan struct sm_stat *sm_unmon_all_1_svc(my_id *, struct svc_req *); 104 1.3 sevan void *sm_simu_crash_1_svc(void *, struct svc_req *); 105 1.3 sevan void *sm_notify_1_svc(stat_chge *, struct svc_req *); 106 1.3 sevan int do_unmon(char *, HostInfo *, void *); 107 1.2 christos 108 1.2 christos /* statd.c */ 109 1.3 sevan void notify_handler(int); 110 1.3 sevan void sync_file(void); 111 1.3 sevan void unmon_hosts(void); 112 1.3 sevan void change_host(char *, HostInfo *); 113 1.3 sevan HostInfo *find_host(char *, HostInfo *); 114 1.3 sevan void reset_database(void); 115 1.2 christos 116 1.3 sevan void sm_prog_1(struct svc_req *, SVCXPRT *); 117 1.2 christos 118 1.2 christos #define NO_ALARM sa.sa_handler == SIG_DFL ? 0 : (sa.sa_handler = SIG_IGN, sigaction(SIGALRM, &sa, NULL)) 119 1.2 christos #define ALARM sa.sa_handler == SIG_DFL ? 0 : (sa.sa_handler = notify_handler, sigaction(SIGALRM, &sa, NULL)) 120 1.2 christos #define CLR_ALARM sa.sa_handler == SIG_DFL ? 0 : (sa.sa_handler = SIG_DFL, sigaction(SIGALRM, &sa, NULL)) 121