-
Notifications
You must be signed in to change notification settings - Fork 596
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Suraj Shirvankar <[email protected]>
- Loading branch information
1 parent
03541c0
commit 406a571
Showing
15 changed files
with
156 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,6 +113,7 @@ enum { | |
CR_FD_PIPES, | ||
CR_FD_TTY_FILES, | ||
CR_FD_MEMFD_FILE, | ||
CR_FD_PIDFD, | ||
|
||
CR_FD_AUTOFS, | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef __CR_PIDFD_H__ | ||
#define __CR_PIDFD_H__ | ||
|
||
#include <sys/stat.h> | ||
#include "images/pidfd.pb-c.h" | ||
#include <sys/syscall.h> | ||
#include <unistd.h> | ||
|
||
struct fd_parms; | ||
|
||
extern const struct fdtype_ops pidfd_dump_ops; | ||
extern struct collect_image_info pidfd_cinfo; | ||
extern int is_pidfd_link(char *link); | ||
|
||
static inline int pidfd_open(pid_t pid, unsigned int flags) | ||
{ | ||
return syscall(SYS_pidfd_open, pid, flags); | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,7 @@ enum { | |
PB_SK_QUEUES, | ||
PB_IPCNS_MSG, | ||
PB_IPCNS_MSG_ENT, | ||
PB_PIDFD, | ||
|
||
PB_MAX, | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include "pidfd.h" | ||
#include "util.h" | ||
|
||
#include "fdinfo.h" | ||
#include "files.h" | ||
#include "imgset.h" | ||
#include "protobuf.h" | ||
#include "fdinfo.pb-c.h" | ||
|
||
int is_pidfd_link(char *link) | ||
{ | ||
return is_anon_link_type(link, "[pidfd]"); | ||
} | ||
|
||
static int dump_one_pidfd(int lfd, u32 id, const struct fd_parms *p) | ||
{ | ||
PidfdEntry tfe = PIDFD_ENTRY__INIT; | ||
FileEntry fe = FILE_ENTRY__INIT; | ||
|
||
if (parse_fdinfo(lfd, FD_TYPES__PIDFD, &tfe)) | ||
return -1; | ||
|
||
tfe.id = id; | ||
tfe.flags = p->flags; | ||
tfe.inode = p->stat.st_ino; | ||
tfe.mnt_id = p->mnt_id; | ||
tfe.fown = (FownEntry *)&p->fown; | ||
|
||
fe.type = FD_TYPES__PIDFD; | ||
fe.id = tfe.id; | ||
fe.pidfd = &tfe; | ||
|
||
return pb_write_one(img_from_set(glob_imgset, CR_FD_FILES), &fe, PB_FILE); | ||
} | ||
|
||
const struct fdtype_ops pidfd_dump_ops = { | ||
.type = FD_TYPES__PIDFD, | ||
.dump = dump_one_pidfd, | ||
}; | ||
|
||
struct pidfd_info { | ||
PidfdEntry *pidfde; | ||
struct file_desc d; | ||
}; | ||
|
||
static int open_pidfd_fd(struct file_desc *d, int *new_fd) | ||
{ | ||
int fd = -1; | ||
struct pidfd_info *info = container_of(d, struct pidfd_info, d); | ||
PidfdEntry *pidfde = info->pidfde; | ||
|
||
pr_info("Creating new pidfd %ld\n", pidfde->pid); | ||
fd = pidfd_open(pidfde->pid, 0); | ||
if (fd < 0) { | ||
pr_perror("Cannot create pidfd"); | ||
return -1; | ||
} | ||
|
||
*new_fd = fd; | ||
return 0; | ||
} | ||
|
||
static struct file_desc_ops pidfd_desc_ops = { | ||
.type = FD_TYPES__PIDFD, | ||
.open = open_pidfd_fd, | ||
}; | ||
|
||
static int collect_one_pidfd(void *o, ProtobufCMessage *msg, struct cr_img *i) | ||
{ | ||
struct pidfd_info *info = o; | ||
|
||
info->pidfde = pb_msg(msg, PidfdEntry); | ||
return file_desc_add(&info->d, info->pidfde->id, &pidfd_desc_ops); | ||
} | ||
|
||
struct collect_image_info pidfd_cinfo = { | ||
.fd_type = CR_FD_PIDFD, | ||
.pb_type = PB_PIDFD, | ||
.priv_size = sizeof(struct pidfd_info), | ||
.collect = collect_one_pidfd, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
syntax = "proto2"; | ||
|
||
import "fown.proto"; | ||
|
||
message pidfd_entry { | ||
required uint32 id = 1; | ||
required uint64 pos = 2; | ||
required uint32 flags = 3; | ||
required uint32 mnt_id = 4; | ||
required uint64 inode = 5; | ||
required int64 pid = 6; | ||
required int64 nspid = 7; | ||
required fown_entry fown = 8; | ||
} |