Bug 16343 - restart server can't work with --user/--group
: restart server can't work with --user/--group
Status: RESOLVED FIXED
Product: Logitech Media Server
Classification: Unclassified
Component: Misc
: 7.5.x
: PC Other
: -- normal (vote)
: 7.6.x
Assigned To: Andy Grundman
: patch_waiting
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-07-04 18:19 UTC by Quentin Garnier
Modified: 2011-08-26 15:01 UTC (History)
3 users (show)

See Also:
Category: ---


Attachments
Tentative fix (643 bytes, patch)
2011-08-21 17:36 UTC, Sébastien Phélep
Details | Diff
Cleaner patch (602 bytes, patch)
2011-08-26 14:34 UTC, Sébastien Phélep
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Quentin Garnier 2010-07-04 18:19:09 UTC
On any Unix, when the server is started with --user and/or --group, it won't be able to restart on its own.  The code will simply refuse to continue as it is not running as root.

I had a try at a patch that introduced a --restart flag when the server was being restarted, and allowed the code to skip changing the credentials when the following conditions were met:
  - the server was passed --restart
  - $> is equal to the target uid
  - $) is equal to the target gid.

However, the server ran into issues with mysqld further on;  I haven't tried very hard, but I might revisit it later.

The patch was also testing for the --restart thing when trying to write its pid to $pidfile, as there is no point in doing that when the server has exec()'d over itself.
Comment 1 Michael Herger 2010-07-06 00:41:55 UTC
what kind of restart are you talking about?
Comment 2 Quentin Garnier 2010-07-06 05:43:47 UTC
The kind that is initiated by main::stopServer(1).  Typically happens when you change the active state of a plugin, in my experience.
Comment 3 Michael Herger 2011-05-27 09:01:07 UTC
*** Bug 16921 has been marked as a duplicate of this bug. ***
Comment 4 Sébastien Phélep 2011-08-21 17:36:12 UTC
Created attachment 7413 [details]
Tentative fix

I'm confirming this bug on my QNAP.

I've attached a fix that will ensure changeEffectiveUserAndGroup() won't be called if the user launching the server is already the one specified with --user.
I've not checked thoroughly, but the effective group should be preserved.

By the way, I can see an obvious error in the original code:
defined($user) eq "root" *CANNOT* be true.

Wasn't sure what it was supposed to do, so left the test there, however.
Maybe that's why I had the same problem on my ReadyNAS?
Comment 5 Sébastien Phélep 2011-08-21 17:36:32 UTC
Confirming the bug, by the way.
Comment 6 Sébastien Phélep 2011-08-21 17:38:45 UTC
And the bug's still there in 7.6.1 r33110.
Comment 7 Charles Razzell 2011-08-21 21:24:04 UTC
Confirmed that Seb's patch was both necessary and effective on 7.6.1 RC3 running on a Buffalo Linkstation. Without the patch, SBS fails to restart when enabling or updating a plugin.
Comment 8 Sébastien Phélep 2011-08-26 14:34:08 UTC
Created attachment 7429 [details]
Cleaner patch

This one looks definitely cleaner.
Comment 9 SVN Bot 2011-08-26 15:01:37 UTC
 == Auto-comment from SVN commit #33230 to the slim repo by agrundman ==
 == http://svn.slimdevices.com/slim?view=revision&revision=33230 ==

Fixed bug 16343, patch from S?\195?\169bastien Ph?\195?\169lep to allow restarting to work with user/group switches