比較提交
7 次程式碼提交
v1.0
...
d62d2956cd
作者 | SHA1 | 日期 | |
---|---|---|---|
d62d2956cd | |||
da1f55e340 | |||
875c176cc1 | |||
2e77170115 | |||
200b6f6c33 | |||
bcc561d578 | |||
898e114eef |
@ -85,6 +85,14 @@ sudo apt-get update
|
||||
sudo apt-get install adhocify
|
||||
```
|
||||
|
||||
## Alpine
|
||||
```
|
||||
wget https://repo.quitesimple.org/repo%40quitesimple.org-5f3d101.rsa.pub -O /etc/apk/repo@quitesimple.org-5f3d101.rsa.pub
|
||||
echo "https://repo.quitesimple.org/alpine/quitesimple/" >> /etc/apk/repositories
|
||||
apk update
|
||||
apk add adhocify
|
||||
```
|
||||
|
||||
## Other
|
||||
To install from source, run
|
||||
```
|
||||
|
77
adhocify.c
77
adhocify.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2014-2017 Albert S. <adhocify@quitesimple.org>
|
||||
* Copyright (c) 2014-2020 Albert S. <adhocify@quitesimple.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@ -278,9 +278,10 @@ bool run_prog(const char *eventfile, uint32_t eventmask)
|
||||
script_arguments[i] = eventfile;
|
||||
}
|
||||
|
||||
execv(prog, script_arguments);
|
||||
perror("execv");
|
||||
return false;
|
||||
execvp(prog, script_arguments);
|
||||
logerror("Exec of %s failed: %s\n", prog, strerror(errno));
|
||||
int exitcode = (errno == ENOENT) ? 127 : EXIT_FAILURE;
|
||||
exit(exitcode);
|
||||
}
|
||||
if(pid == -1)
|
||||
{
|
||||
@ -337,7 +338,6 @@ void check_forkbomb(const char *path_logfile, const char *path_prog)
|
||||
{
|
||||
if(lkp->isdir)
|
||||
{
|
||||
|
||||
char *dir_lkpPath = lkp->path;
|
||||
if( STREQ(dir_lkpPath, dir_log) || STREQ(dir_lkpPath, dir_prog) )
|
||||
{
|
||||
@ -406,11 +406,11 @@ void handle_event(struct inotify_event *event)
|
||||
free(eventfile_abspath);
|
||||
return;
|
||||
}
|
||||
logwrite("Starting execution of child %s\n", prog);
|
||||
logwrite("Starting execution of command %s\n", prog);
|
||||
bool r = run_prog(eventfile_abspath, event->mask);
|
||||
if(!r)
|
||||
{
|
||||
logerror("Execution of child %s failed\n", prog);
|
||||
logerror("Execution of command %s failed\n", prog);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@ -498,7 +498,7 @@ void parse_options(int argc, char **argv)
|
||||
case 'm':
|
||||
optmask = nameToMask(optarg);
|
||||
if(optmask == 0) {
|
||||
logerror("Not supported inotify event: %s\n", optmask);
|
||||
logerror("Not supported inotify event: %s\n", optarg);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
mask |= optmask;
|
||||
@ -577,12 +577,6 @@ void process_options()
|
||||
mask |= IN_CLOSE_WRITE;
|
||||
}
|
||||
|
||||
if(! file_exists(prog))
|
||||
{
|
||||
fprintf(stderr, "File %s does not exist\n", prog);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if(path_logfile)
|
||||
{
|
||||
path_logfile = xrealpath(path_logfile, NULL);
|
||||
@ -590,8 +584,12 @@ void process_options()
|
||||
|
||||
if(forkbombcheck)
|
||||
{
|
||||
char *path_prog = xrealpath(prog, NULL);
|
||||
check_forkbomb(path_logfile, path_prog);
|
||||
char *path_prog = realpath(prog, NULL);
|
||||
if(path_prog != NULL)
|
||||
{
|
||||
check_forkbomb(path_logfile, path_prog);
|
||||
}
|
||||
free(path_prog);
|
||||
}
|
||||
|
||||
if(daemonize)
|
||||
@ -627,7 +625,7 @@ void start_monitoring(int ifd)
|
||||
handle_event(event);
|
||||
offset+=sizeof(struct inotify_event) + event->len;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void child_handler(int signum, siginfo_t *info, void *context)
|
||||
@ -644,36 +642,37 @@ void child_handler(int signum, siginfo_t *info, void *context)
|
||||
logerror("waitpid failed when handling child exit\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if(exit_with_child)
|
||||
|
||||
int adhocify_exit_code = 0;
|
||||
if(WIFEXITED(status))
|
||||
{
|
||||
int adhocify_exit_code = 0;
|
||||
if(WIFEXITED(status))
|
||||
adhocify_exit_code = WEXITSTATUS(status);
|
||||
if(adhocify_exit_code == 127)
|
||||
{
|
||||
adhocify_exit_code = WEXITSTATUS(status);
|
||||
if(awaited_child_exit_code > -1)
|
||||
logwrite("command not found, exiting\n");
|
||||
exit(adhocify_exit_code);
|
||||
}
|
||||
if(exit_with_child && awaited_child_exit_code > -1)
|
||||
{
|
||||
bool must_exit = adhocify_exit_code == awaited_child_exit_code;
|
||||
if(negate_child_exit_code)
|
||||
{
|
||||
bool must_exit = adhocify_exit_code == awaited_child_exit_code;
|
||||
if(negate_child_exit_code)
|
||||
{
|
||||
must_exit = !must_exit;
|
||||
}
|
||||
if(must_exit)
|
||||
{
|
||||
logwrite("child exited with specified exit code, exiting too\n");
|
||||
exit(adhocify_exit_code);
|
||||
}
|
||||
return; //not the exit code we wanted, keep running
|
||||
must_exit = !must_exit;
|
||||
}
|
||||
if(must_exit)
|
||||
{
|
||||
logwrite("command exited with specified exit code, exiting too\n");
|
||||
exit(adhocify_exit_code);
|
||||
}
|
||||
}
|
||||
if(WIFSIGNALED(status))
|
||||
{
|
||||
adhocify_exit_code = 128 + WTERMSIG(status); //copy bash's behaviour
|
||||
}
|
||||
//TODO: coredump?
|
||||
}
|
||||
if(exit_with_child && WIFSIGNALED(status))
|
||||
{
|
||||
adhocify_exit_code = 128 + WTERMSIG(status); //copy bash's behaviour
|
||||
exit(adhocify_exit_code);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void set_signals()
|
||||
{
|
||||
struct sigaction action;
|
||||
|
21
examples/move_downloads.sh
可執行檔
21
examples/move_downloads.sh
可執行檔
@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
#moves all incoming files (e. g. downloads) to another directory.
|
||||
#There, they will be put into subdirectories which are named after the current date (YYYYMMDD) to get some minimal automatic "organization".
|
||||
#adhocify -d -m IN_CLOSE_WRITE -m IN_MOVED_TO -w /home/user/Downloads -w /home/user/other_dir /path/to/move_downloads.sh
|
||||
|
||||
INCOMING="$1"
|
||||
#ignore partial downloads (.part in firefox, .crdownload in chrome)
|
||||
echo "$INCOMING" | grep -q .part$ && exit
|
||||
echo "$INCOMING" | grep -q .crdownload$ && exit
|
||||
today=$(date +%Y%m%d)
|
||||
TARGET_DIR="/target/dir/path"
|
||||
TODAY_DIR="$TARGET_DIR"/$today
|
||||
if [ ! -d "$TODAY_DIR" ] ; then
|
||||
mkdir "$TODAY_DIR"
|
||||
rm -f "$TARGET_DIR"/today
|
||||
ln -s "$TODAY_DIR" "$TARGET_DIR"/today
|
||||
fi
|
||||
#You can also filter/grep the filename here and move certain patterns to other designated locations...
|
||||
mv "$INCOMING" "$TARGET_DIR"/$today/
|
||||
|
||||
|
新增問題並參考
封鎖使用者