init: clean up subcontext_test

subcontext_test had been failing due to setexeccon() failing to
transition to vendor_init context.  This is a good thing as nothing
other than init should be able to transition into this context.

I don't want to add code to skip the setexeccon() call only for the
tests, so I instead call setexeccon() with the return value of
getcon().  This works however only for root, so these tests are
skipped for non-root.

Test: init unit tests
Change-Id: I8a415599e0ec5506511202f7f5018c0e5265837d
diff --git a/init/subcontext.h b/init/subcontext.h
index e920034..eadabee 100644
--- a/init/subcontext.h
+++ b/init/subcontext.h
@@ -35,7 +35,7 @@
 class Subcontext {
   public:
     Subcontext(std::string path_prefix, std::string context)
-        : path_prefix_(std::move(path_prefix)), context_(std::move(context)) {
+        : path_prefix_(std::move(path_prefix)), context_(std::move(context)), pid_(0) {
         Fork();
     }
 
@@ -55,21 +55,6 @@
     android::base::unique_fd socket_;
 };
 
-// For testing, to kill the subcontext after the test has completed.
-class SubcontextKiller {
-  public:
-    SubcontextKiller(const Subcontext& subcontext) : subcontext_(subcontext) {}
-    ~SubcontextKiller() {
-        if (subcontext_.pid() > 0) {
-            kill(subcontext_.pid(), SIGTERM);
-            kill(subcontext_.pid(), SIGKILL);
-        }
-    }
-
-  private:
-    const Subcontext& subcontext_;
-};
-
 int SubcontextMain(int argc, char** argv, const KeywordFunctionMap* function_map);
 std::vector<Subcontext>* InitializeSubcontexts();
 bool SubcontextChildReap(pid_t pid);