• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

yast / yast-yast2 / 13440235285

20 Feb 2025 04:40PM UTC coverage: 41.869% (-0.02%) from 41.889%
13440235285

push

github

web-flow
Merge pull request #1316 from yast/agama_kernel_conf

Respect Agama kernel parameters

2 of 4 new or added lines in 1 file covered. (50.0%)

265 existing lines in 40 files now uncovered.

12605 of 30106 relevant lines covered (41.87%)

10.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.75
/library/system/src/modules/Kernel.rb
1
# ***************************************************************************
2
#
3
# Copyright (c) 2002 - 2012 Novell, Inc.
4
# All Rights Reserved.
5
#
6
# This program is free software; you can redistribute it and/or
7
# modify it under the terms of version 2 of the GNU General Public License as
8
# published by the Free Software Foundation.
9
#
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, contact Novell, Inc.
17
#
18
# To contact Novell about this file by physical or electronic mail,
19
# you may find current contact information at www.novell.com
20
#
21
# ***************************************************************************
22
# File:  modules/Kernel.ycp
23
# Package:  Installation
24
# Summary:  Kernel related functions and data
25
# Authors:  Klaus Kaempf <kkaempf@suse.de>
26
#    Arvin Schnell <arvin@suse.de>
27
#
28
# $Id$
29
#
30
# <ul>
31
# <li>determine kernel rpm</li>
32
# <li>determine flags</li>
33
# <li>determine hard reboot</li>
34
# </ul>
35
require "yast"
1✔
36

37
module Yast
1✔
38
  class KernelClass < Module
1✔
39
    include Yast::Logger
1✔
40

41
    # default configuration file for Kernel modules loaded on boot
42
    MODULES_CONF_FILE = "yast.conf".freeze
1✔
43

44
    # directory where configuration for Kernel modules loaded on boot is stored
45
    MODULES_DIR = "/etc/modules-load.d/".freeze
1✔
46

47
    # SCR path for reading/writing Kernel modules
48
    MODULES_SCR = Path.new(".kernel_modules_to_load")
1✔
49

50
    def main
1✔
51
      Yast.import "Pkg"
21✔
52

53
      Yast.import "Arch"
21✔
54
      Yast.import "Mode"
21✔
55
      Yast.import "Linuxrc"
21✔
56
      Yast.import "PackagesProposal"
21✔
57
      Yast.import "Popup"
21✔
58
      Yast.import "Stage"
21✔
59
      Yast.import "FileUtils"
21✔
60
      Yast.import "ProductFeatures"
21✔
61

62
      textdomain "base"
21✔
63

64
      # kernel packages and binary
65

66
      @kernel_probed = false
21✔
67

68
      # the name of the kernel binary below '/boot'.
69
      @binary = "vmlinuz"
21✔
70

71
      # a list kernels to be installed.
72
      @kernel_packages = []
21✔
73

74
      # the final kernel to be installed after verification and
75
      # availability checking
76
      @final_kernel = ""
21✔
77

78
      # kernel commandline
79

80
      @cmdline_parsed = false
21✔
81

82
      # string the kernel vga paramter
83
      @vgaType = ""
21✔
84

85
      # if "suse_update" given in cmdline
86
      @suse_update = false
21✔
87

88
      # string the kernel command line
89
      # Don't write it directly, @see: AddCmdLine()
90
      @cmdLine = ""
21✔
91

92
      # modules loaded on boot
93

94
      # Kernel modules configured to be loaded on boot
95
      @modules_to_load = nil
21✔
96
      @modules_to_load_old = nil
21✔
97

98
      # kernel was reinstalled
99

100
      #  A flag to indicate if a popup informing about the kernel change should be displayed
101
      @inform_about_kernel_change = false
21✔
102

103
      # other variables
104

105
      # fallback map for kernel
106
      @fallbacks = {
107
        "kernel-pae"       => "kernel-default",
21✔
108
        "kernel-desktop"   => "kernel-default",
109
        # fallback for PPC (#302246)
110
        "kernel-iseries64" => "kernel-ppc64"
111
      }
112
    end
113

114
    #---------------------------------------------------------------
115
    # local defines
116

117
    # Hide passwords in command line option string
118
    # @param [String] in input string
119
    # @return [String] outpit string
120
    def HidePasswords(in_)
