@@ -143,15 +143,21 @@ func (u *UsbGadget) listenKeyboardEvents() {
143
143
default :
144
144
l .Trace ().Msg ("reading from keyboard" )
145
145
if u .keyboardHidFile == nil {
146
- l .Error ().Msg ("keyboardHidFile is nil" )
146
+ u .logWithSupression ("keyboardHidFileNil" , 100 , & l , nil , "keyboardHidFile is nil" )
147
+ // show the error every 100 times to avoid spamming the logs
147
148
time .Sleep (time .Second )
148
149
continue
149
150
}
151
+ // reset the counter
152
+ u .resetLogSuppressionCounter ("keyboardHidFileNil" )
153
+
150
154
n , err := u .keyboardHidFile .Read (buf )
151
155
if err != nil {
152
- l . Error (). Err ( err ). Msg ( "failed to read" )
156
+ u . logWithSupression ( "keyboardHidFileRead" , 100 , & l , err , "failed to read" )
153
157
continue
154
158
}
159
+ u .resetLogSuppressionCounter ("keyboardHidFileRead" )
160
+
155
161
l .Trace ().Int ("n" , n ).Bytes ("buf" , buf ).Msg ("got data from keyboard" )
156
162
if n != 1 {
157
163
l .Trace ().Int ("n" , n ).Msg ("expected 1 byte, got" )
@@ -195,12 +201,12 @@ func (u *UsbGadget) keyboardWriteHidFile(data []byte) error {
195
201
196
202
_ , err := u .keyboardHidFile .Write (data )
197
203
if err != nil {
198
- u .log . Error (). Err ( err ). Msg ( "failed to write to hidg0" )
204
+ u .logWithSupression ( "keyboardWriteHidFile" , 100 , u . log , err , "failed to write to hidg0" )
199
205
u .keyboardHidFile .Close ()
200
206
u .keyboardHidFile = nil
201
207
return err
202
208
}
203
-
209
+ u . resetLogSuppressionCounter ( "keyboardWriteHidFile" )
204
210
return nil
205
211
}
206
212
0 commit comments