diff options
Diffstat (limited to 'ipc/shm.c')
-rw-r--r-- | ipc/shm.c | 86 |
1 files changed, 28 insertions, 58 deletions
diff --git a/ipc/shm.c b/ipc/shm.c index 1d6cf08d950b..dca90489e3b0 100644 --- a/ipc/shm.c +++ b/ipc/shm.c @@ -23,12 +23,12 @@ #include <linux/init.h> #include <linux/file.h> #include <linux/mman.h> -#include <linux/proc_fs.h> #include <linux/shmem_fs.h> #include <linux/security.h> #include <linux/syscalls.h> #include <linux/audit.h> #include <linux/ptrace.h> +#include <linux/seq_file.h> #include <asm/uaccess.h> @@ -51,7 +51,7 @@ static int newseg (key_t key, int shmflg, size_t size); static void shm_open (struct vm_area_struct *shmd); static void shm_close (struct vm_area_struct *shmd); #ifdef CONFIG_PROC_FS -static int sysvipc_shm_read_proc(char *buffer, char **start, off_t offset, int length, int *eof, void *data); +static int sysvipc_shm_proc_show(struct seq_file *s, void *it); #endif size_t shm_ctlmax = SHMMAX; @@ -63,9 +63,10 @@ static int shm_tot; /* total number of shared memory pages */ void __init shm_init (void) { ipc_init_ids(&shm_ids, 1); -#ifdef CONFIG_PROC_FS - create_proc_read_entry("sysvipc/shm", 0, NULL, sysvipc_shm_read_proc, NULL); -#endif + ipc_init_proc_interface("sysvipc/shm", + " key shmid perms size cpid lpid nattch uid gid cuid cgid atime dtime ctime\n", + &shm_ids, + sysvipc_shm_proc_show); } static inline int shm_checkid(struct shmid_kernel *s, int id) @@ -869,63 +870,32 @@ asmlinkage long sys_shmdt(char __user *shmaddr) } #ifdef CONFIG_PROC_FS -static int sysvipc_shm_read_proc(char *buffer, char **start, off_t offset, int length, int *eof, void *data) +static int sysvipc_shm_proc_show(struct seq_file *s, void *it) { - off_t pos = 0; - off_t begin = 0; - int i, len = 0; - - down(&shm_ids.sem); - len += sprintf(buffer, " key shmid perms size cpid lpid nattch uid gid cuid cgid atime dtime ctime\n"); + struct shmid_kernel *shp = it; + char *format; - for(i = 0; i <= shm_ids.max_id; i++) { - struct shmid_kernel* shp; - - shp = shm_lock(i); - if(shp!=NULL) { #define SMALL_STRING "%10d %10d %4o %10u %5u %5u %5d %5u %5u %5u %5u %10lu %10lu %10lu\n" #define BIG_STRING "%10d %10d %4o %21u %5u %5u %5d %5u %5u %5u %5u %10lu %10lu %10lu\n" - char *format; - if (sizeof(size_t) <= sizeof(int)) - format = SMALL_STRING; - else - format = BIG_STRING; - len += sprintf(buffer + len, format, - shp->shm_perm.key, - shm_buildid(i, shp->shm_perm.seq), - shp->shm_flags, - shp->shm_segsz, - shp->shm_cprid, - shp->shm_lprid, - is_file_hugepages(shp->shm_file) ? (file_count(shp->shm_file) - 1) : shp->shm_nattch, - shp->shm_perm.uid, - shp->shm_perm.gid, - shp->shm_perm.cuid, - shp->shm_perm.cgid, - shp->shm_atim, - shp->shm_dtim, - shp->shm_ctim); - shm_unlock(shp); - - pos += len; - if(pos < offset) { - len = 0; - begin = pos; - } - if(pos > offset + length) - goto done; - } - } - *eof = 1; -done: - up(&shm_ids.sem); - *start = buffer + (offset - begin); - len -= (offset - begin); - if(len > length) - len = length; - if(len < 0) - len = 0; - return len; + if (sizeof(size_t) <= sizeof(int)) + format = SMALL_STRING; + else + format = BIG_STRING; + return seq_printf(s, format, + shp->shm_perm.key, + shp->id, + shp->shm_flags, + shp->shm_segsz, + shp->shm_cprid, + shp->shm_lprid, + is_file_hugepages(shp->shm_file) ? (file_count(shp->shm_file) - 1) : shp->shm_nattch, + shp->shm_perm.uid, + shp->shm_perm.gid, + shp->shm_perm.cuid, + shp->shm_perm.cgid, + shp->shm_atim, + shp->shm_dtim, + shp->shm_ctim); } #endif |