Return -errno from setup_mount_destination() if chown() fails

Currently -1 is always returned on failure, and the caller treats
it as EPERM, which is not always relevant.

Bug: None
Test: system_unittest passes
Change-Id: I33b4e4b376e35bdacb94eff950109bce4e916328
diff --git a/system.c b/system.c
index bb1abf9..83f4a6a 100644
--- a/system.c
+++ b/system.c
@@ -315,7 +315,9 @@
 			return -errno;
 		close(fd);
 	}
-	return chown(dest, uid, gid);
+	if (chown(dest, uid, gid))
+		return -errno;
+	return 0;
 }
 
 /*
diff --git a/system_unittest.cc b/system_unittest.cc
index c584808..02d1401 100644
--- a/system_unittest.cc
+++ b/system_unittest.cc
@@ -5,6 +5,7 @@
  * Test system.[ch] module code using gtest.
  */
 
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -200,6 +201,8 @@
   EXPECT_EQ(0, setup_mount_destination("none", path, -1, -1, false));
   // We check it's a directory by deleting it as such.
   EXPECT_EQ(0, rmdir(path));
+  // Confirm that a bad uid/gid fails the function as expected.
+  EXPECT_NE(0, setup_mount_destination("none", path, UINT_MAX / 2, UINT_MAX / 2, false));
 
   free(path);
 }