-
Notifications
You must be signed in to change notification settings - Fork 693
lima-guestagent: support external trigger via sighup notification #3766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
"errors" | ||
"net" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
"time" | ||
|
||
"github.com/mdlayher/vsock" | ||
|
@@ -58,7 +60,43 @@ | |
// without depending on `bpftrace` binary. | ||
// The agent binary will need CAP_BPF file cap. | ||
ticker := time.NewTicker(tick) | ||
return ticker.C, ticker.Stop | ||
|
||
logrus.Info("register for sighup notifications") | ||
sighupC := make(chan os.Signal, 1) | ||
signal.Notify(sighupC, syscall.SIGHUP) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a comment line to explain who sends SIGHUP There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I have added a comment about the purpose of the SIGHUP mechanism and also improved the log message. |
||
|
||
c := make(chan time.Time, 1) | ||
go func() { | ||
defer close(c) | ||
defer close(sighupC) | ||
for { | ||
select { | ||
case _, ok := <-sighupC: | ||
if !ok { | ||
logrus.Info("Sighup channel closed") | ||
sighupC = nil; | ||
} else { | ||
logrus.Debug("Sighup received") | ||
c <- time.Now() | ||
} | ||
case now, ok := <-ticker.C: | ||
if !ok { | ||
break; | ||
} else { | ||
c <- now | ||
} | ||
} | ||
} | ||
logrus.Info("ticker stopped") | ||
}() | ||
|
||
stop := func() { | ||
logrus.Info("stopping ticker") | ||
ticker.Stop() | ||
signal.Stop(sighupC) | ||
} | ||
|
||
return c, stop | ||
} | ||
|
||
agent, err := guestagent.New(newTicker, tick*20) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: probably sighup should be spelled in the upper chars, as it might look like "sigh up" (?) or a typo of sign-up