Commit Graph

40 Commits

Author SHA1 Message Date
Allan Odgaard
8ce1c48fe7 Introduce io::spawn API
This is a wrapper for posix_spawn that sets up pipes for stdin, out, and error.
2013-03-21 14:39:34 +01:00
Allan Odgaard
957d6d018d Don’t treat directories as executables
Related to issue #907.
2013-03-19 14:56:22 +01:00
Allan Odgaard
beb5348e32 Don’t abort when failing to run subcommand
Fixes #907.
2013-03-19 14:56:22 +01:00
Allan Odgaard
0d2af1fbfa Don’t use posix_spawnattr_setpgroup
This appears to fail in rare circumstances and there is no reason why the io::exec code sets up a process group, so easier to just remove this.
2013-03-17 15:44:07 +01:00
Allan Odgaard
dfee671b6a Don’t use POSIX_SPAWN_CLOEXEC_DEFAULT on 10.7
Using this flag on 10.7.5 seems to cause a kernel panic.

Fixes #896.
2013-03-17 15:44:06 +01:00
Allan Odgaard
24f6f3bd2c Use posix_spawn instead of fork/exec
Using Apple’s POSIX_SPAWN_CLOEXEC_DEFAULT appears to be the only safe way to spawn a child process in a multi-threaded program.
2013-03-10 16:07:11 +01:00
Allan Odgaard
f69ac60b0c Limit file descriptors passed to child process
Instead of passing the file descriptor to the child, and have the child close it, we set FD_CLOEXEC on the file descriptor in the parent process.

While it limits the window in which another thread can fork() and cause the file descriptor to be “leaked”, it doesn’t eliminate the problem.
2013-03-10 16:07:10 +01:00
Allan Odgaard
13edc6d131 Use O_CLOEXEC when opening files
This avoids leaking file descriptors into child processes, which would otherwise happen if another thread forks while the file descriptor is open.
2013-03-10 16:07:10 +01:00
Allan Odgaard
cd2b0882f0 Use new test system for a few frameworks 2013-02-22 15:55:28 +01:00
Allan Odgaard
972348687c Make fs-events wrapper thread safe
Previously this wasn’t used from multiple threads, but with the new testing system it can be.
2013-02-22 15:51:51 +01:00
Allan Odgaard
f05c76a882 Implement path::join for initializer lists
This allows passing multiple path components to path::join
2013-02-12 11:09:24 +01:00
Allan Odgaard
099fbdf042 Accept NULL_STR in path::info 2013-02-11 14:21:21 +01:00
Allan Odgaard
9eb4044fdb Switch to simpler regexp::search 2013-02-08 11:20:35 +01:00
Allan Odgaard
bb6d003e4f Read environment variable whitelist from user defaults
This is read using the ‘environmentWhitelist’ key and the value should be a colon-separated list of variables that should be inherited from TextMate’s parent process. If the variable includes an asterisk then it is matched as a glob.

Example:

    defaults write com.macromates.TextMate.preview environmentWhitelist '$default:MANPATH:*EDITOR'

Here ‘$default’ will expand to TextMate’s default whitelist.

Normally TextMate will setup HOME, PATH, TMPDIR, LOGNAME, and USER. If you whitelist any of these, then the variable (if set) will instead be inherited from the parent process.

Closes #718.
2013-02-08 11:20:34 +01:00
Allan Odgaard
759e4d9720 Introduce path::is_child(child, parent)
This also returns true when ‘child == parent’ so perhaps a better name should be chosen for this function.
2013-02-05 15:25:45 +01:00
Allan Odgaard
b0c4363c48 Introduce path::cache
This gives the cache location — this one is not cleaned as often as the temp directory.
2013-01-21 15:03:52 +01:00
Allan Odgaard
6bdf883abf fixup! Optimize path::disambiguate 2013-01-20 12:49:34 +01:00
Allan Odgaard
edbf9ac079 Optimize path::disambiguate
We now sort the reversed paths and do a linear sweep.
2013-01-17 09:16:04 +01:00
Allan Odgaard
3bee6cf5c6 Use path before inode to determine file identity
Previously when opening a file TextMate only looked at the (cached) inode of the open documents to learn if the requested file was already open. This could result in opening two versions of the same file e.g. after ‘git rebase’ as git will write new files with new inodes when updating the working copy.

Closes issue #666.
2013-01-13 13:02:46 +01:00
Allan Odgaard
da6afa03f0 Fix concurrency bug in path::make_dir
The function could fail if the directory was created after the function had tested that it didn’t exist, as the mkdir() would then fail (with “Already Exists”).
2012-09-30 23:06:58 +02:00
Allan Odgaard
a0c4af64bd Remove trailing whitespace
Only removed from non-empty lines.
2012-09-25 14:16:50 +02:00
Allan Odgaard
7df336664a Add set_basic_environment
This is in cases where we don’t want the “clean” environment setup by default.
2012-09-24 21:32:29 +02:00
Allan Odgaard
13f35bd5b1 Whitelist rather than blacklist inherited variables
Initially the environment was clean but it was found that some variables should be inherited, e.g. SSH_AUTH_SOCK.

Therefor a blacklist was introduced, but it seems futile trying to keep it updated with all the variables that may affect the behavior of commands executed from within TextMate, therefor we now use a whitelist.

Probably the whitelist should be user configurable as launchd uses environment variables to communicate dynamically allocated sockets (like SSH_AUTH_SOCK, but there are also some Apple-prefixed variables pointing to named sockets).

Issue #238.
2012-09-21 17:50:52 +02:00
Allan Odgaard
9f339bbae1 Fix thread related crash
Since the std::map hosting the basic environment was using a (function local) static initializer, it would be destroyed during exit — though there might be threads using the basic environment, and joining these might happen after destroying the basic environment.

This should explain the crash in network::launch_tbz.
2012-09-21 17:50:52 +02:00
Allan Odgaard
c7971c5f63 Use range-based for instead of std::for_each 2012-09-20 12:22:21 +02:00
Allan Odgaard
54bf2be75f Make variable const
Just to stress that map is immutable.
2012-09-18 17:33:01 +02:00
Allan Odgaard
aed4c1c27f No longer show dialog for readlink() failure
Only one readlink() failure reported (issue #389) which wouldn’t explain the crashes which the dialog (introduced in 68ed8293) was trying to track down.
2012-09-09 20:43:53 +02:00
Allan Odgaard
68ed829313 Show alert if readlink fails
I am seeing crash reports from resolve_links and I can’t think of any other reason for this crash, than readlink() returning a value which is neither -1 nor in the range [0..len].
2012-08-29 17:43:04 +02:00
Allan Odgaard
0e96a04d76 Remove compatibility checks
Since we now require 10.7 we don’t need all of this. Keeping it around is just noise that can lead to confusion about code paths.
2012-08-29 16:02:29 +02:00
Allan Odgaard
f96de9319e Fix/change path::with_tilde
We now leave a potential trailing slash in the result.

This fixes the issue of the missing slash in ⌘T — while I normally prefer the slash to be stripped, I think path::with_tilde should be an exception since effectively it is just replacing the path prefix, it shouldn’t do any real processing (although we do actually normalize the string).

Also fix a bug where we would use tilde for paths pointing to a user folder for a user with current user’s name as prefix.
2012-08-29 15:43:55 +02:00
Allan Odgaard
cbe91ff831 Assume compiler support for explicit keyword
Since we require a fairly recent clang for other features, there is no reason to test for this one.
2012-08-29 14:27:35 +02:00
Jacob Bandes-Storch
e3aa997b06 Use libc++: replace std::tr1 with std 2012-08-28 13:30:20 +02:00
Allan Odgaard
3415d775c5 Use symbolic name for FD_CLOEXEC
Unsure why I was using ‘1’ — perhaps the symbolic name was missing in the older SDK.
2012-08-24 16:52:45 +02:00
Allan Odgaard
4259a8f884 Add path::is_absolute.
This is actually not entirely trivial since we can have a path that starts with a slash but includes more ‘..’ components than there are actual directories in the path.
2012-08-13 22:53:16 +02:00
Allan Odgaard
a3b8be728d fixup! Turn private run_cmd (scm/utility.h) → io::exec
Forgot to update debug variable.
2012-08-13 18:05:56 +02:00
Allan Odgaard
512e5fdede Prune GIT variables from the inherited environment
Incase we do a git commit that launches TextMate, it will inherit a bunch of variables from git, including GIT_DIR, which will cause issues for the Git bundle.
2012-08-11 20:37:05 +02:00
Allan Odgaard
5f55fcb514 Turn private run_cmd (scm/utility.h) → io::exec 2012-08-11 19:39:18 +02:00
Allan Odgaard
e680130eaf Move oak::basic_environment to the io framework
Previously this was under the OakSystem framework which depends on the io framework meaning that the io framework itself was unable to obtain a basic environment, which is necessary for next commit.
2012-08-11 19:31:10 +02:00
Gerd Knops
8d523c0a66 Rework path::is_local to support disk images.
This enables SCM badges for disk images. The check is done using the new (10.7) kCFURLVolumeIsLocalKey.
2012-08-10 19:15:02 +02:00
Allan Odgaard
9894969e67 Initial commit 2012-08-09 16:25:56 +02:00