func daemon(nochdir, noclose int) int { var ret, ret2 uintptr var err syscall.Errno darwin := runtime.GOOS == "darwin" // already a daemon if syscall.Getppid() == 1 { return 0 } // fork off the parent process ret, ret2, err = syscall.RawSyscall(syscall.SYS_FORK, 0, 0, 0) if err != 0 { return -1 } // failure if ret2 < 0 { os.Exit(-1) } // handle exception for darwin if darwin && ret2 == 1 { ret = 0 } // if we got a good PID, then we call exit the parent process. if ret > 0 { os.Exit(0) } /* Change the file mode mask */ _ = syscall.Umask(0) // create a new SID for the child process s_ret, s_errno := syscall.Setsid() if s_errno != nil { syslog.Error("Error: syscall.Setsid errno: %d", s_errno) } if s_ret < 0 { return -1 } if nochdir == 0 { os.Chdir("/") } if noclose == 0 { f, e := os.OpenFile("/dev/null", os.O_RDWR, 0) if e == nil { fd := f.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 0 }
func (tail InnerPkgTail) ToString() string { str, err := json.Marshal(tail) if err != nil { syslog.Error(err) return "" } return string(str) }
func (head PkgHead) ToString() string { str, err := json.Marshal(head) if err != nil { syslog.Error(err) return "" } return string(str) }
func PipelineGetString(keys []string) []string { rClient := get() defer put(rClient) pipeline := rClient.Client.Pipeline() keysNum := 0 for _, key := range keys { if len(key) > 2 { syslog.Debug("pipeline key ", key) pipeline.Get(key) keysNum++ } } cmds, err := pipeline.Exec() syslog.Debug("pipe result:", cmds, err) result := "" valList := make([]string, keysNum) n := 0 if err != nil && err != redis.Nil { syslog.Debug("redisClient pipeline err %s", err.Error()) ReconnectRedis(rClient) } else { syslog.Debug("redisClient pipeline ok") for _, cmd := range cmds { syslog.Debug(cmd, " ret result:", cmd.(*redis.StringCmd).Val()) if cmd.(*redis.StringCmd).Err() != nil { syslog.Error(cmd.(*redis.StringCmd).Err()) } else { result = cmd.(*redis.StringCmd).Val() } if len(result) > 0 { syslog.Debug(n, result) valList[n] = result n++ } } } return valList }
func (location *LocationInfo) GetLocation(level uint16, hour uint32, page uint16) []LocResult { if level != 1 { syslog.Error("level ", level, " not completed.") return nil } session := common.MongoGet() defer common.MongoPut(session) c := session.DB("du").C("location") selector := bson.M{"loc": bson.M{"$near": location.Loc}} syslog.Debug("selector: ", selector) iter := c.Find(selector).Limit(MAX_ROW*LOCAL_MAX_PAGE + 1).Iter() result := LocationInfo{} retLoc := make([]LocResult, MAX_ROW*30) line := 0 retLoc[line].Uid = location.Uid retLoc[line].Xpos = float64(int64(location.Loc[0]*1000000)) / 1000000 retLoc[line].Ypos = float64(int64(location.Loc[1]*1000000)) / 1000000 syslog.Debug(retLoc[line].Xpos, retLoc[line].Ypos) line++ for iter.Next(&result) && line < MAX_ROW*30 { if result.Uid == location.Uid { continue } syslog.Debug("Uid: ", result.Uid, " Loc: ", result.Loc, " send time: ", result.SendTime, "line:", line) retLoc[line].Uid = result.Uid retLoc[line].Xpos = float64(int64(result.Loc[0]*1000000)) / 1000000 retLoc[line].Ypos = float64(int64(result.Loc[1]*1000000)) / 1000000 //retlocl[line].Xpos = result.Loc[0] //retlocl[line].Ypos = result.Loc[1] line++ } return retLoc[:line] }