Skip to content

Commit ff206ef

Browse files
committed
Code cleanup
1 parent 346b96d commit ff206ef

File tree

2 files changed

+21
-42
lines changed

2 files changed

+21
-42
lines changed

build

+17-35
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ RUN_SHELL=
104104
CCACHE=
105105
DLNOSIGNATURE=
106106
CACHE_DIR=/var/cache/build
107+
MYHOSTNAME=
107108

108109

109110
# This is for insserv
@@ -375,6 +376,7 @@ usage () {
375376
cleanup_and_exit () {
376377
trap EXIT
377378
test -z "$1" && set 0
379+
test -n "$2" && echo "$2"
378380
if test -z "$BUILD_OPTIONS_PARSED" ; then
379381
# if we haven't parsed the options yet we do
380382
# not know the correct build root. just exit.
@@ -629,34 +631,23 @@ copy_oldpackages() {
629631
done
630632
}
631633

632-
become_root_or_fail() {
633-
if test ! -w /root ; then
634-
echo "You have to be root to use $0" >&2
635-
exit 1
636-
fi
637-
cleanup_and_exit 1
638-
}
639-
640634
mkdir_build_root() {
641635
# strip trailing slash
642636
test "$BUILD_ROOT" != / && BUILD_ROOT="${BUILD_ROOT%/}"
643637
if test -d "$BUILD_ROOT" ; then
644638
# check if it is owned by root
645639
if test -z "$RUNNING_IN_VM" -a \! -O "$BUILD_ROOT" -a "`stat -c %u $BUILD_ROOT`" -ne 0 ; then
646-
echo "BUILD_ROOT=$BUILD_ROOT must be owned by root. Exit..."
647-
cleanup_and_exit 1
640+
cleanup_and_exit 1 "BUILD_ROOT=$BUILD_ROOT must be owned by root. Exit..."
648641
fi
649642
else
650643
test "$BUILD_ROOT" != "${BUILD_ROOT%/*}" && mkdir -p "${BUILD_ROOT%/*}"
651644
if ! mkdir $BUILD_ROOT ; then
652-
echo "can not create BUILD_ROOT=$BUILD_ROOT. Exit..."
653-
cleanup_and_exit 1
645+
cleanup_and_exit 1 "can not create BUILD_ROOT=$BUILD_ROOT. Exit..."
654646
fi
655647
fi
656648

657649
if test ! -w "$BUILD_ROOT" ; then
658-
echo "Error: BUILD_ROOT=$BUILD_ROOT not writeable, try --clean."
659-
cleanup_and_exit 3
650+
cleanup_and_exit 3 "Error: BUILD_ROOT=$BUILD_ROOT not writeable, try --clean."
660651
fi
661652

662653
rm -rf "$BUILD_ROOT/.build.packages"
@@ -912,8 +903,7 @@ while test -n "$1"; do
912903
-uid)
913904
needarg
914905
if test -n "${ARG//[0-9:]/}" ; then
915-
echo "--uid argument must be uid:gid"
916-
cleanup_and_exit 1
906+
cleanup_and_exit 1 "--uid argument must be uid:gid"
917907
fi
918908
ABUILD_UID=${ARG%:*}
919909
ABUILD_GID=${ARG#*:}
@@ -936,17 +926,15 @@ while test -n "$1"; do
936926
DLNOSIGNATURE="--nosignature"
937927
;;
938928
---noarg)
939-
echo "$ARG does not take an argument"
940-
cleanup_and_exit 1
929+
cleanup_and_exit 1 "$ARG does not take an argument"
941930
;;
942931
-*)
943932
if vm_parse_options "$@" ; then
944933
set -- "${nextargs[@]}"
945934
elif recipe_parse_options "$@" ; then
946935
set -- "${nextargs[@]}"
947936
else
948-
echo "Unknown option '$PARAM'. Exit."
949-
cleanup_and_exit 1
937+
cleanup_and_exit 1 "Unknown option '$PARAM'. Exit."
950938
fi
951939
;;
952940
*)
@@ -990,11 +978,10 @@ if test -n "$KILL" ; then
990978
vm_kill
991979
else
992980
if ! $BUILD_DIR/killchroot -s 9 $BUILD_ROOT ; then
993-
echo "could not kill build in $BUILD_ROOT"
994-
cleanup_and_exit 1
981+
cleanup_and_exit 1 "could not kill build in $BUILD_ROOT"
995982
fi
996983
fi
997-
cleanup_and_exit 0
984+
cleanup_and_exit
998985
fi
999986

1000987
if test -n "$CLEAN_BUILD" ; then
@@ -1127,8 +1114,7 @@ for RECIPEFILE in "${RECIPEFILES[@]}" ; do
11271114
#
11281115
cd "$SRCDIR"
11291116
if ! test -s "$RECIPEFILE" ; then
1130-
echo "$RECIPEFILE is empty. This should not happen..."
1131-
cleanup_and_exit 1
1117+
cleanup_and_exit 1 "$RECIPEFILE is empty. This should not happen..."
11321118
fi
11331119
MYSRCDIR="$SRCDIR"
11341120

