}
static void init_sock_content(struct file *file,
- struct proc *proc,
struct map_file_data *map_file_data)
{
int fd;
assert(file);
- assert(proc);
fd = file->association;
if (fd >= 0 || fd == -ASSOC_MEM || fd == -ASSOC_SHM) {
struct sock *sock = (struct sock *)file;
- char path[PATH_MAX];
+ char path[PATH_MAX] = {'\0'};
char buf[256];
ssize_t len;
- memset(path, 0, sizeof(path));
+ assert(file->proc);
if (fd >= 0)
- sprintf(path, "/proc/%d/fd/%d", proc->pid, fd);
+ sprintf(path, "/proc/%d/fd/%d", file->proc->pid, fd);
else {
assert(map_file_data);
- sprintf(path, "/proc/%d/map_files/%lx-%lx", proc->pid,
- map_file_data->start, map_file_data->end);
+ sprintf(path, "/proc/%d/map_files/%lx-%lx",
+ file->proc->pid,
+ map_file_data->start,
+ map_file_data->end);
}
len = getxattr(path, "system.sockprotoname", buf, sizeof(buf) - 1);
if (len > 0) {
assert(class);
file = xcalloc(1, class->size);
+
file->class = class;
file->association = association;
file->name = xstrdup(name);
file->stat = *sb;
+ file->proc = proc;
+
+ /* add file to the process */
+ INIT_LIST_HEAD(&file->files);
+ list_add_tail(&file->files, &proc->files);
if (file->association == -ASSOC_SHM || file->association == -ASSOC_MEM) {
static size_t pagesize = 0;
}
if (file->class->initialize_content)
- file->class->initialize_content(file, proc, map_file_data);
+ file->class->initialize_content(file, map_file_data);
return file;
}
return f;
}
-static void enqueue_file(struct proc *proc, struct file * file)
-{
- INIT_LIST_HEAD(&file->files);
- list_add_tail(&file->files, &proc->files);
-}
-
-
static void collect_fd_files_generic(struct proc *proc, const char *proc_template,
struct file *(*collector)(struct proc *,int, struct dirent *, void *),
void *data)
if ((dd = dirfd(dirp)) < 0 )
return;
- while ((dp = xreaddir(dirp))) {
- struct file *file;
-
- if ((file = (* collector)(proc, dd, dp, data)) == NULL)
- continue;
+ while ((dp = xreaddir(dirp)))
+ collector(proc, dd, dp, data);
- enqueue_file(proc, file);
- }
closedir(dirp);
}
return;
for (unsigned int i = 0; i < count; i++) {
- struct file *file;
if (assocs[i] == ASSOC_EXE)
collect_proc_uid(proc, dd);
- if ((file = collect_outofbox_file(proc, dd,
- assoc_names[assocs[i]],
- assocs[i] * -1)) == NULL)
- continue;
-
- enqueue_file(proc, file);
+ collect_outofbox_file(proc, dd,
+ assoc_names[assocs[i]], assocs[i] * -1);
}
closedir(dirp);
}