I did some more testing with this on an openSuSE 10.1 system and found
that it has the same problem.  It seems that startproc forks the new
process using the caller's environment, even if it is starting as a new
user (I confirmed this in the source for startproc as well).

So this means that under SuSE, invoking the init script from root will
always cause HOME to be the HOME of root.  This probably explains why I
found a number of forum entries where people were having problems
getting Slimserver to start after installation, since the SuSE init
scripts all use startproc to invoke Slimserver under the Slimserver
user.

So I began looking for a way to find the user's home directory without
relying on the environment.  The following code should work on Unix,
but not on Windows (but I see that Prefs.pm checks for Unix, so it
should be OK).

It uses 'getpwuid()' (http://perldoc.perl.org/functions/getpwuid.html)
to retreive the user's home directory, based on the UID ("$<") of the
currently running user.


Code:
--------------------
    
  @uvals = getpwuid($<);
  $dir = $uvals[7];
  print ("Retreived home directory = ".$dir."\n");
  
--------------------


Running the above in a Perl script invoked via startproc correctly
gives the user's home directory based on the userid that startproc is
told to use (i.e. if used with "-u slimserver" the output shows
"/usr/local/slimserver" instead of "/root").


-- 
AubreyCTurnerJr
------------------------------------------------------------------------
AubreyCTurnerJr's Profile: http://forums.slimdevices.com/member.php?userid=9795
View this thread: http://forums.slimdevices.com/showthread.php?t=32200

_______________________________________________
discuss mailing list
[email protected]
http://lists.slimdevices.com/lists/listinfo/discuss

Reply via email to