reformat with clangformat - no functional change

This commit is contained in:
Albert S. 2020-11-15 20:37:55 +01:00
parent cf14367aa8
commit 75b7db7d36

View File

@ -38,7 +38,6 @@
#define BUF_SIZE (sizeof(struct inotify_event) + NAME_MAX + 1) * 1024 #define BUF_SIZE (sizeof(struct inotify_event) + NAME_MAX + 1) * 1024
#define STREQ(s1, s2) (strcmp(s1, s2) == 0) #define STREQ(s1, s2) (strcmp(s1, s2) == 0)
#define SCRIPT_PLACE_SPECIFIER "{}" // same as EVENTFILE_PLACEHOLDER for backwards compatibility #define SCRIPT_PLACE_SPECIFIER "{}" // same as EVENTFILE_PLACEHOLDER for backwards compatibility
#define EVENTFILE_PLACEHOLDER "%eventfilepath%" #define EVENTFILE_PLACEHOLDER "%eventfilepath%"
#define EVENTSTR_PLACEHOLDER "%eventmaskstr%" #define EVENTSTR_PLACEHOLDER "%eventmaskstr%"
@ -54,8 +53,6 @@ struct watchlistentry
struct watchlistentry *watchlist_head = NULL; struct watchlistentry *watchlist_head = NULL;
struct watchlistentry **watchlist = &watchlist_head; struct watchlistentry **watchlist = &watchlist_head;
struct ignorelist struct ignorelist
{ {
char *ignore; char *ignore;
@ -65,7 +62,6 @@ struct ignorelist
struct ignorelist *ignorelist_head = NULL; struct ignorelist *ignorelist_head = NULL;
struct ignorelist **ignorelist_current = &ignorelist_head; struct ignorelist **ignorelist_current = &ignorelist_head;
/* Write-once globals. Set from process_arguments*/ /* Write-once globals. Set from process_arguments*/
bool silent = false; bool silent = false;
bool noenv = false; bool noenv = false;
@ -116,7 +112,6 @@ char *xrealpath(const char *path, char *resolved_path)
return tmp; return tmp;
} }
char *ndirname(const char *path) char *ndirname(const char *path)
{ {
if(path == NULL) if(path == NULL)
@ -168,7 +163,6 @@ static inline bool file_exists(const char *path)
return access(path, F_OK) == 0; return access(path, F_OK) == 0;
} }
void add_to_ignore_list(const char *str) void add_to_ignore_list(const char *str)
{ {
*ignorelist_current = xmalloc(sizeof(struct ignorelist)); *ignorelist_current = xmalloc(sizeof(struct ignorelist));
@ -177,8 +171,6 @@ void add_to_ignore_list(const char *str)
ignorelist_current = &(*ignorelist_current)->next; ignorelist_current = &(*ignorelist_current)->next;
} }
void logwrite(const char *format, ...) void logwrite(const char *format, ...)
{ {
if(silent) if(silent)
@ -203,7 +195,6 @@ void logerror(const char *format, ...)
vfprintf(stderr, tmp, args); vfprintf(stderr, tmp, args);
fflush(stderr); fflush(stderr);
va_end(args); va_end(args);
} }
void watchqueue_add_path(const char *pathname) void watchqueue_add_path(const char *pathname)
@ -218,8 +209,6 @@ void watchqueue_add_path(const char *pathname)
watchlist = &e->next; watchlist = &e->next;
} }
void create_watches(int fd, uint32_t mask) void create_watches(int fd, uint32_t mask)
{ {
for(struct watchlistentry *lkp = watchlist_head; lkp != NULL; lkp = lkp->next) for(struct watchlistentry *lkp = watchlist_head; lkp != NULL; lkp = lkp->next)
@ -370,7 +359,6 @@ bool run_prog(const char *eventfile, uint32_t eventmask)
} }
return true; return true;
} }
uint32_t name_to_mask(const char *name) uint32_t name_to_mask(const char *name)
@ -420,7 +408,8 @@ void check_forkbomb(const char *path_logfile, const char *path_prog)
char *dir_lkpPath = lkp->path; char *dir_lkpPath = lkp->path;
if(STREQ(dir_lkpPath, dir_log) || STREQ(dir_lkpPath, dir_prog)) if(STREQ(dir_lkpPath, dir_log) || STREQ(dir_lkpPath, dir_prog))
{ {
logerror("Don't place your logfiles or command in a directory you are watching for events. Pass -b to bypass this check.\n"); logerror("Don't place your logfiles or command in a directory you are watching for events. Pass -b to "
"bypass this check.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
@ -468,7 +457,6 @@ char *get_eventfile_abspath(struct inotify_event *event)
return result; return result;
} }
void handle_event(struct inotify_event *event) void handle_event(struct inotify_event *event)
{ {
if(event->mask & mask) if(event->mask & mask)
@ -511,18 +499,23 @@ void print_usage()
printf("--daemon, -d run as a daemon\n"); printf("--daemon, -d run as a daemon\n");
printf("--path, -w adds the specified path to the watchlist\n"); printf("--path, -w adds the specified path to the watchlist\n");
printf("--logfile, -o path to write output of adhocify and stdout/stderr of launched commands to\n"); printf("--logfile, -o path to write output of adhocify and stdout/stderr of launched commands to\n");
printf("--mask, -m inotify event to watch for (see inotify(7)). Can be specified multiple times to watch for several events\n"); printf("--mask, -m inotify event to watch for (see inotify(7)). Can be specified multiple times to "
printf("--no-env, -a if specified, the inotify event which occured won't be passed to the command as an environment variable\n"); "watch for several events\n");
printf("--no-env, -a if specified, the inotify event which occured won't be passed to the command as an "
"environment variable\n");
printf("--silent, -q surpress any output created by adhocify itself\n"); printf("--silent, -q surpress any output created by adhocify itself\n");
printf("--stdin, -s Read the paths which must be added to the watchlist from stdin. Each path must be in a seperate line\n"); printf("--stdin, -s Read the paths which must be added to the watchlist from stdin. Each path must be "
"in a seperate line\n");
printf("--no-forkbomb-check, -b Disable fork bomb detection\n"); printf("--no-forkbomb-check, -b Disable fork bomb detection\n");
printf("--ignore, -i Shell wildcard pattern (see glob(7)) to ignore events on files for which the pattern matches\n"); printf("--ignore, -i Shell wildcard pattern (see glob(7)) to ignore events on files for which the "
printf("--exit-with-child, -e Exit when the commands exits. You can also specify a return code (e. g. -e=1 to exit only on errors)\n"); printf("\nIf your command should know the file the event occured on, use the {} placeholder when you specify the arguments (like xargs)\n"); "pattern matches\n");
printf("--exit-with-child, -e Exit when the commands exits. You can also specify a return code (e. g. -e=1 to "
"exit only on errors)\n");
printf("\nIf your command should know the file the event occured on, use the {} placeholder when you specify the "
"arguments (like xargs)\n");
} }
static struct option long_options[] = static struct option long_options[] = {{"daemon", no_argument, 0, 'd'},
{
{ "daemon", no_argument, 0, 'd' },
{"logfile", required_argument, 0, 'o'}, {"logfile", required_argument, 0, 'o'},
{"mask", required_argument, 0, 'm'}, {"mask", required_argument, 0, 'm'},
{"path", required_argument, 0, 'w'}, {"path", required_argument, 0, 'w'},
@ -532,8 +525,7 @@ static struct option long_options[] =
{"ignore", required_argument, 0, 'i'}, {"ignore", required_argument, 0, 'i'},
{"silent", no_argument, 0, 'q'}, {"silent", no_argument, 0, 'q'},
{"help", no_argument, 0, 'h'}, {"help", no_argument, 0, 'h'},
{ "exit-with-child", optional_argument, 0, 'e' } {"exit-with-child", optional_argument, 0, 'e'}};
};
// fills global n_script_arguments and script_arguments var // fills global n_script_arguments and script_arguments var
void fill_script_arguments(size_t n_args, char *args[]) void fill_script_arguments(size_t n_args, char *args[])
@ -557,7 +549,6 @@ void fill_script_arguments(size_t n_args, char *args[])
script_arguments = arguments; script_arguments = arguments;
} }
void parse_options(int argc, char **argv) void parse_options(int argc, char **argv)
{ {
char *watchpath = NULL; char *watchpath = NULL;
@ -576,7 +567,8 @@ void parse_options(int argc, char **argv)
break; break;
case 'm': case 'm':
optmask = name_to_mask(optarg); optmask = name_to_mask(optarg);
if(optmask == 0) { if(optmask == 0)
{
logerror("Not supported inotify event: %s\n", optarg); logerror("Not supported inotify event: %s\n", optarg);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -764,7 +756,6 @@ void set_signals()
} }
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
if(argc < 2) if(argc < 2)
@ -776,7 +767,6 @@ int main(int argc, char **argv)
// signal(SIGCHLD, SIG_IGN); // signal(SIGCHLD, SIG_IGN);
set_signals(); set_signals();
parse_options(argc, argv); parse_options(argc, argv);
process_options(); process_options();