Skip to content

Commit

Permalink
🐛 fixes for suse linux (#1800)
Browse files Browse the repository at this point in the history
Migrate #1469 and other
follow-on PRs. I ran a diff for `sysv.go` and migrated a few more things
from latest v8.

Fixes #1475

Signed-off-by: Dominik Richter <[email protected]>
  • Loading branch information
arlimus authored Sep 20, 2023
1 parent 6497412 commit a3e8dfa
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion providers/os/resources/packages/rpm_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (spm *SusePkgManager) Available() (map[string]PackageUpdate, error) {
if spm.isStaticAnalysis() {
return spm.staticAvailable()
}
cmd, err := spm.conn.RunCommand("zypper --xmlout list-updates")
cmd, err := spm.conn.RunCommand("zypper -n --xmlout list-updates")
if err != nil {
log.Debug().Err(err).Msg("mql[packages]> could not read package updates")
return nil, fmt.Errorf("could not read package update list")
Expand Down
2 changes: 1 addition & 1 deletion providers/os/resources/packages/rpm_updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type zypper struct {
}

// for Suse, updates are package updates
// parses the output of `zypper --xmlout list-updates`
// parses the output of `zypper -n --xmlout list-updates`
func ParseZypperUpdates(input io.Reader) (map[string]PackageUpdate, error) {
pkgs := map[string]PackageUpdate{}
zypper, err := ParseZypper(input)
Expand Down
2 changes: 1 addition & 1 deletion providers/os/resources/packages/rpm_updates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestZypperUpdateParser(t *testing.T) {
if err != nil {
t.Fatal(err)
}
c, err := mock.RunCommand("zypper --xmlout list-updates")
c, err := mock.RunCommand("zypper -n --xmlout list-updates")
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions providers/os/resources/packages/testdata/updates_zypper.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[commands."zypper --xmlout list-updates"]
[commands."zypper -n --xmlout list-updates"]
stdout = """<?xml version='1.0'?>
<stream>
<message type="info">Loading repository data...</message>
Expand Down Expand Up @@ -246,7 +246,7 @@ drop-in replacement for sysvinit.</description>
</stream>
"""

[commands."zypper --xmlout list-updates -t patch"]
[commands."zypper -n --xmlout list-updates -t patch"]
stdout = """<?xml version='1.0'?>
<stream>
<progress id="raw-refresh" name="Retrieving repository &apos;NON OSS&apos; metadata" value="0"/>
Expand Down
22 changes: 15 additions & 7 deletions providers/os/resources/services/sysv.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/rs/zerolog/log"
"go.mondoo.com/cnquery/providers/os/connection/shared"
"go.mondoo.com/cnquery/utils/stringx"
)

type SysVServiceManager struct {
Expand All @@ -35,21 +36,28 @@ func (s *SysVServiceManager) List() ([]*Service, error) {
return nil, err
}

// eg. we ignore the following run levels since `service halt status` may shutdown the system
ignored := []string{"boot", "boot.local", "functions", "halt", "halt.local", "killall", "rc", "reboot", "shutdown", "single", "skeleton", ".depend.boot", ".depend.start", ".depend.stop"}
statusServices := []string{}
for i := range services {
service := services[i]
if stringx.Contains(ignored, service) {
continue
}
statusServices = append(statusServices, service)
}

// 3. mimic `service --status-all` by running `service x status` for each detected service
running, err := s.running(services)
running, err := s.running(statusServices)
if err != nil {
return nil, err
}

// aggregate data into service struct
res := []*Service{}

for i := range services {
service := services[i]

if service == "functions" || service == "killall" || service == "halt" {
continue
}
for i := range statusServices {
service := statusServices[i]

srv := &Service{
Name: service,
Expand Down

0 comments on commit a3e8dfa

Please sign in to comment.