Skip to Content.
Sympa Menu

sm-commit - [SM-Commit] GIT changes to master cauldron by Justin Boffemmyer (402116d48b063bcb80aaf7bbf8d25749bee62e40)

sm-commit AT lists.ibiblio.org

Subject: Source Mage code commit list

List archive

Chronological Thread  
  • From: Justin Boffemmyer <scm AT sourcemage.org>
  • To: sm-commit AT lists.ibiblio.org
  • Subject: [SM-Commit] GIT changes to master cauldron by Justin Boffemmyer (402116d48b063bcb80aaf7bbf8d25749bee62e40)
  • Date: Wed, 21 Feb 2018 02:40:34 +0000

GIT changes to master cauldron by Justin Boffemmyer <flux AT sourcemage.org>:

cauldron/etc/cauldron.conf | 2 -
cauldron/lib/lib.chroot | 76
+++++++++++++++++++++++++++++++--------------
cauldron/lib/lib.toolchain | 18 +++++-----
enchantment/lib/lib.chroot | 74 ++++++++++++++++++++++++++++++-------------
lib/liberror | 14 +++++++-
5 files changed, 126 insertions(+), 58 deletions(-)

New commits:
commit 402116d48b063bcb80aaf7bbf8d25749bee62e40
Author: Justin Boffemmyer <flux AT sourcemage.org>
Commit: Justin Boffemmyer <flux AT sourcemage.org>

cauldron: lib.toolchain: workaround for url dl

Somehow, liberror_check is picking up an error code when it gets called,
even
though manually running the url dl results in no error. Adding extra ||
conditionals between the url dl commands and the following liberror_check
calls
alleviates the problem.

commit cbf4b615351328cf33f1b4397b03616b1d6e1424
Author: Justin Boffemmyer <flux AT sourcemage.org>
Commit: Justin Boffemmyer <flux AT sourcemage.org>

cauldron: lib.toolchain: correct liberror message

Add the target path to the liberror message that will appear in case of
error,
rather than assuming the user will understand the path is relative to the
target.

commit bb10aaafcd9173af88ac42500bc11eec662e09cb
Author: Justin Boffemmyer <flux AT sourcemage.org>
Commit: Justin Boffemmyer <flux AT sourcemage.org>

cauldron: don't hardcode main config path

Allow the main config file's path to be overridden by an environment
variable,
rather than hardcoding it.

commit 6c049bb67da754ee62d4f40ef388a1f09c0818b7
Author: Justin Boffemmyer <flux AT sourcemage.org>
Commit: Justin Boffemmyer <flux AT sourcemage.org>

enchantment: lib.chroot: refactor done + cleanup

Refactor the shared code in enchant_chroot_done and
enchant_chroot_cleanup into
a separate, new function enchant_chroot_close. The usage of
enchant_chroot_close is potentially dangerous (whereas cleanup is
guaranteed
dangerous), so it should be used carefully.

Additionally, rather than hardcoding the mountpoints or relying on a
recursive
umount, which may not be available on the host system, get the list of
mount
points to umount from the list of what's actually mounted in that chroot,
but
sorted in reverse order (to guarantee that nested subdirs are unmounted
before
their parents).

commit 0e1939ba51da8d792a437a7965a188a62bc4c0f3
Author: Justin Boffemmyer <flux AT sourcemage.org>
Commit: Justin Boffemmyer <flux AT sourcemage.org>

cauldron: lib.chroot: refactor done + cleanup

Refactor the shared code in cauldron_chroot_done and
cauldron_chroot_cleanup
into a separate, new function cauldron_chroot_close. The usage of
cauldron_chroot_close is potentially dangerous (whereas cleanup is
guaranteed
dangerous), so it should be used carefully.

Additionally, rather than hardcoding the mountpoints or relying on a
recursive
umount, which may not be available on the host system, get the list of
mount
points to umount from the list of what's actually mounted in that chroot,
but
sorted in reverse order (to guarantee that nested subdirs are unmounted
before
their parents).

