Skip to content

Commit 67ca751

Browse files
authored
fix: handle invalid characters in zlogin for alma9
1 parent 8d03862 commit 67ca751

File tree

1 file changed

+34
-21
lines changed

1 file changed

+34
-21
lines changed

lib/vagrant-zones/driver.rb

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,45 +1219,58 @@ def setup(uii)
12191219
def zloginboot(uii)
12201220
name = @machine.name
12211221
config = @machine.provider_config
1222-
lcheck = config.lcheck
1223-
lcheck = ':~' if config.lcheck.nil?
1224-
alcheck = config.alcheck
1225-
alcheck = 'login:' if config.alcheck.nil?
1226-
bstring = ' OK ' if config.booted_string.nil?
1227-
bstring = config.booted_string unless config.booted_string.nil?
1228-
zunlockboot = 'Importing ZFS root pool'
1229-
zunlockboot = config.zunlockboot unless config.zunlockboot.nil?
1230-
zunlockbootkey = config.zunlockbootkey unless config.zunlockbootkey.nil?
1222+
lcheck = config.lcheck || ':~'
1223+
alcheck = config.alcheck || 'login:'
1224+
bstring = config.booted_string || ' OK '
1225+
zunlockboot = config.zunlockboot || 'Importing ZFS root pool'
1226+
zunlockbootkey = config.zunlockbootkey
12311227
pcheck = 'Password:'
1228+
12321229
uii.info(I18n.t('vagrant_zones.automated-zlogin'))
1230+
12331231
PTY.spawn("pfexec zlogin -C #{name}") do |zlogin_read, zlogin_write, pid|
12341232
Timeout.timeout(config.setup_wait) do
12351233
rsp = []
12361234

12371235
loop do
1238-
zlogin_read.expect(/\r\n/) { |line| rsp.push line }
1239-
uii.info(rsp[-1]) if config.debug_boot
1240-
sleep(2) if rsp[-1].to_s.match(/#{zunlockboot}/)
1241-
zlogin_write.printf("#{zunlockbootkey}\n") if rsp[-1].to_s.match(/#{zunlockboot}/)
1242-
zlogin_write.printf("\n") if rsp[-1].to_s.match(/#{zunlockboot}/)
1243-
uii.info(I18n.t('vagrant_zones.automated-zbootunlock')) if rsp[-1].to_s.match(/#{zunlockboot}/)
1244-
sleep(15) if rsp[-1].to_s.match(/#{bstring}/)
1245-
zlogin_write.printf("\n") if rsp[-1].to_s.match(/#{bstring}/)
1246-
break if rsp[-1].to_s.match(/#{bstring}/)
1236+
begin
1237+
zlogin_read.expect(/\r\n/) do |line|
1238+
line = line.first if line.is_a?(Array)
1239+
encoded_line = line.to_s.encode('UTF-8', invalid: :replace, undef: :replace, replace: '')
1240+
rsp.push encoded_line unless encoded_line.empty?
1241+
end
1242+
rescue ArgumentError => e
1243+
next
1244+
end
1245+
1246+
uii.info(rsp[-1]) if config.debug_boot && !rsp.empty?
1247+
1248+
if !rsp.empty? && rsp[-1].match(/#{zunlockboot}/)
1249+
sleep(2)
1250+
zlogin_write.printf("#{zunlockbootkey}\n") if zunlockbootkey
1251+
zlogin_write.printf("\n")
1252+
uii.info(I18n.t('vagrant_zones.automated-zbootunlock'))
1253+
end
1254+
1255+
if !rsp.empty? && rsp[-1].match(/#{bstring}/)
1256+
sleep(15)
1257+
zlogin_write.printf("\n")
1258+
break
1259+
end
12471260
end
1248-
1261+
12491262
if zlogin_read.expect(/#{alcheck}/)
12501263
uii.info(I18n.t('vagrant_zones.automated-zlogin-user'))
12511264
zlogin_write.printf("#{user(@machine)}\n")
12521265
sleep(config.login_wait)
12531266
end
1254-
1267+
12551268
if zlogin_read.expect(/#{pcheck}/)
12561269
uii.info(I18n.t('vagrant_zones.automated-zlogin-pass'))
12571270
zlogin_write.printf("#{vagrantuserpass(@machine)}\n")
12581271
sleep(config.login_wait)
12591272
end
1260-
1273+
12611274
zlogin_write.printf("\n")
12621275
if zlogin_read.expect(/#{lcheck}/)
12631276
uii.info(I18n.t('vagrant_zones.automated-zlogin-root'))

0 commit comments

Comments
 (0)