[PATCH 1/4] kas-container: Move setup_kas_dirs after argument parsing

9 views
Skip to first unread message

Jan Kiszka

unread,
Jun 7, 2026, 12:39:22 PM (12 days ago) Jun 7
to kas-...@googlegroups.com, Felix Moessbauer
From: Jan Kiszka <jan.k...@siemens.com>

If we should just show the help or fail during parsing, there is no need
to have directories already created (if non-default). Furthermore,
tracing of the related mkdir command only works after having set
KAS_VERBOSE in the argument parser.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
kas-container | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kas-container b/kas-container
index 6ab7547..f16b83c 100755
--- a/kas-container
+++ b/kas-container
@@ -317,7 +317,6 @@ setup_kas_dirs()
SSTATE_DIR="$(check_and_expand SSTATE_DIR createrec)"
KAS_BUILDTOOLS_DIR="$(check_and_expand KAS_BUILDTOOLS_DIR createrec)"
}
-setup_kas_dirs

# parse kas-container options, leave build system empty to distinguish between
# explicitly set via flag and implicitly via config.
@@ -485,6 +484,8 @@ podman)
;;
esac

+setup_kas_dirs
+
KAS_RUNTIME_ARGS="${KAS_RUNTIME_ARGS}${KAS_EXTRA_RUNTIME_ARGS}"

[ -n "${KAS_CMD}" ] || usage
--
2.47.3

Jan Kiszka

unread,
Jun 7, 2026, 12:39:22 PM (12 days ago) Jun 7
to kas-...@googlegroups.com, Felix Moessbauer
From: Jan Kiszka <jan.k...@siemens.com>

Makes it easier to read this code. No functional changes.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
kas-container | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/kas-container b/kas-container
index f16b83c..dae046c 100755
--- a/kas-container
+++ b/kas-container
@@ -209,6 +209,19 @@ check_and_expand()
realpath -e "$_varval"
}

+# SC2034: DIR appears unused (ignore, as they are used inside eval)
+# shellcheck disable=2034
+setup_kas_dirs()
+{
+ KAS_WORK_DIR="${KAS_WORK_DIR:-$(pwd)}"
+ KAS_WORK_DIR="$(check_and_expand KAS_WORK_DIR required)"
+ KAS_BUILD_DIR="$(check_and_expand KAS_BUILD_DIR create)"
+ KAS_REPO_REF_DIR="$(check_and_expand KAS_REPO_REF_DIR required)"
+ DL_DIR="$(check_and_expand DL_DIR createrec)"
+ SSTATE_DIR="$(check_and_expand SSTATE_DIR createrec)"
+ KAS_BUILDTOOLS_DIR="$(check_and_expand KAS_BUILDTOOLS_DIR createrec)"
+}
+
# Params: FILE
# Returns: root repo dir of file
repo_path_of_file()
@@ -305,19 +318,6 @@ set_container_image_var()
fi
}

-# SC2034: DIR appears unused (ignore, as they are used inside eval)
-# shellcheck disable=2034
-setup_kas_dirs()
-{
- KAS_WORK_DIR="${KAS_WORK_DIR:-$(pwd)}"
- KAS_WORK_DIR="$(check_and_expand KAS_WORK_DIR required)"
- KAS_BUILD_DIR="$(check_and_expand KAS_BUILD_DIR create)"
- KAS_REPO_REF_DIR="$(check_and_expand KAS_REPO_REF_DIR required)"
- DL_DIR="$(check_and_expand DL_DIR createrec)"
- SSTATE_DIR="$(check_and_expand SSTATE_DIR createrec)"
- KAS_BUILDTOOLS_DIR="$(check_and_expand KAS_BUILDTOOLS_DIR createrec)"
-}
-
# parse kas-container options, leave build system empty to distinguish between
# explicitly set via flag and implicitly via config.
BUILD_SYSTEM=""
--
2.47.3

Jan Kiszka

unread,
Jun 7, 2026, 12:39:22 PM (12 days ago) Jun 7
to kas-...@googlegroups.com, Felix Moessbauer, Cedric Hombourger
Primarily moving every action after the parser and also dropping loop
device support in preparation of rootless build. Cedric, please check if
we can move forward with the loop dev removal by now.

