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

Teams does not run directly, but works via bash #50

Open
greemo opened this issue Mar 8, 2021 · 7 comments
Open

Teams does not run directly, but works via bash #50

greemo opened this issue Mar 8, 2021 · 7 comments
Assignees
Labels
bug Something isn't working has workaround There is an alternative solution to the issue.

Comments

@greemo
Copy link

greemo commented Mar 8, 2021

I installed ego, and I get the following output but the program is not run...

(base) user_1@laptop:~$ ego -v -v -v -v -v --user=user_2 teams

[ego::logging] Log level TRACE
[users::base] Running getpwnam_r for user "user_2"
[users::base] Loading user with uid 1001
Setting up Alter Ego for user user_2 (1001)
Runtime data dir '/run/user/1000' configured
Wayland: WAYLAND_DISPLAY not set, skipping
X11 configured to allow +si:localuser:user_2
Publishing PulseAudio cookie /home/user_1/.config/pulse/cookie to /run/user/1000/ego/pulse-cookie
PulseAudio dir '/run/user/1000/pulse' configured
Running command: machinectl shell '--uid=user_2' '-EDISPLAY=:0' '-EPULSE_SERVER=unix:/run/user/1000/pulse/native' '-EPULSE_COOKIE=/run/user/1000/ego/pulse-cookie' -- .host /bin/sh -c 'dbus-update-activation-environment --systemd DISPLAY PULSE_SERVER PULSE_COOKIE; systemctl --user start xdg-desktop-portal-gtk; exec teams'
Connected to the local host. Press ^] three times within 1s to exit session.

Connection to the local host terminated.

Any thoughts??

@intgr
Copy link
Owner

intgr commented Mar 8, 2021

Hi! A some things to try:

  • What Linux distribution and version are you using?
  • Does it work if you run ego --user=user_2 bash and then run teams from there?
  • Does ego --sudo mode work?
  • Run sudo journalctl -f in the background and then try ego again, see if there are any log messages that might indicate a problem.

@greemo
Copy link
Author

greemo commented Mar 8, 2021

Thanks Marti,

Running ego --user=user_2 bash and then running teams from there worked perfectly.

Now I can log into multiple teams accounts simultaneously on Linux, thanks!

@greemo greemo closed this as completed Mar 8, 2021
@intgr
Copy link
Owner

intgr commented Mar 8, 2021

Great! I'm still curious though, why your original command doesn't work. It's probably something that can be improved in ego.

PS: This is the first user feedback I've received. It's good to hear that somebody finds this useful. :)

@intgr intgr changed the title Program Not Run Teams does not run directly, but works via bash Mar 8, 2021
@intgr intgr self-assigned this Mar 8, 2021
@intgr intgr added bug Something isn't working has workaround There is an alternative solution to the issue. labels Mar 8, 2021
@intgr intgr reopened this Mar 8, 2021
@greemo
Copy link
Author

greemo commented Mar 8, 2021

FYI:

ego --sudo --user=user_2 teams works, but I get the following output on the console:

X Error of failed request: BadName (named color or font does not exist)
Major opcode of failed request: 140 (RANDR)
Minor opcode of failed request: 16 (RRCreateMode)
Serial number of failed request: 34
Current serial number in output stream: 34

Running journalctl before ego --user=user_2 teams:

