Remove -r: It's existence cannot be justified
We already have -s to read from stdin, there is no point to walk paths ourselves. find . -type d | adhocify -s [path to script] is pretty much the same.
This commit is contained in:
szülő
dcd1c2bb7b
commit
bd9bcd8752
46
adhocify.c
46
adhocify.c
@ -45,7 +45,7 @@ struct watchlistentry
|
||||
bool isdir;
|
||||
struct watchlistentry *next;
|
||||
};
|
||||
size_t max_watches = 0;
|
||||
|
||||
size_t watchlistentries = 0;
|
||||
struct watchlistentry *watchlist_head = NULL;
|
||||
struct watchlistentry **watchlist = &watchlist_head;
|
||||
@ -213,45 +213,6 @@ void watchqueue_add_path(const char *pathname)
|
||||
++watchlistentries;
|
||||
}
|
||||
|
||||
static int recursive_walker_callback(const char *path, const struct stat *sb,
|
||||
int typeflag, struct FTW *ftwbuf)
|
||||
|
||||
{
|
||||
if(watchlistentries == max_watches)
|
||||
{
|
||||
fprintf(stderr, "Error: Max number of watches reached\n");
|
||||
return -1;
|
||||
}
|
||||
if(typeflag == FTW_D)
|
||||
{
|
||||
watchqueue_add_path(path);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
void watchqueue_add_recursive(const char *pathname)
|
||||
{
|
||||
FILE *fp = fopen("/proc/sys/fs/inotify/max_user_watches", "r");
|
||||
if(fp == NULL)
|
||||
{
|
||||
fprintf(stderr, "error opening max_user_watches file\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if(fscanf(fp, "%zu", &max_watches) < 1)
|
||||
{
|
||||
fprintf(stderr, "error processing max_user_watches file\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
int walker = nftw(pathname, &recursive_walker_callback, 10, FTW_PHYS);
|
||||
if(walker == -1)
|
||||
{
|
||||
fprintf(stderr, "nftw failed\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void create_watches(int fd, uint32_t mask)
|
||||
@ -468,7 +429,6 @@ void print_usage()
|
||||
|
||||
printf("--daemon, -d\t\t\tdaemonize\n");
|
||||
printf("--path, -w\t\t\tpath -- adds the specified path to the watchlist\n");
|
||||
printf("--recursive, -r\t\t\tpath -- adds the specified path to the watchlist recursively (all subdirectories too. Do not use for large structures!)\n");
|
||||
printf("--logfile, -o\t\t\tlogfile -- output goes here\n");
|
||||
printf("--mask, -m\t\t\tmaskval -- inotify mask value. Can be specified multiple times, will be ORed.\n");
|
||||
printf("--no-env, -a\t\t\tif specified, the inotify event which occured won't be passed to the script as an environment variable.\n");
|
||||
@ -546,10 +506,6 @@ void parse_options(int argc, char **argv)
|
||||
watchpath = optarg;
|
||||
watchqueue_add_path(watchpath);
|
||||
break;
|
||||
case 'r':
|
||||
watchpath = optarg;
|
||||
watchqueue_add_recursive(watchpath);
|
||||
break;
|
||||
case 'a':
|
||||
noenv=true;
|
||||
break;
|
||||
|
Betöltés…
Reference in New Issue
Block a user