commit 77068c26f27de7dffd960c250f18a5f440cf101c
Author: Justin Boffemmyer <flux AT sourcemage.org>
Commit: Justin Boffemmyer <flux AT sourcemage.org>

liberror: improve check functions

Improve the check functions by having them immediately return an "OK"
result if
the incoming error code matches that of ERR_OK. Also have them test
against
ERR_OK instead of hardcoding the OK value as 0.

diff --git a/cauldron/etc/cauldron.conf b/cauldron/etc/cauldron.conf
index 74f53e1..63c7224 100644
--- a/cauldron/etc/cauldron.conf
+++ b/cauldron/etc/cauldron.conf
@@ -2,7 +2,7 @@

# location where the default config files are installed
# default location is /usr/share/smgl/cauldron/config
-CAULDRON_CONF=/usr/share/smgl/cauldron/config
+CAULDRON_CONF="${CAULDRON_CONF:-/usr/share/smgl/cauldron/config}"

# load the architecture definition first
source "$CAULDRON_CONF"/arch/x86.conf
diff --git a/cauldron/lib/lib.chroot b/cauldron/lib/lib.chroot
index d499c92..ad9698f 100644
--- a/cauldron/lib/lib.chroot
+++ b/cauldron/lib/lib.chroot
@@ -106,6 +106,55 @@ function cauldron_chroot_init() {
}


