len = size;
ssize_t cur_pos = lseek64(input, 0, SEEK_CUR);
+ if (cur_pos < 0) {
+ logger.log_error("lseek error: %s", std::system_category().default_error_condition(errno).message());
+ return;
+ }
ssize_t bytes_read;
if ((bytes_read = read(input, buff, len)) == -1) {
Core<T> m_core;
std::ofstream m_core_file;
int prstatus_fd = -1;
+ std::pair <void *, size_t> map_buff;
public:
- explicit LiveDumper(const pid_t pid) : m_pid(pid) {}
+ explicit LiveDumper(const pid_t pid) : m_pid(pid), map_buff(MAP_FAILED, 0) {}
+
+ ~ LiveDumper () {
+ if (map_buff.first != MAP_FAILED)
+ munmap(map_buff.first, map_buff.second);
+ }
void CollectTpids() {
m_tpids.clear();
memcpy(&prstatus.pr_reg, ®isters, sizeof(prstatus.pr_reg));
prstatus.pr_pid = m_pid;
- auto buff = reinterpret_cast<char*>(mmap(nullptr, sizeof(prstatus),
+ map_buff.first = mmap(nullptr, sizeof(prstatus),
PROT_READ | PROT_WRITE,
MAP_SHARED,
prstatus_fd,
- 0));
- if (buff == MAP_FAILED)
+ 0);
+ if (map_buff.first == MAP_FAILED)
return;
- memcpy(buff, &prstatus, sizeof(prstatus));
+ map_buff.second = sizeof prstatus;
+
+ memcpy(static_cast <char *> (map_buff.first), &prstatus, sizeof(prstatus));
}
void AddNotes(const std::vector<std::shared_ptr<MapRecord>> &records) {
int spawn_nullstdfds(spawn_param_s *param)
{
int fd = open("/dev/null", O_RDWR);
+ if (fd < 0)
+ return -1;
+
int ret = dup2(fd, STDIN_FILENO) < 0 || dup2(fd, STDOUT_FILENO) < 0 || dup2(fd, STDERR_FILENO) < 0 ? -1 : 0;
if (fd != STDIN_FILENO && fd != STDOUT_FILENO && fd != STDERR_FILENO)
close(fd);