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

watchtab.h (3567B)


      1 /* watchtab.h - configuration tables for file watches */
      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 #ifndef FILEWATCHER_WATCHTAB_H
     20 #define FILEWATCHER_WATCHTAB_H
     21 
     22 #include <stdio.h>
     23 #include <sys/queue.h>
     24 #include <sys/types.h>
     25 #include <unistd.h>
     26 
     27 
     28 /********************
     29  * TYPE DEFINITIONS *
     30  ********************/
     31 
     32 /* struct watch_entry - a single watch table entry */
     33 struct watch_entry {
     34 	const char	*path;		/* file path to watch */
     35 	u_int		events;		/* vnode event set to watch */
     36 	struct timespec	delay;		/* delay before running command */
     37 	uid_t		uid;		/* uid to set before command */
     38 	gid_t		gid;		/* gid to set before command */
     39 	const char	*chroot;	/* path to chroot before command */
     40 	const char	*command;	/* command to execute */
     41 	char		**envp;		/* environment variables */
     42 	int		fd;		/* file descriptor in kernel queue */
     43 	SLIST_ENTRY(watch_entry) next;
     44 };
     45 
     46 /* struct watchtab - list of watchtab entries */
     47 SLIST_HEAD(watchtab, watch_entry);
     48 
     49 /* struct watch_env - dynamic table of environment variables */
     50 struct watch_env {
     51 	const char	**environ;	/* environment strings */
     52 	size_t		size;		/* index of the last NULL pointer */
     53 	size_t		capacity;	/* number of string slot available */
     54 };
     55 
     56 
     57 /********************
     58  * PUBLIC INTERFACE *
     59  ********************/
     60 
     61 /* wentry_init - initialize a watch_entry with null values */
     62 void
     63 wentry_init(struct watch_entry *wentry);
     64 
     65 /* wentry_release - free internal objects from a watch_entry */
     66 void
     67 wentry_release(struct watch_entry *wentry);
     68 
     69 /* wentry_free - free a watch_entry and the strinigs it contains */
     70 void
     71 wentry_free(struct watch_entry *wentry);
     72 
     73 /* wentry_readline - parse a config file line and fill a struct watch_entry */
     74 int
     75 wentry_readline(struct watch_entry *dest, char *line,
     76     struct watch_env *base_env, int has_home,
     77     const char *filename, unsigned line_no);
     78 
     79 
     80 /* wenv_init - create an empty environment list */
     81 int
     82 wenv_init(struct watch_env *wenv);
     83 
     84 /* wenv_release - free string memory in a struct watch_env but not the struct*/
     85 void
     86 wenv_release(struct watch_env *wenv);
     87 
     88 /* wenv_add - append a string to an existing struct watch_env */
     89 int
     90 wenv_add(struct watch_env *wenv, const char *env_str);
     91 
     92 /* wenv_set - insert or reset an environment variable */
     93 int
     94 wenv_set(struct watch_env *wenv, const char *name, const char *value,
     95     int overwrite);
     96 
     97 /* wenv_get - lookup environment variable */
     98 const char *
     99 wenv_get(struct watch_env *wenv, const char *name);
    100 
    101 /* wenv_dup - deep copy environment strings */
    102 char **
    103 wenv_dup(struct watch_env *wenv);
    104 
    105 
    106 /* wtab_release - release children objects but not the struct watchtab */
    107 void
    108 wtab_release(struct watchtab *tab);
    109 
    110 /* wtab_readfile - parse the given file to build a new watchtab */
    111 int
    112 wtab_readfile(struct watchtab *tab, FILE *input, const char *filename);
    113 
    114 #endif /* ndef FILEWATCHER_WATCHTAB_H */