本文整理汇总了Golang中os/signal.Reset函数的典型用法代码示例。如果您正苦于以下问题:Golang Reset函数的具体用法?Golang Reset怎么用?Golang Reset使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Reset函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: captureSignals
func (g *game) captureSignals() {
g.sigs = make(chan os.Signal)
g.pauseLoop = make(chan struct{})
signal.Notify(g.sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGTSTP)
go func() {
for {
s := <-g.sigs
g.Lock()
if !g.pausedLoop {
g.pauseLoop <- struct{}{}
}
g.cleanup()
if s.String() != syscall.SIGTSTP.String() {
os.Stdout.WriteString("\n")
os.Exit(0)
}
g.pauseInput <- struct{}{}
signal.Reset(syscall.SIGTSTP)
syscall.Kill(os.Getpid(), syscall.SIGTSTP)
signal.Notify(g.sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGTSTP)
g.setTTY()
g.printGround()
g.printAllSnakes()
g.printAllFood()
g.moveTo(position{g.h - 1, g.w - 1})
g.Unlock()
g.pauseInput <- struct{}{}
}
}()
}
示例2: Serve
// Serve listens for and handles API calls. It a blocking function.
func (srv *Server) Serve() error {
// stop the server if a kill signal is caught
sigChan := make(chan os.Signal)
signal.Notify(sigChan, os.Interrupt, os.Kill)
defer signal.Reset(os.Interrupt, os.Kill)
go func() {
<-sigChan
fmt.Println("\rCaught stop signal, quitting...")
srv.listener.Close()
}()
// The server will run until an error is encountered or the listener is
// closed, via either the Close method or the signal handling above.
// Closing the listener will result in the benign error handled below.
err := srv.apiServer.Serve(srv.listener)
if err != nil && !strings.HasSuffix(err.Error(), "use of closed network connection") {
return err
}
// safely close each module
if srv.cs != nil {
srv.cs.Close()
}
if srv.gateway != nil {
srv.gateway.Close()
}
if srv.wallet != nil {
srv.wallet.Lock()
}
return nil
}
示例3: Folder
// Folder does everything
func Folder(dest string, interv int) {
sigs := make(chan os.Signal, 2)
signal.Notify(sigs, os.Interrupt, os.Kill)
tick := time.Tick(time.Duration(interv) * time.Second)
callScrot(dest, time.Now())
pic1, _ := ioutil.ReadDir(dest)
var size1 float64
for _, f := range pic1 {
if n := f.Size(); n > 4096 {
size1 = float64(n) / float64(interv)
break
}
}
estimate(size1)
var numpic int64
numpic = int64(len(pic1))
fmt.Printf("picture #%010d taken\n", numpic)
numpic++
scrotloop:
for {
select {
case <-sigs:
break scrotloop
case t := <-tick:
callScrot(dest, t)
fmt.Printf("picture #%010d taken\n", numpic)
numpic++
}
}
signal.Reset(os.Interrupt, os.Kill)
fmt.Println("")
}
示例4: stopReaper
func (t *tether) stopReaper() {
defer trace.End(trace.Begin("Shutting down child reaping"))
// stop child reaping
log.Info("Shutting down reaper")
signal.Reset(syscall.SIGCHLD)
close(t.incoming)
}
示例5: Notify
func Notify(path, s string) (int, error) {
notifyLock.Lock()
signal.Ignore(syscall.SIGPIPE)
defer func() {
signal.Reset(syscall.SIGPIPE)
notifyLock.Unlock()
}()
return notifyNosig(path, s)
}
示例6: waitForSignal
func (this *CommandServer) waitForSignal() {
for {
select {
case <-this.signalChan:
signal.Reset(syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
this.Stop()
return
}
}
}
示例7: TestForeground
func TestForeground(t *testing.T) {
signal.Ignore(syscall.SIGTTIN, syscall.SIGTTOU)
tty, err := os.OpenFile("/dev/tty", os.O_RDWR, 0)
if err != nil {
t.Skipf("Can't test Foreground. Couldn't open /dev/tty: %s", err)
}
fpgrp := 0
errno := syscall.Ioctl(tty.Fd(), syscall.TIOCGPGRP, uintptr(unsafe.Pointer(&fpgrp)))
if errno != 0 {
t.Fatalf("TIOCGPGRP failed with error code: %s", errno)
}
if fpgrp == 0 {
t.Fatalf("Foreground process group is zero")
}
ppid, ppgrp := parent()
cmd := create(t)
cmd.proc.SysProcAttr = &syscall.SysProcAttr{
Ctty: int(tty.Fd()),
Foreground: true,
}
cmd.Start()
cpid, cpgrp := cmd.Info()
if cpid == ppid {
t.Fatalf("Parent and child have the same process ID")
}
if cpgrp == ppgrp {
t.Fatalf("Parent and child are in the same process group")
}
if cpid != cpgrp {
t.Fatalf("Child's process group is not the child's process ID")
}
cmd.Stop()
errno = syscall.Ioctl(tty.Fd(), syscall.TIOCSPGRP, uintptr(unsafe.Pointer(&fpgrp)))
if errno != 0 {
t.Fatalf("TIOCSPGRP failed with error code: %s", errno)
}
signal.Reset()
}
示例8: runOnChan
// Gives control of chan to caller
func (mr *ModRunner) runOnChan(modchan chan *moddwatch.Mod, readyCallback func()) error {
dworld, err := NewDaemonWorld(mr.Config, mr.Log)
if err != nil {
return err
}
defer dworld.Shutdown(os.Kill)
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill)
defer signal.Reset(os.Interrupt, os.Kill)
go func() {
dworld.Shutdown(<-c)
os.Exit(0)
}()
watchpaths := mr.Config.WatchPatterns()
if mr.ConfReload {
watchpaths = append(watchpaths, filepath.Dir(mr.ConfPath))
}
// FIXME: This takes a long time. We could start it in parallel with the
// first process run in a goroutine
watcher, err := moddwatch.Watch(watchpaths, lullTime, modchan)
if err != nil {
return fmt.Errorf("Error watching: %s", err)
}
defer watcher.Stop()
mr.trigger(nil, dworld)
go readyCallback()
for mod := range modchan {
if mod == nil {
break
}
if mr.ConfReload && mod.Has(mr.ConfPath) {
mr.Log.Notice("Reloading config %s", mr.ConfPath)
err := mr.ReadConfig()
if err != nil {
mr.Log.Warn("%s", err)
continue
} else {
return nil
}
}
mr.Log.SayAs("debug", "Delta: \n%s", mod.String())
mr.trigger(mod, dworld)
}
return nil
}
示例9: GetPass
/* Read non-empty password from terminal */
func GetPass(prompt string) (pass string, err error) {
var resp []byte
fd, err := getTerminalFd()
if err != nil {
return
}
/* Store current terminal state in case the call gets interrupted by signal */
oldState, err := terminal.GetState(fd)
if err != nil {
err = errors.Errorf("failed to get terminal state: %s\n", err)
return
}
/*
* Install signal handler
* Unlike the ReadLine function, using a raw terminal state here does not help.
* If the prompt gets killed by a signal, the terminal state is not restored.
* Hence restore it in a signal handler
*/
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGINT)
go func() {
<-c
terminal.Restore(fd, oldState)
fmt.Fprintln(os.Stderr, "aborting")
os.Exit(1)
}()
for i := 0; len(resp) == 0; i++ {
if i > 0 {
fmt.Printf("\rInvalid response - try again")
time.Sleep(500 * time.Millisecond)
}
/* Clear line - see https://en.wikipedia.org/wiki/ANSI_escape_code */
fmt.Printf("\r\033[2K%s: ", prompt)
/* This function internally takes care of restoring terminal state. */
resp, err = terminal.ReadPassword(fd)
if err != nil {
return
}
resp = bytes.TrimSpace(resp)
}
/* Restore signal handling */
signal.Stop(c)
signal.Reset(syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGINT)
return string(resp), nil
}
示例10: stopReaper
func (t *tether) stopReaper() {
defer trace.End(trace.Begin("Shutting down child reaping"))
// Ordering is important otherwise we may one goroutine closing, and the other goroutine is trying to write afterwards
log.Debugf("Removing the signal notifier")
signal.Reset(syscall.SIGCHLD)
// just closing the incoming channel is not going to stop the iteration
// so we use the context cancellation to signal it
t.cancel()
log.Debugf("Closing the reapers signal channel")
close(t.incoming)
}
示例11: deregisterOnShutdown
func deregisterOnShutdown(client Client, app env.App, ctx context.Context, cancel context.CancelFunc, exit func(int)) {
sigChan := make(chan os.Signal, 1)
signal.Reset(syscall.SIGINT, syscall.SIGHUP, syscall.SIGTERM)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGHUP, syscall.SIGTERM)
go func() {
select {
case <-sigChan:
cancel()
client.Deregister(app)
case <-ctx.Done():
client.Deregister(app)
}
exit(1)
}()
}
示例12: reloadConfig
func reloadConfig(config *Config) *Config {
signalLock.Lock()
defer signalLock.Unlock()
log.Printf("Reloading configuration.\n")
newConfig, err := loadConfig()
if err != nil {
log.Printf("Could not reload config: %v\n", err)
return nil
}
// stop advertising the existing services so that we can
// make sure we update them if ports, etc. change.
stopPolling(config)
forAllServices(config, func(service *ServiceConfig) {
log.Printf("Deregistering service: %s\n", service.Name)
service.Deregister()
})
signal.Reset()
handleSignals(newConfig)
handlePolling(newConfig)
return newConfig // return for debuggability
}
示例13: CatchSignal
func CatchSignal(sig os.Signal, f func()) func() {
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, sig)
go func() {
for {
select {
case _, ok := <-signalChan:
if ok {
f()
os.Exit(1)
} else {
return
}
}
}
}()
return func() {
signal.Reset(sig)
signal.Stop(signalChan)
}
}
示例14: Main
func Main(start func(args []string, errorSink ErrorSink) Daemon) {
runtime.GOMAXPROCS(runtime.NumCPU())
sigs := make(chan os.Signal, 2)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
errorSink := NewErrorSink()
d := start(os.Args, errorSink)
exitCode := 0
var exitSignal os.Signal
select {
case err := <-errorSink:
if err != flag.ErrHelp {
fmt.Fprintln(os.Stderr, err)
exitCode = 1
}
case exitSignal = <-sigs:
}
if d != nil {
d.Stop()
}
if sig, ok := exitSignal.(syscall.Signal); ok {
// Now we have cleaned up, re-kill the process with
// the signal in order to produce a signal exit
// status:
signal.Reset(sig)
syscall.Kill(syscall.Getpid(), sig)
} else if exitSignal != nil {
fmt.Fprintln(os.Stderr, "Exiting with signal ", sig)
}
os.Exit(exitCode)
}
示例15: ResetSIGIO
// ResetSIGIO stops catching SIGIO signals.
//export ResetSIGIO
func ResetSIGIO() {
signal.Reset(syscall.SIGIO)
}