[1/1] Fix ZeroDivisionError for kernels without modules

Message ID 20260417093522.1195617-2-stefan-koch@siemens.com
State New
Headers show
Series Fix ZeroDivisionError for kernels without modules | expand

Commit Message

Koch, Stefan April 17, 2026, 9:34 a.m. UTC
Ensure that `num_pkgs` is at least 1 to avoid division by zero.

Fixes: 88656cc9 ("generate_initramfs: fix progress reporting on dracut")

Signed-off-by: Stefan Koch <stefan-koch@siemens.com>
---
 meta/lib/rootfs_progress.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jan Kiszka April 17, 2026, 10:15 a.m. UTC | #1
On 17.04.26 11:34, Stefan Koch wrote:
> Ensure that `num_pkgs` is at least 1 to avoid division by zero.
> 
> Fixes: 88656cc9 ("generate_initramfs: fix progress reporting on dracut")
> 

I think that commit just armed the bug. It was rather introduced by
938dab363006529f0b5296dfbc09ef306fc8c3d7.

> Signed-off-by: Stefan Koch <stefan-koch@siemens.com>
> ---
>  meta/lib/rootfs_progress.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/meta/lib/rootfs_progress.py b/meta/lib/rootfs_progress.py
> index 6feed9df..58d16574 100644
> --- a/meta/lib/rootfs_progress.py
> +++ b/meta/lib/rootfs_progress.py
> @@ -77,7 +77,7 @@ class InitrdProgressHandler(PkgsProgressHandler):
>          m = re.search(r'^Total number of modules: ([0-9]+)', line)
>          if m:
>              # in MODULES=most mode, we install ~half of all modules
> -            self._num_pkgs = int(m.group(1)) // 2
> +            self._num_pkgs = max(1, int(m.group(1)) // 2)
>              self._stage = 'post-prepare'
>  
>      def process_line(self, line):

Jan
Koch, Stefan April 17, 2026, 11:41 a.m. UTC | #2
On Fri, 2026-04-17 at 12:15 +0200, Jan Kiszka wrote:
> On 17.04.26 11:34, Stefan Koch wrote:
> > Ensure that `num_pkgs` is at least 1 to avoid division by zero.
> > 
> > Fixes: 88656cc9 ("generate_initramfs: fix progress reporting on
> > dracut")
> > 
> 
> I think that commit just armed the bug. It was rather introduced by
> 938dab363006529f0b5296dfbc09ef306fc8c3d7.

v2 fixes description
> 
> > Signed-off-by: Stefan Koch <stefan-koch@siemens.com>
> > ---
> >  meta/lib/rootfs_progress.py | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/meta/lib/rootfs_progress.py
> > b/meta/lib/rootfs_progress.py
> > index 6feed9df..58d16574 100644
> > --- a/meta/lib/rootfs_progress.py
> > +++ b/meta/lib/rootfs_progress.py
> > @@ -77,7 +77,7 @@ class InitrdProgressHandler(PkgsProgressHandler):
> >          m = re.search(r'^Total number of modules: ([0-9]+)', line)
> >          if m:
> >              # in MODULES=most mode, we install ~half of all
> > modules
> > -            self._num_pkgs = int(m.group(1)) // 2
> > +            self._num_pkgs = max(1, int(m.group(1)) // 2)
> >              self._stage = 'post-prepare'
> >  
> >      def process_line(self, line):
> 
> Jan
Koch, Stefan April 17, 2026, 11:47 a.m. UTC | #3
Buildlog without fix:


2026-04-16 10:33:04 - INFO     - NOTE: recipe audis-image-minimal-1.0-
r0: task do_generate_initramfs: Started
2026-04-16 10:33:16 - ERROR    - ERROR: audis-image-minimal-1.0-r0
do_generate_initramfs: Error executing a python function in
exec_func_python() autogenerated:
2026-04-16 10:33:16 - ERROR    - 
2026-04-16 10:33:16 - ERROR    - The stack trace of python calls that
resulted in this exception/failure was:
2026-04-16 10:33:16 - ERROR    - File: 'exec_func_python()
autogenerated', lineno: 2, function: <module>
2026-04-16 10:33:16 - ERROR    - 0001:
2026-04-16 10:33:16 - ERROR    - *** 0002:do_generate_initramfs(d)
2026-04-16 10:33:16 - ERROR    - 0003:
2026-04-16 10:33:16 - ERROR    - File:
'/mnt/data/builds/feature/z003jsce_fix_trixie/audis/audis-isar-
boards/cphera-rtp/audis-isar-boards/build/../isar/meta/classes-
recipe/rootfs.bbclass', lineno: 620, function: do_generate_initramfs
2026-04-16 10:33:16 - ERROR    - 0616:    progress_reporter =
bb.progress.ProgressHandler(d)
2026-04-16 10:33:16 - ERROR    - 0617:    d.rootfs_progress =
progress_reporter
2026-04-16 10:33:16 - ERROR    - 0618:
2026-04-16 10:33:16 - ERROR    - 0619:    try:
2026-04-16 10:33:16 - ERROR    - *** 0620:       
bb.build.exec_func('rootfs_generate_initramfs', d)
2026-04-16 10:33:16 - ERROR    - 0621:    finally:
2026-04-16 10:33:16 - ERROR    - 0622:       
bb.build.exec_func('rootfs_do_umounts', d)
2026-04-16 10:33:16 - ERROR    - 0623:}
2026-04-16 10:33:16 - ERROR    - 0624:
2026-04-16 10:33:16 - ERROR    - File:
'/mnt/data/builds/feature/z003jsce_fix_trixie/audis/audis-isar-
boards/cphera-rtp/audis-isar-boards/isar/bitbake/lib/bb/build.py',
lineno: 260, function: exec_func
2026-04-16 10:33:16 - ERROR    - 0256:    with
bb.utils.fileslocked(lockfiles):
2026-04-16 10:33:16 - ERROR    - 0257:        if ispython:
2026-04-16 10:33:16 - ERROR    - 0258:           
exec_func_python(func, d, runfile, cwd=adir)
2026-04-16 10:33:16 - ERROR    - 0259:        else:
2026-04-16 10:33:16 - ERROR    - *** 0260:           
exec_func_shell(func, d, runfile, cwd=adir)
2026-04-16 10:33:16 - ERROR    - 0261:
2026-04-16 10:33:16 - ERROR    - 0262:    try:
2026-04-16 10:33:16 - ERROR    - 0263:        curcwd = os.getcwd()
2026-04-16 10:33:16 - ERROR    - 0264:    except:
2026-04-16 10:33:16 - ERROR    - File:
'/mnt/data/builds/feature/z003jsce_fix_trixie/audis/audis-isar-
boards/cphera-rtp/audis-isar-boards/isar/bitbake/lib/bb/build.py',
lineno: 527, function: exec_func_shell
2026-04-16 10:33:16 - ERROR    - 0523:    with open(fifopath, 'r+b',
buffering=0) as fifo:
2026-04-16 10:33:16 - ERROR    - 0524:        try:
2026-04-16 10:33:16 - ERROR    - 0525:            bb.debug(2,
"Executing shell function %s" % func)
2026-04-16 10:33:16 - ERROR    - 0526:            with open(os.devnull,
'r+') as stdin, logfile:
2026-04-16 10:33:16 - ERROR    - *** 0527:               
bb.process.run(cmd, shell=False, stdin=stdin, log=logfile,
extrafiles=[(fifo,readfifo)])
2026-04-16 10:33:16 - ERROR    - 0528:        except
bb.process.ExecutionError as exe:
2026-04-16 10:33:16 - ERROR    - 0529:            # Find the backtrace
that the shell trap generated
2026-04-16 10:33:16 - ERROR    - 0530:           
backtrace_marker_regex = re.compile(r"WARNING: Backtrace \(BB generated
script\)")
2026-04-16 10:33:16 - ERROR    - 0531:            stdout_lines =
(exe.stdout or "").split("\n")
2026-04-16 10:33:16 - ERROR    - File:
'/mnt/data/builds/feature/z003jsce_fix_trixie/audis/audis-isar-
boards/cphera-rtp/audis-isar-boards/isar/bitbake/lib/bb/process.py',
lineno: 177, function: run
2026-04-16 10:33:16 - ERROR    - 0173:        else:
2026-04-16 10:33:16 - ERROR    - 0174:            raise CmdError(cmd,
exc)
2026-04-16 10:33:16 - ERROR    - 0175:
2026-04-16 10:33:16 - ERROR    - 0176:    if log:
2026-04-16 10:33:16 - ERROR    - *** 0177:        stdout, stderr =
_logged_communicate(pipe, log, input, extrafiles)
2026-04-16 10:33:16 - ERROR    - 0178:    else:
2026-04-16 10:33:16 - ERROR    - 0179:        stdout, stderr =
pipe.communicate(input)
2026-04-16 10:33:16 - ERROR    - 0180:        if not stdout is None:
2026-04-16 10:33:16 - ERROR    - 0181:            stdout =
stdout.decode("utf-8")
2026-04-16 10:33:16 - ERROR    - File:
'/mnt/data/builds/feature/z003jsce_fix_trixie/audis/audis-isar-
boards/cphera-rtp/audis-isar-boards/isar/bitbake/lib/bb/process.py',
lineno: 145, function: _logged_communicate
2026-04-16 10:33:16 - ERROR    - 0141:
2026-04-16 10:33:16 - ERROR    - 0142:    try:
2026-04-16 10:33:16 - ERROR    - 0143:        # Read all pipes while
the process is open
2026-04-16 10:33:16 - ERROR    - 0144:        while pipe.poll() is
None:
2026-04-16 10:33:16 - ERROR    - *** 0145:           
read_all_pipes(log, rin, outdata, errdata)
2026-04-16 10:33:16 - ERROR    - 0146:
2026-04-16 10:33:16 - ERROR    - 0147:        # Process closed, drain
all pipes...
2026-04-16 10:33:16 - ERROR    - 0148:        read_all_pipes(log, rin,
outdata, errdata)
2026-04-16 10:33:16 - ERROR    - 0149:    finally:
2026-04-16 10:33:16 - ERROR    - File:
'/mnt/data/builds/feature/z003jsce_fix_trixie/audis/audis-isar-
boards/cphera-rtp/audis-isar-boards/isar/bitbake/lib/bb/process.py',
lineno: 136, function: read_all_pipes
2026-04-16 10:33:16 - ERROR    - 0132:            if data is not None
and len(data) > 0:
2026-04-16 10:33:16 - ERROR    - 0133:                try:
2026-04-16 10:33:16 - ERROR    - 0134:                    data =
data.decode("utf-8")
2026-04-16 10:33:16 - ERROR    - 0135:                   
errdata.append(data)
2026-04-16 10:33:16 - ERROR    - *** 0136:                   
log.write(data)
2026-04-16 10:33:16 - ERROR    - 0137:                    log.flush()
2026-04-16 10:33:16 - ERROR    - 0138:                    stderrbuf =
b""
2026-04-16 10:33:16 - ERROR    - 0139:                except
UnicodeDecodeError:
2026-04-16 10:33:16 - ERROR    - 0140:                    stderrbuf =
data
2026-04-16 10:33:16 - ERROR    - File:
'/mnt/data/builds/feature/z003jsce_fix_trixie/audis/audis-isar-
boards/cphera-rtp/audis-isar-
boards/build/../isar/meta/lib/rootfs_progress.py', lineno: 33,
function: write
2026-04-16 10:33:16 - ERROR    - 0029:
2026-04-16 10:33:16 - ERROR    - 0030:            if self._stage ==
'prepare':
2026-04-16 10:33:16 - ERROR    - 0031:               
self.process_total(line)
2026-04-16 10:33:16 - ERROR    - 0032:            else:
2026-04-16 10:33:16 - ERROR    - *** 0033:               
self.process_line(line)
2026-04-16 10:33:16 - ERROR    - 0034:
2026-04-16 10:33:16 - ERROR    - 0035:    def process_total(self,
line):
2026-04-16 10:33:16 - ERROR    - 0036:        m = re.search(r'^([0-9]+)
upgraded, ([0-9]+) newly installed', line)
2026-04-16 10:33:16 - ERROR    - 0037:        if m:
2026-04-16 10:33:16 - ERROR    - File:
'/mnt/data/builds/feature/z003jsce_fix_trixie/audis/audis-isar-
boards/cphera-rtp/audis-isar-
boards/build/../isar/meta/lib/rootfs_progress.py', lineno: 94,
function: process_line
2026-04-16 10:33:16 - ERROR    - 0090:        elif
line.startswith('(excluding'):
2026-04-16 10:33:16 - ERROR    - 0091:            self._pkg +=
len(line.split(' ')) - 1
2026-04-16 10:33:16 - ERROR    - 0092:        else:
2026-04-16 10:33:16 - ERROR    - 0093:            return
2026-04-16 10:33:16 - ERROR    - *** 0094:       
self._progress.update(99 * self._pkg / self._num_pkgs)
2026-04-16 10:33:16 - ERROR    - Exception: ZeroDivisionError: division
by zero
2026-04-16 10:33:16 - ERROR    - 
2026-04-16 10:33:16 - ERROR    - ERROR: Logfile of failure stored in:
/mnt/data/builds/feature/z003jsce_fix_trixie/audis/audis-isar-
boards/cphera-rtp/audis-isar-boards/build/tmp/work/audis-trixie-latest-
arm64/audis-image-minimal-cphera-rtp/1.0-
r0/temp/log.do_generate_initramfs.11839
2026-04-16 10:33:16 - INFO     - NOTE: recipe audis-image-minimal-1.0-
r0: task do_generate_initramfs: Failed
2026-04-16 10:33:16 - ERROR    - ERROR: Task
(/mnt/data/builds/feature/z003jsce_fix_trixie/audis/audis-isar-
boards/cphera-rtp/audis-isar-boards/build/../audis-isar/recipes-
core/images/audis-image-minimal.bb:do_generate_initramfs) failed with
exit code '1'
2026-04-16 10:33:17 - INFO     - NOTE: Tasks Summary: Attempted 129
tasks of which 95 didn't need to be rerun and 1 failed.
2026-04-16 10:33:17 - INFO     - 
2026-04-16 10:33:17 - INFO     - Summary: 1 task failed:
2026-04-16 10:33:17 - INFO     -
/mnt/data/builds/feature/z003jsce_fix_trixie/audis/audis-isar-
boards/cphera-rtp/audis-isar-boards/build/../audis-isar/recipes-
core/images/audis-image-minimal.bb:do_generate_initramfs
2026-04-16 10:33:17 - INFO     - Summary: There were 2 WARNING
messages.
2026-04-16 10:33:17 - INFO     - Summary: There was 1 ERROR message,
returning a non-zero exit code.
2026-04-16 10:33:17 - ERROR    - Command
"/mnt/data/builds/feature/z003jsce_fix_trixie/audis/audis-isar-
boards/cphera-rtp/audis-isar-boards/build$
/mnt/data/builds/feature/z003jsce_fix_trixie/audis/audis-isar-
boards/cphera-rtp/audis-isar-boards/isar/bitbake/bin/bitbake -c build
audis-image-minimal" failed:
['ERROR: audis-image-minimal-1.0-r0 do_generate_initramfs: Error
executing a python function in exec_func_python() autogenerated:\n',
'\n', 'The stack trace of python calls that resulted in this
exception/failure was:\n', "File: 'exec_func_python() autogenerated',
lineno: 2, function: <module>\n", '     0001:\n', ' ***
0002:do_generate_initramfs(d)\n', '     0003:\n', "File:
'/mnt/data/builds/feature/z003jsce_fix_trixie/audis/audis-isar-
boards/cphera-rtp/audis-isar-boards/build/../isar/meta/classes-
recipe/rootfs.bbclass', lineno: 620, function:
do_generate_initramfs\n", '     0616:    progress_reporter =
bb.progress.ProgressHandler(d)\n', '     0617:    d.rootfs_progress =
progress_reporter\n', '     0618:\n', '     0619:    try:\n', " ***
0620:        bb.build.exec_func('rootfs_generate_initramfs', d)\n", ' 
0621:    finally:\n', "     0622:       
bb.build.exec_func('rootfs_do_umounts', d)\n", '     0623:}\n', '    
0624:\n', "File:
'/mnt/data/builds/feature/z003jsce_fix_trixie/audis/audis-isar-
boards/cphera-rtp/audis-isar-boards/isar/bitbake/lib/bb/build.py',
lineno: 260, function: exec_func\n", '     0256:    with
bb.utils.fileslocked(lockfiles):\n', '     0257:        if
ispython:\n', '     0258:            exec_func_python(func, d, runfile,
cwd=adir)\n', '     0259:        else:\n', ' *** 0260:           
exec_func_shell(func, d, runfile, cwd=adir)\n', '     0261:\n', '    
0262:    try:\n', '     0263:        curcwd = os.getcwd()\n', '    
0264:    except:\n', "File:
'/mnt/data/builds/feature/z003jsce_fix_trixie/audis/audis-isar-
boards/cphera-rtp/audis-isar-boards/isar/bitbake/lib/bb/build.py',
lineno: 527, function: exec_func_shell\n", "     0523:    with
open(fifopath, 'r+b', buffering=0) as fifo:\n", '     0524:       
try:\n', '     0525:            bb.debug(2, "Executing shell function
%s" % func)\n', "     0526:            with open(os.devnull, 'r+') as
stdin, logfile:\n", ' *** 0527:                bb.process.run(cmd,
shell=False, stdin=stdin, log=logfile,
extrafiles=[(fifo,readfifo)])\n', '     0528:        except
bb.process.ExecutionError as exe:\n', '     0529:            # Find the
backtrace that the shell trap generated\n', '     0530:           
backtrace_marker_regex = re.compile(r"WARNING: Backtrace \\(BB
generated script\\)")\n', '     0531:            stdout_lines =
(exe.stdout or "").split("\\n")\n', "File:
'/mnt/data/builds/feature/z003jsce_fix_trixie/audis/audis-isar-
boards/cphera-rtp/audis-isar-boards/isar/bitbake/lib/bb/process.py',
lineno: 177, function: run\n", '     0173:        else:\n', '     0174:
raise CmdError(cmd, exc)\n', '     0175:\n', '     0176:    if log:\n',
' *** 0177:        stdout, stderr = _logged_communicate(pipe, log,
input, extrafiles)\n', '     0178:    else:\n', '     0179:       
stdout, stderr = pipe.communicate(input)\n', '     0180:        if not
stdout is None:\n', '     0181:            stdout = stdout.decode("utf-
8")\n', "File:
'/mnt/data/builds/feature/z003jsce_fix_trixie/audis/audis-isar-
boards/cphera-rtp/audis-isar-boards/isar/bitbake/lib/bb/process.py',
lineno: 145, function: _logged_communicate\n", '     0141:\n', '    
0142:    try:\n', '     0143:        # Read all pipes while the process
is open\n', '     0144:        while pipe.poll() is None:\n', ' ***
0145:            read_all_pipes(log, rin, outdata, errdata)\n', '    
0146:\n', '     0147:        # Process closed, drain all pipes...\n', '
0148:        read_all_pipes(log, rin, outdata, errdata)\n', '     0149:
finally:\n', "File:
'/mnt/data/builds/feature/z003jsce_fix_trixie/audis/audis-isar-
boards/cphera-rtp/audis-isar-boards/isar/bitbake/lib/bb/process.py',
lineno: 136, function: read_all_pipes\n", '     0132:            if
data is not None and len(data) > 0:\n', '     0133:               
try:\n', '     0134:                    data = data.decode("utf-8")\n',
'     0135:                    errdata.append(data)\n', ' *** 0136:   
log.write(data)\n', '     0137:                    log.flush()\n', '  
0138:                    stderrbuf = b""\n', '     0139:              
except UnicodeDecodeError:\n', '     0140:                    stderrbuf
= data\n', "File:
'/mnt/data/builds/feature/z003jsce_fix_trixie/audis/audis-isar-
boards/cphera-rtp/audis-isar-
boards/build/../isar/meta/lib/rootfs_progress.py', lineno: 33,
function: write\n", '     0029:\n', "     0030:            if
self._stage == 'prepare':\n", '     0031:               
self.process_total(line)\n', '     0032:            else:\n', ' ***
0033:                self.process_line(line)\n', '     0034:\n', '    
0035:    def process_total(self, line):\n', "     0036:        m =
re.search(r'^([0-9]+) upgraded, ([0-9]+) newly installed', line)\n", '
0037:        if m:\n', "File:
'/mnt/data/builds/feature/z003jsce_fix_trixie/audis/audis-isar-
boards/cphera-rtp/audis-isar-
boards/build/../isar/meta/lib/rootfs_progress.py', lineno: 94,
function: process_line\n", "     0090:        elif
line.startswith('(excluding'):\n", "     0091:            self._pkg +=
len(line.split(' ')) - 1\n", '     0092:        else:\n', '     0093: 
return\n', ' *** 0094:        self._progress.update(99 * self._pkg /
self._num_pkgs)\n', 'Exception: ZeroDivisionError: division by zero\n',
'\n', 'ERROR: Logfile of failure stored in:
/mnt/data/builds/feature/z003jsce_fix_trixie/audis/audis-isar-
boards/cphera-rtp/audis-isar-boards/build/tmp/work/audis-trixie-latest-
arm64/audis-image-minimal-cphera-rtp/1.0-
r0/temp/log.do_generate_initramfs.11839\n', "ERROR: Task
(/mnt/data/builds/feature/z003jsce_fix_trixie/audis/audis-isar-
boards/cphera-rtp/audis-isar-boards/build/../audis-isar/recipes-
core/images/audis-image-minimal.bb:do_generate_initramfs) failed with
exit code '1'\n"]
2026-04-16 10:33:17 - ERROR    - Command
"/mnt/data/builds/feature/z003jsce_fix_trixie/audis/audis-isar-
boards/cphera-rtp/audis-isar-boards/isar/bitbake/bin/bitbake -c build
audis-image-minimal" failed with error 1
real	6m27.437s
user	0m1.742s
sys	0m1.589s



On Fri, 2026-04-17 at 13:41 +0200, Stefan Koch wrote:
> On Fri, 2026-04-17 at 12:15 +0200, Jan Kiszka wrote:
> > On 17.04.26 11:34, Stefan Koch wrote:
> > > Ensure that `num_pkgs` is at least 1 to avoid division by zero.
> > > 
> > > Fixes: 88656cc9 ("generate_initramfs: fix progress reporting on
> > > dracut")
> > > 
> > 
> > I think that commit just armed the bug. It was rather introduced by
> > 938dab363006529f0b5296dfbc09ef306fc8c3d7.
> 
> v2 fixes description
> > 
> > > Signed-off-by: Stefan Koch <stefan-koch@siemens.com>
> > > ---
> > >  meta/lib/rootfs_progress.py | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/meta/lib/rootfs_progress.py
> > > b/meta/lib/rootfs_progress.py
> > > index 6feed9df..58d16574 100644
> > > --- a/meta/lib/rootfs_progress.py
> > > +++ b/meta/lib/rootfs_progress.py
> > > @@ -77,7 +77,7 @@ class
> > > InitrdProgressHandler(PkgsProgressHandler):
> > >          m = re.search(r'^Total number of modules: ([0-9]+)',
> > > line)
> > >          if m:
> > >              # in MODULES=most mode, we install ~half of all
> > > modules
> > > -            self._num_pkgs = int(m.group(1)) // 2
> > > +            self._num_pkgs = max(1, int(m.group(1)) // 2)
> > >              self._stage = 'post-prepare'
> > >  
> > >      def process_line(self, line):
> > 
> > Jan

Patch

diff --git a/meta/lib/rootfs_progress.py b/meta/lib/rootfs_progress.py
index 6feed9df..58d16574 100644
--- a/meta/lib/rootfs_progress.py
+++ b/meta/lib/rootfs_progress.py
@@ -77,7 +77,7 @@  class InitrdProgressHandler(PkgsProgressHandler):
         m = re.search(r'^Total number of modules: ([0-9]+)', line)
         if m:
             # in MODULES=most mode, we install ~half of all modules
-            self._num_pkgs = int(m.group(1)) // 2
+            self._num_pkgs = max(1, int(m.group(1)) // 2)
             self._stage = 'post-prepare'
 
     def process_line(self, line):