1 /* 2 * extern.h 3 * 4 * Public exports. 5 */ 6 7 /* 8 * Copyright (C) 2000-2005 Kern Sibbald 9 * 10 * This program is free software; you can redistribute it and/or 11 * modify it under the terms of version 2 of the GNU General 12 * Public License as published by the Free Software Foundation. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public 20 * License along with this program; if not, write to the Free 21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 22 * MA 02110-1335, USA. 23 */ 24 25 #ifndef _EXTERN_H 26 #define _EXTERN_H 27 28 /* Function Prototypes */ 29 30 extern UPSINFO *core_ups; 31 extern char argvalue[MAXSTRING]; 32 extern void (*error_out) (const char *file, int line, const char *fmt, va_list arg_ptr); 33 extern void (*error_cleanup) (void); 34 extern void error_out_wrapper(const char *file, int line, const char *fmt, ...) __attribute__((noreturn)); 35 36 extern UPSCOMMANDS ups_event[]; 37 extern UPSCMDMSG event_msg[]; 38 39 40 /* Serial bits */ 41 extern int le_bit; 42 extern int dtr_bit; 43 extern int rts_bit; 44 extern int st_bit; 45 extern int sr_bit; 46 extern int cts_bit; 47 extern int cd_bit; 48 extern int rng_bit; 49 extern int dsr_bit; 50 51 /* File opened */ 52 extern int flags; 53 extern struct termios newtio; 54 extern int debug_net; 55 56 /* getopt flags (see apcoptd.c) */ 57 extern int show_version; 58 extern char *cfgfile; 59 extern int configure_ups; 60 extern int update_battery_date; 61 extern int debug_level; 62 extern int rename_ups; 63 extern int terminate_on_powerfail; 64 extern int hibernate_ups; 65 extern int shutdown_ups; 66 extern int dumb_mode_test; 67 extern int go_background; 68 69 /* In apcopt.c */ 70 extern int parse_options(int argc, char *argv[]); 71 72 /* In apcupsd.c */ 73 extern void apcupsd_terminate(int sig); 74 extern void clear_files(void); 75 76 /* In apcdevice.c */ 77 bool setup_device(UPSINFO *ups); 78 extern void initiate_hibernate(UPSINFO *ups); 79 extern void initiate_shutdown(UPSINFO *ups); 80 extern void prep_device(UPSINFO *ups); 81 extern void do_device(UPSINFO *ups); 82 extern int fillUPS(UPSINFO *ups); 83 84 /* In apcaction.c */ 85 extern void do_action(UPSINFO *ups); 86 extern void generate_event(UPSINFO *ups, int event); 87 88 /* In apclock.c */ 89 extern int create_lockfile(UPSINFO *ups); 90 extern void delete_lockfile(UPSINFO *ups); 91 92 /* In apcfile.c */ 93 extern int make_file(UPSINFO *ups, const char *path); 94 extern void make_pid_file(void); 95 extern void make_pid(void); 96 97 /* In apcconfig.c */ 98 extern char APCCONF[APC_FILENAME_MAX]; 99 extern void init_ups_struct(UPSINFO *ups); 100 extern void check_for_config(UPSINFO *ups, char *cfgfile); 101 102 /* In apcnis.c */ 103 extern void do_server(UPSINFO *ups); 104 extern int check_wrappers(char *av, int newsock); 105 106 /* In apcstatus.c */ 107 extern int output_status(UPSINFO *ups, int fd, void s_open(UPSINFO * ups), 108 void s_write(UPSINFO *ups, const char *fmt, ...), int s_close(UPSINFO * ups, int fd)); 109 extern void stat_open(UPSINFO *ups); 110 extern int stat_close(UPSINFO *ups, int fd); 111 extern void stat_print(UPSINFO *ups, const char *fmt, ...); 112 113 /* In apcevents.c */ 114 extern int trim_eventfile(UPSINFO *ups); 115 extern int output_events(int sockfd, FILE *events_file); 116 117 /* In apcreports.c */ 118 extern void clear_files(void); 119 extern int log_status(UPSINFO *ups); 120 extern void do_reports(UPSINFO *ups); 121 122 /* In apcsignal.c */ 123 extern void init_signals(void (*handler) (int)); 124 125 /* In newups.c */ 126 extern UPSINFO *new_ups(void); 127 extern UPSINFO *attach_ups(UPSINFO *ups); 128 extern void detach_ups(UPSINFO *ups); 129 extern void destroy_ups(UPSINFO *ups); 130 131 #define read_lock(ups) _read_lock(__FILE__, __LINE__, (ups)) 132 #define read_unlock(ups) _read_unlock(__FILE__, __LINE__, (ups)) 133 #define write_lock(ups) _write_lock(__FILE__, __LINE__, (ups)) 134 #define write_unlock(ups) _write_unlock(__FILE__, __LINE__, (ups)) 135 #define read_lock(ups) _read_lock(__FILE__, __LINE__, (ups)) 136 137 extern void _read_lock(const char *file, int line, UPSINFO *ups); 138 extern void _read_unlock(const char *file, int line, UPSINFO *ups); 139 extern void _write_lock(const char *file, int line, UPSINFO *ups); 140 extern void _write_unlock(const char *file, int line, UPSINFO *ups); 141 142 /* In apcexec.c */ 143 extern int start_thread(UPSINFO *ups, void (*action) (UPSINFO * ups), 144 const char *proctitle, char *argv0); 145 extern int execute_command(UPSINFO *ups, UPSCOMMANDS cmd); 146 extern void clean_threads(void); 147 148 /* In apclog.c */ 149 extern void log_event(const UPSINFO *ups, int level, const char *fmt, ...); 150 extern void logf(const char *fmt, ...); 151 extern int format_date(time_t timestamp, char *dest, size_t destlen); 152 153 /* In apcerror.c */ 154 extern void generic_error_out(const char *file, int line, const char *fmt, ...); 155 extern void generic_error_exit(const char *fmt, ...); 156 157 /* In asys.c */ 158 int avsnprintf(char *str, size_t size, const char *format, va_list ap); 159 int asnprintf(char *str, size_t size, const char *fmt, ...); 160 #ifndef HAVE_STRLCPY 161 size_t strlcpy(char *dst, const char *src, size_t size); 162 #endif 163 #ifndef HAVE_STRLCAT 164 size_t strlcat(char *dst, const char *src, size_t size); 165 #endif 166 167 /* In sleep.c */ 168 #ifndef HAVE_NANOSLEEP 169 int nanosleep(const struct timespec *req, struct timespec *rem); 170 #endif 171 172 /* In sockcloexec.c */ 173 sock_t socket_cloexec(int domain, int type, int protocol); 174 sock_t accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen); 175 176 /* 177 * Common interface to the various versions of gethostbyname_r(). 178 * Implemented in gethostname.c. 179 */ 180 struct hostent * gethostname_re 181 (const char *host,struct hostent *hostbuf,char **tmphstbuf,size_t *hstbuflen); 182 183 #endif /* _EXTERN_H */ 184