func DropPrivileges(name string) { cname := C.CString(name) home := C.CString("HOME") slash := C.CString("/") defer C.cfree(unsafe.Pointer(home)) defer C.cfree(unsafe.Pointer(cname)) defer C.cfree(unsafe.Pointer(slash)) cpw := C.getpwnam(cname) C.setgid(cpw.pw_gid) C.setuid(cpw.pw_uid) C.setenv(home, cpw.pw_dir, 1) C.setsid() C.chdir(slash) C.umask(022) }
func daemon2() { p := C.fork() if p > 0 { //main process exit os.Exit(0) } else if p < 0 { os.Exit(1) } C.setsid() p = C.fork() if p > 0 { //main process exit os.Exit(0) } else if p < 0 { os.Exit(1) } ////change working directory //C.chdir(C.CString("/tmp")) //C.umask(0) }