1✔
121
      ret = ""
25✔
122

123
      if in_.nil?
25✔
124
        ret = nil
×
125
      else
126
        parts = Builtins.splitstring(in_, " ")
25✔
127

128
        first = true
25✔
129
        Builtins.foreach(parts) do |p|
25✔
130
          cmdopt = p
76✔
131
          if Builtins.regexpmatch(p, "^INST_PASSWORD=")
76✔
132
            cmdopt = "INST_PASSWORD=******"
×
133
          elsif Builtins.regexpmatch(p, "^FTPPASSWORD=")
76✔
134
            cmdopt = "FTPPASSWORD=********"
×
135
          end
136
          if first
76✔
137
            first = false
25✔
138
          else
139
            ret = Ops.add(ret, " ")
51✔
140
          end
141
          ret = Ops.add(ret, cmdopt)
76✔
142
        end
143
      end
144

145
      ret
25✔
146
    end
147

148
    # AddCmdLine ()
149
    # @param [String] name of parameter
150
    # @param  string  args of parameter
151
    #
152
    # add "name=args" to kernel boot parameters
153
    # add just "name" if args = ""
154
    # @see #cmdLine
155
    def AddCmdLine(name, arg)
1✔
156
      ParseInstallationKernelCmdline() if !@cmdline_parsed
17✔
157
      @cmdLine = Ops.add(Ops.add(@cmdLine, " "), name)
17✔
158
      @cmdLine = Ops.add(Ops.add(@cmdLine, "="), arg) if arg != ""
17✔
159
      Builtins.y2milestone("cmdLine '%1'", HidePasswords(@cmdLine))
17✔
160
      nil
17✔
161
    end
162

163
    # Parse the installation-time kernel command line
164
    # - the `vga` parameter is separated, see {#GetVgaType}
165
    # - some specific parameters are ignored
166
    # - the rest is passed on to @cmdLine for which {#GetCmdLine} is a reader
167
    # @return [void]
168
    def ParseInstallationKernelCmdline
1✔
169
      @cmdline_parsed = true
8✔
170
      return if !(Stage.initial || Stage.cont)
8✔
171

172
      # Check if /etc/install.inf exists
173
      tmp = if !SCR.Dir(path(".etc.install_inf")).empty?
8✔
174
        SCR.Read(path(".etc.install_inf.Cmdline")).to_s
8✔
175
      # else check if there is agama specific filtered kernel options
NEW
176
      elsif ::File.exist?("/run/agama/cmdline.d/kernel.conf")
×
NEW
177
        WFM.Read(path(".local.string"), "/run/agama/cmdline.d/kernel.conf").to_s
×
178
      else
179
        # not using dedicated agent in order to use the same parser for cmdline
180
        # independently on whether it comes from /proc/cmdline or /etc/install.inf
181
        # use local read as it does not make sense to depend on binding it to chroot
182
        WFM.Read(path(".local.string"), "/proc/cmdline").to_s
×
183
      end
184

185
      Builtins.y2milestone(
8✔
186
        "cmdline from install.inf is: %1",
187
        HidePasswords(tmp)
188
      )
189
      if !tmp.nil?
8✔
190
        # extract extra boot parameters given in installation
191
        ExtractCmdlineParameters(tmp)
8✔
192
      end
193

194
      nil
8✔
195
    end
196

197
    # Get the vga= kernel parameter
198
    # @return [String] the vga= kernel parameter
199
    def GetVgaType
1✔
200
      ParseInstallationKernelCmdline() if !@cmdline_parsed
1✔
201
      @vgaType
1✔
202
    end
203

204
    # Get the kernel command line
205
    # @return [String] the command line
206
    def GetCmdLine
1✔
207
      ParseInstallationKernelCmdline() if !@cmdline_parsed
7✔
208
      @cmdLine
7✔
209
    end
210

211
    # Simple check any graphical desktop was selected
212
    def IsGraphicalDesktop
1✔
213
      # Get patterns set for installation during desktop selection
214
      # (see DefaultDesktop::packages_proposal_ID_patterns for the first argument)
215
      pt = PackagesProposal.GetResolvables("DefaultDesktopPatterns", :pattern)
×
216
      Builtins.contains(pt, "x11")
×
217
    end
218

219
    #---------------------------------------------------------------
