Compare commits

..
3 Commits
Author SHA1 Message Date
Eelco Dolstra 29fd60131b * Add a primop to return the context of a string. 2010-01-31 20:54:44 +00:00
Eelco Dolstra 6d1abdc6d9 * In string contexts containing derivations
(e.g. "${somePkg}/bin/foo"), store the original derivation
  expression in the context.
2010-01-31 20:08:57 +00:00
Eelco Dolstra 25fc95d56d 2010-01-31 20:06:58 +00:00
27 changed files with 392 additions and 304 deletions

No files matched your search

-1
View File
@@ -262,7 +262,6 @@ AC_CHECK_FUNCS([setresuid setreuid lchown])
# Nice to have, but not essential.
AC_CHECK_FUNCS([strsignal])
AC_CHECK_FUNCS([posix_fallocate])
AC_CHECK_FUNCS([fdatasync])
# This is needed if ATerm or bzip2 are static libraries,
-3
View File
@@ -1,8 +1,5 @@
#! @shell@ -e
# Cygwin compatibility hack: bunzip2 expects cygwin.dll in $PATH.
export PATH=@coreutils@
@coreutils@/mkdir $out
@coreutils@/mkdir $out/tmp
cd $out/tmp
+1 -5
View File
@@ -8,7 +8,7 @@
<!--==================================================================-->
<section xml:id="ssec-relnotes-0.14"><title>Release 0.14 (February 4, 2010)</title>
<section xml:id="ssec-relnotes-0.14"><title>Release 0.14 (TBA)</title>
<para>This release has the following improvements:</para>
@@ -37,10 +37,6 @@
not very useful in practice.</para>
</listitem>
<listitem>
<para>On Windows, Nix now requires Cygwin 1.7.x.</para>
</listitem>
<listitem>
<para>A few bug fixes.</para>
</listitem>
-2
View File
@@ -15,7 +15,6 @@ install-exec-local: readmanifest.pm download-using-manifests.pl copy-from-other-
$(INSTALL) -d $(DESTDIR)$(libexecdir)/nix
$(INSTALL_DATA) readmanifest.pm $(DESTDIR)$(libexecdir)/nix
$(INSTALL_DATA) readconfig.pm $(DESTDIR)$(libexecdir)/nix
$(INSTALL_DATA) ssh.pm $(DESTDIR)$(libexecdir)/nix
$(INSTALL_PROGRAM) find-runtime-roots.pl $(DESTDIR)$(libexecdir)/nix
$(INSTALL_PROGRAM) generate-patches.pl $(DESTDIR)$(libexecdir)/nix
$(INSTALL_PROGRAM) build-remote.pl $(DESTDIR)$(libexecdir)/nix
@@ -32,7 +31,6 @@ EXTRA_DIST = nix-collect-garbage.in \
nix-channel.in \
readmanifest.pm.in \
readconfig.pm.in \
ssh.pm \
nix-build.in \
download-using-manifests.pl.in \
copy-from-other-stores.pl.in \
+113 -97
View File
@@ -1,10 +1,9 @@
#! @perl@ -w -I@libexecdir@/nix
#! @perl@ -w
use strict;
use Fcntl ':flock';
use English '-no_match_vars';
use IO::Handle;
use ssh qw/sshOpts openSSHConnection/;
# General operation:
#
@@ -23,14 +22,6 @@ use ssh qw/sshOpts openSSHConnection/;
# The nice thing about this scheme is that if we die prematurely, the
# locks are released automatically.
# Make sure that we don't get any SSH passphrase or host key popups -
# if there is any problem it should fail, not do something
# interactive.
$ENV{"DISPLAY"} = "";
$ENV{"SSH_ASKPASS"} = "";
my $loadIncreased = 0;
my ($amWilling, $localSystem, $neededSystem, $drvPath, $maxSilentTime) = @ARGV;
@@ -71,7 +62,6 @@ while (<CONF>) {
, sshKeys => $3
, maxJobs => $4
, speedFactor => 1.0 * ($6 || 1)
, enabled => 1
};
}
@@ -93,97 +83,89 @@ sub openSlotLock {
}
my $hostName;
my $slotLock;
# Find all machine that can execute this build, i.e., that support
# builds for the given platform and are not at their job limit.
my $rightType = 0;
my @available = ();
LOOP: foreach my $cur (@machines) {
if (grep { $neededSystem eq $_ } @{$cur->{systemTypes}}) {
$rightType = 1;
while (1) {
# Find all machine that can execute this build, i.e., that support
# builds for the given platform and are not at their job limit.
my $rightType = 0;
my @available = ();
LOOP: foreach my $cur (@machines) {
if ($cur->{enabled} && grep { $neededSystem eq $_ } @{$cur->{systemTypes}}) {
$rightType = 1;
# We have a machine of the right type. Determine the load on
# the machine.
my $slot = 0;
my $load = 0;
my $free;
while ($slot < $cur->{maxJobs}) {
my $slotLock = openSlotLock($cur, $slot);
if (flock($slotLock, LOCK_EX | LOCK_NB)) {
$free = $slot unless defined $free;
flock($slotLock, LOCK_UN) or die;
} else {
$load++;
}
close $slotLock;
$slot++;
# We have a machine of the right type. Determine the load on
# the machine.
my $slot = 0;
my $load = 0;
my $free;
while ($slot < $cur->{maxJobs}) {
my $slotLock = openSlotLock($cur, $slot);
if (flock($slotLock, LOCK_EX | LOCK_NB)) {
$free = $slot unless defined $free;
flock($slotLock, LOCK_UN) or die;
} else {
$load++;
}
close $slotLock;
$slot++;
}
push @available, { machine => $cur, load => $load, free => $free }
push @available, { machine => $cur, load => $load, free => $free }
if $load < $cur->{maxJobs};
}
}
if (defined $ENV{NIX_DEBUG_HOOK}) {
print STDERR "load on " . $_->{machine}->{hostName} . " = " . $_->{load} . "\n"
foreach @available;
}
# Didn't find any available machine? Then decline or postpone.
if (scalar @available == 0) {
# Postpone if we have a machine of the right type, except if the
# local system can and wants to do the build.
if ($rightType && !$canBuildLocally) {
sendReply "postpone";
exit 0;
} else {
decline;
}
}
# Prioritise the available machines as follows:
# - First by load divided by speed factor, rounded to the nearest
# integer. This causes fast machines to be preferred over slow
# machines with similar loads.
# - Then by speed factor.
# - Finally by load.
sub lf { my $x = shift; return int($x->{load} / $x->{machine}->{speedFactor} + 0.4999); }
@available = sort
{ lf($a) <=> lf($b)
|| $b->{machine}->{speedFactor} <=> $a->{machine}->{speedFactor}
|| $a->{load} <=> $b->{load}
} @available;
# Select the best available machine and lock a free slot.
my $selected = $available[0];
my $machine = $selected->{machine};
$slotLock = openSlotLock($machine, $selected->{free});
flock($slotLock, LOCK_EX | LOCK_NB) or die;
utime undef, undef, $slotLock;
close MAINLOCK;
# Connect to the selected machine.
@sshOpts = ("-i", $machine->{sshKeys}, "-x");
$hostName = $machine->{hostName};
last if openSSHConnection $hostName;
warn "unable to open SSH connection to $hostName, trying other available machines...\n";
$machine->{enabled} = 0;
}
if (defined $ENV{NIX_DEBUG_HOOK}) {
print STDERR "load on " . $_->{machine}->{hostName} . " = " . $_->{load} . "\n"
foreach @available;
}
# Didn't find any available machine? Then decline or postpone.
if (scalar @available == 0) {
# Postpone if we have a machine of the right type, except if the
# local system can and wants to do the build.
if ($rightType && !$canBuildLocally) {
sendReply "postpone";
exit 0;
} else {
decline;
}
}
# Prioritise the available machines as follows:
# - First by load divided by speed factor, rounded to the nearest
# integer. This causes fast machines to be preferred over slow
# machines with similar loads.
# - Then by speed factor.
# - Finally by load.
sub lf { my $x = shift; return int($x->{load} / $x->{machine}->{speedFactor} + 0.4999); }
@available = sort
{ lf($a) <=> lf($b)
|| $b->{machine}->{speedFactor} <=> $a->{machine}->{speedFactor}
|| $a->{load} <=> $b->{load}
} @available;
# Select the best available machine and lock a free slot.
my $selected = $available[0];
my $machine = $selected->{machine};
my $slotLock = openSlotLock($machine, $selected->{free});
flock($slotLock, LOCK_EX | LOCK_NB) or die;
utime undef, undef, $slotLock;
close MAINLOCK;
# Tell Nix we've accepted the build.
sendReply "accept";
if (defined $ENV{NIX_DEBUG_HOOK}) {
my $hostName = $machine->{hostName};
my $sp = $machine->{speedFactor};
print STDERR "building `$drvPath' on `$hostName' - $sp - " . $selected->{free} . "\n";
sleep 10;
exit 0;
}
my $x = <STDIN>;
chomp $x;
@@ -193,8 +175,42 @@ if ($x ne "okay") {
# Do the actual build.
my $hostName = $machine->{hostName};
print STDERR "building `$drvPath' on `$hostName'\n";
# Make sure that we don't get any SSH passphrase or host key popups -
# if there is any problem it should fail, not do something
# interactive.
$ENV{"DISPLAY"} = "";
$ENV{"SSH_PASSWORD_FILE="} = "";
$ENV{"SSH_ASKPASS="} = "";
my $sshOpts = "-i " . $machine->{sshKeys} . " -x";
# Hack to support Cygwin: if we login without a password, we don't
# have exactly the same rights as when we do. This causes the
# Microsoft C compiler to fail with certain flags:
#
# http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=99676
#
# So as a workaround, we pass a verbatim password. ssh tries to makes
# this very hard; the trick is to make it call SSH_ASKPASS to get the
# password. (It only calls this command when there is no controlling
# terminal, but Nix ensures that is is the case. When doing this
# manually, use setsid(1).)
if ($machine->{sshKeys} =~ /^password:/) {
my $passwordFile = $machine->{sshKeys};
$passwordFile =~ s/^password://;
$sshOpts = "ssh -x";
$ENV{"SSH_PASSWORD_FILE"} = $passwordFile;
$ENV{"SSH_ASKPASS"} = "/tmp/writepass";
open WRITEPASS, ">/tmp/writepass" or die;
print WRITEPASS "#! /bin/sh\ncat \"\$SSH_PASSWORD_FILE\"";
close WRITEPASS;
chmod 0755, "/tmp/writepass" or die;
}
my $inputs = `cat inputs`; die if ($? != 0);
$inputs =~ s/\n/ /g;
@@ -206,7 +222,7 @@ print "copying inputs...\n";
my $maybeSign = "";
$maybeSign = "--sign" if -e "/nix/etc/nix/signing-key.sec";
system("NIX_SSHOPTS=\"@sshOpts\" @bindir@/nix-copy-closure $hostName $maybeSign $drvPath $inputs") == 0
system("NIX_SSHOPTS=\"$sshOpts\" @bindir@/nix-copy-closure $hostName $maybeSign $drvPath $inputs") == 0
or die "cannot copy inputs to $hostName: $?";
print "building...\n";
@@ -218,10 +234,10 @@ my $buildFlags = "--max-silent-time $maxSilentTime";
# connection dies. Without it, the remote process might continue to
# run indefinitely (that is, until it next tries to write to
# stdout/stderr).
if (system("ssh $hostName @sshOpts -tt 'nix-store --realise $buildFlags $drvPath > /dev/null'") != 0) {
if (system("ssh -tt $sshOpts $hostName 'nix-store --realise $buildFlags $drvPath > /dev/null'") != 0) {
# If we couldn't run ssh or there was an ssh problem (indicated by
# exit code 255), then we return exit code 1; otherwise we assume
# that the builder failed, which we indicate to Nix using exit
# that the builder failed, which we indicated to Nix using exit
# code 100. It's important to distinguish between the two because
# the first is a transient failure and the latter is permanent.
my $res = $? == -1 || ($? >> 8) == 255 ? 1 : 100;
@@ -235,6 +251,6 @@ foreach my $output (split '\n', $outputs) {
my $maybeSignRemote = "";
$maybeSignRemote = "--sign" if $UID != 0;
system("ssh $hostName @sshOpts 'nix-store --export $maybeSignRemote $output' | @bindir@/nix-store --import > /dev/null") == 0
system("ssh $sshOpts $hostName 'nix-store --export $maybeSignRemote $output' | @bindir@/nix-store --import > /dev/null") == 0
or die "cannot copy $output from $hostName: $?";
}
+3 -1
View File
@@ -73,7 +73,7 @@ if ($ARGV[0] eq "--query") {
}
elsif ($ARGV[0] ne "--substitute") {
die;
die "syntax: $0 [--query-paths | --query-info PATHS... | --substitute PATH]\n";
}
@@ -85,6 +85,8 @@ my $targetPath = $ARGV[1];
my $tmpDir = tempdir("nix-download.XXXXXX", CLEANUP => 1, TMPDIR => 1)
or die "cannot create a temporary directory";
chdir $tmpDir or die "cannot change to `$tmpDir': $!";
my $tmpNar = "$tmpDir/nar";
my $tmpNar2 = "$tmpDir/nar2";
+12 -18
View File
@@ -1,6 +1,4 @@
#! @perl@ -w -I@libexecdir@/nix
use ssh;
#! @perl@ -w
my $binDir = $ENV{"NIX_BIN_DIR"} || "@bindir@";
@@ -16,11 +14,12 @@ EOF
# Get the target host.
my $sshHost;
my @sshOpts = split ' ', ($ENV{"NIX_SSHOPTS"} or "");
my $sign = 0;
my $compressor = "";
my $decompressor = "";
my $compressor = "cat";
my $decompressor = "cat";
my $toMode = 1;
@@ -35,8 +34,8 @@ while (@ARGV) {
$sign = 1;
}
elsif ($arg eq "--gzip") {
$compressor = "| gzip";
$decompressor = "gunzip |";
$compressor = "gzip";
$decompressor = "gunzip";
}
elsif ($arg eq "--from") {
$toMode = 0;
@@ -53,9 +52,6 @@ while (@ARGV) {
}
openSSHConnection $sshHost or die "$0: unable to start SSH\n";
if ($toMode) { # Copy TO the remote machine.
my @allStorePaths;
@@ -73,10 +69,11 @@ if ($toMode) { # Copy TO the remote machine.
# Ask the remote host which paths are invalid.
open(READ, "ssh $sshHost @sshOpts nix-store --check-validity --print-invalid @allStorePaths|");
open(READ, "ssh @sshOpts $sshHost nix-store --check-validity --print-invalid @allStorePaths|");
my @missing = ();
while (<READ>) {
chomp;
print STDERR "target machine needs $_\n";
push @missing, $_;
}
close READ or die;
@@ -84,11 +81,9 @@ if ($toMode) { # Copy TO the remote machine.
# Export the store paths and import them on the remote machine.
if (scalar @missing > 0) {
print STDERR "copying these missing paths:\n";
print STDERR " $_\n" foreach @missing;
my $extraOpts = "";
$extraOpts .= "--sign" if $sign == 1;
system("nix-store --export $extraOpts @missing $compressor | ssh $sshHost @sshOpts '$decompressor nix-store --import'") == 0
system("nix-store --export $extraOpts @missing | $compressor | ssh @sshOpts $sshHost '$decompressor | nix-store --import'") == 0
or die "copying store paths to remote machine `$sshHost' failed: $?";
}
@@ -119,6 +114,7 @@ else { # Copy FROM the remote machine.
my @missing = ();
while (<READ>) {
chomp;
print STDERR "local machine needs $_\n";
push @missing, $_;
}
close READ or die;
@@ -126,12 +122,10 @@ else { # Copy FROM the remote machine.
# Export the store paths on the remote machine and import them on locally.
if (scalar @missing > 0) {
print STDERR "copying these missing paths:\n";
print STDERR " $_\n" foreach @missing;
my $extraOpts = "";
$extraOpts .= "--sign" if $sign == 1;
system("ssh $sshHost @sshOpts 'nix-store --export $extraOpts @missing $compressor' | $decompressor @bindir@/nix-store --import") == 0
or die "copying store paths from remote machine `$sshHost' failed: $?";
system("ssh @sshOpts $sshHost 'nix-store --export $extraOpts @missing | $compressor' | $decompressor | @bindir@/nix-store --import") == 0
or die "copying store paths to remote machine `$sshHost' failed: $?";
}
}
-47
View File
@@ -1,47 +0,0 @@
use strict;
use File::Temp qw(tempdir);
our @sshOpts = split ' ', ($ENV{"NIX_SSHOPTS"} or "");
my $sshStarted = 0;
my $sshHost;
# Open a master SSH connection to `host', unless there already is a
# running master connection (as determined by `-O check').
sub openSSHConnection {
my ($host) = @_;
die if $sshStarted;
$sshHost = $host;
return 1 if system("ssh $sshHost @sshOpts -O check 2> /dev/null") == 0;
my $tmpDir = tempdir("nix-ssh.XXXXXX", CLEANUP => 1, TMPDIR => 1)
or die "cannot create a temporary directory";
push @sshOpts, "-S", "$tmpDir/control";
# Start the master. We can't use the `-f' flag (fork into
# background after establishing the connection) because then the
# child continues to run if we are killed. So instead make SSH
# print "started" when it has established the connection, and wait
# until we see that.
open SSH, "ssh $sshHost @sshOpts -M -N -o LocalCommand='echo started' -o PermitLocalCommand=yes |" or die;
while (<SSH>) {
chomp;
last if /started/;
}
$sshStarted = 1;
return 1;
}
# Tell the master SSH client to exit.
sub closeSSHConnection {
if ($sshStarted) {
system("ssh $sshHost @sshOpts -O exit 2> /dev/null") == 0
or warn "unable to stop SSH master: $?";
}
}
END { my $saved = $?; closeSSHConnection; $? = $saved; }
return 1;
+18 -13
View File
@@ -242,7 +242,7 @@ LocalNoInline(Expr updateAttrs(Expr e1, Expr e2))
}
string evalString(EvalState & state, Expr e, PathSet & context)
string evalString(EvalState & state, Expr e, ATermList & context)
{
e = evalExpr(state, e);
string s;
@@ -254,11 +254,10 @@ string evalString(EvalState & state, Expr e, PathSet & context)
string evalStringNoCtx(EvalState & state, Expr e)
{
PathSet context;
ATermList context;
string s = evalString(state, e, context);
if (!context.empty())
throw EvalError(format("the string `%1%' is not allowed to refer to a store path (such as `%2%')")
% s % *(context.begin()));
if (context != ATempty)
throw EvalError(format("the string `%1%' is not allowed to refer to a store path") % s);
return s;
}
@@ -312,7 +311,7 @@ ATermList flattenList(EvalState & state, Expr e)
}
string coerceToString(EvalState & state, Expr e, PathSet & context,
string coerceToString(EvalState & state, Expr e, Context & context,
bool coerceMore, bool copyToStore)
{
e = evalExpr(state, e);
@@ -343,7 +342,7 @@ string coerceToString(EvalState & state, Expr e, PathSet & context,
% path % dstPath);
}
context.insert(dstPath);
context.set(toATerm(dstPath), makeNull());
return dstPath;
}
@@ -351,7 +350,13 @@ string coerceToString(EvalState & state, Expr e, PathSet & context,
if (matchAttrs(e, es)) {
Expr e2 = queryAttr(e, "outPath");
if (!e2) throwTypeError("cannot coerce an attribute set (except a derivation) to a string");
return coerceToString(state, e2, context, coerceMore, copyToStore);
/* !!! hacky */
ATermList c;
string s = evalString(state, e2, c);
Context c2; matchContext(c, c2);
foreach (Context::const_iterator, i, c2)
context.set(i->key, e);
return s;
}
if (coerceMore) {
@@ -385,9 +390,9 @@ string coerceToString(EvalState & state, Expr e, PathSet & context,
static ATerm concatStrings(EvalState & state, ATermVector & args,
string separator = "")
{
if (args.empty()) return makeStr("", PathSet());
if (args.empty()) return makeStr("", ATempty);
PathSet context;
Context context;
std::ostringstream s;
/* If the first element is a path, then the result will also be a
@@ -403,7 +408,7 @@ static ATerm concatStrings(EvalState & state, ATermVector & args,
s << coerceToString(state, *i, context, false, !isPath);
}
if (isPath && !context.empty())
if (isPath && context.size() != 0)
throw EvalError(format("a string that refers to a store path cannot be appended to a path, in `%1%'")
% s.str());
@@ -413,7 +418,7 @@ static ATerm concatStrings(EvalState & state, ATermVector & args,
}
Path coerceToPath(EvalState & state, Expr e, PathSet & context)
Path coerceToPath(EvalState & state, Expr e, Context & context)
{
string path = coerceToString(state, e, context, false, false);
if (path == "" || path[0] != '/')
@@ -600,7 +605,7 @@ LocalNoInline(Expr evalPlusConcat(EvalState & state, Expr e))
"concatenation of a derivation and a path is deprecated; "
"you should write `drv + \"%1%\"' instead of `drv + %1%'")
% aterm2String(p));
PathSet context;
Context context;
return makeStr(
coerceToString(state, makeSelect(e1, toATerm("outPath")), context)
+ aterm2String(p), context);
+3 -3
View File
@@ -61,7 +61,7 @@ Expr evalFile(EvalState & state, const Path & path);
Expr strictEvalExpr(EvalState & state, Expr e);
/* Specific results. */
string evalString(EvalState & state, Expr e, PathSet & context);
string evalString(EvalState & state, Expr e, ATermList & context);
string evalStringNoCtx(EvalState & state, Expr e);
int evalInt(EvalState & state, Expr e);
bool evalBool(EvalState & state, Expr e);
@@ -74,13 +74,13 @@ ATermList flattenList(EvalState & state, Expr e);
/* String coercion. Converts strings, paths and derivations to a
string. If `coerceMore' is set, also converts nulls, integers,
booleans and lists to a string. */
string coerceToString(EvalState & state, Expr e, PathSet & context,
string coerceToString(EvalState & state, Expr e, Context & context,
bool coerceMore = false, bool copyToStore = true);
/* Path coercion. Converts strings, paths and derivations to a path.
The result is guaranteed to be an canonicalised, absolute path.
Nothing is copied to the store. */
Path coerceToPath(EvalState & state, Expr e, PathSet & context);
Path coerceToPath(EvalState & state, Expr e, Context & context);
/* Automatically call a function for which each argument has a default
value or has a binding in the `args' map. Note: result is a call,
+4 -4
View File
@@ -23,12 +23,12 @@ static XMLAttrs singletonAttrs(const string & name, const string & value)
typedef set<Expr> ExprSet;
static void printTermAsXML(Expr e, XMLWriter & doc, PathSet & context,
static void printTermAsXML(Expr e, XMLWriter & doc, Context & context,
ExprSet & drvsSeen);
static void showAttrs(const ATermMap & attrs, XMLWriter & doc,
PathSet & context, ExprSet & drvsSeen)
Context & context, ExprSet & drvsSeen)
{
StringSet names;
for (ATermMap::const_iterator i = attrs.begin(); i != attrs.end(); ++i)
@@ -65,7 +65,7 @@ static void printPatternAsXML(Pattern pat, XMLWriter & doc)
}
static void printTermAsXML(Expr e, XMLWriter & doc, PathSet & context,
static void printTermAsXML(Expr e, XMLWriter & doc, Context & context,
ExprSet & drvsSeen)
{
XMLAttrs attrs;
@@ -144,7 +144,7 @@ static void printTermAsXML(Expr e, XMLWriter & doc, PathSet & context,
}
void printTermAsXML(Expr e, std::ostream & out, PathSet & context)
void printTermAsXML(Expr e, std::ostream & out, Context & context)
{
XMLWriter doc(true, out);
XMLOpenElement root(doc, "expr");
+1 -1
View File
@@ -9,7 +9,7 @@
namespace nix {
void printTermAsXML(Expr e, std::ostream & out, PathSet & context);
void printTermAsXML(Expr e, std::ostream & out, Context & context);
}
+3 -3
View File
@@ -17,7 +17,7 @@ string DrvInfo::queryDrvPath(EvalState & state) const
if (a && matchPath(evalExpr(state, a), t))
return aterm2String(t);
PathSet context;
Context context;
(string &) drvPath = a ? coerceToPath(state, a, context) : "";
}
return drvPath;
@@ -29,7 +29,7 @@ string DrvInfo::queryOutPath(EvalState & state) const
if (outPath == "") {
Expr a = attrs->get(toATerm("outPath"));
if (!a) throw TypeError("output path missing");
PathSet context;
Context context;
(string &) outPath = coerceToPath(state, a, context);
}
return outPath;
@@ -49,7 +49,7 @@ MetaInfo DrvInfo::queryMetaInfo(EvalState & state) const
for (ATermMap::const_iterator i = attrs2.begin(); i != attrs2.end(); ++i) {
Expr e = evalExpr(state, i->value);
string s;
PathSet context;
ATermList context;
MetaValue value;
int n;
ATermList es;
+2
View File
@@ -45,6 +45,8 @@ Int | int | Expr |
Str | string ATermList | Expr |
Str | string | Expr | ObsoleteStr
ContextElem | string Expr | ContextElem |
# Internal to the parser, doesn't occur in ASTs.
IndStr | string | Expr |
+34 -12
View File
@@ -336,25 +336,47 @@ Expr makeBool(bool b)
}
bool matchStr(Expr e, string & s, PathSet & context)
bool matchStr(Expr e, string & s, ATermList & context)
{
ATermList l;
ATerm s_;
if (!matchStr(e, s_, l)) return false;
if (!matchStr(e, s_, context)) return false;
s = aterm2String(s_);
for (ATermIterator i(l); i; ++i)
context.insert(aterm2String(*i));
return true;
}
Expr makeStr(const string & s, const PathSet & context)
bool matchStr(Expr e, string & s, Context & context)
{
return makeStr(toATerm(s), toATermList(context));
ATermList c;
if (!matchStr(e, s, c)) return false;
matchContext(c, context);
return true;
}
Expr makeStr(const string & s, ATermList context)
{
return makeStr(toATerm(s), context);
}
Expr makeStr(const string & s, const Context & context)
{
ATermList l = ATempty;
/* !!! should define a canonical ordering of context elements. */
foreach (Context::const_iterator, i, context)
l = ATinsert(l, makeContextElem(i->key, i->value));
return makeStr(s, l);
}
void matchContext(ATermList context, Context & result)
{
for (ATermIterator i(context); i; ++i) {
ATerm s, e;
if (!matchContextElem(*i, s, e)) abort();
result.set(s, e);
}
}
@@ -380,7 +402,7 @@ string showType(Expr e)
string showValue(Expr e)
{
PathSet context;
ATermList context;
string s;
ATerm s2;
int i;
+12 -4
View File
@@ -26,6 +26,7 @@ typedef ATerm DefaultValue;
typedef ATerm Pos;
typedef ATerm Pattern;
typedef ATerm ATermBool;
typedef ATerm ContextElem;
/* A STL vector of ATerms. Should be used with great care since it's
@@ -104,11 +105,18 @@ Expr canonicaliseExpr(Expr e);
Expr makeBool(bool b);
/* Manipulation of Str() nodes. Note: matchStr() does not clear
context! */
bool matchStr(Expr e, string & s, PathSet & context);
/* Manipulation of Str() nodes. */
typedef ATermMap Context;
Expr makeStr(const string & s, const PathSet & context = PathSet());
bool matchStr(Expr e, string & s, ATermList & context);
bool matchStr(Expr e, string & s, Context & context);
Expr makeStr(const string & s, ATermList context = ATempty);
Expr makeStr(const string & s, const Context & context);
void matchContext(ATermList context, Context & result);
/* Showing types, values. */
+60 -60
View File
@@ -93,16 +93,17 @@ static Expr prim_currentTime(EvalState & state, const ATermVector & args)
argument. */
static Expr prim_import(EvalState & state, const ATermVector & args)
{
PathSet context;
Context context;
Path path = coerceToPath(state, args[0], context);
for (PathSet::iterator i = context.begin(); i != context.end(); ++i) {
assert(isStorePath(*i));
if (!store->isValidPath(*i))
foreach (Context::const_iterator, i, context) {
Path p = aterm2String(i->key);
assert(isStorePath(p));
if (!store->isValidPath(p))
throw EvalError(format("cannot import `%1%', since path `%2%' is not valid")
% path % *i);
if (isDerivation(*i))
store->buildDerivations(singleton<PathSet>(*i));
% path % p);
if (isDerivation(p))
store->buildDerivations(singleton<PathSet>(p));
}
return evalFile(state, path);
@@ -136,8 +137,8 @@ static Expr prim_isInt(EvalState & state, const ATermVector & args)
static Expr prim_isString(EvalState & state, const ATermVector & args)
{
string s;
PathSet l;
return makeBool(matchStr(evalExpr(state, args[0]), s, l));
ATermList context;
return makeBool(matchStr(evalExpr(state, args[0]), s, context));
}
/* Determine whether the argument is an Bool. */
@@ -197,7 +198,7 @@ static Expr prim_genericClosure(EvalState & state, const ATermVector & args)
static Expr prim_abort(EvalState & state, const ATermVector & args)
{
PathSet context;
ATermList context;
throw Abort(format("evaluation aborted with the following error message: `%1%'") %
evalString(state, args[0], context));
}
@@ -205,7 +206,7 @@ static Expr prim_abort(EvalState & state, const ATermVector & args)
static Expr prim_throw(EvalState & state, const ATermVector & args)
{
PathSet context;
ATermList context;
throw ThrownError(format("user-thrown exception: %1%") %
evalString(state, args[0], context));
}
@@ -213,7 +214,7 @@ static Expr prim_throw(EvalState & state, const ATermVector & args)
static Expr prim_addErrorContext(EvalState & state, const ATermVector & args)
{
PathSet context;
ATermList context;
try {
return evalExpr(state, args[1]);
} catch (Error & e) {
@@ -257,7 +258,7 @@ static Expr prim_trace(EvalState & state, const ATermVector & args)
{
Expr e = evalExpr(state, args[0]);
string s;
PathSet context;
ATermList context;
if (matchStr(e, s, context))
printMsg(lvlError, format("trace: %1%") % s);
else
@@ -360,7 +361,7 @@ static Expr prim_derivationStrict(EvalState & state, const ATermVector & args)
/* Build the derivation expression by processing the attributes. */
Derivation drv;
PathSet context;
Context context;
string outputHash, outputHashAlgo;
bool outputHashRecursive = false;
@@ -421,8 +422,8 @@ static Expr prim_derivationStrict(EvalState & state, const ATermVector & args)
/* Everything in the context of the strings in the derivation
attributes should be added as dependencies of the resulting
derivation. */
foreach (PathSet::iterator, i, context) {
Path path = *i;
foreach (Context::const_iterator, i, context) {
Path path = aterm2String(i->key);
/* Paths marked with `=' denote that the path of a derivation
is explicitly passed to the builder. Since that allows the
@@ -525,9 +526,9 @@ static Expr prim_derivationStrict(EvalState & state, const ATermVector & args)
/* !!! assumes a single output */
ATermMap outAttrs(2);
outAttrs.set(toATerm("outPath"),
makeAttrRHS(makeStr(outPath, singleton<PathSet>(drvPath)), makeNoPos()));
makeAttrRHS(makeStr(outPath, ATmakeList1(makeContextElem(toATerm(drvPath), makeNull()))), makeNoPos()));
outAttrs.set(toATerm("drvPath"),
makeAttrRHS(makeStr(drvPath, singleton<PathSet>("=" + drvPath)), makeNoPos()));
makeAttrRHS(makeStr(drvPath, ATmakeList1(makeContextElem(toATerm("=" + drvPath), makeNull()))), makeNoPos()));
return makeAttrs(outAttrs);
}
@@ -561,7 +562,7 @@ static Expr prim_derivationLazy(EvalState & state, const ATermVector & args)
/* Convert the argument to a path. !!! obsolete? */
static Expr prim_toPath(EvalState & state, const ATermVector & args)
{
PathSet context;
Context context;
string path = coerceToPath(state, args[0], context);
return makeStr(canonPath(path), context);
}
@@ -577,23 +578,23 @@ static Expr prim_toPath(EvalState & state, const ATermVector & args)
corner cases. */
static Expr prim_storePath(EvalState & state, const ATermVector & args)
{
PathSet context;
Context context;
Path path = canonPath(coerceToPath(state, args[0], context));
if (!isInStore(path))
throw EvalError(format("path `%1%' is not in the Nix store") % path);
Path path2 = toStorePath(path);
if (!store->isValidPath(path2))
throw EvalError(format("store path `%1%' is not valid") % path2);
context.insert(path2);
context.set(toATerm(path2), makeNull());
return makeStr(path, context);
}
static Expr prim_pathExists(EvalState & state, const ATermVector & args)
{
PathSet context;
Context context;
Path path = coerceToPath(state, args[0], context);
if (!context.empty())
if (context.size() != 0)
throw EvalError(format("string `%1%' cannot refer to other paths") % path);
return makeBool(pathExists(path));
}
@@ -603,7 +604,7 @@ static Expr prim_pathExists(EvalState & state, const ATermVector & args)
following the last slash. */
static Expr prim_baseNameOf(EvalState & state, const ATermVector & args)
{
PathSet context;
Context context;
return makeStr(baseNameOf(coerceToString(state, args[0], context)), context);
}
@@ -613,7 +614,7 @@ static Expr prim_baseNameOf(EvalState & state, const ATermVector & args)
of the argument. */
static Expr prim_dirOf(EvalState & state, const ATermVector & args)
{
PathSet context;
Context context;
Expr e = evalExpr(state, args[0]); ATerm dummy;
bool isPath = matchPath(e, dummy);
Path dir = dirOf(coerceToPath(state, e, context));
@@ -624,9 +625,9 @@ static Expr prim_dirOf(EvalState & state, const ATermVector & args)
/* Return the contents of a file as a string. */
static Expr prim_readFile(EvalState & state, const ATermVector & args)
{
PathSet context;
Context context;
Path path = coerceToPath(state, args[0], context);
if (!context.empty())
if (context.size() != 0)
throw EvalError(format("string `%1%' cannot refer to other paths") % path);
return makeStr(readFile(path));
}
@@ -643,7 +644,7 @@ static Expr prim_readFile(EvalState & state, const ATermVector & args)
static Expr prim_toXML(EvalState & state, const ATermVector & args)
{
std::ostringstream out;
PathSet context;
Context context;
printTermAsXML(strictEvalExpr(state, args[0]), out, context);
return makeStr(out.str(), context);
}
@@ -653,14 +654,15 @@ static Expr prim_toXML(EvalState & state, const ATermVector & args)
as an input by derivations. */
static Expr prim_toFile(EvalState & state, const ATermVector & args)
{
PathSet context;
ATermList context;
string name = evalStringNoCtx(state, args[0]);
string contents = evalString(state, args[1], context);
PathSet refs;
for (PathSet::iterator i = context.begin(); i != context.end(); ++i) {
Path path = *i;
Context context2; matchContext(context, context2);
foreach (Context::const_iterator, i, context2) {
Path path = aterm2String(i->key);
if (path.at(0) == '=') path = string(path, 1);
if (isDerivation(path))
throw EvalError(format("in `toFile': the file `%1%' cannot refer to derivation outputs") % name);
@@ -675,7 +677,7 @@ static Expr prim_toFile(EvalState & state, const ATermVector & args)
result, since `storePath' itself has references to the paths
used in args[1]. */
return makeStr(storePath, singleton<PathSet>(storePath));
return makeStr(storePath, ATmakeList1(makeContextElem(toATerm(storePath), makeNull())));
}
@@ -712,9 +714,9 @@ struct FilterFromExpr : PathFilter
static Expr prim_filterSource(EvalState & state, const ATermVector & args)
{
PathSet context;
Context context;
Path path = coerceToPath(state, args[1], context);
if (!context.empty())
if (context.size() != 0)
throw EvalError(format("string `%1%' cannot refer to other paths") % path);
FilterFromExpr filter(state, args[0]);
@@ -723,7 +725,7 @@ static Expr prim_filterSource(EvalState & state, const ATermVector & args)
? computeStorePathForPath(path, true, htSHA256, filter).first
: store->addToStore(path, true, htSHA256, filter);
return makeStr(dstPath, singleton<PathSet>(dstPath));
return makeStr(dstPath, ATmakeList1(makeContextElem(toATerm(dstPath), makeNull())));
}
@@ -746,7 +748,7 @@ static Expr prim_attrNames(EvalState & state, const ATermVector & args)
ATermList list = ATempty;
for (StringSet::const_reverse_iterator i = names.rbegin();
i != names.rend(); ++i)
list = ATinsert(list, makeStr(*i, PathSet()));
list = ATinsert(list, makeStr(*i));
return makeList(list);
}
@@ -1001,7 +1003,7 @@ static Expr prim_lessThan(EvalState & state, const ATermVector & args)
`"/nix/store/whatever..."'. */
static Expr prim_toString(EvalState & state, const ATermVector & args)
{
PathSet context;
Context context;
string s = coerceToString(state, args[0], context, true, false);
return makeStr(s, context);
}
@@ -1015,7 +1017,7 @@ static Expr prim_substring(EvalState & state, const ATermVector & args)
{
int start = evalInt(state, args[0]);
int len = evalInt(state, args[1]);
PathSet context;
Context context;
string s = coerceToString(state, args[2], context);
if (start < 0) throw EvalError("negative start position in `substring'");
@@ -1026,7 +1028,7 @@ static Expr prim_substring(EvalState & state, const ATermVector & args)
static Expr prim_stringLength(EvalState & state, const ATermVector & args)
{
PathSet context;
Context context;
string s = coerceToString(state, args[0], context);
return makeInt(s.size());
}
@@ -1034,9 +1036,9 @@ static Expr prim_stringLength(EvalState & state, const ATermVector & args)
static Expr prim_unsafeDiscardStringContext(EvalState & state, const ATermVector & args)
{
PathSet context;
Context context;
string s = coerceToString(state, args[0], context);
return makeStr(s, PathSet());
return makeStr(s);
}
@@ -1048,20 +1050,31 @@ static Expr prim_unsafeDiscardStringContext(EvalState & state, const ATermVector
drv.inputDrvs. */
static Expr prim_unsafeDiscardOutputDependency(EvalState & state, const ATermVector & args)
{
PathSet context;
Context context;
string s = coerceToString(state, args[0], context);
PathSet context2;
foreach (PathSet::iterator, i, context) {
Path p = *i;
Context context2;
foreach (Context::const_iterator, i, context) {
Path p = aterm2String(i->key);
if (p.at(0) == '=') p = "~" + string(p, 1);
context2.insert(p);
context2.set(toATerm(p), i->value);
}
return makeStr(s, context2);
}
static Expr prim_queryStringContext(EvalState & state, const ATermVector & args)
{
Context context;
string s = coerceToString(state, args[0], context);
ATermList l = ATempty;
foreach (Context::const_iterator, i, context)
l = ATinsert(l, i->value);
return makeList(l);
}
/* Expression serialization/deserialization */
@@ -1072,18 +1085,6 @@ static Expr prim_exprToString(EvalState & state, const ATermVector & args)
}
static Expr prim_stringToExpr(EvalState & state, const ATermVector & args)
{
/* !!! this can introduce arbitrary garbage terms in the
evaluator! */;
string s;
PathSet l;
if (!matchStr(evalExpr(state, args[0]), s, l))
throw EvalError("stringToExpr needs string argument!");
return ATreadFromString(s.c_str());
}
/*************************************************************
* Versions
*************************************************************/
@@ -1140,10 +1141,8 @@ void EvalState::addPrimOps()
addPrimOp("__getEnv", 1, prim_getEnv);
addPrimOp("__trace", 2, prim_trace);
// Expr <-> String
addPrimOp("__exprToString", 1, prim_exprToString);
addPrimOp("__stringToExpr", 1, prim_stringToExpr);
// Derivations
addPrimOp("derivation!", 1, prim_derivationStrict);
@@ -1192,6 +1191,7 @@ void EvalState::addPrimOps()
addPrimOp("__stringLength", 1, prim_stringLength);
addPrimOp("__unsafeDiscardStringContext", 1, prim_unsafeDiscardStringContext);
addPrimOp("__unsafeDiscardOutputDependency", 1, prim_unsafeDiscardOutputDependency);
addPrimOp("__queryStringContext", 1, prim_queryStringContext);
// Versions
addPrimOp("__parseDrvName", 1, prim_parseDrvName);
+10 -18
View File
@@ -162,7 +162,6 @@ struct Child
{
WeakGoalPtr goal;
set<int> fds;
bool monitorForSilence;
bool inBuildSlot;
time_t lastOutput; /* time we last got output on stdout/stderr */
};
@@ -235,7 +234,7 @@ public:
/* Registers a running child process. `inBuildSlot' means that
the process counts towards the jobs limit. */
void childStarted(GoalPtr goal, pid_t pid,
const set<int> & fds, bool inBuildSlot, bool monitorForSilence);
const set<int> & fds, bool inBuildSlot);
/* Unregisters a running child process. `wakeSleepers' should be
false if there is no sense in waking up goals that are sleeping
@@ -1263,7 +1262,7 @@ DerivationGoal::HookReply DerivationGoal::tryBuildHook()
pid.setKillSignal(SIGTERM);
logPipe.writeSide.close();
worker.childStarted(shared_from_this(),
pid, singleton<set<int> >(logPipe.readSide), false, false);
pid, singleton<set<int> >(logPipe.readSide), false);
toHook.readSide.close();
@@ -1768,7 +1767,7 @@ void DerivationGoal::startBuilder()
pid.setSeparatePG(true);
logPipe.writeSide.close();
worker.childStarted(shared_from_this(), pid,
singleton<set<int> >(logPipe.readSide), true, true);
singleton<set<int> >(logPipe.readSide), true);
if (printBuildTrace) {
printMsg(lvlError, format("@ build-started %1% %2% %3% %4%")
@@ -2275,7 +2274,7 @@ void SubstitutionGoal::tryToRun()
pid.setKillSignal(SIGTERM);
logPipe.writeSide.close();
worker.childStarted(shared_from_this(),
pid, singleton<set<int> >(logPipe.readSide), true, true);
pid, singleton<set<int> >(logPipe.readSide), true);
state = &SubstitutionGoal::finished;
@@ -2475,15 +2474,13 @@ unsigned Worker::getNrLocalBuilds()
void Worker::childStarted(GoalPtr goal,
pid_t pid, const set<int> & fds, bool inBuildSlot,
bool monitorForSilence)
pid_t pid, const set<int> & fds, bool inBuildSlot)
{
Child child;
child.goal = goal;
child.fds = fds;
child.lastOutput = time(0);
child.inBuildSlot = inBuildSlot;
child.monitorForSilence = monitorForSilence;
children[pid] = child;
if (inBuildSlot) nrLocalBuilds++;
}
@@ -2604,16 +2601,12 @@ void Worker::waitForInput()
if (maxSilentTime != 0) {
time_t oldest = 0;
foreach (Children::iterator, i, children) {
if (i->second.monitorForSilence) {
oldest = oldest == 0 || i->second.lastOutput < oldest
? i->second.lastOutput : oldest;
}
}
if (oldest) {
useTimeout = true;
timeout.tv_sec = std::max((time_t) 0, oldest + maxSilentTime - before);
printMsg(lvlVomit, format("sleeping %1% seconds") % timeout.tv_sec);
oldest = oldest == 0 || i->second.lastOutput < oldest
? i->second.lastOutput : oldest;
}
useTimeout = true;
timeout.tv_sec = std::max((time_t) 0, oldest + maxSilentTime - before);
printMsg(lvlVomit, format("sleeping %1% seconds") % timeout.tv_sec);
}
/* If we are polling goals that are waiting for a lock, then wake
@@ -2688,7 +2681,6 @@ void Worker::waitForInput()
}
if (maxSilentTime != 0 &&
j->second.monitorForSilence &&
after - j->second.lastOutput >= (time_t) maxSilentTime)
{
printMsg(lvlError,
+38
View File
@@ -15,6 +15,11 @@
#include <fcntl.h>
#include <unistd.h>
#ifdef __CYGWIN__
#include <windows.h>
#include <sys/cygwin.h>
#endif
namespace nix {
@@ -174,6 +179,15 @@ void LocalStore::addTempRoot(const Path & path)
fdGCLock.close();
/* Note that on Cygwin a lot of the following complexity
is unnecessary, since we cannot delete open lock
files. If we have the lock file open, then it's valid;
if we can delete it, then it wasn't in use any more.
Also note that on Cygwin we cannot "upgrade" a lock
from a read lock to a write lock. */
#ifndef __CYGWIN__
debug(format("acquiring read lock on `%1%'") % fnTempRoots);
lockFile(fdTempRoots, ltRead, true);
@@ -187,6 +201,10 @@ void LocalStore::addTempRoot(const Path & path)
/* The garbage collector deleted this file before we could
get a lock. (It won't delete the file after we get a
lock.) Try again. */
#else
break;
#endif
}
}
@@ -199,9 +217,14 @@ void LocalStore::addTempRoot(const Path & path)
string s = path + '\0';
writeFull(fdTempRoots, (const unsigned char *) s.c_str(), s.size());
#ifndef __CYGWIN__
/* Downgrade to a read lock. */
debug(format("downgrading to read lock on `%1%'") % fnTempRoots);
lockFile(fdTempRoots, ltRead, true);
#else
debug(format("releasing write lock on `%1%'") % fnTempRoots);
lockFile(fdTempRoots, ltNone, true);
#endif
}
@@ -229,6 +252,19 @@ static void readTempRoots(PathSet & tempRoots, FDs & fds)
Path path = (format("%1%/%2%/%3%") % nixStateDir % tempRootsDir % *i).str();
debug(format("reading temporary root file `%1%'") % path);
#ifdef __CYGWIN__
/* On Cygwin we just try to delete the lock file. */
char win32Path[MAX_PATH];
cygwin_conv_to_full_win32_path(path.c_str(), win32Path);
if (DeleteFile(win32Path)) {
printMsg(lvlError, format("removed stale temporary roots file `%1%'")
% path);
continue;
} else
debug(format("delete of `%1%' failed: %2%") % path % GetLastError());
#endif
FDPtr fd(new AutoCloseFD(open(path.c_str(), O_RDWR, 0666)));
if (*fd == -1) {
/* It's okay if the file has disappeared. */
@@ -240,6 +276,7 @@ static void readTempRoots(PathSet & tempRoots, FDs & fds)
//FDPtr fd(new AutoCloseFD(openLockFile(path, false)));
//if (*fd == -1) continue;
#ifndef __CYGWIN__
/* Try to acquire a write lock without blocking. This can
only succeed if the owning process has died. In that case
we don't care about its temporary roots. */
@@ -250,6 +287,7 @@ static void readTempRoots(PathSet & tempRoots, FDs & fds)
writeFull(*fd, (const unsigned char *) "d", 1);
continue;
}
#endif
/* Acquire a read lock. This will prevent the owning process
from upgrading to a write lock, therefore it will block in
+58 -3
View File
@@ -8,6 +8,11 @@
#include <sys/stat.h>
#include <fcntl.h>
#ifdef __CYGWIN__
#include <windows.h>
#include <sys/cygwin.h>
#endif
namespace nix {
@@ -16,24 +21,72 @@ int openLockFile(const Path & path, bool create)
{
AutoCloseFD fd;
#ifdef __CYGWIN__
/* On Cygwin we have to open the lock file without "DELETE"
sharing mode; otherwise Windows will allow open lock files to
be deleted (which is almost but not quite what Unix does). */
char win32Path[MAX_PATH + 1];
cygwin_conv_to_full_win32_path(path.c_str(), win32Path);
SECURITY_ATTRIBUTES sa; /* required, otherwise inexplicably bad shit happens */
sa.nLength = sizeof sa;
sa.lpSecurityDescriptor = 0;
sa.bInheritHandle = TRUE;
HANDLE h = CreateFile(win32Path, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, &sa,
(create ? OPEN_ALWAYS : OPEN_EXISTING),
FILE_ATTRIBUTE_NORMAL, 0);
if (h == INVALID_HANDLE_VALUE) {
if (create || GetLastError() != ERROR_FILE_NOT_FOUND)
throw Error(format("opening lock file `%1%'") % path);
fd = -1;
}
else
fd = cygwin_attach_handle_to_fd((char *) path.c_str(), -1, h, 1, O_RDWR);
#else
fd = open(path.c_str(), O_RDWR | (create ? O_CREAT : 0), 0666);
if (fd == -1 && (create || errno != ENOENT))
throw SysError(format("opening lock file `%1%'") % path);
#endif
return fd.borrow();
}
void deleteLockFile(const Path & path, int fd)
void deleteLockFilePreClose(const Path & path, int fd)
{
#ifndef __CYGWIN__
/* Get rid of the lock file. Have to be careful not to introduce
races. Write a (meaningless) token to the file to indicate to
races. */
/* On Unix, write a (meaningless) token to the file to indicate to
other processes waiting on this lock that the lock is stale
(deleted). */
unlink(path.c_str());
writeFull(fd, (const unsigned char *) "d", 1);
/* Note that the result of unlink() is ignored; removing the lock
file is an optimisation, not a necessity. */
#endif
}
void deleteLockFilePostClose(const Path & path)
{
#ifdef __CYGWIN__
/* On Windows, just try to delete the lock file. This will fail
if anybody still has the file open. We cannot use unlink()
here, because Cygwin emulates Unix semantics of allowing an
open file to be deleted (but fakes it - the file isn't actually
deleted until later, so a file with the same name cannot be
created in the meantime). */
char win32Path[MAX_PATH + 1];
cygwin_conv_to_full_win32_path(path.c_str(), win32Path);
if (DeleteFile(win32Path))
debug(format("delete of `%1%' succeeded") % path.c_str());
else
/* Not an error: probably means that the lock is still opened
by someone else. */
debug(format("delete of `%1%' failed: %2%") % path.c_str() % GetLastError());
#endif
}
@@ -167,13 +220,15 @@ PathLocks::~PathLocks()
void PathLocks::unlock()
{
foreach (list<FDPair>::iterator, i, fds) {
if (deletePaths) deleteLockFile(i->second, i->first);
if (deletePaths) deleteLockFilePreClose(i->second, i->first);
lockedPaths.erase(i->second);
if (close(i->first) == -1)
printMsg(lvlError,
format("error (ignored): cannot close lock file on `%1%'") % i->second);
if (deletePaths) deleteLockFilePostClose(i->second);
debug(format("lock released on `%1%'") % i->second);
}
+4 -2
View File
@@ -12,8 +12,10 @@ namespace nix {
because it doesn't exist. Any other error throws an exception. */
int openLockFile(const Path & path, bool create);
/* Delete an open lock file. */
void deleteLockFile(const Path & path, int fd);
/* Delete an open lock file. Both must be called to be fully portable
between Unix and Windows. */
void deleteLockFilePreClose(const Path & path, int fd);
void deleteLockFilePostClose(const Path & path);
enum LockType { ltRead, ltWrite, ltNone };
+1
View File
@@ -2,6 +2,7 @@
#define __ATERM_MAP_H
#include <aterm1.h>
#include <aterm2.h>
#include <assert.h>
+12
View File
@@ -1,5 +1,9 @@
#include "config.h"
#ifdef __CYGWIN__
#include <windows.h>
#endif
#include <iostream>
#include <cerrno>
#include <cstdio>
@@ -901,7 +905,15 @@ void closeMostFDs(const set<int> & exceptions)
void quickExit(int status)
{
#ifdef __CYGWIN__
/* Hack for Cygwin: _exit() doesn't seem to work quite right,
since some Berkeley DB code appears to be called when a child
exits through _exit() (e.g., because execve() failed). So call
the Windows API directly. */
ExitProcess(status);
#else
_exit(status);
#endif
}
-4
View File
@@ -12,10 +12,6 @@
#include <cstdio>
#ifndef HAVE_FDATASYNC
#define fdatasync fsync
#endif
namespace nix {
+1 -1
View File
@@ -327,7 +327,7 @@ static bool createUserEnv(EvalState & state, DrvInfos & elems,
makeBind(toATerm("derivations"),
makeList(ATreverse(manifest)), makeNoPos()),
makeBind(toATerm("manifest"),
makeStr(manifestFile, singleton<PathSet>(manifestFile)), makeNoPos())
makeStr(manifestFile, ATmakeList1(makeContextElem(toATerm(manifestFile), makeNull()))), makeNoPos())
)));
/* Instantiate it. */
+1 -1
View File
@@ -40,7 +40,7 @@ static bool indirectRoot = false;
static void printResult(EvalState & state, Expr e,
bool evalOnly, bool xmlOutput, const ATermMap & autoArgs)
{
PathSet context;
Context context;
if (evalOnly)
if (xmlOutput)
+1 -1
View File
@@ -27,7 +27,7 @@ clearStore
rm -f $SHARED.cur $SHARED.max
drvPath=$($nixinstantiate parallel.nix --argstr sleepTime 15)
drvPath=$($nixinstantiate parallel.nix --argstr sleepTime 8)
cmd="$nixstore -j1 -r $drvPath"