Skip to content

Commit 0b75e71

Browse files
Fix misc breakages and extract solaris-specific method
Result of a lot of hacking on CI to make it turn green Signed-off-by: Lamont Granquist <[email protected]>
1 parent 4408377 commit 0b75e71

File tree

2 files changed

+60
-17
lines changed

2 files changed

+60
-17
lines changed

lib/omnibus/health_check.rb

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def initialize(project)
6666
def run!
6767
measure("Health check time") do
6868
log.info(log_key) { "Running health on #{project.name}" }
69-
bad_libs, good_libs = case Ohai["platform"]
69+
bad_libs, good_libs = case Ohai["platform"]
7070
when "mac_os_x"
7171
health_check_otool
7272
when "aix"
@@ -76,10 +76,12 @@ def run!
7676
# explicit dependencies on windows. Most dependencies are
7777
# implicit and hence not detected.
7878
log.warn(log_key) { "Skipping dependency health checks on Windows." }
79-
{}
79+
[{}, {}]
80+
when "solaris2"
81+
health_check_solaris
8082
else
8183
health_check_ldd
82-
end
84+
end
8385

8486
unresolved = []
8587
unreliable = []
@@ -167,8 +169,8 @@ def run!
167169
raise HealthCheckFailed
168170
end
169171

170-
unless good_libs.keys.length > 0
171-
raise "Internal error: no good libraries or bad libraries were found"
172+
if good_libs.keys.length == 0 && !windows?
173+
raise "Internal error: no good libraries were found"
172174
end
173175

174176
conflict_map = {}
@@ -297,7 +299,7 @@ def health_check_otool
297299
end
298300
end
299301

300-
return bad_libs, good_libs
302+
[bad_libs, good_libs]
301303
end
302304

303305
#
@@ -311,7 +313,7 @@ def health_check_aix
311313
bad_libs = {}
312314
good_libs = {}
313315

314-
read_shared_libs("find #{project.install_dir}/ -type f | xargs file | grep \"RISC System\" | awk -F: '{print $1}'", "xargs -n 1 ldd") do |line|
316+
read_shared_libs("find #{project.install_dir}/ -type f | xargs file | grep \"XCOFF\" | awk -F: '{print $1}'", "xargs -n 1 ldd") do |line|
315317
case line
316318
when /^(.+) needs:$/
317319
current_library = Regexp.last_match[1]
@@ -326,7 +328,42 @@ def health_check_aix
326328
end
327329
end
328330

329-
return bad_libs, good_libs
331+
[bad_libs, good_libs]
332+
end
333+
334+
#
335+
# Run healthchecks on Solaris.
336+
#
337+
# @return [Hash<String, Hash<String, Hash<String, Int>>>]
338+
# the bad libraries (library_name -> dependency_name -> satisfied_lib_path -> count)
339+
#
340+
def health_check_solaris
341+
current_library = nil
342+
bad_libs = {}
343+
good_libs = {}
344+
345+
read_shared_libs("find #{project.install_dir}/ -type f | xargs file | grep \"ELF\" | awk -F: '{print $1}' | sed -e 's/:$//'", "xargs -n 1 ldd") do |line|
346+
case line
347+
when /^(.+):$/
348+
current_library = Regexp.last_match[1]
349+
log.debug(log_key) { "Analyzing dependencies for #{current_library}" }
350+
when /^\s+(.+) \=\>\s+(.+)( \(.+\))?$/
351+
name = Regexp.last_match[1]
352+
linked = Regexp.last_match[2]
353+
( bad_libs, good_libs ) = check_for_bad_library(bad_libs, good_libs, current_library, name, linked)
354+
when /^\s+(.+) \(.+\)$/
355+
next
356+
when /^\s+statically linked$/
357+
next
358+
when /^\s+not a dynamic executable$/ # ignore non-executable files
359+
else
360+
log.warn(log_key) do
361+
"Line did not match for #{current_library}\n#{line}"
362+
end
363+
end
364+
end
365+
366+
[bad_libs, good_libs]
330367
end
331368

