Skip to content

Commit

Permalink
commands: pass around intmax_t
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Aug 31, 2018
1 parent 6b28940 commit 9234406
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/lxc/commands.c
Expand Up @@ -375,26 +375,36 @@ int lxc_try_cmd(const char *name, const char *lxcpath)
pid_t lxc_cmd_get_init_pid(const char *name, const char *lxcpath)
{
int ret, stopped;
intmax_t pid;
struct lxc_cmd_rr cmd = {
.req = {
.cmd = LXC_CMD_GET_INIT_PID
},
.rsp = {
.data = INT_TO_PTR((int){-1})
.data = INTMAX_TO_PTR((intmax_t){-1})
}
};

ret = lxc_cmd(name, &cmd, &stopped, lxcpath, NULL);
if (ret < 0)
return -1;

return PTR_TO_INT(cmd.rsp.data);
pid = PTR_TO_INTMAX(cmd.rsp.data);
if (pid < 0)
return -1;

/* We need to assume that pid_t can actually hold any pid given to us
* by the kernel. If it can't it's a libc bug.
*/
return (pid_t)pid;
}

static int lxc_cmd_get_init_pid_callback(int fd, struct lxc_cmd_req *req,
struct lxc_handler *handler)
{
struct lxc_cmd_rsp rsp = { .data = INT_TO_PTR(handler->pid) };
struct lxc_cmd_rsp rsp = {
.data = INTMAX_TO_PTR(handler->pid)
};

return lxc_cmd_rsp_send(fd, &rsp);
}
Expand Down
3 changes: 3 additions & 0 deletions src/lxc/macro.h
Expand Up @@ -312,4 +312,7 @@ extern int __build_bug_on_failed;
#define PTR_TO_INT(p) ((int)((intptr_t)(p)))
#define INT_TO_PTR(u) ((void *)((intptr_t)(u)))

#define PTR_TO_INTMAX(p) ((intmax_t)((intptr_t)(p)))
#define INTMAX_TO_PTR(u) ((void *)((intptr_t)(u)))

#endif /* __LXC_MACRO_H */

0 comments on commit 9234406

Please sign in to comment.