minijail: Add a way to allow arbitrary fd redirects

This change allows for the parent to redirect arbtitrary file
descriptors into the child, in a way that works even when the
minijail_close_open_fds() is used.

This can be used to pass in additional pipes to the jailed process.

Bug: 63904978
Test: make tests
Change-Id: Ia47eec575c92a08eb5380cc15dc4561572a209b3
diff --git a/libminijail.h b/libminijail.h
index 372c1a4..a783067 100644
--- a/libminijail.h
+++ b/libminijail.h
@@ -238,6 +238,17 @@
 		      minijail_hook_event_t event);
 
 /*
+ * minijail_preserve_fd: preserves @parent_fd and makes it available as
+ * @child_fd in the child process. @parent_fd will be closed if no other
+ * redirect has claimed it as a @child_fd.  This works even if
+ * minijail_close_open_fds() is invoked.
+ * @j         minijail to add the fd to
+ * @parent_fd the fd in the parent process
+ * @child_fd  the fd that will be available in the child process
+ */
+int minijail_preserve_fd(struct minijail *j, int parent_fd, int child_fd);
+
+/*
  * Lock this process into the given minijail. Note that this procedure cannot
  * fail, since there is no way to undo privilege-dropping; therefore, if any
  * part of the privilege-drop fails, minijail_enter() will abort the entire