Jan


CC: Cedric Hombourger <cedric.h...@siemens.com>

Jan Kiszka (4):
kas-container: Move setup_kas_dirs after argument parsing
kas-container: Move setup_kas_dirs implementation close to
check_and_expand
kas-container: Initialize KAS_OPTIONS_DIRECT
kas-container: Drop support for loop device

kas-container | 60 +++++++++++++++------------------------------------
1 file changed, 17 insertions(+), 43 deletions(-)

--
2.47.3

Jan Kiszka

unread,
Jun 7, 2026, 12:39:22 PM (12 days ago) Jun 7
to kas-...@googlegroups.com, Felix Moessbauer
From: Jan Kiszka <jan.k...@siemens.com>

Clear this local var to avoid picking up anything from the environment.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
kas-container | 1 +
1 file changed, 1 insertion(+)

diff --git a/kas-container b/kas-container
index dae046c..5db5403 100755
--- a/kas-container
+++ b/kas-container
@@ -321,6 +321,7 @@ set_container_image_var()
# parse kas-container options, leave build system empty to distinguish between
# explicitly set via flag and implicitly via config.
BUILD_SYSTEM=""
+KAS_OPTIONS_DIRECT=""
while [ $# -gt 0 ]; do
case "$1" in
--isar)
--
2.47.3

Jan Kiszka

unread,
Jun 7, 2026, 12:39:22 PM (12 days ago) Jun 7
to kas-...@googlegroups.com, Felix Moessbauer
From: Jan Kiszka <jan.k...@siemens.com>

This simplifies the transition to rootless builds where it would not be
available anyway and we would only have to detect and reject it. For
current privileged builds, this should no longer play are role anymore
as well.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
kas-container | 30 +-----------------------------
1 file changed, 1 insertion(+), 29 deletions(-)

