elves / elvish

Powerful scripting language & versatile interactive shell
https://elv.sh/
BSD 2-Clause "Simplified" License
5.69k stars 300 forks source link

Elvish is how did to ignore CTRL - Z (SIGTSTP) ? #931

Closed m9rco closed 4 years ago

m9rco commented 4 years ago

Hi.

I recently doing a restricted shell, Think through golang development, but I don't want to elvish based, because this project will be very large,In fact, I just want to know how to circumvent the CTRL -z signal is elvish

m9rco commented 4 years ago

I think you can ignore the signal signal is acquired by the way, but in fact

  var (
   ch     chan os.Signal
    status os.Signal
  )

  ch = make(chan os.Signal, 1)
  signal.Notify(ch,
   syscall.SIGTTIN, syscall.SIGTTOU, syscall.SIGHUP, syscall.SIGUSR1, syscall.SIGQUIT,
   syscall.SIGTERM, syscall.SIGINT, syscall.SIGTSTP, syscall.SIGCONT)

  signal.Ignore(syscall.SIGTSTP)
  for {
   select {
   case status = <-ch:
     fmt.Println(status)
     switch status {
     case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
       return
     case syscall.SIGHUP:
       fmt.Println("SIGHUP")
       continue
     case syscall.SIGCONT:
       fmt.Println("SIGCONT")
       continue
     case syscall.SIGUSR1:
     case syscall.SIGTSTP:
       fmt.Println("SIGTSTP")
       continue
     case syscall.SIGSTOP:
       fmt.Println("SIGSTOP")
       continue
     default:
       fmt.Println(status)
       continue
     }
   }
  }
krader1961 commented 4 years ago

Are you asking for help writing Go code to ignore SIGTSTP? If, yes, then you're probably looking for stackoverflow.com or the golang-nuts mailing list.

Are you asking if the elvish shell can be made to ignore SIGTSTP? If, yes, then note that elvish currently does ignore SIGTSTP based on a quick interactive test.

m9rco commented 4 years ago

yes ,I want to know how the elvish,stackoverflow.com is answer can't elvish ignore SIGTSTP

xiaq commented 4 years ago

Elvish does not handle SIGTSTP specifically. Instead, it listens on all signals, which has the side effect of suppressing the default handling of SIGTSTP:

https://github.com/elves/elvish/blob/7325c89be4131a8fc22e4d405f474f31ef56f11b/pkg/program/shell/shell.go#L79