From 7e0dc553966e9ac1d0506e8cce9ae3f4708f124b Mon Sep 17 00:00:00 2001 From: Jeremie Koenig Date: Fri, 13 Aug 2010 19:05:13 +0200 Subject: update_pid_entries(): fix awkwardly indented uninitialized memory leak * procfs_pid_files.c (update_pid_entries): Replace dynamic allocation of `stat' with automatic allocation. Memset `stat' to 0. --- procfs_pid_files.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/procfs_pid_files.c b/procfs_pid_files.c index 46861531..d44a2a22 100644 --- a/procfs_pid_files.c +++ b/procfs_pid_files.c @@ -46,14 +46,12 @@ update_pid_entries (struct procfs_dir *dir, const char *name, time_t timestamp, const char *symlink_target) { - struct procfs_dir_entry *dir_entry; - struct stat *stat = (struct stat *) malloc (sizeof (struct stat)); - stat->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH; + struct stat stat; - dir_entry = update_entries_list (dir, name, stat, - timestamp, symlink_target); + memset (&stat, 0, sizeof stat); + stat->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH; - return dir_entry; + return update_entries_list (dir, name, &stat, timestamp, symlink_target); } /* Creates files to store process information for DIR -- cgit v1.2.3 From 0e63733ee60d0b9fa56ec47bdb088d4b835ec217 Mon Sep 17 00:00:00 2001 From: Jeremie Koenig Date: Fri, 13 Aug 2010 19:05:14 +0200 Subject: Set an appropriate st_mode on symlinks. * procfs_pid_files.c (update_pid_entries): When symlink_target is not NULL, set st_size to the symlink length and st_mode to S_IFLNK | 0777. --- procfs_pid_files.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/procfs_pid_files.c b/procfs_pid_files.c index d44a2a22..26a0af33 100644 --- a/procfs_pid_files.c +++ b/procfs_pid_files.c @@ -49,7 +49,16 @@ update_pid_entries (struct procfs_dir *dir, const char *name, struct stat stat; memset (&stat, 0, sizeof stat); - stat->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH; + if (symlink_target) + { + stat.st_size = strlen (symlink_target); + stat.st_mode = S_IFLNK | 0777; + } + else + { + stat.st_size = 0; + stat.st_mode = S_IFREG | 0444; + } return update_entries_list (dir, name, &stat, timestamp, symlink_target); } -- cgit v1.2.3 From 7070feccb2e4d135d5620805de6cec177722b837 Mon Sep 17 00:00:00 2001 From: Jeremie Koenig Date: Mon, 16 Aug 2010 13:36:52 +0200 Subject: Implement /proc/mounts as a symlink to /etc/mtab * procfs_nonpid_files.c (procfs_create_mounts): New function. * procfs_dir.c (procfs_fill_root_dir): Call procfs_create_mounts. Signed-off-by: Jeremie Koenig --- procfs_dir.c | 3 +++ procfs_nonpid_files.c | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/procfs_dir.c b/procfs_dir.c index f76e6a4b..bd1e49d6 100644 --- a/procfs_dir.c +++ b/procfs_dir.c @@ -654,6 +654,9 @@ procfs_fill_root_dir(struct procfs_dir *dir, time_t timestamp) if ((err = procfs_create_loadavg (dir, &node, timestamp)) != 0) return err; + if ((err = procfs_create_mounts (dir, &node, timestamp)) != 0) + return err; + return 0; } diff --git a/procfs_nonpid_files.c b/procfs_nonpid_files.c index 2c1209ee..f1300666 100644 --- a/procfs_nonpid_files.c +++ b/procfs_nonpid_files.c @@ -166,6 +166,19 @@ error_t procfs_create_loadavg (struct procfs_dir *dir, return err; } +error_t procfs_create_mounts (struct procfs_dir *dir, + struct node **node, + time_t timestamp) +{ + struct procfs_dir_entry *dir_entry; + int err; + + dir_entry = update_pid_entries (dir, "mounts", timestamp, "/etc/mtab"); + err = procfs_create_node (dir_entry, "mounts", node); + + return err; +} + error_t get_uptime (struct timeval *uptime) { struct timeval boot_time, now; -- cgit v1.2.3