@@ -1161,7 +1147,7 @@ for RECIPEFILE in "${RECIPEFILES[@]}" ; do
11611147

11621148
if test -n "$VM_TYPE" -a -z "$RUNNING_IN_VM"; then
11631149
vm_first_stage
1164-
cleanup_and_exit 0
1150+
cleanup_and_exit
11651151
fi
11661152

11671153
if test "$DO_INIT" = true ; then
@@ -1190,8 +1176,7 @@ for RECIPEFILE in "${RECIPEFILES[@]}" ; do
11901176
# ensure that old stat is not failing (RHEL4)
11911177
if df $BUILD_ROOT 2>/dev/null | grep -q "100%"; then
11921178
df -h $BUILD_ROOT
1193-
echo "build does not work on a completely full filesystem"
1194-
cleanup_and_exit 1
1179+
cleanup_and_exit 1 "build does not work on a completely full filesystem"
11951180
fi
11961181
fi
11971182
mount -n -tproc none $BUILD_ROOT/proc || true
@@ -1306,17 +1291,15 @@ for RECIPEFILE in "${RECIPEFILES[@]}" ; do
13061291
VM_TELNET_DEVICE=${VM_TELNET_DEVICE#lo }
13071292
VM_TELNET_DEVICE=${VM_TELNET_DEVICE%% *}
13081293
if test -z "$VM_TELNET_DEVICE"; then
1309-
echo "ERROR: no network device found for telnet server"
1310-
cleanup_and_exit 1
1294+
cleanup_and_exit 1 "ERROR: no network device found for telnet server"
13111295
fi
13121296
if test -x /sbin/ip ; then
13131297
ip addr add 10.0.2.15/8 dev ${VM_TELNET_DEVICE}
13141298
ip addr add ::1/24 dev ${VM_TELNET_DEVICE}
13151299
ip link set ${VM_TELNET_DEVICE} up
13161300
else
13171301
if ! test -x /sbin/ifconfig ; then
1318-
echo "ERROR: /usr/sbin/in.telnetd is not running, please specify right package via -x option"
1319-
cleanup_and_exit 1
1302+
cleanup_and_exit 1 "ERROR: /usr/sbin/in.telnetd is not running, please specify correct package via -x option"
13201303
fi
13211304
ifconfig ${VM_TELNET_DEVICE} 10.0.2.15 up
13221305
ifconfig ${VM_TELNET_DEVICE} add ::1/24
@@ -1328,10 +1311,9 @@ for RECIPEFILE in "${RECIPEFILES[@]}" ; do
13281311
if test -n "$VM_TELNET"; then
13291312
echo WARNING: telnet option used, setting up telnet server ${VM_TELNET_DEVICE}
13301313
if test -x /usr/sbin/in.telnetd; then
1331-
( /usr/sbin/in.telnetd -L /.build/telnet_login_wrapper -debug 23 & )
1314+
( /usr/sbin/in.telnetd -L /.build/telnet_login_wrapper -debug 23 & )
13321315
else
1333-
echo "ERROR: /usr/sbin/in.telnetd is not running, please specify right package via -x option"
1334-
cleanup_and_exit 1
1316+
cleanup_and_exit 1 "ERROR: /usr/sbin/in.telnetd is not running, please specify right package via -x option"
13351317
fi
13361318
fi
13371319
fi

build-validate-params

+4-7
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ validate_init() {
4141
validate_buildroot[${#validate_buildroot[@]}]="$_flag"
4242
;;
4343
*)
44-
echo "unknown directive in $cf: $_key"
45-
cleanup_and_exit 1
44+
cleanup_and_exit 1 "unknown directive in $cf: $_key"
4645
;;
4746
esac
4847
done < "$cf"
@@ -70,11 +69,10 @@ validate_param() {
7069
done
7170
if test -z "$ok" ; then
7271
if test -n "$envvar" ; then
73-
echo "build: environment variable $envvar=$arg not allowed"
72+
cleanup_and_exit 1 "build: environment variable $envvar=$arg not allowed"
7473
else
75-
echo "build: parameter --$param $arg not allowed"
74+
cleanup_and_exit 1 "build: parameter --$param $arg not allowed"
7675
fi
77-
cleanup_and_exit 1
7876
fi
7977
}
8078

@@ -99,8 +97,7 @@ validate_buildroot() {
9997
fi
10098
done
10199
if test -z "$ok" ; then
102-
echo "$error"
103-
cleanup_and_exit 1
100+
cleanup_and_exit 1 "$error"
104101
fi
105102
}
106103

0 commit comments

Comments
 (0)