Skip to content

Commit

Permalink
Optimized shell code with <'s (instead of cat + |)
Browse files Browse the repository at this point in the history
This patch optimizes shell code as reading a single file as input using a 'cat' command to a program.

It is considered to be a Useless Use of Cat (UUOC).

It's more efficient to simply use redirection.

However, in some cases, even using the redirection operator '<' seems unnecessary.

Signed-off-by: KKrypt <sankalpacharya1211@gmail.com>
  • Loading branch information
sankalp-12 authored and avagin committed Mar 17, 2023
1 parent 618d622 commit a807c42
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion test/jenkins/criu-fault.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ prep
./test/zdtm.py run -t zdtm/static/maps00 --fault 3 --report report -f h || fail

# FIXME: fhandles looks broken on btrfs
cat /proc/self/mountinfo | grep -P "/.* / " | grep -q btrfs || NOBTRFS=$?
grep -P "/.* / " /proc/self/mountinfo | grep -q btrfs || NOBTRFS=$?
if [ $NOBTRFS -eq 1 ] ; then
./test/zdtm.py run -t zdtm/static/inotify_irmap --fault 128 --pre 2 -f uns || fail
fi
Expand Down
2 changes: 1 addition & 1 deletion test/others/mem-snap/run-predump-2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function stop_test {
wtime=1
cd ../../zdtm/static/
make maps04.stop
cat maps04.out | fgrep PASS || fail "Test failed"
fgrep PASS maps04.out || fail "Test failed"
echo "OK"
}

Expand Down
2 changes: 1 addition & 1 deletion test/others/mem-snap/run-predump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ ${CRIU} restore -D "${IMGDIR}/$NRSNAP/" -o restore.log -d -v4 || fail "Fail to r

cd ../../zdtm/static/
make mem-touch.stop
cat mem-touch.out | fgrep PASS || fail "Test failed"
fgrep PASS mem-touch.out || fail "Test failed"

echo "Test PASSED"
2 changes: 1 addition & 1 deletion test/others/mem-snap/run-snap-auto-dedup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ ${CRIU} restore -D "${IMGDIR}/$NRSNAP/" -o restore.log -d -v4 || fail "Fail to r

cd ../../zdtm/static/
make mem-touch.stop
cat mem-touch.out | fgrep PASS || fail "Test failed"
fgrep PASS mem-touch.out || fail "Test failed"

if [[ $dedup_ok_2 -ne 0 || $dedup_ok_1 -ne 0 ]]; then
fail "Dedup test failed"
Expand Down
2 changes: 1 addition & 1 deletion test/others/mem-snap/run-snap-dedup-on-restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fi

cd ../../zdtm/static/
make mem-touch.stop
cat mem-touch.out | fgrep PASS || fail "Test failed"
fgrep PASS mem-touch.out || fail "Test failed"

if [ $restore_dedup_ok -ne 0 ]; then
fail "Dedup test failed"
Expand Down
2 changes: 1 addition & 1 deletion test/others/mem-snap/run-snap-dedup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ ${CRIU} restore -D "${IMGDIR}/$NRSNAP/" -o restore.log -d -v4 || fail "Fail to r

cd ../../zdtm/static/
make mem-touch.stop
cat mem-touch.out | fgrep PASS || fail "Test failed"
fgrep PASS mem-touch.out || fail "Test failed"

if [[ $dedup_ok_2 -ne 0 || $dedup_ok_1 -ne 0 ]]; then
fail "Dedup test failed"
Expand Down
2 changes: 1 addition & 1 deletion test/others/mem-snap/run-snap-maps04.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ ${CRIU} restore -D "${IMGDIR}/$NRSNAP/" -o restore.log --auto-dedup -d -v4 || fa
make -C ../../zdtm/static/ maps04.stop
sleep 1

cat "../zdtm/static/maps04.out" | fgrep PASS || fail "Test failed"
fgrep PASS "../zdtm/static/maps04.out" || fail "Test failed"