diff --git a/kas-container b/kas-container
index 5db5403..e0c6734 100755
--- a/kas-container
+++ b/kas-container
@@ -68,9 +68,6 @@ usage()
printf "%b" "\nOptional arguments:\n"
printf "%b" "--isar\t\t\tUse kas-isar container to build Isar image. To force\n"
printf "%b" " \t\t\tthe use of run0 over sudo, set KAS_SUDO_CMD=run0.\n"
- printf "%b" "--with-loop-dev Pass a loop device to the " \
- "container. Only required if\n"
- printf "%b" "\t\t\tloop-mounting is used by recipes.\n"
printf "%b" "--runtime-args\t\tAdditional arguments to pass to the " \
"container runtime\n"
printf "%b" "\t\t\tfor running the build.\n"
@@ -328,31 +325,6 @@ while [ $# -gt 0 ]; do
BUILD_SYSTEM="isar"
shift 1
;;
- --with-loop-dev)
- if ! KAS_LOOP_DEV=$(/sbin/losetup -f 2>/dev/null); then
- if [ "$(id -u)" -eq 0 ]; then
- fatal_error "loop device not available!"
- fi
- prepare_sudo_cmd
- if ! [ "$KAS_SUDO_CMD" = "sudo" ]; then
- fatal_error '--with-loop-dev requires sudo for device setup.'
- fi
- sudo_command="/sbin/losetup -f"
- sudo_message="[sudo] enter password to setup loop"
- sudo_message="$sudo_message devices by calling"
- sudo_message="$sudo_message '$sudo_command': "
- # SC2086: Double quote to prevent globbing and word splitting.
- # shellcheck disable=2086
- if ! KAS_LOOP_DEV=$(sudo -p "$sudo_message" $sudo_command \
- 2>/dev/null); then
- fatal_error "loop device setup unsuccessful!" \
- "try calling '$sudo_command' with root" \
- "permissions manually."
- fi
- fi
- KAS_WITH_LOOP_DEV="--device ${KAS_LOOP_DEV}"
- shift 1
- ;;
--runtime-args | --docker-args)
[ $# -gt 0 ] || usage
KAS_EXTRA_RUNTIME_ARGS=" $2"
@@ -768,7 +740,7 @@ fi

# SC2086: Double quote to prevent globbing and word splitting.
# shellcheck disable=2086
-set -- "$@" ${KAS_ISAR_ARGS} ${KAS_WITH_LOOP_DEV} ${KAS_RUNTIME_ARGS} \
+set -- "$@" ${KAS_ISAR_ARGS} ${KAS_RUNTIME_ARGS} \
${KAS_CONTAINER_IMAGE} ${KAS_OPTIONS_DIRECT} ${KAS_CMD} ${KAS_OPTIONS}
if [ -n "${KAS_BITBAKE_C_OPTION_ARGS}" ]; then
set -- "$@" -c "${KAS_BITBAKE_C_OPTION_ARGS}"
--
2.47.3

MOESSBAUER, Felix

unread,
Jun 8, 2026, 5:12:01 AM (11 days ago) Jun 8
to Kiszka, Jan, kas-...@googlegroups.com, Hombourger, Cedric
On Sun, 2026-06-07 at 18:39 +0200, 'Jan Kiszka' via kas-devel wrote:
> Primarily moving every action after the parser and also dropping loop
> device support in preparation of rootless build. Cedric, please check if
> we can move forward with the loop dev removal by now.

We are almost there. Please also move the variable declaration into the
function and move the trap below the argument parser.

Once done, we probably should add a comment that above this line only
functions should be defined.

KAS_GIT_OVERLAY_FILE=""
kas_container_cleanup()
{
if [ -f "${KAS_GIT_OVERLAY_FILE}" ]; then
trace rm -f "${KAS_GIT_OVERLAY_FILE}"
fi
}
trap kas_container_cleanup EXIT INT TERM

Felix

>
> Jan
>
>
> CC: Cedric Hombourger <cedric.h...@siemens.com>
>
> Jan Kiszka (4):
> kas-container: Move setup_kas_dirs after argument parsing
> kas-container: Move setup_kas_dirs implementation close to
> check_and_expand
> kas-container: Initialize KAS_OPTIONS_DIRECT
> kas-container: Drop support for loop device
>
> kas-container | 60 +++++++++++++++------------------------------------
> 1 file changed, 17 insertions(+), 43 deletions(-)
>
> --
> 2.47.3
>

> --
> You received this message because you are subscribed to the Google Groups "kas-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kas-devel+...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/kas-devel/cover.1780850358.git.jan.kiszka%40siemens.com.

Jan Kiszka

unread,
Jun 8, 2026, 7:13:13 AM (11 days ago) Jun 8
to Moessbauer, Felix (FT RPD CED OES-DE), kas-...@googlegroups.com, Hombourger, Cedric (FT FDS CES LX)
On 08.06.26 11:11, Moessbauer, Felix (FT RPD CED OES-DE) wrote:
> On Sun, 2026-06-07 at 18:39 +0200, 'Jan Kiszka' via kas-devel wrote:
>> Primarily moving every action after the parser and also dropping loop
>> device support in preparation of rootless build. Cedric, please check if
>> we can move forward with the loop dev removal by now.
>
> We are almost there. Please also move the variable declaration into the
> function and move the trap below the argument parser.
>

Why?

> Once done, we probably should add a comment that above this line only
> functions should be defined.
>
> KAS_GIT_OVERLAY_FILE=""
> kas_container_cleanup()
> {
> if [ -f "${KAS_GIT_OVERLAY_FILE}" ]; then
> trace rm -f "${KAS_GIT_OVERLAY_FILE}"
> fi
> }
> trap kas_container_cleanup EXIT INT TERM
>

This part I actually forgot to move. At least the trap setup needs to
become part of the scope that needs it, no longer top-level.

Jan

--
Siemens AG, Foundational Technologies
Linux Expert Center

MOESSBAUER, Felix

unread,
Jun 8, 2026, 8:01:14 AM (11 days ago) Jun 8
to Kiszka, Jan, kas-...@googlegroups.com, Hombourger, Cedric

Agree. Your patch "kas-container: Move kas_container_cleanup into scope
that requires it" perfectly solves this.

Felix

Reply all
Reply to author
Forward
0 new messages