Skip to content

Commit 67268af

Browse files
authored
fix: rpm-ostree updater segfault, error reporting (#65)
* fix: rpm-ostree updater segfault, error reporting * chore: implement small suggestions
1 parent 69c3c58 commit 67268af

File tree

4 files changed

+30
-33
lines changed

4 files changed

+30
-33
lines changed

cmd/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func Update(cmd *cobra.Command, args []string) {
111111

112112
mainSystemDriver, mainSystemDriverConfig, _, _ := system.InitializeSystemDriver(*initConfiguration)
113113

114-
enableUpd, err := false, nil
114+
enableUpd, err := true, nil
115115
// if there's no force flag, check for updates
116116
if !force {
117117
enableUpd, err = mainSystemDriver.Check()

drv/rpmostree/rpmostree.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,13 @@ func (up RpmOstreeUpdater) Outdated() (bool, error) {
5757

5858
func (up RpmOstreeUpdater) Update() (*[]CommandOutput, error) {
5959
var finalOutput = []CommandOutput{}
60-
var cmd *exec.Cmd
6160
binaryPath := up.BinaryPath
61+
6262
cli := []string{binaryPath, "upgrade"}
63+
up.Config.Logger.Debug("Executing update", slog.Any("cli", cli))
64+
cmd := exec.Command(cli[0], cli[1:]...)
6365
out, err := session.RunLog(up.Config.Logger, slog.LevelDebug, cmd)
66+
6467
tmpout := CommandOutput{}.New(out, err)
6568
tmpout.Cli = cli
6669
tmpout.Failure = err != nil

drv/system/system.go

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ func (up SystemUpdater) Update() (*[]CommandOutput, error) {
7373
var finalOutput = []CommandOutput{}
7474
var cmd *exec.Cmd
7575
binaryPath := up.BinaryPath
76+
7677
cli := []string{binaryPath, "upgrade", "--quiet"}
7778
up.Config.Logger.Debug("Executing update", slog.Any("cli", cli))
7879
cmd = exec.Command(cli[0], cli[1:]...)
7980
out, err := session.RunLog(up.Config.Logger, slog.LevelDebug, cmd)
81+
8082
tmpout := CommandOutput{}.New(out, err)
8183
tmpout.Failure = err != nil
8284
tmpout.Context = "System Update"
@@ -121,55 +123,44 @@ func (up SystemUpdater) Check() (bool, error) {
121123
return updateNecessary, nil
122124
}
123125

124-
func BootcCompatible(binaryPath string) (bool, error) {
126+
func BootcCompatible(binaryPath string) bool {
125127
cmd := exec.Command(binaryPath, "status", "--format=json")
126128
out, err := cmd.CombinedOutput()
127129
if err != nil {
128-
return false, nil
130+
return false
129131
}
130132
var status bootcStatus
131133
err = json.Unmarshal(out, &status)
132134
if err != nil {
133-
return false, nil
135+
return false
134136
}
135-
return !(status.Status.Booted.Incompatible || status.Status.Staged.Incompatible), nil
137+
return !(status.Status.Booted.Incompatible || status.Status.Staged.Incompatible)
136138
}
137139

138140
func InitializeSystemDriver(initConfiguration UpdaterInitConfiguration) (SystemUpdateDriver, DriverConfiguration, bool, error) {
139-
var enableUpd bool = true
140141

141142
rpmOstreeUpdater, err := rpmostree.RpmOstreeUpdater{}.New(initConfiguration)
142-
if err != nil {
143-
enableUpd = false
144-
}
145143

146144
systemUpdater, err := SystemUpdater{}.New(initConfiguration)
147-
if err != nil {
148-
enableUpd = false
149-
}
150145

151-
isBootc, err := BootcCompatible(systemUpdater.BinaryPath)
152-
if err != nil {
153-
isBootc = false
154-
}
146+
isBootc := BootcCompatible(systemUpdater.BinaryPath)
155147

156148
if !isBootc {
157149
slog.Debug("Using rpm-ostree fallback as system driver")
158150
}
159151

160152
// The system driver to be applied needs to have the correct "enabled" value since it will NOT update from here onwards.
161-
systemUpdater.Config.Enabled = systemUpdater.Config.Enabled && isBootc && enableUpd
162-
rpmOstreeUpdater.Config.Enabled = rpmOstreeUpdater.Config.Enabled && !isBootc && enableUpd
153+
systemUpdater.Config.Enabled = systemUpdater.Config.Enabled && isBootc
154+
155+
rpmOstreeUpdater.Config.Enabled = rpmOstreeUpdater.Config.Enabled && !isBootc
163156

164-
var finalConfig DriverConfiguration
157+
// var finalConfig DriverConfiguration
165158
var mainSystemDriver SystemUpdateDriver
166159
if isBootc {
167-
mainSystemDriver = &systemUpdater
168-
finalConfig = systemUpdater.Config
169-
} else {
170-
mainSystemDriver = &rpmOstreeUpdater
171-
finalConfig = systemUpdater.Config
160+
mainSystemDriver = systemUpdater
161+
return mainSystemDriver, systemUpdater.Config, isBootc, err
172162
}
163+
mainSystemDriver = rpmOstreeUpdater
164+
return mainSystemDriver, rpmOstreeUpdater.Config, isBootc, err
173165

174-
return mainSystemDriver, finalConfig, isBootc, err
175166
}

pkg/session/session.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,21 @@ func RunLog(logger *slog.Logger, level slog.Level, command *exec.Cmd) ([]byte, e
2727
stdout, _ := command.StdoutPipe()
2828
stderr, _ := command.StderrPipe()
2929
multiReader := io.MultiReader(stdout, stderr)
30-
actuallogger := slog.Default()
31-
32-
if err := command.Start(); err != nil {
33-
actuallogger.Warn("Error occoured starting external command", slog.Any("error", err))
30+
actualLogger := slog.Default()
31+
err := command.Start()
32+
if err != nil {
33+
actualLogger.Warn("Error occurred starting external command", slog.Any("error", err))
34+
return []byte{}, err
3435
}
3536
scanner := bufio.NewScanner(multiReader)
3637
scanner.Split(bufio.ScanLines)
3738
for scanner.Scan() {
38-
actuallogger.Log(context.TODO(), level, scanner.Text())
39+
actualLogger.Log(context.TODO(), level, scanner.Text())
3940
}
40-
if err := command.Wait(); err != nil {
41-
actuallogger.Warn("Error occoured while waiting for external command", slog.Any("error", err))
41+
err = command.Wait()
42+
if err != nil {
43+
actualLogger.Warn("Error occurred while waiting for external command", slog.Any("error", err))
44+
return []byte{}, err
4245
}
4346

4447
return scanner.Bytes(), scanner.Err()

0 commit comments

Comments
 (0)