220

221
    # specifies limit of memory which can be addressed without pae on 32-bit system
222
    PAE_LIMIT = 3_221_225_472
1✔
223
    # select kernel depending on architecture and system type.
224
    #
225
    # @return [void]
226
    def ProbeKernel
1✔
227
      kernel_desktop_exists = ((Mode.normal || Mode.repair) &&
1✔
228
        Pkg.PkgInstalled("kernel-desktop")) ||
229
        Pkg.PkgAvailable("kernel-desktop")
230
      Builtins.y2milestone(
1✔
231
        "Desktop kernel available: %1",
232
        kernel_desktop_exists
233
      )
234

235
      @kernel_packages = ["kernel-default"]
1✔
236

237
      # add Xen paravirtualized drivers to a full virtualized host
238
      xen = Convert.to_boolean(SCR.Read(path(".probe.is_xen")))
1✔
239
      if xen.nil?
1✔
240
        Builtins.y2warning("XEN detection failed, assuming XEN is NOT running")
×
241
        xen = false
×
242
      end
243

244
      Builtins.y2milestone("Detected XEN: %1", xen)
1✔
245

246
      if Arch.is_uml
1✔
247
        Builtins.y2milestone("ProbeKernel: UML")
×
248
        @kernel_packages = ["kernel-um"]
×
249
      elsif Arch.is_xen
1✔
250
        # kernel-xen contains PAE kernel (since oS11.0)
251
        @kernel_packages = ["kernel-xen"]
×
252
      elsif Arch.i386
1✔
253
        # get flags from WFM /proc/cpuinfo (for pae and tsc tests below)
254

255
        cpuinfo_flags = Convert.to_string(
1✔
256
          SCR.Read(path(".proc.cpuinfo.value.\"0\".\"flags\""))
257
        ) # check only first processor
258
        cpuflags = []
1✔
259

260
        # bugzilla #303842
261
        if cpuinfo_flags
1✔
262
          cpuflags = cpuinfo_flags.empty? ? [] : cpuinfo_flags.split
×
263
        else
264
          Builtins.y2error("Cannot read cpuflags")
1✔
265
          Builtins.y2milestone(
1✔
266
            "Mounted: %1",
267
            SCR.Execute(path(".target.bash_output"), "/usr/bin/mount -l")
268
          )
269
        end
270

271
        # check for "roughly" >= 4GB memory (see bug #40729)
272
        memories = Convert.to_list(SCR.Read(path(".probe.memory")))
1✔
273
        memsize = Ops.get_integer(
1✔
274
          memories,
275
          [0, "resource", "phys_mem", 0, "range"],
276
          0
277
        )
278
        Builtins.y2milestone("Physical memory %1", memsize)
1✔
279

280
        # for memory > 4GB and PAE support we install kernel-pae,
281
        # PAE kernel is needed if NX flag exists as well (bnc#467328)
282
        if (Ops.greater_or_equal(memsize, PAE_LIMIT) ||
1✔
283
            Builtins.contains(cpuflags, "nx")) &&
284
            Builtins.contains(cpuflags, "pae")
285
          Builtins.y2milestone("Kernel switch: PAE detected")
×
286
          if kernel_desktop_exists && IsGraphicalDesktop()
×
287
            @kernel_packages = ["kernel-desktop"]
×
288

289
            # add PV drivers
290
            if xen
×
291
              Builtins.y2milestone("Adding Xen PV drivers: xen-kmp-desktop")
×
292
              @kernel_packages = Builtins.add(
×
293
                @kernel_packages,
294
                "xen-kmp-desktop"
295
              )
296
            end
297
          else
298
            @kernel_packages = ["kernel-pae"]
×
299

300
            # add PV drivers
301
            if xen
×
302
              Builtins.y2milestone("Adding Xen PV drivers: xen-kmp-pae")
×
303
              @kernel_packages = Builtins.add(@kernel_packages, "xen-kmp-pae")
×
304
            end
305
          end
306
        # add PV drivers
307
        elsif xen
1✔
308
          Builtins.y2milestone("Adding Xen PV drivers: xen-kmp-default")
×
309
          @kernel_packages = Builtins.add(@kernel_packages, "xen-kmp-default")
×
310
        end
311
      elsif Arch.x86_64
