Skip to content

Commit 392dbdd

Browse files
committed
lint
1 parent e9ebc2d commit 392dbdd

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

internal/app/machined/pkg/controllers/runtime/kmsg_log_storage.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ func (ctrl *KmsgLogStorageController) deliverLogs(ctx context.Context, r control
122122
return fmt.Errorf("error receiving kernel logs: %w", msg.Err)
123123
}
124124

125-
ctrl.logWriter.Write([]byte(
125+
if _, err := ctrl.logWriter.Write([]byte(
126126
msg.Message.Timestamp.String() + ": " + msg.Message.Facility.String() + ": " + msg.Message.Message,
127-
))
127+
)); err != nil {
128+
return err
129+
}
128130
}
129131
}

internal/app/machined/pkg/controllers/runtime/log_persistence.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (ctrl *LogPersistenceController) Outputs() []controller.Output {
6464
}
6565
}
6666

67-
func (ctrl *LogPersistenceController) filenameForId(id string) string {
67+
func (ctrl *LogPersistenceController) filenameForID(id string) string {
6868
return filepath.Join(constants.LogMountPoint, id+".log")
6969
}
7070

@@ -77,7 +77,7 @@ func (ctrl *LogPersistenceController) getLogFile(id string, overwrite bool) (*os
7777
return f, nil
7878
}
7979

80-
f, err = os.OpenFile(ctrl.filenameForId(id), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
80+
f, err = os.OpenFile(ctrl.filenameForID(id), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
8181
if err != nil {
8282
return nil, fmt.Errorf("error opening log file for %q: %w", id, err)
8383
}
@@ -89,6 +89,7 @@ func (ctrl *LogPersistenceController) getLogFile(id string, overwrite bool) (*os
8989
return f, nil
9090
}
9191

92+
// WriteLog writes a single log line into the corresponding file.
9293
func (ctrl *LogPersistenceController) WriteLog(id string, line []byte) error {
9394
var err error
9495

@@ -116,13 +117,15 @@ func (ctrl *LogPersistenceController) stopLogging() error {
116117
// Stop all logging activities, close files
117118
// after this call we should not hold /var/log
118119
ctrl.canLog.Lock()
120+
119121
ctrl.filesMutex.Lock()
120122
defer ctrl.filesMutex.Unlock()
121123

122124
for id := range ctrl.files {
123125
if err := ctrl.files[id].Close(); err != nil {
124126
return fmt.Errorf("error closing log file for %q: %w", id, err)
125127
}
128+
126129
delete(ctrl.files, id)
127130
}
128131

@@ -142,15 +145,16 @@ func (ctrl *LogPersistenceController) rotate(id string) error {
142145
return fmt.Errorf("error closing log file for %q: %w", id, err)
143146
}
144147

145-
filename := ctrl.filenameForId(id)
148+
filename := ctrl.filenameForID(id)
149+
146150
err := os.Rename(filename, filename+".1")
147151
if err != nil {
148-
return fmt.Errorf("rename: %w", err)
152+
return fmt.Errorf("error renaming log file for %q: %w", id, err)
149153
}
150154

151155
_, err = ctrl.getLogFile(id, true)
152156
if err != nil {
153-
return fmt.Errorf("create: %w", err)
157+
return fmt.Errorf("error creating log file for %q: %w", id, err)
154158
}
155159

156160
return nil
@@ -175,10 +179,11 @@ func (ctrl *LogPersistenceController) Run(ctx context.Context, r controller.Runt
175179
return nil
176180
case <-tickerC:
177181
for id := range ctrl.files {
178-
st, err := os.Stat(ctrl.filenameForId(id))
182+
st, err := os.Stat(ctrl.filenameForID(id))
179183
if err != nil {
180184
return fmt.Errorf("error stat logfile %s: %w", id, err)
181185
}
186+
182187
if st.Size() >= 512*1024 {
183188
err = ctrl.rotate(id)
184189
if err != nil {

internal/app/machined/pkg/runtime/logging/circular.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func (manager *CircularBufferLoggingManager) SetLineWriter(w runtime.LogWriter)
108108
case manager.lineWriter <- w:
109109
default:
110110
<-manager.lineWriter
111+
111112
manager.lineWriter <- w
112113
}
113114
}

0 commit comments

Comments
 (0)