Mar 08 11:51:46 laptop polkitd(authority=local)[946]: Registered Authentication Agent for unix-process:200399:73989715 (system bus name :1.791 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_AU.UTF-8)
Mar 08 11:51:50 laptop polkitd(authority=local)[946]: Operator of unix-session:c2 successfully authenticated as unix-user:user_1 to gain TEMPORARY authorization for action org.freedesktop.machine1.host-shell for system-bus-name::1.792 [machinectl shell --uid=user_2 -EDISPLAY=:0 -EPULSE_SERVER=unix:/run/user/1000/pulse/native -EPULSE_COOKIE=/run/user/1000/ego/pulse-cookie -- .host /bin/sh -c dbus-update-activation-environment --systemd DISPLAY PULSE_SERVER PULSE_COOKIE; systemctl --user start xdg-desktop-portal-gtk; exec teams] (owned by unix-user:user_1)
Mar 08 11:51:50 laptop systemd[1]: Started Shell for User user_2.
Mar 08 11:51:50 laptop systemd[200414]: pam_unix(login:session): session opened for user user_2 by (uid=0)
Mar 08 11:51:50 laptop systemd-logind[956]: New session 128 of user user_2.
Mar 08 11:51:50 laptop systemd[1]: Started Session 128 of user user_2.
Mar 08 11:51:50 laptop systemd[1]: [email protected]: Succeeded.
Mar 08 11:51:50 laptop systemd[1]: session-128.scope: Succeeded.
Mar 08 11:51:50 laptop systemd-logind[956]: Session 128 logged out. Waiting for processes to exit.
Mar 08 11:51:50 laptop systemd-logind[956]: Removed session 128.
Mar 08 11:51:50 laptop polkitd(authority=local)[946]: Unregistered Authentication Agent for unix-process:200399:73989715 (system bus name :1.791, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_AU.UTF-8) (disconnected from bus)

Cheers

@intgr
Copy link
Owner

intgr commented Mar 13, 2021

OK I tried it and I see the issue now. The teams command forks a background process and exits immediately. Since the command exits, the session quits and systemd tears down background processes with it.

This demonstrates the issue by keeping the session around for 5 more seconds. Teams has a chance to start up and then exits.

ego sh -c 'teams && sleep 5'

Hopefully there is a nice way to handle this situation that doesn't add much complexity, I'll have to do some research.

@intgr
Copy link
Owner

intgr commented Mar 23, 2021

Jotting down notes about this issue...

  • teams escapes the process hierarchy by double-forking, becoming an orphan process.
    • Even with a systemd user session, on my system, orphans inherit PID 1 as their parent, so we lose track of them.
    • I was under the impression that systemd user session uses PR_SET_CHILD_SUBREAPER so that it would become the parent process. Dunno why this isn't working. (https://unix.stackexchange.com/a/177361)
  • The teams processes still belong to the current session by process sesssion ID (e.g. ps o pid,ppid,pgid,sid,comm), so it's possible to track them that way. (https://unix.stackexchange.com/a/18178)
  • Cannot use wait on these processes because they aren't subprocesses of the shell ("bash: wait: pid 295517 is not a child of this shell")
  • They can also be tracked by the login session in the cgroups tree (systemd-cgls -u user-$UID.slice)
    │ └─user-979.slice 
    │   ├─session-382.scope 
    │   │ ├─298304 /usr/share/teams/teams --disable-namespace-sandbox --disable-setuid-sandbox
    
    • Maybe some properties can be tweaked on the scope level systemctl show session-$XDG_SESSION_ID.scope
      • Change kill signal to SIGHUP instead of SIGKILL? https://www.freedesktop.org/software/systemd/man/systemd.kill.html
        • Seems like these settings can't be changed (systemctl set-property session-406.scope KillMode=none) and it's a bad idea anyway ("allows processes to escape the service manager's lifecycle and resource management").
    • loginctl enable-linger ego can be used to keep systemd around before and after the scope. But teams (and I guess everything in the session scope) still gets killed when I close the shell. :(
  • loginctl also allows inspecting session information (loginctl show-session -a $XDG_SESSION_ID loginctl session-status $XDG_SESSION_ID).
    • I guess when the session main process ("leader") dies, systemd kills everything in the session.
      • So maybe instead of launching teams as the main session process, I can run something that keeps track and waits for children? Although this is more complexity than I was hoping :(

@lucasvienna
Copy link

lucasvienna commented Apr 5, 2021

Stumbled upon ego while trying to run Teams on a different user session. Had the exact same issue, where running ego teams would instantly exit without any discernible effect. I'm using Elementary OS 5.1.7 Hera (Ubuntu 18.04).

The bash -> teams workflow does work for me as well.

EDIT: if I can provide logs or any sort of debug data to help feel free to ask, I'd be happy to!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working has workaround There is an alternative solution to the issue.
Projects
None yet
Development

No branches or pull requests

3 participants