×
312
        if kernel_desktop_exists && IsGraphicalDesktop()
×
313
          @kernel_packages = ["kernel-desktop"]
×
314
          if xen
×
315
            Builtins.y2milestone("Adding Xen PV drivers: xen-kmp-desktop")
×
316
            @kernel_packages = Builtins.add(@kernel_packages, "xen-kmp-desktop")
×
317
          end
318
        elsif xen
×
319
          Builtins.y2milestone("Adding Xen PV drivers: xen-kmp-default")
×
320
          @kernel_packages = Builtins.add(@kernel_packages, "xen-kmp-default")
×
321
        end
322
      elsif Arch.ppc
×
323
        @binary = "vmlinux"
×
324

325
        @kernel_packages = if Arch.board_iseries
×
326
          ["kernel-iseries64"]
×
327
        elsif Arch.ppc32
×
328
          ["kernel-default"]
×
329
        else
330
          ["kernel-ppc64"]
×
331
        end
332
      elsif Arch.s390
×
333
        @kernel_packages = ["kernel-default"]
×
334
        @binary = "image"
×
335
      end
336

337
      @kernel_probed = true
1✔
338
      Builtins.y2milestone("ProbeKernel determined: %1", @kernel_packages)
1✔
339

340
      nil
1✔
341
    end
342

343
    # Set a custom kernel.
344
    # @param custom_kernels a list of kernel packages
345
    def SetPackages(custom_kernels)
1✔
346
      custom_kernels = deep_copy(custom_kernels)
×
347
      # probe to avoid later probing
348
      ProbeKernel() if !@kernel_probed
×
349
      @kernel_packages = deep_copy(custom_kernels)
×
350

UNCOV
351
      nil
×
352
    end
353

354
    # functinos related to kernel packages
355

356
    # Het the name of kernel binary under /boot
357
    # @return [String] the name of the kernel binary
358
    def GetBinary
1✔
359
      ProbeKernel() if !@kernel_probed
×
360
      @binary
×
361
    end
362

363
    # Get the list of kernel packages
364
    # @return a list of kernel packages
365
    def GetPackages
1✔
366
      ProbeKernel() if !@kernel_probed
1✔
367
      deep_copy(@kernel_packages)
1✔
368
    end
369

370
    # Compute kernel package
371
    # @return [String] selected kernel
372
    def ComputePackage
1✔
373
      packages = GetPackages()
×
374
      the_kernel = Ops.get(packages, 0, "")
×
375
      Builtins.y2milestone("Selecting '%1' as kernel package", the_kernel)
×
376

377
      # Check for provided kernel packages in installed system
378
      if Mode.normal || Mode.repair
×
379
        while the_kernel != "" && !Pkg.PkgInstalled(the_kernel)
×
380
          the_kernel = Ops.get(@fallbacks, the_kernel, "")
×
381
          Builtins.y2milestone("Not provided, falling back to '%1'", the_kernel)
×
382
        end
383
      else
384
        while the_kernel != "" && !Pkg.PkgAvailable(the_kernel)
×
385
          the_kernel = Ops.get(@fallbacks, the_kernel, "")
×
386
          Builtins.y2milestone(
×
387
            "Not available, falling back to '%1'",
388
            the_kernel
389
          )
390
        end
391
      end
392

393
      if the_kernel == ""
×
394
        Builtins.y2warning(
×
395
          "%1 not available, using kernel-default",
396
          @kernel_packages
397
        )
398

399
        @final_kernel = "kernel-default"
×
400
      else
401
        @final_kernel = the_kernel
×
402
      end
403
      @final_kernel
×
404
    end
405

406
    def GetFinalKernel
1✔
407
      ComputePackage() if @final_kernel == ""
×
408
      @final_kernel
×
409
    end
410

411
    # Compute kernel package for the specified base kernel package
412
    # @param [String] base string the base kernel package name (eg. kernel-default)
413
    # @param [Boolean] check_avail boolean if true, additional packages are checked for
414
    #  for being available on the medias before adding to the list
415
    # @return a list of all kernel packages (including the base package) that
416
    #  are to be installed together with the base package
417
    def ComputePackagesForBase(base, _check_avail)
1✔
418
      # NOTE: kernel-*-nongpl packages have been dropped, use base only
419
      ret = [base]
×
420

