static int attach_context_container(struct attach_context *ctx)
{
+ int fret = 0;
+
for (int i = 0; i < LXC_NS_MAX; i++) {
int ret;
continue;
ret = setns(ctx->ns_fd[i], ns_info[i].clone_flag);
- if (ret < 0)
- return log_error_errno(-1, errno,
- "Failed to attach to %s namespace of %d",
- ns_info[i].proc_name, ctx->init_pid);
+ if (ret)
+ return log_error_errno(-errno, errno, "Failed to attach to %s namespace of %d", ns_info[i].proc_name, ctx->init_pid);
- DEBUG("Attached to %s namespace of %d",
- ns_info[i].proc_name, ctx->init_pid);
+ DEBUG("Attached to %s namespace of %d", ns_info[i].proc_name, ctx->init_pid);
+
+ if (close(ctx->ns_fd[i])) {
+ fret = -errno;
+ SYSERROR("Failed to close file descriptor for %s namespace", ns_info[i].proc_name);
+ }
+ ctx->ns_fd[i] = -EBADF;
}
- return 0;
+ return fret;
}
/*
_exit(EXIT_FAILURE);
}
- /* close namespace file descriptors */
- close_nsfds(ctx);
-
/* Attach succeeded, try to cwd. */
if (options->initial_cwd)
new_cwd = options->initial_cwd;