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

added libutempter #3583

Closed
wants to merge 3 commits into from
Closed

added libutempter #3583

wants to merge 3 commits into from

Conversation

sn00pster
Copy link

mosh now builds against libutempter, this is a requirement for adding support for displaying detached sessions.

Motivation: Trying to add support to show detached sessions upon connection.
Linked issues: #3582

Checklist

  • [] Build rule all-supported completed successfully
  • [] Package upgrade completed successfully
  • [] New installation of package completed successfully

mosh now builds against libutempter, this is a requirement for adding support for displaying detached sessions.
@m4tt075
Copy link
Contributor

m4tt075 commented Jan 17, 2019

@sn00pster Yes, this looks great!

Just one observation and one question. The observation: I think the latest package is 1.1.6. It might better to use that. The question: Does this actually solve the original problem you investigated?

@sn00pster
Copy link
Author

sn00pster commented Jan 17, 2019

Humn, I just downloaded the archive and that is 1.1.5, the release list of archives only showed this as the latest. Looking at the CVS there is a later version but it looks like there were no real changes, just changes to documentation.

I’ll see if they have a later archive version, I just assumed the archive on the official page would be the latest.....

And no, it doesn’t fix the issue, I need to investigate why utmp doesn’t work with it, but this was a prerequisite for that support.

@m4tt075
Copy link
Contributor

m4tt075 commented Jan 17, 2019

OK. Does that mean, your problem has been solved, then?

@sn00pster
Copy link
Author

Sorry, no the problem has not been solved. I was hopeful that just adding this library would, but unfortunately it doesn’t.

However, this library is required to enable the feature I’m after, so having it build and be used is a requirement for getting the feature working. I need to debug the actual mosh server itself to see why it’s not adding the records to utmp, once I’ve done that hopefully it will work.

This work that I’ve done so far would also allow somebody else to debug the issue.

@sn00pster
Copy link
Author