421
      Builtins.y2milestone("Packages for base %1: %2", base, ret)
×
422
      deep_copy(ret)
×
423
    end
424

425
    # Compute kernel packages
426
    # @return [Array] of selected kernel packages
427
    def ComputePackages
1✔
428
      kernel = ComputePackage()
×
429

430
      ret = ComputePackagesForBase(kernel, true)
×
431

432
      if Ops.greater_than(Builtins.size(@kernel_packages), 1)
×
433
        # get the extra packages
434
        extra_pkgs = Builtins.remove(@kernel_packages, 0)
×
435

436
        # add available extra packages
437
        Builtins.foreach(extra_pkgs) do |pkg|
×
438
          if Pkg.IsAvailable(pkg)
×
439
            ret = Builtins.add(ret, pkg)
×
440
            Builtins.y2milestone("Added extra kernel package: %1", pkg)
×
441
          else
442
            Builtins.y2warning(
×
443
              "Extra kernel package '%1' is not available",
444
              pkg
445
            )
446
          end
447
        end
448
      end
449

450
      Builtins.y2milestone("Computed kernel packages: %1", ret)
×
451

452
      deep_copy(ret)
×
453
    end
454

455
    # functions related to kernel's modules loaded on boot
456

457
    # Resets the internal cache
458
    def reset_modules_to_load
1✔
459
      @modules_to_load = nil
22✔
460
    end
461

462
    # Returns hash of kernel modules to be loaded on boot
463
    # - key is the config file
464
    # - value is list of modules in that particular file
465
    #
466
    # @return [Hash] of modules
467
    def modules_to_load
1✔
468
      read_modules_to_load if @modules_to_load.nil?
42✔
469

470
      @modules_to_load
42✔
471
    end
472

473
    # Returns whether the given kernel module is included in list of modules
474
    # to be loaded on boot
475
    #
476
    # @param [String] kernel module
477
    # @return [Boolean] whether the given module is in the list
478
    def module_to_be_loaded?(kernel_module)
1✔
479
      modules_to_load.values.any? { |m| m.include?(kernel_module) }
138✔
480
    end
481

482
    # Add a kernel module to the list of modules to load after boot
483
    # @param string module name
484
    def AddModuleToLoad(name)
1✔
485
      Builtins.y2milestone("Adding module to be loaded at boot: %1", name)
4✔
486

487
      @modules_to_load[MODULES_CONF_FILE] << name unless module_to_be_loaded?(name)
4✔
488
    end
489

490
    # Remove a kernel module from the list of modules to load after boot
491
    # @param [String] name string the name of the module
492
    def RemoveModuleToLoad(name)
1✔
493
      modules_to_load
3✔
494

495
      return true unless module_to_be_loaded?(name)
3✔
496

497
      Builtins.y2milestone("Removing module to be loaded at boot: %1", name)
2✔
498
      @modules_to_load.each do |_key, val|
2✔
499
        val.delete(name)
8✔
500
      end
501
    end
502

503
    # SaveModuleToLoad ()
504
    # save the sysconfig variable to /etc/modules-load.d/*.conf configuration files
505
    # @return [Boolean] true on success
506
    def SaveModulesToLoad
1✔
507
      modules_to_load
2✔
508

509
      unless FileUtils.Exists(MODULES_DIR)
2✔
510
        log.warn "Directory #{MODULES_DIR} does not exist, creating"
1✔
511

512
        unless SCR::Execute(path(".target.mkdir"), MODULES_DIR)
1✔
513
          log.error "Cannot create directory #{MODULES_DIR}"
1✔
514
          return false
1✔
515
        end
516
      end
517

518
      success = true
1✔
519

520
      @modules_to_load.each do |file, modules|
1✔
521
        # The content hasn't changed
522
        next if modules.sort == @modules_to_load_old[file].sort
4✔
523

524
        if !register_modules_agent(file)
2✔
525
          Builtins.y2error("Cannot register new SCR agent for #{file_path} file")
×
526
          success = false
×
527
          next
×
528
        end
529

530
        SCR::Write(MODULES_SCR, modules)
2✔
531
        SCR.UnregisterAgent(MODULES_SCR)
2✔
532
      end
533

534
      success
1✔
535
    end
536

537
    # kernel was reinstalled stuff
538

539
    #  Set inform_about_kernel_change.
