dongxiz5342 2016-02-01 20:57 采纳率: 100%
浏览 27

使用其他用户的凭据启动子流程时,Go应用程序挂起

I've been using a simple game server management application on Ubuntu 14.04 for the last 6 months or so. After a recent server update & reboot the application would hang on when trying to start a subprocess. After some debugging it seems that whenever I try to start a subprocess with another user's credentials (I'm running as a root) any command will hang.

Here's a simple application to demonstrate what causes the hang:

package main
import (
    "os/exec"
    "syscall"
    "fmt"
)

func main() {
    proc := exec.Command("ls")

    proc.SysProcAttr = &syscall.SysProcAttr{}
    proc.SysProcAttr.Credential = &syscall.Credential{Uid: 1022, Gid: 1023}
    err := proc.Run()
    if err != nil {
        fmt.Printf("err: %v", err)
    }
}

By removing the syscall.Credential part, the application will run without any issues.

My question is: is there some platform/update specific reason that causes this behaviour? Is this no longer a correct way to run a subprocess as another user?

EDIT: Here's the last 5 lines of strace -f

[pid  3994] futex(0xc21000a888, FUTEX_WAKE, 1 <unfinished ...>
[pid  3995] <... futex resumed> )       = 0
[pid  3994] <... futex resumed> )       = 1
[pid  3995] futex(0xc21000a888, FUTEX_WAIT, 0, NULL <unfinished ...>
[pid  3994] select(0, NULL, NULL, NULL, {0, 20}) = 0 (Timeout)
[pid  3994] futex(0x7f615c51a4f8, FUTEX_WAIT, 0, NULL

So apparently if I'm interpreting this right it's blocking at futex_wait.

  • 写回答

1条回答 默认 最新

  • duanping1632 2016-02-01 22:46
    关注

    You should execute your application with strace. So strace myapp and see where it locks up. It could be you have something else that's forking before your application executes, which is causing it to hang.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题