GNU Screen -ls总是返回非零值吗?


0

我正在做一些涉及屏幕的脚本,似乎screen -ls 总是返回1。这正常吗?

屏幕手册页说如果通过了它会做一些有趣的事情screen -ls -q,但是我没有这样做(可能还值得注意的是,-q这似乎不起作用)。


好吧,现在我真的困惑。我正在寻找gnu屏幕源:

if (lsflag) {
    int i, fo, oth;

    if (multi)
        real_uid = multi_uid;
    SET_GUID();
    i = FindSocket((int *)NULL, &fo, &oth, SocketMatch);
    if (quietflag) {
        if (rflag)
            exit(10 + i);
        else
            exit(9 + (fo || oth ? 1 : 0) + fo);
    }
    if (fo == 0)
        Panic(0, "No Sockets found in %s.\n", SocketPath);
    Msg(0, "%d Socket%s in %s.", fo, fo > 1 ? "s" : "", SocketPath);
    eexit(0);
}

lsflag如果发出-l-ls命令,eexit则设置为:

void eexit(int e)
{
    if (ServerSocket != -1) {
        if (setgid(real_gid))
            AddStr("Failed to set gid\r\n");
        if (setuid(real_uid))
            AddStr("Failed to set uid\r\n");
        if (unlink(SocketPath))
            AddStr("Failed to remove socket\r\n");
    }
    exit(e);
}

甚至不可能screen -ls返回1。

Answers:


0

在源中进行更多的挖掘可以找到答案。像往常一样,这是因为debian正在交付核心组件的旧版本。

 if (lsflag)
    {
      int i, fo, oth;

#ifdef MULTIUSER
      if (multi)
        real_uid = multi_uid;
#endif
      SET_GUID();
      i = FindSocket((int *)NULL, &fo, &oth, SockMatch);
      if (quietflag) {
        if (rflag)
          exit(10 + i);
        else
          exit(9 + (fo || oth ? 1 : 0) + fo);
      }
      if (fo == 0)
        Panic(0, "No Sockets found in %s.\n", SockPath);
      Panic(0, "%d Socket%s in %s.\n", fo, fo > 1 ? "s" : "", SockPath);
      /* NOTREACHED */
    }

哪里出现恐慌

void Panic (int err, const char *fmt, VA_DOTS)
{
  char buf[MAXPATHLEN*2];
  PROCESS_MESSAGE(buf);

  debug3("Panic('%s'); display=%x displays=%x\n", buf, display, displays);
  if (displays == 0 && display == 0)
    {
      printf("%s\r\n", buf);
      if (PanicPid)
        Kill(PanicPid, SIG_BYE);
    }
  else if (displays == 0)
    {
      /* no displays but a display - must have forked.
       * send message to backend!
       */
      char *tty = D_usertty;
      display = 0;
      SendErrorMsg(tty, buf);
      sleep(2);
      _exit(1);
    }
  else
    for (display = displays; display; display = display->d_next)
      {
        if (D_status)
      RemoveStatus();
        FinitTerm();
        Flush(3);
#ifdef UTMPOK
        RestoreLoginSlot();
#endif
        SetTTY(D_userfd, &D_OldMode);
        fcntl(D_userfd, F_SETFL, 0);
        write(D_userfd, buf, strlen(buf));
        write(D_userfd, "\n", 1);
        freetty();
    if (D_userpid)
      Kill(D_userpid, SIG_BYE);
      }
#ifdef MULTIUSER
  if (tty_oldmode >= 0)
    {
# ifdef USE_SETEUID
      if (setuid(own_uid))
        xseteuid(own_uid);  /* may be a loop. sigh. */
# else
      setuid(own_uid);
# endif
      debug1("Panic: changing back modes from %s\n", attach_tty);
      chmod(attach_tty, tty_oldmode);
    }
#endif
  eexit(1);
}

至于为什么Panic()不返回通过err成员传递给它的错误代码,您的猜测和我的一样好。-Q尽管存在,但论据似乎也被打破了。

基本上,其中的版本apt已损坏。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.