size=$(du -sh -BK dump/1/pages-*.img | grep -Eo '[0-9]+' | head -1)
if [ $size -ne 0 ] ; then
Expand Down
2 changes: 1 addition & 1 deletion test/others/mem-snap/run-snap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ ${CRIU} restore -D "${IMGDIR}/$NRSNAP/" -o restore.log -d -v4 || fail "Fail to r

cd ../../zdtm/static/
make mem-touch.stop
cat mem-touch.out | fgrep PASS || fail "Test failed"
fgrep PASS mem-touch.out || fail "Test failed"

echo "Test PASSED"
2 changes: 1 addition & 1 deletion test/others/mounts/mounts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cd $INMNTNS

mount --make-rprivate /

for i in `cat /proc/self/mounts | awk '{ print $2 }'`; do
for i in `awk '{ print $2 }' < /proc/self/mounts`; do
[ '/' = "$i" ] && continue
[ '/proc' = "$i" ] && continue
[ '/dev' = "$i" ] && continue
Expand Down
4 changes: 2 additions & 2 deletions test/others/mounts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ kill -0 $pid || exit
cat /proc/$pid/mountinfo | sort -k 4
echo "Suspend server"
${CRIU} dump -D dump -o dump.log -t $pid -v4 || {
cat dump/dump.log | grep Error
grep Error dump/dump.log
exit 1
}
echo "Resume server"
${CRIU} restore -d -D dump -o restore.log -v4 || {
cat dump/dump.log | grep Error
grep Error dump/dump.log
exit 1
}
cat /proc/$pid/mountinfo | sort -k 4
Expand Down
4 changes: 2 additions & 2 deletions test/others/ns_ext/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ exec 33< $MNT1
exec 34< $MNT2
$CRIU dump -v4 -t $pid -o dump.log -D images --external $NS[$ino]:test_ns --external $NS[$ino2]:test_ns2
RESULT=$?
cat images/dump.log | grep -B 5 Error || echo ok
grep -B 5 Error images/dump.log || echo ok
[ "$RESULT" != "0" ] && {
echo "CRIU dump failed"
echo FAIL
Expand All @@ -70,7 +70,7 @@ cat images/dump.log | grep -B 5 Error || echo ok

$CRIU restore -v4 -o restore.log -D images --inherit-fd fd[33]:test_ns --inherit-fd fd[34]:test_ns2 -d
RESULT=$?
cat images/restore.log | grep -B 5 Error || echo ok
grep -B 5 Error images/restore.log || echo ok
[ "$RESULT" != "0" ] && {
echo "CRIU restore failed"
echo FAIL
Expand Down
4 changes: 2 additions & 2 deletions test/others/ns_ext/run_pidns.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ mkdir -p images_pidns
echo "$CRIU dump -v4 -o dump.log -t $PID -D images_pidns --external $PIDNS:exti"
$CRIU dump -v4 -o dump.log -t $PID -D images_pidns --external $PIDNS:exti
RESULT=$?
cat images_pidns/dump.log | grep -B 5 Error || echo ok
grep -B 5 Error images_pidns/dump.log || echo ok
[ "$RESULT" != "0" ] && {
echo "CRIU dump failed"
echo FAIL
Expand All @@ -48,7 +48,7 @@ exec {pidns_fd}< /proc/self/ns/pid
echo "$CRIU restore -v4 -o restore.log -D images_pidns --restore-detached --inherit-fd fd[$pidns_fd]:exti"
$CRIU restore -v4 -o restore.log -D images_pidns --restore-detached --inherit-fd fd[$pidns_fd]:exti --pidfile test.pidfile
RESULT=$?
cat images_pidns/restore.log | grep -B 5 Error || echo ok
grep -B 5 Error images_pidns/restore.log || echo ok
[ "$RESULT" != "0" ] && {
echo "CRIU restore failed"
echo FAIL
Expand Down
2 changes: 1 addition & 1 deletion test/others/unix-callback/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ done
${CRIU} restore -D data -o restore.log -v4 --lib `pwd`/lib -d || exit 1
kill $pid
while :; do
cat output | grep PASS && break
grep PASS output && break
sleep 1
done

Expand Down

0 comments on commit a807c42

Please sign in to comment.