Albirew/nyaa-pantsu
Albirew
/
nyaa-pantsu
Archivé
1
0
Bifurcation 0

Prevent race condition.

It is possible for an os.Interrupt signal to be raised after
signals.RegisterCloser() and before startup of goroutine signals.Handle().

Race is prevented by synchronously calling signal.Notify().
Cette révision appartient à :
John Smith 2017-05-28 11:08:46 +02:00 révisé par Eliot Whalan
Parent 57980a8ebc
révision 92c92e09c1
Signature inconnue de Forgejo
ID de la clé GPG: C0A42175139840D6
3 fichiers modifiés avec 33 ajouts et 29 suppressions

Voir le fichier

@ -141,7 +141,7 @@ func main() {
if err != nil {
log.Fatal(err.Error())
}
go signals.Handle()
signals.Handle()
if len(config.TorrentFileStorage) > 0 {
err := os.MkdirAll(config.TorrentFileStorage, 0700)
if err != nil {

Voir le fichier

@ -22,22 +22,24 @@ func handleReload() {
func Handle() {
chnl := make(chan os.Signal)
signal.Notify(chnl, syscall.SIGHUP, os.Interrupt)
for {
sig, ok := <-chnl
if !ok {
break
go func(chnl chan os.Signal) {
for {
sig, ok := <-chnl
if !ok {
break
}
switch sig {
case syscall.SIGHUP:
handleReload()
break
case os.Interrupt:
interrupted()
return
default:
break
}
}
switch sig {
case syscall.SIGHUP:
handleReload()
break
case os.Interrupt:
interrupted()
return
default:
break
}
}
}(chnl)
}
// unix implementation of interrupt

Voir le fichier

@ -12,20 +12,22 @@ func Handle() {
chnl := make(chan os.Signal)
signal.Notify(chnl, os.Interrupt)
for {
sig, ok := <-chnl
if !ok {
break
go func(chnl chan os.Signal) {
for {
sig, ok := <-chnl
if !ok {
break
}
switch sig {
case os.Interrupt:
// this also closes listeners
interrupted()
return
default:
break
}
}
switch sig {
case os.Interrupt:
// this also closes listeners
interrupted()
return
default:
break
}
}
}(chnl)
}
// win32 interrupt handler