332369
#
@@ -340,7 +377,8 @@ def health_check_ldd
340377
bad_libs = {}
341378
good_libs = {}
342379

343-
read_shared_libs("find #{project.install_dir}/ -type f", "xargs ldd") do |line|
380+
# This algorithm runs on both Linux and FreeBSD and needs to be MANUALLY tested on both
381+
read_shared_libs("find #{project.install_dir}/ -type f", "xargs -n 1 ldd") do |line|
344382
case line
345383
when /^(.+):$/
346384
current_library = Regexp.last_match[1]
@@ -353,11 +391,11 @@ def health_check_ldd
353391
next
354392
when /^\s+statically linked$/
355393
next
356-
when /^\s+libjvm.so/
394+
when /^\s+libjvm.so/ # FIXME: should remove if it doesn't blow up server
357395
next
358-
when /^\s+libjava.so/
396+
when /^\s+libjava.so/ # FIXME: should remove if it doesn't blow up server
359397
next
360-
when /^\s+libmawt.so/
398+
when /^\s+libmawt.so/ # FIXME: should remove if it doesn't blow up server
361399
next
362400
when /^\s+not a dynamic executable$/ # ignore non-executable files
363401
else
@@ -367,7 +405,7 @@ def health_check_ldd
367405
end
368406
end
369407

370-
return bad_libs, good_libs
408+
[bad_libs, good_libs]
371409
end
372410

373411
private
@@ -403,14 +441,13 @@ def whitelist_files
403441
# each line
404442
#
405443
def read_shared_libs(find_command, ldd_command, &output_proc)
406-
407444
#
408445
# construct the list of files to check
409446
#
410447

411448
find_output = shellout!(find_command).stdout.lines
412449

413-
find_output.reject! { |file| IGNORED_ENDINGS.any? { |ending| file.end_with?(ending) } }
450+
find_output.reject! { |file| IGNORED_ENDINGS.any? { |ending| file.end_with?("#{ending}\n") } }
414451

415452
find_output.reject! { |file| IGNORED_SUBSTRINGS.any? { |substr| file.include?(substr) } }
416453

@@ -429,7 +466,7 @@ def read_shared_libs(find_command, ldd_command, &output_proc)
429466
#
430467

431468
# this command will typically fail if the last file isn't a valid lib/binary which happens often
432-
ldd_output = shellout(ldd_command, input: find_output.join("\n")).stdout
469+
ldd_output = shellout(ldd_command, input: find_output.join).stdout
433470

434471
#
435472
# do the output process to determine if the files are good or bad
@@ -501,7 +538,7 @@ def check_for_bad_library(bad_libs, good_libs, current_library, name, linked)
501538
log.debug(log_key) { " -> PASSED: #{name} is either whitelisted or safely provided." }
502539
end
503540

504-
return bad_libs, good_libs
541+
[bad_libs, good_libs]
505542
end
506543
end
507544
end

lib/omnibus/whitelist.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
/libkvm\.so/,
178178
/libprocstat\.so/,
179179
/libmd\.so/,
180+
/libdl\.so/,
180181
].freeze
181182

182183
IGNORED_ENDINGS = %w{
@@ -215,6 +216,7 @@
215216
.lua
216217
.md
217218
.mkd
219+
.mo
218220
.npmignore
219221
.out
220222
.packlist
@@ -229,19 +231,23 @@
229231
.pyo
230232
.rake
231233
.rb
234+
.rbs
232235
.rdoc
233236
.rhtml
234237
.ri
238+
.rpm
235239
.rst
236240
.scss
237241
.sh
238242
.sql
239243
.svg
240244
.toml
245+
.tt
241246
.ttf
242247
.txt
243248
.xml
244249
.yml
250+
COPYING
245251
Gemfile
246252
LICENSE
247253
Makefile

0 commit comments

Comments
 (0)