Skip to content

Commit

Permalink
Merge pull request #269 from tclahr/remove_xargs_max_procs_param
Browse files Browse the repository at this point in the history
fix: xargs max-procs concurrency
  • Loading branch information
tclahr authored Aug 14, 2024
2 parents 87ae5c2 + 2908a52 commit 6c95a63
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 45 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
- The message 'The strings command requires the command line developer tools.' will no longer appear on macOS systems without developer tools installed ([#171](https://github.com/tclahr/uac/issues/171)).
- Error messages generated by executed commands (stderr) are now recorded in the uac.log file ([#150](https://github.com/tclahr/uac/issues/150)).
- New '-H/--hash-collected' command line option. Enabling this option will cause UAC to hash all collected files and save the results in a hash file. To accomplish this, all collected data must first be copied to the destination directory. Therefore, ensure you have twice the free space available on the system: once for the collected data and once for the output file. Additionally, note that this process will increase the running time ([#189](https://github.com/tclahr/uac/issues/189)).
- New '-t/--max-thread' command line option. It can be used to specify the number of files that will be processed in parallel by the 'hash' and 'stat' collectors.
- You can now validate profiles using the '--validate-profile' command line option.

### Artifacts
Expand Down
12 changes: 6 additions & 6 deletions lib/find_based_collector.sh
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ _find_based_collector()

if [ -n "${__fc_hashing_tool}" ]; then
if ${__fc_is_file_list}; then
__fc_hash_command="sed 's|.|\\\\&|g' \"${__fc_path}\" | xargs ${__UAC_TOOL_XARGS_MAX_PROCS_PARAM}${__UAC_TOOL_XARGS_MAX_PROCS_PARAM:+ }${__fc_hashing_tool}"
__fc_hash_command="sed 's|.|\\\\&|g' \"${__fc_path}\" | xargs ${__fc_hashing_tool}"
elif ${__UAC_TOOL_FIND_PRINT0_SUPPORT} && ${__UAC_TOOL_XARGS_NULL_DELIMITER_SUPPORT}; then
__fc_find_command=`_build_find_command \
"${__fc_path}" \
Expand All @@ -185,7 +185,7 @@ _find_based_collector()
"true" \
"${__fc_start_date_days}" \
"${__fc_end_date_days}"`
__fc_hash_command="${__fc_find_command} | xargs -0 ${__UAC_TOOL_XARGS_MAX_PROCS_PARAM}${__UAC_TOOL_XARGS_MAX_PROCS_PARAM:+ }${__fc_hashing_tool}"
__fc_hash_command="${__fc_find_command} | xargs -0 ${__fc_hashing_tool}"
else
__fc_find_command=`_build_find_command \
"${__fc_path}" \
Expand All @@ -201,7 +201,7 @@ _find_based_collector()
"" \
"${__fc_start_date_days}" \
"${__fc_end_date_days}"`
__fc_hash_command="${__fc_find_command} | sed 's|.|\\\\&|g' | xargs ${__UAC_TOOL_XARGS_MAX_PROCS_PARAM}${__UAC_TOOL_XARGS_MAX_PROCS_PARAM:+ }${__fc_hashing_tool}"
__fc_hash_command="${__fc_find_command} | sed 's|.|\\\\&|g' | xargs ${__fc_hashing_tool}"
fi
_verbose_msg "${__UAC_VERBOSE_CMD_PREFIX}${__fc_hash_command}"
_run_command "${__fc_hash_command}" \
Expand All @@ -212,7 +212,7 @@ _find_based_collector()
"stat")
if [ -n "${__UAC_TOOL_STAT_BIN}" ]; then
if ${__fc_is_file_list}; then
__fc_stat_command="sed 's|.|\\\\&|g' \"${__fc_path}\" | xargs ${__UAC_TOOL_XARGS_MAX_PROCS_PARAM}${__UAC_TOOL_XARGS_MAX_PROCS_PARAM:+ }${__UAC_TOOL_STAT_BIN}${__UAC_TOOL_STAT_PARAMS:+ }${__UAC_TOOL_STAT_PARAMS}"
__fc_stat_command="sed 's|.|\\\\&|g' \"${__fc_path}\" | xargs ${__UAC_TOOL_STAT_BIN}${__UAC_TOOL_STAT_PARAMS:+ }${__UAC_TOOL_STAT_PARAMS}"
elif ${__UAC_TOOL_FIND_PRINT0_SUPPORT} && ${__UAC_TOOL_XARGS_NULL_DELIMITER_SUPPORT}; then
__fc_find_command=`_build_find_command \
"${__fc_path}" \
Expand All @@ -228,7 +228,7 @@ _find_based_collector()
"true" \
"${__fc_start_date_days}" \
"${__fc_end_date_days}"`
__fc_stat_command="${__fc_find_command} | xargs -0 ${__UAC_TOOL_XARGS_MAX_PROCS_PARAM}${__UAC_TOOL_XARGS_MAX_PROCS_PARAM:+ }${__UAC_TOOL_STAT_BIN}${__UAC_TOOL_STAT_PARAMS:+ }${__UAC_TOOL_STAT_PARAMS}"
__fc_stat_command="${__fc_find_command} | xargs -0 ${__UAC_TOOL_STAT_BIN}${__UAC_TOOL_STAT_PARAMS:+ }${__UAC_TOOL_STAT_PARAMS}"
else
__fc_find_command=`_build_find_command \
"${__fc_path}" \
Expand All @@ -244,7 +244,7 @@ _find_based_collector()
"" \
"${__fc_start_date_days}" \
"${__fc_end_date_days}"`
__fc_stat_command="${__fc_find_command} | sed 's|.|\\\\&|g' | xargs ${__UAC_TOOL_XARGS_MAX_PROCS_PARAM}${__UAC_TOOL_XARGS_MAX_PROCS_PARAM:+ }${__UAC_TOOL_STAT_BIN}${__UAC_TOOL_STAT_PARAMS:+ }${__UAC_TOOL_STAT_PARAMS}"
__fc_stat_command="${__fc_find_command} | sed 's|.|\\\\&|g' | xargs ${__UAC_TOOL_STAT_BIN}${__UAC_TOOL_STAT_PARAMS:+ }${__UAC_TOOL_STAT_PARAMS}"
fi
_verbose_msg "${__UAC_VERBOSE_CMD_PREFIX}${__fc_stat_command}"
_run_command "${__fc_stat_command}" \
Expand Down
16 changes: 1 addition & 15 deletions lib/parse_command_line_arguments.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,7 @@ _parse_command_line_arguments()
fi
;;
"-H"|"--hash-collected")
__UAC_HASH_COLLECTED=true
;;
"-t"|"--max-threads")
if [ -n "${2:-}" ]; then
if [ "${2}" = "list" ]; then
__ua_nproc=`_get_nproc`
printf "Number of processing units: %s\n" "${__ua_nproc}"
_exit_success
fi
__UAC_MAX_THREADS="${2}"
shift
else
_error_msg "option '${1}' requires an argument.\nTry 'uac --help' for more information."
return 1
fi
__UAC_HASH_COLLECTED=true
;;
"-u"|"--run-as-non-root")
__UAC_RUN_AS_NON_ROOT=true
Expand Down
7 changes: 6 additions & 1 deletion lib/remove_non_regular_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ _remove_non_regular_files()
return 1
fi

__rn_command="sed 's|.|\\\\&|g' \"${__rn_file}\" | xargs ${__UAC_TOOL_XARGS_MAX_PROCS_PARAM}${__UAC_TOOL_XARGS_MAX_PROCS_PARAM:+ }find"
if [ ! -s "${__rn_file}" ]; then
_log_msg DBG "_remove_non_regular_files: skipping empty file '${__rn_file}'"
return 1
fi

__rn_command="sed 's|.|\\\\&|g' \"${__rn_file}\" | xargs find"

_verbose_msg "${__UAC_VERBOSE_CMD_PREFIX}${__rn_command}"
eval "${__rn_command}" \
Expand Down
4 changes: 0 additions & 4 deletions lib/setup_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ _setup_tools()
__UAC_TOOL_FIND_CTIME_SUPPORT=false
__UAC_TOOL_FIND_PRINT0_SUPPORT=false
__UAC_TOOL_XARGS_NULL_DELIMITER_SUPPORT=false
__UAC_TOOL_XARGS_MAX_PROCS_PARAM=""
__UAC_TOOL_STAT_BIN=""
__UAC_TOOL_STAT_PARAMS=""
__UAC_TOOL_STAT_BTIME=false
Expand Down Expand Up @@ -68,9 +67,6 @@ _setup_tools()
if echo "uac" | xargs -0 echo >/dev/null; then
__UAC_TOOL_XARGS_NULL_DELIMITER_SUPPORT=true
fi
if echo "uac" | xargs -P 2 echo >/dev/null; then
__UAC_TOOL_XARGS_MAX_PROCS_PARAM="-P ${__UAC_MAX_THREADS}"
fi

# check which stat tool and options are available for the target system
if statx "${__UAC_MOUNT_POINT}" | grep -q -E "\|[0-9]+\|[0-9]+\|[0-9]+$"; then
Expand Down
5 changes: 0 additions & 5 deletions lib/usage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ Collection Arguments:
netscaler, openbsd, solaris
-H, --hash-collected
Hash all collected files.
-t, --max-threads THREADS
Specify the number of files that will be processed in
parallel by the hash and stat collectors (default: 2).
Use '--max-threads list' to list the number of processing
units available on the system.
-u, --run-as-non-root
Disable root user check.
Note that data collection may be limited.
Expand Down
13 changes: 0 additions & 13 deletions uac
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ __UAC_HASH_COLLECTED=false
__UAC_CONFIG_FILE="${__UAC_DIR}/config/uac.conf"
__UAC_MOUNT_POINT="/"
__UAC_OPERATING_SYSTEM=""
__UAC_MAX_THREADS="2"
__UAC_RUN_AS_NON_ROOT=false
__UAC_PROCESSING_UNITS=""
__UAC_HOSTNAME=""
Expand Down Expand Up @@ -145,13 +144,6 @@ if [ -z "${__UAC_HOSTNAME}" ]; then
__UAC_HOSTNAME=`_get_hostname "${__UAC_MOUNT_POINT}"`
fi

# check if max-threads is a positive integer (greater than zero)
if _is_digit "${__UAC_MAX_THREADS}" && [ "${__UAC_MAX_THREADS}" -ge 1 ]; then
true
else
_exit_fatal "'max-threads' must be a positive integer."
fi

# check whether is running as root
if _is_root || ${__UAC_RUN_AS_NON_ROOT}; then
true
Expand Down Expand Up @@ -401,11 +393,6 @@ else
_log_msg INF "perl command exists: false"
fi
_log_msg INF "xargs -0 support: ${__UAC_TOOL_XARGS_NULL_DELIMITER_SUPPORT}"
if [ -n "${__UAC_TOOL_XARGS_MAX_PROCS_PARAM}" ]; then
_log_msg INF "xargs -P support: true"
else
_log_msg INF "xargs -P support: false"
fi
_log_msg INF "MD5 hashing tool: ${__UAC_TOOL_MD5_BIN}"
_log_msg INF "SHA1 hashing tool: ${__UAC_TOOL_SHA1_BIN}"
_log_msg INF "SHA256 hashing tool: ${__UAC_TOOL_SHA256_BIN}"
Expand Down

0 comments on commit 6c95a63

Please sign in to comment.