0

I'm doing some scripting involving screen, and it seems that screen -ls always returns 1. Is this normal?

The screen man pages say that it does interesting things if passed screen -ls -q, but I'm not doing that (it's probably also worth noting that -q doesn't seem to work).


Ok, now I'm really confused. I'm looking in the gnu screen source:

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 is set if you issue a -l or -ls command, eexit is:

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);
}

It shouldn't even be possible for screen -ls to return 1.

0

More digging in the source yielded the answer. As usual this is because debian is shipping ancient versions of core components.

 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 */
    }

Where Panic is the following

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);
}

As for why Panic() doesn't return the error code passed to it via the err member, your guess is as good as mine. It appears the -Q argument is broken as well, despite being present.

Basically, the version in apt is broken.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.