#-------------------------------------------------------------------------------
+## @param chroot index (optional)
+## @param target chroot paths (optional)
+##
+## Unmounts required mount points in the chroot and unsets the related CHROOT
+## variables. If no target chroot is not provided, it will close ALL known
+## chroot paths.
+##
+#-------------------------------------------------------------------------------
+function cauldron_chroot_close() {
+ local index="$1"
+ local chroot=
+ local target=
+
+ shift 1
+ chroot=( "$@" )
+ [[ -z "$chroot" ]] && chroot=( "${LIBCHROOT_PATHS[@]}" )
+
+ for target in "${chroot[@]}"
+ do
+ local mounts=( $(grep -o "$target[^[:space:]]*" | sort -r) )
+ [[ -n "$mounts" ]] || mounts=( sys run dev/pts dev proc )
+ cauldron_verbose "closing chroot mounts: ${mounts[@]}"
+
+ # unmount the chroot mount points
+ for mnt in "${mounts[@]}"
+ do
+ if grep -q "$mnt" "$target/proc/mounts"
+ then
+ "${CAULDRON_CMD_UNMOUNT[@]}" "$target/$mnt" ||
+ return $ERR_CHROOT_DONE
+ fi
+ done
+ done
+
+ # clear the chroot definitions
+ if [[ -n "$index" ]]
+ then
+ unset LIBCHROOT_USERS[index]
+ unset LIBCHROOT_PATHS[index]
+ else
+ unset LIBCHROOT_USERS
+ unset LIBCHROOT_PATHS
+ fi
+ unset CAULDRON_CHROOT
+
+ return $ERR_OK
+}
+
+#-------------------------------------------------------------------------------
## @param target chroot dir
##
## Cleans up the chroot environment after it is no longer needed.
@@ -131,14 +180,8 @@ function cauldron_chroot_done() {
then
LIBCHROOT_USERS[index]=$((LIBCHROOT_USERS[index]-1))
else
- # unmount the chroot mount points
- "${CAULDRON_CMD_UNMOUNT_RECURSIVE[@]}" "$target"/* ||
- return $ERR_CHROOT_DONE
-
- # clear the chroot definitions
- unset CAULDRON_CHROOT
- unset LIBCHROOT_USERS[index]
- unset LIBCHROOT_PATHS[index]
+ cauldron_chroot_close "$index" "$target"
+ liberror_check || return $?
fi
fi
done
@@ -153,21 +196,8 @@ function cauldron_chroot_done() {
##

#-------------------------------------------------------------------------------
function cauldron_chroot_cleanup() {
- local target=
-
- for target in "${LIBCHROOT_PATHS[@]}"
- do
- # unmount the chroot mount points
- "${CAULDRON_CMD_UNMOUNT_RECURSIVE[@]}" "$target"/* ||
- return $ERR_CHROOT_DONE
- done
-
- # clear the chroot definitions
- unset LIBCHROOT_USERS
- unset LIBCHROOT_PATHS
- unset CAULDRON_CHROOT
-
- return $ERR_OK
+ cauldron_chroot_close
+ liberror_check || return $?
}


#-------------------------------------------------------------------------------
diff --git a/cauldron/lib/lib.toolchain b/cauldron/lib/lib.toolchain
index e5ad9cf..a62fa3c 100644
--- a/cauldron/lib/lib.toolchain
+++ b/cauldron/lib/lib.toolchain
@@ -61,7 +61,7 @@ function cauldron_toolchain_compiler_test() {

# run the generated binary to make sure it was properly compiled
cauldron_chroot "/$comptest"
- liberror_check "execute $comptest" || return $?
+ liberror_check "execute $chroot/$comptest" || return $?

cauldron_chroot_done "$chroot"
liberror_check || return $?
@@ -141,14 +141,14 @@ function cauldron_toolchain_baseroot() {
# get a fresh basesystem chroot package
(
cd "$CAULDRON_TMP"
- "${CAULDRON_CMD_URL_DL[@]}" "$baseroot_url"
- liberror_check $ERR_TOOLCHAIN_BASEROOT \
- "could not acquire baseroot image file" ||
- return $ERR_TOOLCHAIN_BASEROOT
- "${CAULDRON_CMD_URL_DL[@]}" "$baseroot_sig"
- liberror_check $ERR_TOOLCHAIN_BASEROOT \
- "could not acquire baseroot signature file" ||
- return $ERR_TOOLCHAIN_BASEROOT
+ "${CAULDRON_CMD_URL_DL[@]}" "$baseroot_url" ||
+ liberror_check $ERR_TOOLCHAIN_BASEROOT \
+ "could not acquire baseroot image file" ||
+ return $ERR_TOOLCHAIN_BASEROOT
+ "${CAULDRON_CMD_URL_DL[@]}" "$baseroot_sig" ||
+ liberror_check $ERR_TOOLCHAIN_BASEROOT \
+ "could not acquire baseroot signature file" ||
+ return $ERR_TOOLCHAIN_BASEROOT
)
liberror_check || return $?
fi
diff --git a/enchantment/lib/lib.chroot b/enchantment/lib/lib.chroot
index ab710e5..de61ff1 100644
--- a/enchantment/lib/lib.chroot
+++ b/enchantment/lib/lib.chroot
@@ -106,6 +106,55 @@ function enchant_chroot_init() {
}


#-------------------------------------------------------------------------------
+## @param chroot index (optional)
+## @param target chroot paths (optional)
+##
+## Unmounts required mount points in the chroot and unsets the related CHROOT
+## variables. If no target chroot is not provided, it will close ALL known
+## chroot paths.
+##
+#-------------------------------------------------------------------------------
+function enchant_chroot_close() {
+ local index="$1"
+ local chroot=
+ local target=
+
+ shift 1
+ chroot=( "$@" )
+ [[ -z "$chroot" ]] && chroot=( "${LIBCHROOT_PATHS[@]}" )
+
+ for target in "${chroot[@]}"
+ do
+ local mounts=( $(grep -o "$target[^[:space:]]*" | sort -r) )
+ [[ -n "$mounts" ]] || mounts=( sys run dev/pts dev proc )
+ cauldron_verbose "closing chroot mounts: ${mounts[@]}"
+
+ # unmount the chroot mount points
+ for mnt in "${mounts[@]}"
+ do
+ if grep -q "$mnt" "$target/proc/mounts"
+ then
+ "${CAULDRON_CMD_UNMOUNT[@]}" "$target/$mnt" ||
+ return $ERR_CHROOT_DONE
+ fi
+ done
+ done
+
+ # clear the chroot definitions
+ if [[ -n "$index" ]]
+ then
+ unset LIBCHROOT_USERS[index]
+ unset LIBCHROOT_PATHS[index]
+ else
+ unset LIBCHROOT_USERS
+ unset LIBCHROOT_PATHS
+ fi
+ unset CAULDRON_CHROOT
+
+ return $ERR_OK
+}
+
+#-------------------------------------------------------------------------------
## @param target dir to chroot into (optional)
##
## Cleans up the chroot environment after it is no longer needed
@@ -131,14 +180,7 @@ function enchant_chroot_done() {
then
LIBCHROOT_USERS[index]=$((LIBCHROOT_USERS[index]-1))
else
- # unmount the chroot mount points
- "${ENCHANT_CMD_UNMOUNT_RECURSIVE[@]}" "$target"/* ||
- return $ERR_CHROOT_DONE
-
- # clear the chroot definitions
- unset ENCHANT_CHROOT
- unset LIBCHROOT_USERS[index]
- unset LIBCHROOT_PATHS[index]
+ enchant_chroot_close "$index" "$target"
fi
fi
done
@@ -153,21 +195,7 @@ function enchant_chroot_done() {
##

#-------------------------------------------------------------------------------
function enchant_chroot_cleanup() {
- local target=
-
- for target in "${LIBCHROOT_PATHS[@]}"
- do
- # unmount the chroot mount points
- "${ENCHANT_CMD_UNMOUNT_RECURSIVE[@]}" "$target"/* ||
- return $ERR_CHROOT_DONE
- done
-
- # clear the chroot definitions
- unset LIBCHROOT_USERS
- unset LIBCHROOT_PATHS
- unset ENCHANT_CHROOT
-
- return $ERR_OK
+ enchant_chroot_close
}


#-------------------------------------------------------------------------------
diff --git a/lib/liberror b/lib/liberror
index fe48938..54bf0c0 100644
--- a/lib/liberror
+++ b/lib/liberror
@@ -184,6 +184,9 @@ function liberror_check() {
local error="$?"
local info=""

+ # return "OK" immediately if the error code matches ERR_OK
+ [[ "$error" -eq "$ERR_OK" ]] && return 0
+
# if we were given two parameters, the first is the error name (override),
and
# the second is the info message. Otherwise, the first parameter (if
given) is
# the info message, and error is taken from the $? resulting from whatever
@@ -196,7 +199,7 @@ function liberror_check() {
info="$1"
fi

- [[ "$error" -gt 0 ]] && liberror_print_error "$error" "$info"
+ liberror_print_error "$error" "$info"

# return the same error back so that we don't modify the return value
# environment
@@ -226,6 +229,9 @@ function liberror_check_fatal() {
local error="$?"
local info=""

+ # return "OK" immediately if the error code matches ERR_OK
+ [[ "$error" -eq "$ERR_OK" ]] && return 0
+
# if we were given two parameters, the first is the error name (override),
and
# the second is the info message. Otherwise, the first parameter (if
given) is
# the info message, and error is taken from the $? resulting from whatever
@@ -238,8 +244,12 @@ function liberror_check_fatal() {
info="$1"
fi

- [[ "$error" -gt 0 ]] && liberror_die "$error" "$info"
+ liberror_die "$error" "$info"

+ # liberror_die calls exit so we should never reach the following return
+ # statement
+ # in the event that we do reach it, we don't want to cycle errors
endlessly,
+ # so return "OK"
return $ERR_OK
}




  • [SM-Commit] GIT changes to master cauldron by Justin Boffemmyer (402116d48b063bcb80aaf7bbf8d25749bee62e40), Justin Boffemmyer, 02/20/2018

Archive powered by MHonArc 2.6.24.

Top of Page