From 85561ddcda0da820d62b205d69346c8f28ae7839 Mon Sep 17 00:00:00 2001 From: Christoph Klaffl Date: Fri, 25 Jan 2019 23:46:58 +0100 Subject: [PATCH 1/2] handle the case of mistyped dataset name nicely --- syncoid | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/syncoid b/syncoid index 3f6f9ba..6040110 100755 --- a/syncoid +++ b/syncoid @@ -263,6 +263,12 @@ sub syncdataset { my $sync = getzfsvalue($sourcehost,$sourcefs,$sourceisroot,'syncoid:sync'); + if (!defined $sync) { + # zfs already printed the corresponding error + if ($exitcode < 2) { $exitcode = 2; } + return 0; + } + if ($sync eq 'true' || $sync eq '-' || $sync eq '') { # empty is handled the same as unset (aka: '-') # definitely sync this dataset - if a host is called 'true' or '-', then you're special @@ -978,6 +984,11 @@ sub getzfsvalue { open FH, "$rhost $mysudocmd $zfscmd get -H $property $fsescaped |"; my $value = ; close FH; + + if (!defined $value) { + return undef; + } + my @values = split(/\t/,$value); $value = $values[2]; return $value; @@ -1468,7 +1479,7 @@ sub getreceivetoken() { my ($rhost,$fs,$isroot) = @_; my $token = getzfsvalue($rhost,$fs,$isroot,"receive_resume_token"); - if ($token ne '-' && $token ne '') { + if (defined $token && $token ne '-' && $token ne '') { return $token; } From 132c765e28316116735d1682bed38b609efd58a1 Mon Sep 17 00:00:00 2001 From: Christoph Klaffl Date: Fri, 25 Jan 2019 23:58:12 +0100 Subject: [PATCH 2/2] error out if no datasets are processed with recursive arg --- syncoid | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/syncoid b/syncoid index 6040110..8f17c13 100755 --- a/syncoid +++ b/syncoid @@ -124,6 +124,12 @@ if (!defined $args{'recursive'}) { if ($debug) { print "DEBUG: recursive sync of $sourcefs.\n"; } my @datasets = getchilddatasets($sourcehost, $sourcefs, $sourceisroot); + if (!@datasets) { + warn "CRITICAL ERROR: no datasets found"; + @datasets = (); + $exitcode = 2; + } + my @deferred; foreach my $datasetProperties(@datasets) {