filewatcherd

FreeBSD daemon that watches files and runs commands when they change
git clone https://git.instinctive.eu/filewatcherd.git
Log | Files | Refs | README | LICENSE

log.h (4868B)


      1 /* log.h - report errors to the outside world */
      2 
      3 /*
      4  * Copyright (c) 2013, Natacha Porté
      5  *
      6  * Permission to use, copy, modify, and distribute this software for any
      7  * purpose with or without fee is hereby granted, provided that the above
      8  * copyright notice and this permission notice appear in all copies.
      9  *
     10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     17  */
     18 
     19 /*
     20  * This module gather all error-formating functions, so that all user-facing
     21  * strings are gathered in one place.
     22  */
     23 
     24 #ifndef FILEWATCHER_LOG_H
     25 #define FILEWATCHER_LOG_H
     26 
     27 #include "watchtab.h"
     28 
     29 
     30 /*************
     31  * REPORTING *
     32  *************/
     33 
     34 /* report_fn - report callback, same semantics as syslog() */
     35 typedef void (*report_fn)(int priority, const char *message, ...)
     36     __attribute__((format (printf, 2, 3)));
     37 
     38 /* report_to_stderr - wrapper to send the message to standard error output */
     39 void
     40 report_to_stderr(int priority, const char *message, ...);
     41 
     42 /* set_report - use the given callback for error reporting */
     43 void
     44 set_report(report_fn callback);
     45 
     46 /*******************
     47  * ERROR FORMATING *
     48  *******************/
     49 
     50 /* log_alloc - memory allocation failure */
     51 void
     52 log_alloc(const char *subsystem);
     53 
     54 /* log_assert - internal inconsistency */
     55 void
     56 log_assert(const char *reason, const char *source, unsigned line);
     57 #define LOG_ASSERT(m) log_assert((m), __FILE__, __LINE__)
     58 
     59 /* log_bad_delay - invalid string provided for delay value */
     60 void
     61 log_bad_delay(const char *opt);
     62 
     63 /* log_chdir - chdir("/") failed after successful chroot() */
     64 void
     65 log_chdir(const char *newroot);
     66 
     67 /* log_chroot - chroot() failed */
     68 void
     69 log_chroot(const char *newroot);
     70 
     71 /* log_entry_wait - watchtab entry successfully inserted in the queue */
     72 void
     73 log_entry_wait(struct watch_entry *wentry);
     74 
     75 /* log_exec - execve() failed */
     76 void
     77 log_exec(struct watch_entry *wentry);
     78 
     79 /* log_fork - fork() failed */
     80 void
     81 log_fork(void);
     82 
     83 /* log_kevent_entry - kevent() failed when adding an event for a file entry */
     84 void
     85 log_kevent_entry(const char *path);
     86 
     87 /* log_kevent_proc - kevent() failed when adding a command watcher */
     88 void
     89 log_kevent_proc(struct watch_entry *wentry, pid_t pid);
     90 
     91 /* log_kevent_timer - kevent() failed when adding a timer */
     92 void
     93 log_kevent_timer(void);
     94 
     95 /* log_kevent_timer_off - kevent() failed when removing a timer */
     96 void
     97 log_kevent_timer_off(void);
     98 
     99 /* log_kevent_wait - kevent() failed while waiting for an event */
    100 void
    101 log_kevent_wait(void);
    102 
    103 /* log_kevent_watchtab - kevent() failed when adding a watchtab event */
    104 void
    105 log_kevent_watchtab(const char *path);
    106 
    107 /* log_kqueue - kqueue() failed */
    108 void
    109 log_kqueue(void);
    110 
    111 /* log_lookup_group - getgrnam() failed */
    112 /* WARNING: errno must explicitly be zeroed before calling getgrnam() */
    113 void
    114 log_lookup_group(const char *group);
    115 
    116 /* log_lookup_pw - getpwnam() failed */
    117 /* WARNING: errno must explicitly be zeroed before calling getpwnam() */
    118 void
    119 log_lookup_pw(const char *login);
    120 
    121 /* log_lookup_self - getlogin() or getpwnam() failed */
    122 /* WARNING: errno must explicitly be zeroed before calling getpwnam() */
    123 void
    124 log_lookup_self(void);
    125 
    126 /* log_open_entry - open() failed on watchtab entry file */
    127 void
    128 log_open_entry(const char *path);
    129 
    130 /* log_open_watchtab - watchtab file open() failed */
    131 void
    132 log_open_watchtab(const char *path);
    133 
    134 /* log_running - a watchtab entry has been triggered */
    135 void
    136 log_running(struct watch_entry *wentry);
    137 
    138 /* log_setgid - setgid() failed */
    139 void
    140 log_setgid(gid_t gid);
    141 
    142 /* log_setuid - setuid() failed */
    143 void
    144 log_setuid(uid_t uid);
    145 
    146 /* log_signal - signal() failed */
    147 void
    148 log_signal(int sig);
    149 
    150 /* log_watchtab_invalid_action - invalid action line in watchtab */
    151 void
    152 log_watchtab_invalid_action(const char *filename, unsigned line_no);
    153 
    154 /* log_watchtab_invalid_delay - invalid delay field in watchtab entry */
    155 void
    156 log_watchtab_invalid_delay(const char *filename, unsigned line_no,
    157     const char *field);
    158 
    159 /* log_watchtab_invalid_events - parse error in watchtab event set */
    160 void
    161 log_watchtab_invalid_events(const char *filename, unsigned line_no,
    162     const char *field, size_t len);
    163 
    164 /* log_watchtab_loaded - watchtab has been successfully loaded */
    165 void
    166 log_watchtab_loaded(const char *path);
    167 
    168 /* log_watchtab_read - read error on watchtab */
    169 void
    170 log_watchtab_read(void);
    171 
    172 /* print_usage - output usage text upon request or after argument error */
    173 void
    174 print_usage(int after_error, int argc, char **argv);
    175 
    176 #endif /* ndef FILEWATCHER_LOG_H */