Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a -u flag in mosh-server to print detached mosh sessions th… #1327

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

john-at-charpa
Copy link

Greetings,
I noticed that there was no way (aside from manually starting mosh-server) to get a list of currently detached sessions. Since a few other people have asked for this feature, and I needed it myself, I went ahead and took at swing at seeing if it was possible. As it turns out very little code was needed. I tried to implement it as simply and unobtrusively as possible. Please consider merging this in as it will satisfy a feature request for 1.5. The code can also be applied to the current 1.4.0 release.

Cheers!

@achernya
Copy link
Collaborator

achernya commented Jul 2, 2024

I took a look at the proposed change and I'm a bit confused --- won't this print an unattached session, not all unattached sessions?

@john-at-charpa
Copy link
Author

john-at-charpa commented Jul 2, 2024

The function warn_unattached() finds them all and prints based on the count.

else if ( unattached_mosh_servers.size() == 1 ) {
    printf( "\033[37;44mMosh: You have a detached Mosh session on this server (%s).\033[m\n\n",
            unattached_mosh_servers.front().c_str() );
  } else {
    std::string pid_string;

    for ( std::vector<std::string>::const_iterator it = unattached_mosh_servers.begin();
          it != unattached_mosh_servers.end();
          it++ ) {
      pid_string += "        - " + *it + "\n";
    }

    printf( "\033[37;44mMosh: You have %d detached Mosh sessions on this server, with PIDs:\n%s\033[m\n",
            (int)unattached_mosh_servers.size(),
            pid_string.c_str() );
  }

The call I make is the same call made automatically when mosh-server is run. The only change is that by using the -u flag it calls it and exits (0) instead of spawning another mosh-server.

$ mosh-server -u
Mosh: You have 3 detached Mosh sessions on this server, with PIDs:
        - mosh [81287]
        - mosh [82619]
        - mosh [84020]

So the sum total of changes is really just:
o Move char utmp_entry[64] = { 0 }; to be global so that main can also access it
o Add a check for the -u flag and call the same code called by the server start-up code (in the same manner, too).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants