diff options
| author | Nils | 2015-07-14 10:03:31 +0200 |
|---|---|---|
| committer | Nils | 2015-07-14 10:03:31 +0200 |
| commit | 7af3ba89aa11eee89e6b22a9db43074c4c1bd12b (patch) | |
| tree | 858e2c445f693da4cdfc21e8963b47f0af06d3b9 | |
| parent | c634f714bc82b46db84c700354841c0b5810a962 (diff) | |
added usage of nice when ionice is not available
On some platforms (e.g. NetBSD, OS X), ionice is not available by default. This patch checks for ionice availability, and switch back to nice if needed. In the case none of them are installed, an error is displayed.
| -rwxr-xr-x | phpmalwarefinder | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/phpmalwarefinder b/phpmalwarefinder index 0a85d85..1fbe4cf 100755 --- a/phpmalwarefinder +++ b/phpmalwarefinder | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | 2 | ||
| 3 | YARA=$(which yara) | 3 | YARA=$(which yara) |
| 4 | CONFIG_PATH='/etc/phpmalwarefinder/malwares.yara' | 4 | CONFIG_PATH='/etc/phpmalwarefinder/malwares.yara' |
| 5 | IONICE_BIN=$(which ionice) | ||
| 6 | NICE_BIN=$(which nice) | ||
| 5 | 7 | ||
| 6 | if [ ! -f "$YARA" ] | 8 | if [ ! -f "$YARA" ] |
| 7 | then | 9 | then |
| @@ -13,6 +15,18 @@ then | |||
| 13 | CONFIG_PATH='./malwares.yara' | 15 | CONFIG_PATH='./malwares.yara' |
| 14 | fi | 16 | fi |
| 15 | 17 | ||
| 18 | if [ -f "${IONICE_BIN}" ] | ||
| 19 | then | ||
| 20 | NICE=${IONICE_BIN} | ||
| 21 | NICE_OPTS="-c 3" | ||
| 22 | else | ||
| 23 | if [ -f "${NICE_BIN}" ] | ||
| 24 | then | ||
| 25 | NICE=${NICE_BIN} | ||
| 26 | NICE_OPTS="-n 20" | ||
| 27 | fi | ||
| 28 | fi | ||
| 29 | |||
| 16 | show_help() { | 30 | show_help() { |
| 17 | cat << EOF | 31 | cat << EOF |
| 18 | Usage ${0##*/} [-cfhw] <file|folder> ... | 32 | Usage ${0##*/} [-cfhw] <file|folder> ... |
| @@ -65,6 +79,12 @@ then | |||
| 65 | exit 1 | 79 | exit 1 |
| 66 | fi | 80 | fi |
| 67 | 81 | ||
| 82 | if [ ! -e ${NICE} ] | ||
| 83 | then | ||
| 84 | echo "no nice program available. Please install ionice or nice." | ||
| 85 | exit 1 | ||
| 86 | fi | ||
| 87 | |||
| 68 | OPTS="${OPTS} -r ${CONFIG_PATH}" | 88 | OPTS="${OPTS} -r ${CONFIG_PATH}" |
| 69 | 89 | ||
| 70 | ionice -c3 $YARA $OPTS $@ | 90 | ${NICE} ${NICE_OPTS} $YARA $OPTS $@ |
