char buf[1024], *dev;
dev = get_blktap2_device(ctx, disk->physpath, device_disk_string_of_phystype(disk->phystype));
if (dev == NULL) {
- if (pipe(p) < 0) {
- XL_LOG(ctx, XL_LOG_ERROR, "Failed to create a pipe");
- return -1;
- }
- rc = fork();
- if (rc < 0) {
- XL_LOG(ctx, XL_LOG_ERROR, "Failed to fork a new process");
- return -1;
- } else if (!rc) { /* child */
+ rc= libxl_pipe(ctx, p); if (rc==-1) return -1;
+ rc= libxl_fork(ctx); if (rc==-1) return -1;
+ if (!rc) { /* child */
int null_r, null_w;
char *args[4];
args[0] = "tapdisk2";
#include "libxl.h"
#include "libxl_internal.h"
-static pid_t libxl_fork(struct libxl_ctx *ctx)
-{
- pid_t pid;
-
- pid = fork();
- if (pid == -1) {
- XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "fork failed");
- return -1;
- }
-
- return pid;
-}
-
static int call_waitpid(pid_t (*waitpid_cb)(pid_t, int *, int), pid_t pid, int *status, int options)
{
return (waitpid_cb) ? waitpid_cb(pid, status, options) : waitpid(pid, status, options);
dup2(stderrfd, STDERR_FILENO);
for (i = 4; i < 256; i++)
close(i);
+
+ signal(SIGPIPE, SIG_DFL);
+ /* in case our caller set it to IGN. subprocesses are entitled
+ * to assume they got DFL. */
+
execv(arg0, args);
_exit(-1);
}
READ_WRITE_EXACTLY(read, 1, /* */)
READ_WRITE_EXACTLY(write, 0, const)
+
+
+pid_t libxl_fork(struct libxl_ctx *ctx)
+{
+ pid_t pid;
+
+ pid = fork();
+ if (pid == -1) {
+ XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "fork failed");
+ return -1;
+ }
+
+ return pid;
+}
+
+int libxl_pipe(struct libxl_ctx *ctx, int pipes[2])
+{
+ if (pipe(pipes) < 0) {
+ XL_LOG(ctx, XL_LOG_ERROR, "Failed to create a pipe");
+ return -1;
+ }
+ return 0;
+}
* logged using filename (which is only used for logging) and what
* (which may be 0). */
+pid_t libxl_fork(struct libxl_ctx *ctx);
+int libxl_pipe(struct libxl_ctx *ctx, int pipes[2]);
+ /* Just like fork(2), pipe(2), but log errors. */
+
#endif