Just as an aside, I checked the FTP site and they have 1.1.6 on there (they just haven't updated the link), so modified it for 1.1.6, still no change in that it doesn't work, but as least it's now the latest version.

Now I need to figure out the best way of debugging the issue at hand!

@m4tt075
Copy link
Contributor

m4tt075 commented Jan 18, 2019

Right. I'm afraid I won't be able to help you much more then. I only have one additional recommendation: It might be worthwhile to ensure that libutempter is REALLY automatically detected and correctly linked into mosh. As you basically had to "hardcode" the library and include pathes in the libutempter cross-package, automatic detection in mosh might(!) fail. I've epxerienced that with other packages. If so, you might have to add configuration arguments in the cross/mosh/Makefile to fix it.

Otherwise, I'd probably look for mosh experts on other forums to help you debug.

@sn00pster
Copy link
Author

sn00pster commented Jan 18, 2019 via email

@sn00pster
Copy link
Author

sn00pster commented Jan 18, 2019 via email

Copy link
Contributor

@ymartin59 ymartin59 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor improvement proposals.


.PHONY: libutempter_post_patch
libutempter_post_patch:
$(RUN) sed -e 's#@INSTALL_PREFIX@#$(STAGING_INSTALL_PREFIX)#' -i Makefile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am interested in a more "elegant" way to apply STAGING_INSTALL_PREFIX at "install" step... maybe overriding "DESTDIR" as make install command option may do the trick

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m really not familiar at all with spksrc, with matts help I’ve managed to get this far with libutempter but that’s the extent of my knowledge, I don’t know where to start with doing this another way!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need a bit of a “you need to do these changes” help for this, I’m new to spksrc and generally Makefiles (30 years of commercial development and I’ve avoided Makefiles!).

-libdir = /usr/lib
-libexecdir = /usr/lib
-includedir = /usr/include
-mandir = /usr/share/man
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mandir has been discarded, so man3dir will be mangled. OK it does not matter in our case, but I like when things are clean.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ll take a look tomorrow at this, I might have just got over zeleous

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ll fix this.

@ymartin59
Copy link
Contributor

@sn00pster
Copy link
Author

Right, the good news is that writing a small c program to manually fudge an entry into utmp works, so whatever the issue is it should be resolvable with a bit of debugging.

@sn00pster
Copy link
Author

This lib may be useful to tmux either: https://unix.stackexchange.com/questions/181824/compile-static-tmux-with-libutempter-support

Good to know this work might be usable for something else in synocommunity!

@sn00pster
Copy link
Author

Ok, I think I know what the issue is....I didn’t realise the library was quite so trivial and that it was an interface to a separate binary, so although I’ve compiled and linked to the library, I haven’t bundled the helper application that it builds and that actually does the work! This should work fine when I’ve made that change.

It will have to wait a few days as I’m currently at hospital having a liver transplant assessment done!

@sn00pster
Copy link
Author

I have this working now, but I am not at a computer and have done the work remotely on my iPad, when I'm back at the computer tomorrow I will finish up the work and submit a new pull request.

@m4tt075
Copy link
Contributor

m4tt075 commented Jan 21, 2019

Yay! Congrats! Looking forward to the new pull request!

@sn00pster
Copy link
Author

Any idea how we deal with permissions and groups?

the permissions and group need to be modified on the /var/run/utmp file, as per normal Synology behaviour a reboot of the NAS resets any changes made.

The group and mode need to be changed on the file to allow it to run with setgid.

Furthermore every user will need to be a member of the group, so how do we deal with existing and future users?

@m4tt075
Copy link
Contributor

m4tt075 commented Jan 22, 2019

Yes, can be done. You are entering the beautiful world of Synology (=ACL) permission management. I'd recommend reading the corresponding Wiki sections:

Then, you can look at the Gateone package as implementation example, i.e.

  • spk/gateone/Makefile (SERVICE_USER, SERVICE_SETUP, etc, are the relevant bits)
  • spk/gateone/src/service-setup.sh (although a lot in there is package dependent)

Just get back to us if you get stuck...

@sn00pster
Copy link
Author

Thanks, I’m shattered from my assessment so this is going to be a job for tomorrow.

@m4tt075
Copy link
Contributor

m4tt075 commented Jan 22, 2019

@sn00pster Whenever you are ready. Keeping my fingers crossed for you!

@sn00pster
Copy link
Author

I’ve taken a quick look at that, I don’t think the way that package does it will work for this on, the issue is that the permissions and group on a Synology system file (var/run/utmp) get reset after a boot of the NAS. While using postinst would work straight away, it wouldn’t survive a reboot.

I will take a look at the official plex spk as that has to do the same to the GPU driver for hardware transcoding.

@m4tt075
Copy link
Contributor

m4tt075 commented Jan 22, 2019

Hmh, not sure I understand correctly. Doesn't that file have read permissions already? Does libutempter really have to modify it?

@sn00pster
Copy link
Author

sn00pster commented Jan 22, 2019 via email

@m4tt075
Copy link
Contributor

m4tt075 commented Jan 22, 2019

Ugh, that's ugly. Packages can run as root. They did in the past. But all the premission changes, those by Synology, and subsequently here, had the main objective to avoid that...

@sn00pster
Copy link
Author

Quick question, In the past I hand crafted an spk for a much newer version than what Synology provided, I now no longer use docker on the Synology so have not bothered maintaining that any longer.

From memory there’s a script which gets called on start or stop of the service and I believe that it runs as root, so any objections if inside there I do th relevant chmod and chggrp commands so that th file becomes available to members of a utmp group?

Unless there’s a cleaner way?

I’ve verified that the group and permission changes work perfectly, so we’re nearly there with support for this.

@sn00pster
Copy link
Author

Thinking about this, the best way of sorting the group issue is to set the group of the file to users, any objections to this?

@m4tt075
Copy link
Contributor

m4tt075 commented Jan 23, 2019

Give it a try, but I don't think this works, as I think(!) the group still only has read permissions on that file, hasn'T it? I believe the only "clean" solution is to use the SERVICE functionalities and run the package as root. A viable approach is outlined in our Wiki (scroll down): https://github.com/SynoCommunity/spksrc/wiki/Service-Support. Never had to use this option myself so far though...

@sn00pster
Copy link
Author

sn00pster commented Jan 23, 2019 via email

@m4tt075
Copy link
Contributor

m4tt075 commented Jan 23, 2019

I'm pretty sure the SERVICE scripts can be used. You can specify whether they are startable or not. Using those scripts, whatever you would like to include in a start-stop-status just sits in the general section of service-setup.sh. I'd recommend employing those scripts because they will facilitate and ensure permission setting on your NAS works the way you intend it to be (the way how Synology handles this is NOT AT ALL straight forward!). Just ensure that the scripts run as root as outlined in the Wiki and you can play around with the service-setup.sh script, including all kind of chmods or other permission settings as needed.

Just to be clear, I don't think that you should run libutempter as a service, but that you need to amend the mosh package to achieve what you want...

@sn00pster
Copy link
Author

sn00pster commented Jan 24, 2019

Ok, so I looked at this briefly earlier, the synocli-net package does not run as a service, that is to say the only option available in the package manager is “uninstall”, there is no start stop option.

This makes sense for mosh as the initial connection is made over ssh and the mosh server is run and then ssh disconnects.

I’m going to have to do a bit more delving I think.

Apologies for seeming a bit dumb about this, I greatly appreciate all the help you’ve given me, I wouldn’t be at this point without you!

@m4tt075
Copy link
Contributor

m4tt075 commented Jan 24, 2019

@sn00pster You have been coming a long way with only very little! And mosh seems to be demanding. What you are trying to achieve is not straight-forward at all! You are doing great!

To be honest, I forgot that mosh is part of the syncli-net package. It might be easier if you (at least temporarily) create a separate spk/mosh package, so that testing is easier. Then you can try to convert that to a service.

@sn00pster
Copy link
Author

I’m pretty stuck :( I’m out of my depth here with the whole spksrc architecture.

My only other thought (which does work, but it’s not nice) is to create a task in the scheduler which runs at boot and as root and sets the permissions and group for the /var/run/utmp to 664 and users respectively.

It’s not a pretty solution.

I don’t know whether this can be automated with spksrc and even if it could whether it’s anywhere near an appropriate thing to be doing, it seems a very hacky way of doing it.

@ymartin59
Copy link
Contributor

I have found that old "cross/openssh" has disabled "utmp" support probably because of same permission troubles... Probably mosh and tmux binaries has to have "setuid" flag set to operate properly. Will do some testing...

@sn00pster
Copy link
Author

Yeah, it requires setuid on the helper binary.

Sorry, I forgot to sort out the rest of the changes I made, I will try to do that today and push them, but to get it to work I had to create a task to set the permissions so that the utmp file can be written.

It’s actually quite important that mosh is built with a working libutempter otherwise you could potentially end up with a lot of stale sessions running and be unaware of this.

@sn00pster
Copy link
Author

Ok, I seem to have lost the rest of the changes. :(

The fix I just pushed is required because the helper application doesn't seem to like checking for the std io and fails under DSM, so I just removed them so that the helper works.

The rest of the changes were to:

1.) Modify the make file so that the libexec points to the installed target
2.) Modify the files that are installed so that the helper binary is installed as well.

These are minor changes that would take an experienced dev here a minute to perform, I sadly don't have the time at the moment to recreate these as it will require me digging once again through the spksrc documentation.

Once these are done, you should have a working libutempter and helper binary, but due to the permissions problem it still will not work, which is why I use a startup task to set them.

I'm hopeful somebody else can run with this, as I mentioned earlier this is an important requirement for mosh, I'd even say that it shouldn't be an optional thing in the mosh code because without it you can end up with a lot of stale sessions.

@ymartin59
Copy link
Contributor

Have you done that changes manually on DSM or in a package itself? If so, you can upload in comment your binary package and I will reverse-engineer your "changes".
For permissions on that utmp file, is it possible to use ACL? By the way, I guess DSM update flushes them too.

@sn00pster
Copy link
Author

sn00pster commented Feb 9, 2019 via email

@sn00pster
Copy link
Author

I no longer have a synology as I have replaced it with a Unraid server, hopefully somebody else will pick up where I left off.

@m4tt075
Copy link
Contributor

m4tt075 commented Mar 27, 2019

@sn00pster I agree. You have come a long way. Many thanks for your contribution and all the best for your Unraid experience...

@ymartin59
Copy link
Contributor

I have worked on this, including utempter into tmux (which is easier/faster to test) but cannot confirm as "last" does not exist on DSM, I tried to confirm with "w" from "synogear" package... but I am not sure yet tmux properly enlists user login/logout thanks to utempter...

@ymartin59 ymartin59 mentioned this pull request Jul 15, 2019
3 tasks
@ymartin59
Copy link
Contributor

Hello @hgy59
As you seem to like challenges and succeed in delivering, I have one to propose you: get "libutempter" to work in DSM context so that it can be used in both tmux and mosh to manage sessions.
Again many thanks for your help

- if (fstat(i, &sb) < 0)
- /* At this stage, we shouldn't even report error. */
- exit(EXIT_FAILURE);
- }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any idea what this code is for?
what it the reason to remove it?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't work on synology, I removed it because it caused a failure and it doesn’t actually do anything than check the std channels.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for info I’m sn00pster, I created a new github account.

@ymartin59 ymartin59 mentioned this pull request Oct 10, 2020
3 tasks
@hgy59 hgy59 mentioned this pull request Jun 3, 2021
3 tasks
@hgy59
Copy link
Contributor

hgy59 commented Jun 3, 2021

Hello @hgy59
As you seem to like challenges and succeed in delivering, I have one to propose you: get "libutempter" to work in DSM context so that it can be used in both tmux and mosh to manage sessions.
Again many thanks for your help

Finally I created a new PR for this #4667

@hgy59 hgy59 closed this in #4667 Oct 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants