attach: simplify opening of /proc/self

parent 4475fabb
...@@ -361,11 +361,7 @@ static int get_attach_context(struct attach_context *ctx, ...@@ -361,11 +361,7 @@ static int get_attach_context(struct attach_context *ctx,
if (ctx->init_pid < 0) if (ctx->init_pid < 0)
return log_error(-1, "Failed to get init pid"); return log_error(-1, "Failed to get init pid");
ret = snprintf(path, sizeof(path), "/proc/%d", lxc_raw_getpid()); ctx->dfd_self_pid = openat(-EBADF, "/proc/self", O_CLOEXEC | O_NOCTTY | O_PATH | O_DIRECTORY);
if (ret < 0 || ret >= sizeof(path))
return ret_errno(EIO);
ctx->dfd_self_pid = openat(-EBADF, path, O_CLOEXEC | O_NOCTTY | O_NOFOLLOW | O_PATH | O_DIRECTORY);
if (ctx->dfd_self_pid < 0) if (ctx->dfd_self_pid < 0)
return log_error_errno(-errno, errno, "Failed to open /proc/self"); return log_error_errno(-errno, errno, "Failed to open /proc/self");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment