本文整理汇总了Golang中os/signal.Ignore函数的典型用法代码示例。如果您正苦于以下问题:Golang Ignore函数的具体用法?Golang Ignore怎么用?Golang Ignore使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Ignore函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: childMain
func childMain() error {
var err error
pipe := os.NewFile(uintptr(3), "pipe")
if pipe != nil {
defer pipe.Close()
if err == nil {
pipe.Write([]byte{DaemonSuccess})
} else {
pipe.Write([]byte{DaemonFailure})
}
}
signal.Ignore(syscall.SIGCHLD)
syscall.Close(0)
syscall.Close(1)
syscall.Close(2)
syscall.Setsid()
syscall.Umask(022)
// syscall.Chdir("/")
return nil
}
示例2: OnInterrupt
func OnInterrupt(fn func(), onExitFunc func()) {
// deal with control+c,etc
signalChan := make(chan os.Signal, 1)
// controlling terminal close, daemon not exit
signal.Ignore(syscall.SIGHUP)
signal.Notify(signalChan,
os.Interrupt,
os.Kill,
syscall.SIGALRM,
// syscall.SIGHUP,
// syscall.SIGINFO, this causes windows to fail
syscall.SIGINT,
syscall.SIGTERM,
// syscall.SIGQUIT, // Quit from keyboard, "kill -3"
)
go func() {
for _ = range signalChan {
fn()
if onExitFunc != nil {
onExitFunc()
}
os.Exit(0)
}
}()
}
示例3: afterDaemonize
func afterDaemonize(err error) {
// Ignore SIGCHLD signal
signal.Ignore(syscall.SIGCHLD)
// Close STDOUT, STDIN, STDERR
syscall.Close(0)
syscall.Close(1)
syscall.Close(2)
// Become the process group leader
syscall.Setsid()
// // Clear umask
syscall.Umask(022)
// // chdir for root directory
syscall.Chdir("/")
// Notify that the child process started successfuly
pipe := os.NewFile(uintptr(3), "pipe")
if pipe != nil {
defer pipe.Close()
if err == nil {
pipe.Write([]byte{DAEMONIZE_SUCCESS})
} else {
pipe.Write([]byte{DAEMONIZE_FAIL})
}
}
}
示例4: main
func main() {
flag.Usage = usage
flag.Parse()
if flag.NArg() < 1 {
usage()
}
if isatty(1) {
dofile()
}
if isatty(2) {
os.Stderr = os.Stdout
}
signal.Ignore(syscall.SIGHUP)
args := flag.Args()
cmd := exec.Command(args[0], args[1:]...)
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
err := cmd.Run()
if err != nil {
fmt.Fprintln(os.Stderr, err)
if _, ok := err.(*exec.ExitError); ok {
os.Exit(126)
}
os.Exit(127)
}
}
示例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: main
func main() {
flag.Usage = usage
flag.Parse()
if *sigint {
signal.Ignore(os.Interrupt)
}
mode := os.O_CREATE | os.O_WRONLY
if *append_ {
mode |= os.O_APPEND
} else {
mode |= os.O_TRUNC
}
var files []*os.File
var writers []*bufio.Writer
for _, name := range flag.Args() {
f, err := os.OpenFile(name, mode, 0666)
if ck(err) {
continue
}
files = append(files, f)
writers = append(writers, bufio.NewWriter(f))
}
writers = append(writers, bufio.NewWriter(os.Stdout))
for {
var buf [8192]byte
n, err := os.Stdin.Read(buf[:])
if n > 0 {
for _, w := range writers {
w.Write(buf[:n])
}
}
if err == io.EOF {
break
}
ck(err)
}
for _, w := range writers {
err := w.Flush()
ck(err)
}
for _, f := range files {
err := f.Close()
ck(err)
}
os.Exit(status)
}
示例7: InitSignalHandling
func InitSignalHandling() {
signal.Ignore(syscall.SIGTTOU, syscall.SIGTTIN)
signals := []os.Signal{syscall.SIGINT, syscall.SIGTSTP}
incoming = make(chan os.Signal, len(signals))
signal.Notify(incoming, signals...)
go broker()
}
示例8: initSignalHandling
func initSignalHandling(cli ui) {
signal.Ignore(unix.SIGTTOU, unix.SIGTTIN)
signals := []os.Signal{unix.SIGINT, unix.SIGTSTP}
incoming = make(chan os.Signal, len(signals))
signal.Notify(incoming, signals...)
go broker(cli)
}
示例9: 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()
}
示例10: handleflags
//Parses all the flags and sets variables accordingly
func handleflags() int {
flag.Parse()
oflags := os.O_WRONLY | os.O_CREATE
if *cat {
oflags |= os.O_APPEND
}
if *ignore {
signal.Ignore(os.Interrupt)
}
return oflags
}
示例11: main
func main() {
// store information about this fake process into JSON
signal.Ignore()
var data outputData
data.PID = os.Getpid()
data.Args = os.Args[1:]
// validate command line arguments
// expect them to look like
// fake-thing agent -config-dir=/some/path/to/some/dir
if len(data.Args) == 0 {
log.Fatal("expecting command as first argment")
}
var configDir string
var recursors stringSlice
flagSet := flag.NewFlagSet("", flag.ExitOnError)
flagSet.StringVar(&configDir, "config-dir", "", "config directory")
flagSet.Var(&recursors, "recursor", "recursor")
flagSet.Parse(data.Args[1:])
if configDir == "" {
log.Fatal("missing required config-dir flag")
}
writeOutput(configDir, data)
// read input options provided to us by the test
var inputOptions struct {
WaitForHUP bool
}
if optionsBytes, err := ioutil.ReadFile(filepath.Join(configDir, "options.json")); err == nil {
json.Unmarshal(optionsBytes, &inputOptions)
}
fmt.Fprintf(os.Stdout, "some standard out")
fmt.Fprintf(os.Stderr, "some standard error")
if inputOptions.WaitForHUP {
for {
time.Sleep(time.Second)
}
}
}
示例12: main
func main() {
var (
flags int = (os.O_WRONLY | os.O_CREATE)
exitval int
files []io.Writer = []io.Writer{os.Stdout}
)
appendFlag := flag.Bool("a", false, "Append the output to the files rather than overwriting them.")
interruptFlag := flag.Bool("i", false, "Ignore the SIGINT signal.")
flag.Usage = usage
flag.Parse()
if *interruptFlag {
signal.Ignore(syscall.SIGINT)
}
if *appendFlag {
flags |= os.O_APPEND
} else {
flags |= os.O_TRUNC
}
for _, arg := range flag.Args() {
if arg == "-" {
continue
}
if f, err := os.OpenFile(arg, flags, os.ModePerm); err != nil {
log.Printf("%s - %v", arg, err)
exitval = 1
} else {
defer f.Close()
files = append(files, f)
}
}
if _, err := io.Copy(io.MultiWriter(files...), os.Stdin); err != nil {
log.Printf("%v", err)
exitval = 1
}
os.Exit(exitval)
}
示例13: OnInterrupt
func OnInterrupt(fn func()) {
// deal with control+c,etc
signalChan := make(chan os.Signal, 1)
// controlling terminal close, daemon not exit
signal.Ignore(syscall.SIGHUP)
signal.Notify(signalChan,
os.Interrupt,
os.Kill,
syscall.SIGALRM,
// syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
for _ = range signalChan {
fn()
os.Exit(0)
}
}()
}
示例14: Daemon
func Daemon(nochdir int) error {
signal.Ignore(syscall.SIGINT, syscall.SIGHUP, syscall.SIGPIPE)
if syscall.Getppid() == 1 {
return nil
}
ret1, ret2, eno := syscall.RawSyscall(syscall.SYS_FORK, 0, 0, 0)
if eno != 0 || ret2 < 0 {
return errors.New("Fork fail")
}
/* exit parent */
if ret1 > 0 {
os.Exit(0)
}
_ = syscall.Umask(0)
ret, err := syscall.Setsid()
if ret < 0 || err != nil {
return errors.New("Set sid failed")
}
if nochdir == 0 {
err = os.Chdir("/")
if err != nil {
return errors.New("Chdir failed")
}
}
file, err := os.OpenFile("/dev/null", os.O_RDWR, 0)
if err == nil {
fd := file.Fd()
syscall.Dup2(int(fd), int(os.Stdin.Fd()))
syscall.Dup2(int(fd), int(os.Stdout.Fd()))
// syscall.Dup2(int(fd), int(os.Stderr.Fd()))
}
return nil
}
示例15: childMain
func childMain() {
// 初期化処理があればここに
var err error
// 子プロセスの起動状態を親プロセスに通知する
pipe := os.NewFile(uintptr(3), "pipe")
if pipe != nil {
defer pipe.Close()
if err == nil {
pipe.Write([]byte{DAEMON_SUCCESS})
} else {
pipe.Write([]byte{DAEMON_FAIL})
}
}
// SIGCHILDを無視する
signal.Ignore(syscall.SIGCHLD)
// STDOUT, STDIN, STDERRをクローズ
syscall.Close(0)
syscall.Close(1)
syscall.Close(2)
// プロセスグループリーダーになる
syscall.Setsid()
// Umaskをクリア
syscall.Umask(022)
// / にchdirする
syscall.Chdir("/")
// main loop
for {
time.Sleep(1000 * time.Millisecond)
}
}