"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/inotifywait.c" between
inotify-tools-3.20.2.2.tar.gz and inotify-tools-3.20.11.0.tar.gz

About: inotify-tools offers commandline utilities relating to inotify (wait for or watch particular events on files).

inotifywait.c  (inotify-tools-3.20.2.2):inotifywait.c  (inotify-tools-3.20.11.0)
skipping to change at line 37 skipping to change at line 37
extern char *optarg; extern char *optarg;
extern int optind, opterr, optopt; extern int optind, opterr, optopt;
#define MAX_STRLEN 4096 #define MAX_STRLEN 4096
#define nasprintf(...) niceassert(-1 != asprintf(__VA_ARGS__), "out of memory") #define nasprintf(...) niceassert(-1 != asprintf(__VA_ARGS__), "out of memory")
// METHODS // METHODS
bool parse_opts(int *argc, char ***argv, int *events, bool *monitor, int *quiet, bool parse_opts(int *argc, char ***argv, int *events, bool *monitor, int *quiet,
long int *timeout, int *recursive, bool *csv, bool *daemon, long int *timeout, int *recursive, bool *csv, bool *daemon,
bool *syslog, char **format, char **timefmt, char **fromfile, bool *syslog, bool *no_dereference, char **format,
char **outfile, char **exc_regex, char **exc_iregex, char **timefmt, char **fromfile, char **outfile,
char **inc_regex, char **inc_iregex); char **exc_regex, char **exc_iregex, char **inc_regex,
char **inc_iregex, bool *no_newline);
void print_help(); void print_help();
char *csv_escape(char *string) { char *csv_escape(char *string) {
static char csv[MAX_STRLEN + 1]; static char csv[MAX_STRLEN + 1];
static unsigned int i, ind; static unsigned int i, ind;
if (string == NULL) { if (string == NULL) {
return NULL; return NULL;
} }
skipping to change at line 139 skipping to change at line 140
int main(int argc, char **argv) { int main(int argc, char **argv) {
int events = 0; int events = 0;
int orig_events; int orig_events;
bool monitor = false; bool monitor = false;
int quiet = 0; int quiet = 0;
long int timeout = BLOCKING_TIMEOUT; long int timeout = BLOCKING_TIMEOUT;
int recursive = 0; int recursive = 0;
bool csv = false; bool csv = false;
bool dodaemon = false; bool dodaemon = false;
bool syslog = false; bool syslog = false;
bool no_dereference = false;
char *format = NULL; char *format = NULL;
char *timefmt = NULL; char *timefmt = NULL;
char *fromfile = NULL; char *fromfile = NULL;
char *outfile = NULL; char *outfile = NULL;
char *exc_regex = NULL; char *exc_regex = NULL;
char *exc_iregex = NULL; char *exc_iregex = NULL;
char *inc_regex = NULL; char *inc_regex = NULL;
char *inc_iregex = NULL; char *inc_iregex = NULL;
bool no_newline = false;
int fd; int fd;
// Parse commandline options, aborting if something goes wrong // Parse commandline options, aborting if something goes wrong
if (!parse_opts(&argc, &argv, &events, &monitor, &quiet, &timeout, if (!parse_opts(&argc, &argv, &events, &monitor, &quiet, &timeout,
&recursive, &csv, &dodaemon, &syslog, &format, &timefmt, &recursive, &csv, &dodaemon, &syslog, &no_dereference,
&fromfile, &outfile, &exc_regex, &exc_iregex, &inc_regex, &format, &timefmt, &fromfile, &outfile, &exc_regex,
&inc_iregex)) { &exc_iregex, &inc_regex, &inc_iregex, &no_newline)) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (!inotifytools_initialize()) { if (!inotifytools_initialize()) {
warn_inotify_init_error(); warn_inotify_init_error();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (timefmt) if (timefmt)
inotifytools_set_printf_timefmt(timefmt); inotifytools_set_printf_timefmt(timefmt);
skipping to change at line 193 skipping to change at line 196
validate_format(format); validate_format(format);
// Attempt to watch file // Attempt to watch file
// If events is still 0, make it all events. // If events is still 0, make it all events.
if (events == 0) if (events == 0)
events = IN_ALL_EVENTS; events = IN_ALL_EVENTS;
orig_events = events; orig_events = events;
if (monitor && recursive) { if (monitor && recursive) {
events = events | IN_CREATE | IN_MOVED_TO | IN_MOVED_FROM; events = events | IN_CREATE | IN_MOVED_TO | IN_MOVED_FROM;
} }
if (no_dereference) {
events = events | IN_DONT_FOLLOW;
}
FileList list = construct_path_list(argc, argv, fromfile); FileList list = construct_path_list(argc, argv, fromfile);
if (0 == list.watch_files[0]) { if (0 == list.watch_files[0]) {
fprintf(stderr, "No files specified to watch!\n"); fprintf(stderr, "No files specified to watch!\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
// Daemonize - BSD double-fork approach // Daemonize - BSD double-fork approach
if (dodaemon) { if (dodaemon) {
skipping to change at line 415 skipping to change at line 421
if ((events & event->mask) == 0) { if ((events & event->mask) == 0) {
// ...then most likely something bad happened, like IGNORE etc. // ...then most likely something bad happened, like IGNORE etc.
return EXIT_FAILURE; return EXIT_FAILURE;
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
bool parse_opts(int *argc, char ***argv, int *events, bool *monitor, int *quiet, bool parse_opts(int *argc, char ***argv, int *events, bool *monitor, int *quiet,
long int *timeout, int *recursive, bool *csv, bool *daemon, long int *timeout, int *recursive, bool *csv, bool *daemon,
bool *syslog, char **format, char **timefmt, char **fromfile, bool *syslog, bool *no_dereference, char **format,
char **outfile, char **exc_regex, char **exc_iregex, char **timefmt, char **fromfile, char **outfile,
char **inc_regex, char **inc_iregex) { char **exc_regex, char **exc_iregex, char **inc_regex,
char **inc_iregex, bool *no_newline) {
assert(argc); assert(argc);
assert(argv); assert(argv);
assert(events); assert(events);
assert(monitor); assert(monitor);
assert(quiet); assert(quiet);
assert(timeout); assert(timeout);
assert(csv); assert(csv);
assert(daemon); assert(daemon);
assert(syslog); assert(syslog);
assert(no_dereference);
assert(format); assert(format);
assert(timefmt); assert(timefmt);
assert(fromfile); assert(fromfile);
assert(outfile); assert(outfile);
assert(exc_regex); assert(exc_regex);
assert(exc_iregex); assert(exc_iregex);
assert(inc_regex); assert(inc_regex);
assert(inc_iregex); assert(inc_iregex);
// Settings for options // Settings for options
skipping to change at line 448 skipping to change at line 456
// How many times --exclude has been specified // How many times --exclude has been specified
unsigned int exclude_count = 0; unsigned int exclude_count = 0;
// How many times --excludei has been specified // How many times --excludei has been specified
unsigned int excludei_count = 0; unsigned int excludei_count = 0;
const char *regex_warning = const char *regex_warning =
"only the last option will be taken into consideration.\n"; "only the last option will be taken into consideration.\n";
// format with trailing newline // format provided by the user
static char *newlineformat; static char *customformat = NULL;
// Short options // Short options
static const char opt_string[] = "mrhcdsqt:fo:e:"; static const char opt_string[] = "mrhcdsPqt:fo:e:";
// Long options // Long options
static const struct option long_opts[] = { static const struct option long_opts[] = {
{"help", no_argument, NULL, 'h'}, {"help", no_argument, NULL, 'h'},
{"event", required_argument, NULL, 'e'}, {"event", required_argument, NULL, 'e'},
{"monitor", no_argument, NULL, 'm'}, {"monitor", no_argument, NULL, 'm'},
{"quiet", no_argument, NULL, 'q'}, {"quiet", no_argument, NULL, 'q'},
{"timeout", required_argument, NULL, 't'}, {"timeout", required_argument, NULL, 't'},
{"filename", no_argument, NULL, 'f'}, {"filename", no_argument, NULL, 'f'},
{"recursive", no_argument, NULL, 'r'}, {"recursive", no_argument, NULL, 'r'},
{"csv", no_argument, NULL, 'c'}, {"csv", no_argument, NULL, 'c'},
{"daemon", no_argument, NULL, 'd'}, {"daemon", no_argument, NULL, 'd'},
{"syslog", no_argument, NULL, 's'}, {"syslog", no_argument, NULL, 's'},
{"no-dereference", no_argument, NULL, 'P'},
{"format", required_argument, NULL, 'n'}, {"format", required_argument, NULL, 'n'},
{"no-newline", no_argument, NULL, '0'},
{"timefmt", required_argument, NULL, 'i'}, {"timefmt", required_argument, NULL, 'i'},
{"fromfile", required_argument, NULL, 'z'}, {"fromfile", required_argument, NULL, 'z'},
{"outfile", required_argument, NULL, 'o'}, {"outfile", required_argument, NULL, 'o'},
{"exclude", required_argument, NULL, 'a'}, {"exclude", required_argument, NULL, 'a'},
{"excludei", required_argument, NULL, 'b'}, {"excludei", required_argument, NULL, 'b'},
{"include", required_argument, NULL, 'j'}, {"include", required_argument, NULL, 'j'},
{"includei", required_argument, NULL, 'k'}, {"includei", required_argument, NULL, 'k'},
{NULL, 0, 0, 0}, {NULL, 0, 0, 0},
}; };
skipping to change at line 522 skipping to change at line 532
(*daemon) = true; (*daemon) = true;
(*monitor) = true; (*monitor) = true;
(*syslog) = true; (*syslog) = true;
break; break;
// --syslog or -s // --syslog or -s
case 's': case 's':
(*syslog) = true; (*syslog) = true;
break; break;
// --no-dereference or -P
case 'P':
(*no_dereference) = true;
break;
// --filename or -f // --filename or -f
case 'f': case 'f':
fprintf(stderr, "The '--filename' option no longer exists. " fprintf(stderr, "The '--filename' option no longer exists. "
"The option it enabled in earlier\nversions of " "The option it enabled in earlier\nversions of "
"inotifywait is now turned on by default.\n"); "inotifywait is now turned on by default.\n");
return false; return false;
break; break;
// --format // --format
case 'n': case 'n':
newlineformat = (char *)malloc(strlen(optarg) + 2); customformat = (char *)malloc(strlen(optarg) + 2);
strcpy(newlineformat, optarg); strcpy(customformat, optarg);
strcat(newlineformat, "\n"); break;
(*format) = newlineformat;
// --no-newline
case '0':
(*no_newline) = true;
break; break;
// --timefmt // --timefmt
case 'i': case 'i':
(*timefmt) = optarg; (*timefmt) = optarg;
break; break;
// --exclude // --exclude
case 'a': case 'a':
(*exc_regex) = optarg; (*exc_regex) = optarg;
skipping to change at line 613 skipping to change at line 631
// Add the new event to the event mask // Add the new event to the event mask
(*events) = ((*events) | new_event); (*events) = ((*events) | new_event);
break; break;
} }
curr_opt = getopt_long(*argc, *argv, opt_string, long_opts, NULL); curr_opt = getopt_long(*argc, *argv, opt_string, long_opts, NULL);
} }
if (customformat) {
if(!(*no_newline)) {
strcat(customformat, "\n");
}
(*format) = customformat;
}
if (*exc_regex && *exc_iregex) { if (*exc_regex && *exc_iregex) {
fprintf(stderr, "--exclude and --excludei cannot both be specified.\n"); fprintf(stderr, "--exclude and --excludei cannot both be specified.\n");
return false; return false;
} }
if (*inc_regex && *inc_iregex) { if (*inc_regex && *inc_iregex) {
fprintf(stderr, "--include and --includei cannot both be specified.\n"); fprintf(stderr, "--include and --includei cannot both be specified.\n");
return false; return false;
} }
skipping to change at line 635 skipping to change at line 660
fprintf(stderr, fprintf(stderr,
"include and exclude regexp cannot both be specified.\n"); "include and exclude regexp cannot both be specified.\n");
return false; return false;
} }
if (*format && *csv) { if (*format && *csv) {
fprintf(stderr, "-c and --format cannot both be specified.\n"); fprintf(stderr, "-c and --format cannot both be specified.\n");
return false; return false;
} }
if (!*format && *no_newline) {
fprintf(stderr, "--no-newline cannot be specified without --format.\n");
return false;
}
if (!*format && *timefmt) { if (!*format && *timefmt) {
fprintf(stderr, "--timefmt cannot be specified without --format.\n"); fprintf(stderr, "--timefmt cannot be specified without --format.\n");
return false; return false;
} }
if (*format && strstr(*format, "%T") && !*timefmt) { if (*format && strstr(*format, "%T") && !*timefmt) {
fprintf(stderr, "%%T is in --format string, but --timefmt was not " fprintf(stderr, "%%T is in --format string, but --timefmt was not "
"specified.\n"); "specified.\n");
return false; return false;
} }
skipping to change at line 696 skipping to change at line 726
printf("\t--includei <pattern>\n" printf("\t--includei <pattern>\n"
"\t \tLike --include but case insensitive.\n"); "\t \tLike --include but case insensitive.\n");
printf("\t-m|--monitor \tKeep listening for events forever or until " printf("\t-m|--monitor \tKeep listening for events forever or until "
"--timeout expires.\n" "--timeout expires.\n"
"\t \tWithout this option, inotifywait will exit after " "\t \tWithout this option, inotifywait will exit after "
"one event is received.\n"); "one event is received.\n");
printf( printf(
"\t-d|--daemon \tSame as --monitor, except run in the background\n" "\t-d|--daemon \tSame as --monitor, except run in the background\n"
"\t \tlogging events to a file specified by --outfile.\n" "\t \tlogging events to a file specified by --outfile.\n"
"\t \tImplies --syslog.\n"); "\t \tImplies --syslog.\n");
printf("\t-P|--no-dereference\n"
"\t \tDo not follow symlinks.\n");
printf("\t-r|--recursive\tWatch directories recursively.\n"); printf("\t-r|--recursive\tWatch directories recursively.\n");
printf("\t--fromfile <file>\n" printf("\t--fromfile <file>\n"
"\t \tRead files to watch from <file> or `-' for " "\t \tRead files to watch from <file> or `-' for "
"stdin.\n"); "stdin.\n");
printf("\t-o|--outfile <file>\n" printf("\t-o|--outfile <file>\n"
"\t \tPrint events to <file> rather than stdout.\n"); "\t \tPrint events to <file> rather than stdout.\n");
printf("\t-s|--syslog \tSend errors to syslog rather than stderr.\n"); printf("\t-s|--syslog \tSend errors to syslog rather than stderr.\n");
printf("\t-q|--quiet \tPrint less (only print events).\n"); printf("\t-q|--quiet \tPrint less (only print events).\n");
printf("\t-qq \tPrint nothing (not even events).\n"); printf("\t-qq \tPrint nothing (not even events).\n");
printf("\t--format <fmt>\tPrint using a specified printf-like format\n" printf("\t--format <fmt>\tPrint using a specified printf-like format\n"
"\t \tstring; read the man page for more details.\n"); "\t \tstring; read the man page for more details.\n");
printf("\t--no-newline \tDon't print newline symbol after\n"
"\t \t--format string.\n");
printf("\t--timefmt <fmt>\tstrftime-compatible format string for use with\n" printf("\t--timefmt <fmt>\tstrftime-compatible format string for use with\n"
"\t \t%%T in --format string.\n"); "\t \t%%T in --format string.\n");
printf("\t-c|--csv \tPrint events in CSV format.\n"); printf("\t-c|--csv \tPrint events in CSV format.\n");
printf("\t-t|--timeout <seconds>\n" printf("\t-t|--timeout <seconds>\n"
"\t \tWhen listening for a single event, time out " "\t \tWhen listening for a single event, time out "
"after\n" "after\n"
"\t \twaiting for an event for <seconds> seconds.\n" "\t \twaiting for an event for <seconds> seconds.\n"
"\t \tIf <seconds> is negative, inotifywait will never " "\t \tIf <seconds> is negative, inotifywait will never "
"time " "time "
"out.\n"); "out.\n");
 End of changes. 17 change blocks. 
16 lines changed or deleted 50 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)