Skip to content
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

refactor(tm2/pkg/autofile): use SIGTERM #1006

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tm2/pkg/autofile/autofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const (
)

// AutoFile automatically closes and re-opens file for writing. The file is
// automatically setup to close itself every 1s and upon receiving SIGHUP.
// automatically setup to close itself every 1s and upon receiving SIGTERM.
//
// This is useful for using a log file with the logrotate tool.
type AutoFile struct {
Expand Down Expand Up @@ -68,9 +68,9 @@ func OpenAutoFile(path string) (*AutoFile, error) {
return nil, err
}

// Close file on SIGHUP.
// Close file on SIGTERM.
af.hupc = make(chan os.Signal, 1)
signal.Notify(af.hupc, syscall.SIGHUP)
signal.Notify(af.hupc, syscall.SIGTERM)
go func() {
for range af.hupc {
af.closeFile()
Expand All @@ -82,7 +82,7 @@ func OpenAutoFile(path string) (*AutoFile, error) {
return af, nil
}

// Close shuts down the closing goroutine, SIGHUP handler and closes the
// Close shuts down the closing goroutine, SIGTERM handler and closes the
// AutoFile.
func (af *AutoFile) Close() error {
af.closeTicker.Stop()
Expand Down
6 changes: 3 additions & 3 deletions tm2/pkg/autofile/autofile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
osm "github.com/gnolang/gno/tm2/pkg/os"
)

func TestSIGHUP(t *testing.T) {
func TestSIGTERM(t *testing.T) {
// First, create an AutoFile writing to a tempfile dir
file, err := ioutil.TempFile("", "sighup_test")
require.NoError(t, err)
Expand All @@ -34,8 +34,8 @@ func TestSIGHUP(t *testing.T) {
err = os.Rename(name, name+"_old")
require.NoError(t, err)

// Send SIGHUP to self.
syscall.Kill(syscall.Getpid(), syscall.SIGHUP)
// Send SIGTERM to self.
syscall.Kill(syscall.Getpid(), syscall.SIGTERM)

// Wait a bit... signals are not handled synchronously.
time.Sleep(time.Millisecond * 10)
Expand Down