Bug 8461 - MySQL (and therefore SqueezeCenter) fail to start if TMP/TMPDIR env vars present
: MySQL (and therefore SqueezeCenter) fail to start if TMP/TMPDIR env vars present
Status: RESOLVED WONTFIX
Product: Logitech Media Server
Classification: Unclassified
Component: Database
: 7.2
: PC Other
: -- normal (vote)
: Future
Assigned To: Matt Wise
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-06-17 18:37 UTC by Peter Watkins
Modified: 2009-09-08 09:12 UTC (History)
0 users

See Also:
Category: ---


Attachments
patch against SVN that fixes the problem (867 bytes, patch)
2008-12-20 17:34 UTC, Peter Watkins
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Watkins 2008-06-17 18:37:41 UTC
I've been unable to start SC7.2 on an Ubuntu 6.06 LTS system. Today I found the culprit. I have login scripts that set TMP and TMPDIR environment variables for security reasons. If such variables are set, MySQL fails to start and SC7 keeps restarting in hopes that MySQL will come up. This means tha SC7 will start when my machine boots (the init process doesn't set TMP/TMPDIR), but from a command line I could not start/restart SqueezeCenter.

The simplest solution is to unset the TMP and TMPDIR environment variables in the init script, e.g.

--- /etc/init.d/squeezecenter   2008/03/28 16:19:48     1.1
+++ /etc/init.d/squeezecenter   2008/06/18 01:36:57
@@ -23,6 +23,9 @@
 LOGDIR=/var/log/$NAME/
 CACHEDIR=/var/lib/$NAME/cache
 SLIMOPTIONS=
+# unset TMP/TMPDIR env vars so mysql won't try using a dir it cannot access
+unset TMP
+unset TMPDIR

 # Read config file if it is present.
Comment 1 Chris Owens 2008-06-19 10:31:13 UTC
Matt are you the right person to consider this fix?
Comment 2 Matt Wise 2008-06-19 11:08:45 UTC
I'm not sure this is somethign we should fix... in the case where someone sets a specific TMP dir, that is usually done for a good reason and we don't want to be overwriting that setting. Rather, in the specific case where a user overrides these directories with a TMP and TMPDIR variable that do not work, I think it should be up to them to solve the issue for their system.

The much more common reason to replace TMP and TMPDIR is to point them to a memory disk partition, or some other system location where all users have access to write files. In this case, mysqld should start up just fine ... but if we override the TMP and TMPDIR variables, then we start writing files somewhere the sysadmin of that box had not intended.

Does that make sense? 
Comment 3 Peter Watkins 2008-06-19 15:31:38 UTC
I follow your argument. In my experience TMP/TMPDIR are generally used for security reasons (most apps default to /tmp which is world-writable and often tmpfs anyway). That said, you're right that security isn't the only motivator for TMPDIR, and regardless of the user's motivation, SC7 shouldn't ignore TMPDIR if it specifies a workable location.

Here's a different approach that takes care of both concerns -- it detects problems with TMPDIR, complains, and unsets TMPDIR *only* if trying to honor TMPDIR would cause MySQL to fail. If an admin has set TMPDIR to a value that SC7 can use, this patch will leave TMPDIR intact. Sound good?

--- squeezecenter_safe  2008/06/18 01:33:46     1.1
+++ squeezecenter_safe  2008/06/19 21:33:22
@@ -27,6 +27,14 @@

 echo `date "+%F %H:%M:%S"` "squeezecenter_safe started." >> /var/log/squeezecenter/server.log

+# make sure TMPDIR won't keep MySQL from starting
+if [ "$TMPDIR" != "" ]; then
+  if [ \( \! -d "$TMPDIR" \) -o \( \! -w "$TMPDIR" \) ]; then
+    echo `date "+%F %H:%M:%S"` "squeezecenter_safe: TMPDIR \"${TMPDIR}\" not valid, will not be used " >> /var/log/squeezecenter/server.log
+    unset TMPDIR
+  fi
+fi
+
 while true
 do
   # From the Bash Reference Manual:
Comment 4 Matt Wise 2008-08-04 09:15:12 UTC
I wonder if this change can actually be made in slimserver.pl... if I just make the change to the _safe file, it only affects ReadyNas and Debian. 

Comment 5 Mickey Gee 2008-08-07 11:42:45 UTC
Moving to 7.3 ....
Comment 6 Matt Wise 2008-11-07 09:23:47 UTC
Peter,
  Sorry its taken a while... Can you look at the new OSDetect code that has been split up into individual modules and work up a patch for that code? Once we have it we'll review the patch and implement it. 
Comment 7 Blackketter Dean 2008-11-23 14:22:17 UTC
Ping peter...
Comment 8 Peter Watkins 2008-12-18 06:04:22 UTC
Sorry, guys. I've been pretty busy over here & haven't had time to look at the new code beyond looking at the wiki page. It'll likely be a(nother) week before I can really look at this.
Comment 9 Peter Watkins 2008-12-20 17:34:04 UTC
Created attachment 4489 [details]
patch against SVN that fixes the problem

OK, I found some time to look at this. At first glance, MySQLHelper::startServer() looks like the most appropriate place to add the logic. I haven't tested this with a proper OS build (.deb/.rpm/.dmg/.EXE), but it tests fine with the SVN code (recognizes bad TMPDIR values & rejects them, recognizes good values & respects them).
Comment 10 Peter Watkins 2008-12-21 05:34:00 UTC
I just used 'strings' to look at the included Linux binaries; 'alac' also appears to use TMPDIR. With 8.0 moving away from MySQL, maybe the TMPDIR check should reside elsewhere to prevent weird hard-to-debug transcoding problems.
Comment 11 Peter Watkins 2008-12-21 05:35:35 UTC
...and references to TMPDIR are sprinkled throughout the CPAN File code...
Comment 12 James Richardson 2009-01-08 09:54:32 UTC
Matt: can you have a look at the patch in comment 9 and assign this bug an appropriate target?
Comment 13 Matt Wise 2009-05-04 12:10:01 UTC
No longer applicable. Next major release of SqueezeCenter will use SQLLite as DB back end instead of MySQL.