Module: Yast::Y2StartHelpers
- Defined in:
- src/ruby/yast/y2start_helpers.rb
Constant Summary collapse
- RES_CLIENT_RESULT =
client returned special result, this is used as offset (or as generic error)
16
- RES_OK =
yast succeed
0
- FAILED_SYMBOLS =
Symbols representing failure
[:abort, :cancel]
- LOG_LOCATIONS =
["/var/log/YaST2/signal", "y2signal.log"]
Class Method Summary collapse
-
.application_title(client_name) ⇒ Object
Returns application title string.
-
.config_env ⇒ Object
Configure global environment for YaST.
-
.generate_exit_code(value) ⇒ Object
transform various ruby objects to exit code.
- .help ⇒ Object
-
.parse_arguments(args) ⇒ Object
Parses ARGV of y2start.
-
.redirect_scr(target) ⇒ Integer
Open a new SCR instance with chroot.
-
.setup_signals ⇒ Object
so how works signals in ruby version? It logs what we know about signal and then continue with standard ruby handler, which raises SignalException that can be processed.
Class Method Details
.application_title(client_name) ⇒ Object
Returns application title string
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'src/ruby/yast/y2start_helpers.rb', line 92 def self.application_title(client_name) # do not fail if gethostname failed hostname = Socket.gethostname rescue "" hostname = "" if hostname == "(none)" hostname = " @ #{hostname}" unless hostname.empty? if is_s390 # e.g. stdout "2964 = z13 IBM z13" transfered into "IBM z13" arch_array = read_values.split("=") arch_array.shift if arch_array.size > 1 architecture = arch_array.join(' ').strip arch_array = architecture.split(' ') arch_array.shift if arch_array.size > 1 architecture = arch_array.join(' ') if !Yast::UI.TextMode # Show the S390 architecutue in the QT banner only. # The environment variable YAST_BANNER will be read and shown # in libyui-qt. ENV["YAST_BANNER"] = architecture architecture = "" end else architecture = "" end left_title = "YaST2 - #{client_name}#{hostname}" left_title + architecture.rjust(78-left_title.size) end |
.config_env ⇒ Object
Configure global environment for YaST
Currently it only sets values for $PATH and $GODEBUG.
By configuring $PATH, it ensures that correct external programs are executed when relative paths are given, so possible CVEs are avoided when running YaST.
$GODEBUG is configured to enable CN (Common Name) matching in SSL certificates used by Go programs (suseconnect-ng used by registration). See https://bugzilla.suse.com/show_bug.cgi?id=1195220
Note that forked processes will inherit the environment configuration, for example when executing commands via SCR or Cheetah.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'src/ruby/yast/y2start_helpers.rb', line 19 def self.config_env ENV["PATH"] = "/sbin:/usr/sbin:/usr/bin:/bin" # Note: this setting was removed in go-1.17 (https://go.dev/doc/go1.17), # SLE15 uses go-1.16 if ENV["GODEBUG"] # check if already enabled if !ENV["GODEBUG"].include?("x509ignoreCN=0") # append to existing settings ENV["GODEBUG"] = "#{ENV["GODEBUG"]},x509ignoreCN=0" end else ENV["GODEBUG"] = "x509ignoreCN=0" end end |
.generate_exit_code(value) ⇒ Object
transform various ruby objects to exit code. Useful to detection if YaST process failed and in CLI
139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'src/ruby/yast/y2start_helpers.rb', line 139 def self.generate_exit_code(value) case value when nil, true RES_OK when false RES_CLIENT_RESULT when Integer RES_CLIENT_RESULT + value when Symbol FAILED_SYMBOLS.include?(value) ? RES_CLIENT_RESULT : RES_OK else RES_OK end end |
.help ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'src/ruby/yast/y2start_helpers.rb', line 57 def self.help "Usage: y2start [GenericOpts] Client [ClientOpts] Server " \ "[Specific ServerOpts]\n" \ "\n" \ "GenericOptions are:\n" \ " -h --help : Sprint this help\n" \ "\n" \ "ClientOptions are:\n" \ " -a --arg : add argument for client. Can be used multiple times.\n" \ "\n" \ "Specific ServerOptions are any options passed on unevaluated.\n" \ "\n" \ "Examples:\n" \ "y2start installation qt\n" \ " Start binary y2start with intallation.ycp as client and qt as server\n" \ "y2start installation -a initial qt\n" \ " Provide parameter initial for client installation\n" \ "y2start installation qt -geometry 800x600\n" \ " Provide geometry information as specific server options\n" end |
.parse_arguments(args) ⇒ Object
Parses ARGV of y2start. it returns map with keys:
- :generic_options [Hash]
- :client_name [String]
- :client_options [Hash] always contains
params:
with Array of client arguments - :server_name [String]
- :server_options Array
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'src/ruby/yast/y2start_helpers.rb', line 43 def self.parse_arguments(args) ret = {} ret[:generic_options] = (args) # for --help early quit as other argument are ignored return ret if ret[:generic_options][:help] ret[:client_name] = args.shift or raise "Missing client name." ret[:client_options] = (args) ret[:server_name] = args.shift or raise "Missing server name." ret[:server_options] = args ret end |
.redirect_scr(target) ⇒ Integer
Open a new SCR instance with chroot
124 125 126 127 128 129 |
# File 'src/ruby/yast/y2start_helpers.rb', line 124 def self.redirect_scr(target) old_handle = Yast::WFM.SCRGetDefault handle = Yast::WFM.SCROpen("chroot=#{target}:scr", false) Yast::WFM.SCRSetDefault(handle) old_handle end |
.setup_signals ⇒ Object
so how works signals in ruby version? It logs what we know about signal and then continue with standard ruby handler, which raises SignalException that can be processed. If it is not catched, it show popup asking for report bug.
82 83 84 85 86 87 88 89 |
# File 'src/ruby/yast/y2start_helpers.rb', line 82 def self.setup_signals Signal.trap("PIPE", "IGNORE") # SEGV, ILL and FPE is reserved, so cannot be set ["HUP", "INT", "QUIT", "ABRT", "TERM"].each do |name| Signal.trap(name) { signal_handler(name) } end end |