• 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

38.46
/library/systemd/src/modules/Systemd.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/Systemd.ycp
23
# Package:  yast2
24
# Summary:  systemd configuration
25
# Authors:  Ladislav Slezák <lslezak@suse.cz>
26
#
27
# $Id$
28
#
29
# Functions for setting systemd options
30
require "yast"
1✔
31
require "shellwords"
1✔
32

33
module Yast
1✔
34
  class SystemdClass < Module
1✔
35
    def main
1✔
36
      Yast.import "FileUtils"
1✔
37

38
      @systemd_path = "/usr/lib/systemd/systemd"
1✔
39
      @default_target_symlink = "/etc/systemd/system/default.target"
1✔
40
      @systemd_targets_dir = "/usr/lib/systemd/system"
1✔
41

42
      textdomain "base"
1✔
43
    end
44

45
    # Check whether the systemd package is installed
46
    def Installed
1✔
47
      # check for systemd executable
48
      Ops.greater_or_equal(SCR.Read(path(".target.size"), @systemd_path), 0)
×
49
    end
50

51
    # Check whether systemd init is currently running
52
    # @return boolean true if systemd init is running
53
    def Running
1✔
54
      WFM.Read(path(".local.string"), "/proc/1/comm")&.chomp == "systemd"
×
55
    end
56

57
    # Set default runlevel for systemd (assumes systemd is installed)
58
    # @param [Integer] runlevel the default runlevel to set (integer in range 0..6)
59
    # @return [Boolean] true on success
60
    def SetDefaultRunlevel(selected_runlevel)
1✔
61
      if selected_runlevel.nil? || Ops.less_than(selected_runlevel, 0) ||
×
62
          Ops.greater_than(selected_runlevel, 6)
63
        Builtins.y2error(
×
64
          "Invalid default runlevel (must be in range 0..6): %1",
65
          selected_runlevel
66
        )
67
        return false
×
68
      end
69

70
      Builtins.y2milestone(
×
71
        "Setting systemd default runlevel: %1",
72
        selected_runlevel
73
      )
74

75
      # create symbolic link, -f to rewrite the current link (if exists)
76
      command = Builtins.sformat(
×
77
        "/bin/ln -s -f %1/runlevel%2.target %3",
78
        @systemd_targets_dir.shellescape,
79
        selected_runlevel.to_s.shellescape,
80
        @default_target_symlink.shellescape
81
      )
82
      Builtins.y2milestone("Executing: %1", command)
×
83

84
      res = Convert.to_integer(SCR.Execute(path(".target.bash"), command))
×
85
      Builtins.y2debug("Result: %1", res)
×
86

87
      ret = res == 0
×
88
      Builtins.y2milestone("Default runlevel set: %1", ret)
×
89

90
      ret
×
91
    end
92

93
    # Get the default runlevel for systemd
94
    # @return [Fixnum] the default runlevel (or nil on error or unknown runlevel)
95
    def DefaultRunlevel
1✔
96
      target = Convert.to_string(
×
97
        SCR.Read(path(".target.symlink"), @default_target_symlink)
98
      )
99
      Builtins.y2milestone("Default symlink points to: %1", target)
×
100

101
      if target.nil?
×
102
        Builtins.y2error(
×
103
          "Cannot read symlink target of %1",
104
          @default_target_symlink
105
        )
106
        return nil
×
107
      end
108

109
      # check runlevel<number>.target
110
      runlevel = Builtins.regexpsub(target, "/runlevel([0-6]).target$", "\\1")
×
111
      if !runlevel.nil?
×
112
        ret = Builtins.tointeger(runlevel)
×
113
        Builtins.y2milestone("Default runlevel: %1", ret)
×
114

115
        return ret
×
116
      end
117

118
      # check runlevel specified by a symbolic name
119
      # (this is written in systemd documentation how to change the default,
120
      # YaST should also support this style in case users do a manual change)
121
      runlevel_name = Builtins.regexpsub(target, "/([^/]*).target$", "\\1")
×
122
      if !runlevel_name.nil?
×
123
        Builtins.y2milestone(
×
124
          "Detected default runlevel name: %1",
125
          runlevel_name
126
        )
127
        mapping = {
×
128
          "poweroff"   => 0,
129
          "rescue"     => 1,
130
          # this is ambiguous, runlevels 2 and 4 also point to multi-user
131
          # assume runlevel 3 in this case (the most probable)
132
          "multi-user" => 3,
133
          "graphical"  => 5,
134
          "reboot"     => 6
135
        }
136

137
        ret = Ops.get(mapping, runlevel_name)
×
138
        Builtins.y2milestone("Default runlevel: %1", ret)
×
139

140
        return ret
×
141
      end
142

143
      Builtins.y2error("Cannot determine the default runlevel")
×
UNCOV
144
      nil
×
145
    end
146

147
    publish function: :Installed, type: "boolean ()"
1✔
148
    publish function: :Running, type: "boolean ()"
1✔
149
    publish function: :SetDefaultRunlevel, type: "boolean (integer)"
1✔
150
    publish function: :DefaultRunlevel, type: "integer ()"
1✔
151
  end
152

153
  Systemd = SystemdClass.new
1✔
154
  Systemd.main
1✔
155
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