Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GNU Parallel Semaphores Added #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions files/internals/functions
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ eout() {
fi
fi
}
export -f eout

trap_exit() {
if [ "$svc" == "m" ]; then
Expand Down Expand Up @@ -287,9 +288,11 @@ usage $0 [ OPTION ]
Scan files created/modified in the last X days (default: 7d, wildcard: ?)
e.g: maldet -r /home/?/public_html 2

-a, --scan-all PATH
-a, --scan-all PATH MAX-PROCS
Scan all files in path (default: /home, wildcard: ?)
e.g: maldet -a /home/?/public_html
e.g: maldet -a /home/?/public_html 15
(will parallelize the scanning to 15 threads)

-i, --include-regex REGEX
Include paths/files from file list based on supplied posix-egrep regular
Expand Down Expand Up @@ -668,6 +671,7 @@ scan() {
scan_start=`date +"%s"`
spath=`echo $1 | tr '?' '*' | tr ',' ' '`
days="$2"
maxcpu="$3"
scanid="$datestamp.$$"
if [ "$file_list" ]; then
spath="$file_list"
Expand Down Expand Up @@ -958,10 +962,17 @@ scan() {
echo -en "\\033[${res_col}G" && echo -n "maldet($$): {scan} $cnt/$tot_files files scanned: $tot_hit hits $cl_hit cleaned"
fi
if [ -f "$rpath" ]; then
scan_stage1 "$rpath" >> /dev/null 2>&1
export md5sum=$md5sum
export sig_cust_md5_file=$sig_cust_md5_file
export sig_md5_file=$sig_md5_file
sem -j $maxcpu scan_stage1 "$rpath"
# parallel --max-procs $maxcpu scan_stage1 ::: $rpath
# scan_stage1 "$rpath" >> /dev/null 2>&1
# echo $rpath
fi

done
sem --wait
IFS=$SAVEIFS
fi

Expand Down Expand Up @@ -1059,6 +1070,7 @@ scan_stage1() {
eout "{scan} error could not read or hash $file, do we have permission?"
fi
}
export -f scan_stage1

scan_stage2() {
file="$1"
Expand Down
8 changes: 6 additions & 2 deletions files/maldet
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,18 @@ else
svc=a
trap trap_exit 2
spath="$1"
maxprocs="$2"
if [ "$spath" == "" ]; then
spath=/home
fi
if [ "$maxprocs" == "" ] ; then
maxprocs=1;
fi
if [ "$set_background" == "1" ]; then
eout "{scan} launching scan of $spath to background, see $maldet_log for progress" 1
scan "$spath" all >> /dev/null 2>&1 &
scan "$spath" all $maxprocs >> /dev/null 2>&1 &
else
scan "$spath" all
scan "$spath" all $maxprocs
fi
;;
-r|--scan-recent)
Expand Down