540
    def SetInformAboutKernelChange(value)
1✔
541
      @inform_about_kernel_change = value
×
542

UNCOV
543
      nil
×
544
    end
545

546
    #  Get inform_about_kernel_change.
547
    def GetInformAboutKernelChange
1✔
548
      @inform_about_kernel_change
1✔
549
    end
550

551
    #  Display popup about new kernel that was installed
552
    def InformAboutKernelChange
1✔
553
      if GetInformAboutKernelChange()
1✔
554
        # inform the user that he/she has to reboot to activate new kernel
555
        Popup.Message(_("Reboot your system\nto activate the new kernel.\n"))
×
556
      end
557
      @inform_about_kernel_change
1✔
558
    end
559

560
    # gets if YaST should propose hibernation aka Kernel resume parameter
561
    # @return [Boolean] true if hibernation should be proposed
562
    def propose_hibernation?
1✔
563
      # Do not support s390. (jsc#SLE-6926)
564
      return false unless Arch.i386 || Arch.x86_64
2✔
565

566
      true
1✔
567
    end
568

569
    publish function: :AddCmdLine, type: "void (string, string)"
1✔
570
    publish function: :GetVgaType, type: "string ()"
1✔
571
    publish function: :GetCmdLine, type: "string ()"
1✔
572
    publish function: :ProbeKernel, type: "void ()"
1✔
573
    publish function: :SetPackages, type: "void (list <string>)"
1✔
574
    publish function: :GetBinary, type: "string ()"
1✔
575
    publish function: :GetPackages, type: "list <string> ()"
1✔
576
    publish function: :ComputePackage, type: "string ()"
1✔
577
    publish function: :GetFinalKernel, type: "string ()"
1✔
578
    publish function: :ComputePackagesForBase, type: "list <string> (string, boolean)"
1✔
579
    publish function: :ComputePackages, type: "list <string> ()"
1✔
580
    publish function: :SetInformAboutKernelChange, type: "void (boolean)"
1✔
581
    publish function: :GetInformAboutKernelChange, type: "boolean ()"
1✔
582
    publish function: :InformAboutKernelChange, type: "boolean ()"
1✔
583

584
    # Handling for Kernel modules loaded on boot
585
    publish function: :AddModuleToLoad, type: "void (string)"
1✔
586
    publish function: :RemoveModuleToLoad, type: "void (string)"
1✔
587
    publish function: :SaveModulesToLoad, type: "boolean ()"
1✔
588
    publish function: :reset_modules_to_load, type: "void ()"
1✔
589
    publish function: :modules_to_load, type: "map <string, list> ()"
1✔
590

591
  private
1✔
592

593
    # Registers new SCR agent for a file given as parameter
594
    #
595
    # @param [String] file name in directory defined in MODULES_DIR
596
    def register_modules_agent(file_name)
1✔
597
      full_path = File.join(MODULES_DIR, file_name)
27✔
598

599
      SCR::RegisterAgent(
27✔
600
        MODULES_SCR,
601
        term(
602
          :ag_anyagent,
603
          term(
604
            :Description,
605
            term(
606
              :File,
607
              full_path
608
            ),
609
            # Comments
610
            "#\n",
611
            # Read-only?
612
            false,
613
            term(
614
              :List,
615
              term(:String, "^\n"),
616
              "\n"
617
            )
618
          )
619
        )
620
      )
621
    end
622

623
    # Loads the current configuration of Kernel modules
624
    # to be loaded on boot to the internal cache
625
    #
626
    # @return [Hash] with the configuration
627
    def read_modules_to_load
1✔
628
      @modules_to_load = { MODULES_CONF_FILE => [] }
10✔
629

630
      if FileUtils.Exists(MODULES_DIR)
10✔
631
        config_files = SCR::Read(path(".target.dir"), MODULES_DIR)
8✔
632
      else
633
        log.error "Cannot read modules to load on boot, directory #{MODULES_DIR} does not exist"
2✔
634
      end
635

636
      if config_files.nil?
10✔
637
        log.error "Cannot read config files from #{MODULES_DIR}"
2✔
638
        config_files = []
2✔
639
      end
640

641
      config_files.each do |file_name|
10✔
642
        next unless file_name =~ /^.+\.conf$/
33✔
643

