Issue 64421 - Mac OS X: create temp files in /tmp instead of /var/tmp
Summary: Mac OS X: create temp files in /tmp instead of /var/tmp
Status: CLOSED FIXED
Alias: None
Product: porting
Classification: Code
Component: MacOSX (show other issues)
Version: current
Hardware: All All
: P4 Trivial (vote)
Target Milestone: OOo 2.0.3
Assignee: pavel
QA Contact: issues@porting
URL:
Keywords:
: 55865 (view as issue list)
Depends on: 64399
Blocks:
  Show dependency tree
 
Reported: 2006-04-15 23:06 UTC by pavel
Modified: 2006-05-08 13:39 UTC (History)
4 users (show)

See Also:
Issue Type: PATCH
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments
Does this make at least sv???.tmp directories go into /tmp? (1006 bytes, patch)
2006-04-16 11:20 UTC, pavel
no flags Details | Diff
New version (1.86 KB, patch)
2006-04-17 19:15 UTC, pavel
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this issue.
Description pavel 2006-04-15 23:06:51 UTC
Facts:
Current OOo creates *some* files in /var/tmp and some in /tmp.
/tmp is cleaned up on system boot. /var/tmp is not.
The variable P_tmpdir is defined in stdio.h as "/var/tmp".
Some parts of the code use different strategy to find the directory for
temporary files.

Apple suggests
(http://developer.apple.com/documentation/MacOSX/Conceptual/BPFileSystem/Articles/WhereToPutFiles.html#//apple_ref/doc/uid/TP40001411-111010):

--- citation ---
Mac OS X provides an established set of directories for storing temporary files.
The primary directory (/tmp) is where most local files go, but you should never
hardcode this path into your application. Using hardcoded paths limits the
portability and longevity of your code. Instead, Carbon applications should use
the FSFindFolder function (in the Core Services framework) to obtain a reference
to the temporary directory; Cocoa applications should use the
NSTemporaryDirectory function in Foundation Kit.
--- citation ---

I experimented a bit with this function and here are the results:

# kUserDomain
macmini:~/q oo$ gcc -Wall tmpdir.c -framework CoreServices; ./a.out 
Temp directory is /Volumes/Build/oo/Library/Caches.
# kSystemDomain
macmini:~/q oo$ gcc -Wall tmpdir.c -framework CoreServices; ./a.out 
Temp directory is /private/var/tmp/folders.502/TemporaryItems.
macmini:~/q oo$ 

No /tmp ;-) Hmm. So: how "standard" we want to be? Do we want to put temporary
directories to system directory or user's temporary directory?

Source file for testing:

#include <stdio.h>
#include <CoreServices/CoreServices.h>

int main ()
{
  OSStatus status;
  FSRef tmpDirRef;
  UInt8 *path;

  status = FSFindFolder( kSystemDomain, kTemporaryFolderType,
                        kDontCreateFolder, &tmpDirRef);

  status = FSRefMakePath(&tmpDirRef,
                         path, PATH_MAX);

  printf("Temp directory is %s.\n", path);

  return 0;
}
Comment 1 moxfox 2006-04-16 01:20:24 UTC
I think we should do one of these:

1) Use a proper cocoa function to find the tempfile and use that
2) Use a proper carbon function to find the tempfile and use that
3) Do unix style and just use /tmp. IMHO The documentation does suggest to use
/tmp if the "proper" functions are not used.
Comment 2 pavel 2006-04-16 08:33:51 UTC
I forgot to assign to me ;-)

mox: we can't do Cocoa and Apple docs explicitly said: "but you should never
hardcode this path into your application." ;-)

But I prefer /tmp anyway...
Comment 3 moxfox 2006-04-16 08:43:31 UTC
Quote: ***
The primary directory (/tmp) is where most local files go, but you should never
hardcode this path into your application.
***

To me the text above means: If you are unable to use the functions we give you
(Cocoa/Carbon), you should use /tmp as your temporary files directory.
Comment 4 pavel 2006-04-16 08:50:44 UTC
mox: yes, I understand it. And "we should never hardcode /tmp into our
application" ;-)
Comment 5 pavel 2006-04-16 11:20:52 UTC
Created attachment 35737 [details]
Does this make at least sv???.tmp directories go into /tmp?
Comment 6 moxfox 2006-04-16 20:38:17 UTC
Unfortunately your patch did not make a difference (at least when I patched,
compiled and delivered the tools -directory)
Comment 7 pavel 2006-04-17 10:49:51 UTC
mox: yup, it worked here, but it can't work for you, because I forgot to include
module sal in the patch but I had it patched in my tree.

I'll test the complete patch first in my clean build and then will attach it.
Comment 8 pavel 2006-04-17 19:15:26 UTC
Created attachment 35758 [details]
New version
Comment 9 pavel 2006-04-17 19:18:48 UTC
The new version of the patch attached. I verified it works here with m163.

Temporary files are created in /tmp:

macmini:/tmp oo$ lsof |grep soffice|grep tmp
soffice.b  4440   oo   24u    unix 0x01b3f1e0        0t0         
/tmp/OSL_PIPE_502_SingleOfficeIPC_87c150c14f373b49fa46612c5c9d8c5c
soffice.b  4440   oo   36u    VREG       14,2          0  9237790
/private/tmp/sv62m.tmp/sv62n.tmp
macmini:/tmp oo$ 

mox: can you please confirm it too?
Comment 10 moxfox 2006-04-18 11:26:06 UTC
Pavel: Yes, your patch fixes the issue. Confirmed.
Comment 11 pavel 2006-04-18 21:05:01 UTC
mox: thanks. I'll wait for pj53 integration and will create new cws for this
/tmp and /var/tmp stuff once m164 is ready.
Comment 12 pavel 2006-04-25 12:05:45 UTC
Patch applied to pj54.

mox: Please verify.
Comment 13 tino.rachui 2006-04-26 07:01:48 UTC
*** Issue 55865 has been marked as a duplicate of this issue. ***
Comment 14 jjmckenzie 2006-04-30 07:25:11 UTC
Temporary files are now created in /tmp.  Cleaned out /var/tmp to confirm.

James
Comment 15 pavel 2006-05-08 13:39:59 UTC
Seen in m167.