You are here

Environment variables

9 posts / 0 new
Last post
rab040ma
Offline
Last seen: 5 months 2 days ago
Joined: 2007-08-27 13:35
Environment variables

Has there been discussion of environment variables? I know lots of programs ignore them, but some don't, and it might be helpful to do some things with them.

One would be the TEMP variable (not the registry setting, but the variable passed in the environment). I think one can change the environment that a program receives from the program that launches it. Is that the case in Windows? If so, could the PAM look at the TEMP (and TMP) environment variables it inherits, make a subdirectory there, set the two variables to that subdirectory, and pass that environment variable to programs it starts? One benefit of this is that the PAM could, as it closes, remove files from that directory, and the directory itself (assuming they are not still locked). Programs that are well-behaved enough to honor the environment variable would likely also clean up the temp directory after themselves, but it might add one level of cleanup to the system. The PAM could also store random characters in any files it finds there, then delete them, to make it that much harder for someone to get good data from undeleted files.

I'd say redirect the temp directory to the USB stick, but that would slow things down a bit.

The other environment variable I would like to see PAM check is HOME. There are some programs that honor it. If the environment inherited by portable apps had %HOME% pointing at, say, the documents directory on the USB drive, that might help them find their settings. It's not like %APPDATA% or %PROFILE%, which are closely tied to the operating system, so it is unlikely to interfere.

Perhaps this has already been discussed somewhere? Or perhaps it was assumed that not enough programs would honor that environment to implement it? I did a search but couldn't find anything in the forum about a previous discussion.

m2
Offline
Last seen: 13 years 9 months ago
Joined: 2006-12-12 12:00
I think one can change the

I think one can change the environment that a program receives from the program that launches it. Is that the case in Windows?
Yes, EnvVars are inherited.

I'd say redirect the temp directory to the USB stick, but that would slow things down a bit.
1. Sometimes, not a bit. There are machines with TEMP on ram drive. And Portable Drives on bluetooth cell phones. For app that makes extensive use of TEMP, that's really a big difference. Secure deletion would slow it even more. I think this "sometimes" is too much for generic thing like menu. Launcher for specific app could do it, but..
2. It would mean increased wear on flash drives.
3. You would need higher drive capacity.
4. What for? You can monitor TEMP changes and overwrite deleted files spawned by your apps with random characters.

"Those people who think they know everything are a great annoyance to those of us who do." Asimov

rab040ma
Offline
Last seen: 5 months 2 days ago
Joined: 2007-08-27 13:35
yup

I think we agree. Temporary files are best stored in the place the OS defines for temporary files. Deleting them would be a good start for cleanup; overwriting them even once with random data would be another magnitude of benefit, though still not huge.

MC

John T. Haller
John T. Haller's picture
Offline
Last seen: 3 hours 41 min ago
AdminDeveloperModeratorTranslator
Joined: 2005-11-28 22:21
Next Version

Actually, the next version of PAM is setting the TEMP variable to a sub-directory within TEMP on the local machine. (It can't be on the drive as that would slow things down a lot on flash drives, which most folks use).

Funny someone else posted this when it was one of the 'surprises' I was doing in the next release.

As for HOME, *very* few apps honor this, and the ones that do are usually GTK-based or similar, so they require a custom launcher already, anyway. Part of what that launcher does is set that variable (check GIMP for an example). Adding it into PAM won't buy us anything.

And we'd discussed APPDATA and USERPROFILE. As you'd mentioned, these aren't really an option as they mess up too many things.

Sometimes, the impossible can become possible, if you're awesome!

rab040ma
Offline
Last seen: 5 months 2 days ago
Joined: 2007-08-27 13:35
discuss

Hmm, minds thinking alike or something.

If it isn't too much trouble, I'd set TMP too; again, the programs that honor it are either CL or GTK, but it shouldn't add a whole lot of overhead, especially setting it to the same as TEMP.

What's the word on clearing the files in that directory on exit? Again, I'm not proposing a DoD standard erasure, just a simple clear-before-delete, quietly ignoring files that remain locked, or logging them ... or in verbose mode, doing a popup to ask if the user has not left something running by mistake...

Is this discussion going on some place that is publicly accessible? If so I seem to have missed it.

MC

m2
Offline
Last seen: 13 years 9 months ago
Joined: 2006-12-12 12:00
Deleting files can cause

Deleting files can cause data loss... My progs leave nothing in temp, but sometimes I do. Of course, only when I know I will use the same machine soon.
I'm not against it, but against setting it on by default.

"Those people who think they know everything are a great annoyance to those of us who do." Asimov

rab040ma
Offline
Last seen: 5 months 2 days ago
Joined: 2007-08-27 13:35
file storage

I used to have to deal with people who stored files in their Trash, because it was out of the way. They complained that every once in a while their trash got emptied, and the file they wanted was gone.

I realize different people have different needs and ways of working, but I have less sympathy for people who think Trash or Temp are places to keep data for any length of time.

If you are putting the file there yourself, as opposed to a program storing temporary data there, you can put it in the real "Temp" directory, not the subdirectory we are suggesting PA set the environment variable to. Or it would only take you a few tries to figure out that there are other, safer places to put data...

MC

m2
Offline
Last seen: 13 years 9 months ago
Joined: 2006-12-12 12:00
Temp IS the right place to

Temp IS the right place to store temporary data. And when PAM changes the variable, subdirectory becomes the real temp directory. I'm not going to change hotkeys from "cd %TEMP%" to "cd %TEMP%\..", because it would not be portable.

And temp is a safe place to put data - I never found a program that deleted all files there w/out asking me first.. I believe programs should never touch files that belong to them unless user asked them to do it. Don't you agree?

"Those people who think they know everything are a great annoyance to those of us who do." Asimov

rab040ma
Offline
Last seen: 5 months 2 days ago
Joined: 2007-08-27 13:35
If the PAM is setting the

If the PAM is setting the environment so %TEMP% points to a subdirectory, then you are correct that you shouldn't have to worry about it; the "environment" your application "inherits" has %TEMP% pointing to the correct subdirectory already. So, yes, as far as your application can tell, it is using the temp directory it is supposed to.

By convention the temp directory is used to story temporary files being used by an application. By that same convention, the application isn't using them any more when it exits, so the application deletes those temporary files as part of its shutdown activity. By this convention if the program itself is not running, but there are files stored in the temporary directory, they are by definition leftover files that didn't get cleaned up properly, perhaps because the application or computer crashed. Since data that needs to be kept from one session to the next is stored in AppData or My Documents or whatever, there is no problem deleting the leftover temporary files that are found in the temp directory.

On the other hand, it is good for applications not to delete things that the user wants kept around.

Conventions about the Temp directory conflict with expectations about whether programs should delete files without asking first. The question is what the user expects. If the user expects that "real" data, important data that should be kept, is only stored in My Documents or AppData (or the corresponding data folders that PA sets up), then there is no problem deleting temporary files that didn't get cleaned up. If the user expects that applications are going to store data wherever they want, including the temp directory, and that the data might be needed in the future, then one shouldn't clean up temp directories.

Obviously, one shouldn't go deleting temporary files while they are being used. The normal time to clean up temporary directories is when the user is logging off or on. The corresponding event for PA is when the PAM is started on insertion, or when the PAM exits prior to the USB being removed.

One also needs to differentiate between system temporary files, my own temporary files, and temporary files being used by others in a multi-user environment. But in general the same convention applies: if there are files left in the temp directory when the application (or user) has exited, they can and should be cleaned up.

Does any of that match your experience?

MC

Log in or register to post comments