644
        if !register_modules_agent(file_name)
25✔
645
          log.error "Cannot register new SCR agent for #{file_path} file"
×
646
          next
×
647
        end
648

649
        @modules_to_load[file_name] = SCR::Read(MODULES_SCR)
25✔
650
        SCR.UnregisterAgent(MODULES_SCR)
25✔
651
      end
652

653
      @modules_to_load_old = deep_copy(@modules_to_load)
10✔
654
      @modules_to_load
10✔
655
    end
656

657
    # @param [String] line to parse
658
    # @return [Array<String>] line splitted to individual params, respecting quotes there
659
    def list_of_params(line)
1✔
660
      line = line.delete("\n")
8✔
661
      cmdlist = []
8✔
662
      parse_index = 0
8✔
663
      in_quotes = false
8✔
664
      after_backslash = false
8✔
665
      current_param = ""
8✔
666
      while parse_index < line.size
8✔
667
        current_char = line[parse_index]
282✔
668
        in_quotes = !in_quotes if current_char == "\"" && !after_backslash
282✔
669
        if current_char == " " && !in_quotes
282✔
670
          cmdlist << current_param
18✔
671
          current_param = ""
18✔
672
        else
673
          current_param << current_char
264✔
674
        end
675
        # For the in-kernel parser, a backslash is a regular character.
676
        # For this parser, it is a "stupid escape": the first backslash
677
        # does not escape the second one.
678
        after_backslash = current_char == "\\"
282✔
679
        parse_index += 1
282✔
680
      end
681
      cmdlist << current_param
8✔
682
    end
683

684
    S390_ZIPL_ARGS = ["User", "init", "ramdisk_size"].freeze
1✔
685
    # constructs list of keys to discard from command line
686
    # @param [Array<String>] list of command line entries
687
    # @return [Array<String>] list of keys to discard
688
    def params_to_discard(cmdlist)
1✔
689
      discardlist = []
8✔
690
      # some systems (pseries) can autodetect the serial console
691
      if cmdlist.include?("AUTOCONSOLE")
8✔
692
        # NOTE: `console` is the only value that depends on the input argument.
693
        discardlist << "console"
×
694
        discardlist << "AUTOCONSOLE"
×
695
      end
696

697
      # add special key filtering for s390
698
      # bnc#462276 Extraneous parameters in /etc/zipl.conf from the installer
699
      discardlist.concat(S390_ZIPL_ARGS) if Arch.s390
8✔
700

701
      # get rid of live-installer-specific parameters
702
      discardlist.push("initrd", "ramdisk_size", "ramdisk_blocksize", "liveinstall", "splash", "quiet", "lang") if Mode.live_installation
8✔
703

704
      # TODO: is it still needed?
705
      # backdoor to re-enable update on UL/SLES
706
      if cmdlist.include?("suse_update")
8✔
707
        discardlist << "suse_update"
×
708
        @suse_update = true
×
709
      end
710

711
      discardlist
8✔
712
    end
713

714
    # @param  [String] cmdline to parse
715
    #
716
    # @return  [void]
717
    # Filters out yast2 specific boot parameters and sets
718
    # Parameters to the important cmdline parts.
719
    def ExtractCmdlineParameters(line)
1✔
720
      return unless line
8✔
721

722
      # list of parameters to be discarded (yast internals)
723
      cmdlist = list_of_params(line)
8✔
724

725
      discardlist = params_to_discard(cmdlist)
8✔
726

727
      cmdlist.each do |parameter|
8✔
728
        next unless parameter
26✔
729
        next if parameter.empty?
26✔
730

731
        key, value = parameter.split("=", 2)
22✔
732
        next unless key
22✔
733

734
        value ||= ""
22✔
735
        next if discardlist.include?(key)
22✔
736

737
        if key == "vga"
19✔
738
          if value.match?(/^(((0x)?\h+)|(ask)|(ext)|(normal))$/)
2✔
739
            @vgaType = value
2✔
740
          else
741
            Builtins.y2warning("Incorrect VGA kernel parameter: %1", value)
×
742
          end
743
        else
744
          AddCmdLine(key, value)
17✔
745
        end
746
      end
747

748
      nil
8✔
749
    end
750
  end
751

752
  Kernel = KernelClass.new
1✔
753
  Kernel.main
1✔
754
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc