diff options
| author | Jeff Garzik <jgarzik@pobox.com> | 2005-09-08 05:37:58 -0400 |
|---|---|---|
| committer | Jeff Garzik <jgarzik@pobox.com> | 2005-09-08 05:37:58 -0400 |
| commit | 5a2cec83a9bb1b4295aa8ab728fcb8ca1811a33c (patch) | |
| tree | 2f83dc6949763e77cf6422e696dc6146684dcf4e /ipc | |
| parent | f2c853bca542f5ac0b036377637192a74f2091c2 (diff) | |
| parent | caf39e87cc1182f7dae84eefc43ca14d54c78ef9 (diff) | |
Merge /spare/repo/linux-2.6/
Diffstat (limited to 'ipc')
| -rw-r--r-- | ipc/compat.c | 12 | ||||
| -rw-r--r-- | ipc/msg.c | 82 | ||||
| -rw-r--r-- | ipc/sem.c | 73 | ||||
| -rw-r--r-- | ipc/shm.c | 86 | ||||
| -rw-r--r-- | ipc/util.c | 156 | ||||
| -rw-r--r-- | ipc/util.h | 8 |
6 files changed, 248 insertions, 169 deletions
diff --git a/ipc/compat.c b/ipc/compat.c index 3881d564c668..1fe95f6659dd 100644 --- a/ipc/compat.c +++ b/ipc/compat.c | |||
| @@ -42,10 +42,10 @@ struct compat_msgbuf { | |||
| 42 | 42 | ||
| 43 | struct compat_ipc_perm { | 43 | struct compat_ipc_perm { |
| 44 | key_t key; | 44 | key_t key; |
| 45 | compat_uid_t uid; | 45 | __compat_uid_t uid; |
| 46 | compat_gid_t gid; | 46 | __compat_gid_t gid; |
| 47 | compat_uid_t cuid; | 47 | __compat_uid_t cuid; |
| 48 | compat_gid_t cgid; | 48 | __compat_gid_t cgid; |
| 49 | compat_mode_t mode; | 49 | compat_mode_t mode; |
| 50 | unsigned short seq; | 50 | unsigned short seq; |
| 51 | }; | 51 | }; |
| @@ -174,8 +174,8 @@ static inline int __put_compat_ipc_perm(struct ipc64_perm *p, | |||
| 174 | struct compat_ipc_perm __user *up) | 174 | struct compat_ipc_perm __user *up) |
| 175 | { | 175 | { |
| 176 | int err; | 176 | int err; |
| 177 | compat_uid_t u; | 177 | __compat_uid_t u; |
| 178 | compat_gid_t g; | 178 | __compat_gid_t g; |
| 179 | 179 | ||
| 180 | err = __put_user(p->key, &up->key); | 180 | err = __put_user(p->key, &up->key); |
| 181 | SET_UID(u, p->uid); | 181 | SET_UID(u, p->uid); |
| @@ -26,6 +26,7 @@ | |||
| 26 | #include <linux/sched.h> | 26 | #include <linux/sched.h> |
| 27 | #include <linux/syscalls.h> | 27 | #include <linux/syscalls.h> |
| 28 | #include <linux/audit.h> | 28 | #include <linux/audit.h> |
| 29 | #include <linux/seq_file.h> | ||
| 29 | #include <asm/current.h> | 30 | #include <asm/current.h> |
| 30 | #include <asm/uaccess.h> | 31 | #include <asm/uaccess.h> |
| 31 | #include "util.h" | 32 | #include "util.h" |
| @@ -74,16 +75,16 @@ static struct ipc_ids msg_ids; | |||
| 74 | static void freeque (struct msg_queue *msq, int id); | 75 | static void freeque (struct msg_queue *msq, int id); |
| 75 | static int newque (key_t key, int msgflg); | 76 | static int newque (key_t key, int msgflg); |
| 76 | #ifdef CONFIG_PROC_FS | 77 | #ifdef CONFIG_PROC_FS |
| 77 | static int sysvipc_msg_read_proc(char *buffer, char **start, off_t offset, int length, int *eof, void *data); | 78 | static int sysvipc_msg_proc_show(struct seq_file *s, void *it); |
| 78 | #endif | 79 | #endif |
| 79 | 80 | ||
| 80 | void __init msg_init (void) | 81 | void __init msg_init (void) |
| 81 | { | 82 | { |
| 82 | ipc_init_ids(&msg_ids,msg_ctlmni); | 83 | ipc_init_ids(&msg_ids,msg_ctlmni); |
| 83 | 84 | ipc_init_proc_interface("sysvipc/msg", | |
| 84 | #ifdef CONFIG_PROC_FS | 85 | " key msqid perms cbytes qnum lspid lrpid uid gid cuid cgid stime rtime ctime\n", |
| 85 | create_proc_read_entry("sysvipc/msg", 0, NULL, sysvipc_msg_read_proc, NULL); | 86 | &msg_ids, |
| 86 | #endif | 87 | sysvipc_msg_proc_show); |
| 87 | } | 88 | } |
| 88 | 89 | ||
| 89 | static int newque (key_t key, int msgflg) | 90 | static int newque (key_t key, int msgflg) |
| @@ -113,6 +114,7 @@ static int newque (key_t key, int msgflg) | |||
| 113 | return -ENOSPC; | 114 | return -ENOSPC; |
| 114 | } | 115 | } |
| 115 | 116 | ||
| 117 | msq->q_id = msg_buildid(id,msq->q_perm.seq); | ||
| 116 | msq->q_stime = msq->q_rtime = 0; | 118 | msq->q_stime = msq->q_rtime = 0; |
| 117 | msq->q_ctime = get_seconds(); | 119 | msq->q_ctime = get_seconds(); |
| 118 | msq->q_cbytes = msq->q_qnum = 0; | 120 | msq->q_cbytes = msq->q_qnum = 0; |
| @@ -123,7 +125,7 @@ static int newque (key_t key, int msgflg) | |||
| 123 | INIT_LIST_HEAD(&msq->q_senders); | 125 | INIT_LIST_HEAD(&msq->q_senders); |
| 124 | msg_unlock(msq); | 126 | msg_unlock(msq); |
| 125 | 127 | ||
| 126 | return msg_buildid(id,msq->q_perm.seq); | 128 | return msq->q_id; |
| 127 | } | 129 | } |
| 128 | 130 | ||
| 129 | static inline void ss_add(struct msg_queue* msq, struct msg_sender* mss) | 131 | static inline void ss_add(struct msg_queue* msq, struct msg_sender* mss) |
| @@ -808,55 +810,25 @@ out_unlock: | |||
| 808 | } | 810 | } |
| 809 | 811 | ||
| 810 | #ifdef CONFIG_PROC_FS | 812 | #ifdef CONFIG_PROC_FS |
| 811 | static int sysvipc_msg_read_proc(char *buffer, char **start, off_t offset, int length, int *eof, void *data) | 813 | static int sysvipc_msg_proc_show(struct seq_file *s, void *it) |
| 812 | { | 814 | { |
| 813 | off_t pos = 0; | 815 | struct msg_queue *msq = it; |
| 814 | off_t begin = 0; | 816 | |
| 815 | int i, len = 0; | 817 | return seq_printf(s, |
| 816 | 818 | "%10d %10d %4o %10lu %10lu %5u %5u %5u %5u %5u %5u %10lu %10lu %10lu\n", | |
| 817 | down(&msg_ids.sem); | 819 | msq->q_perm.key, |
| 818 | len += sprintf(buffer, " key msqid perms cbytes qnum lspid lrpid uid gid cuid cgid stime rtime ctime\n"); | 820 | msq->q_id, |
| 819 | 821 | msq->q_perm.mode, | |
| 820 | for(i = 0; i <= msg_ids.max_id; i++) { | 822 | msq->q_cbytes, |
| 821 | struct msg_queue * msq; | 823 | msq->q_qnum, |
| 822 | msq = msg_lock(i); | 824 | msq->q_lspid, |
| 823 | if(msq != NULL) { | 825 | msq->q_lrpid, |
| 824 | len += sprintf(buffer + len, "%10d %10d %4o %10lu %10lu %5u %5u %5u %5u %5u %5u %10lu %10lu %10lu\n", | 826 | msq->q_perm.uid, |
| 825 | msq->q_perm.key, | 827 | msq->q_perm.gid, |
| 826 | msg_buildid(i,msq->q_perm.seq), | 828 | msq->q_perm.cuid, |
| 827 | msq->q_perm.mode, | 829 | msq->q_perm.cgid, |
| 828 | msq->q_cbytes, | 830 | msq->q_stime, |
| 829 | msq->q_qnum, | 831 | msq->q_rtime, |
| 830 | msq->q_lspid, | 832 | msq->q_ctime); |
| 831 | msq->q_lrpid, | ||
| 832 | msq->q_perm.uid, | ||
| 833 | msq->q_perm.gid, | ||
| 834 | msq->q_perm.cuid, | ||
| 835 | msq->q_perm.cgid, | ||
| 836 | msq->q_stime, | ||
| 837 | msq->q_rtime, | ||
| 838 | msq->q_ctime); | ||
| 839 | msg_unlock(msq); | ||
| 840 | |||
| 841 | pos += len; | ||
| 842 | if(pos < offset) { | ||
| 843 | len = 0; | ||
| 844 | begin = pos; | ||
| 845 | } | ||
| 846 | if(pos > offset + length) | ||
| 847 | goto done; | ||
| 848 | } | ||
| 849 | |||
| 850 | } | ||
| 851 | *eof = 1; | ||
| 852 | done: | ||
| 853 | up(&msg_ids.sem); | ||
| 854 | *start = buffer + (offset - begin); | ||
| 855 | len -= (offset - begin); | ||
| 856 | if(len > length) | ||
| 857 | len = length; | ||
| 858 | if(len < 0) | ||
| 859 | len = 0; | ||
| 860 | return len; | ||
| 861 | } | 833 | } |
| 862 | #endif | 834 | #endif |
| @@ -73,6 +73,7 @@ | |||
| 73 | #include <linux/security.h> | 73 | #include <linux/security.h> |
| 74 | #include <linux/syscalls.h> | 74 | #include <linux/syscalls.h> |
| 75 | #include <linux/audit.h> | 75 | #include <linux/audit.h> |
| 76 | #include <linux/seq_file.h> | ||
| 76 | #include <asm/uaccess.h> | 77 | #include <asm/uaccess.h> |
| 77 | #include "util.h" | 78 | #include "util.h" |
| 78 | 79 | ||
| @@ -89,7 +90,7 @@ static struct ipc_ids sem_ids; | |||
| 89 | static int newary (key_t, int, int); | 90 | static int newary (key_t, int, int); |
| 90 | static void freeary (struct sem_array *sma, int id); | 91 | static void freeary (struct sem_array *sma, int id); |
| 91 | #ifdef CONFIG_PROC_FS | 92 | #ifdef CONFIG_PROC_FS |
| 92 | static int sysvipc_sem_read_proc(char *buffer, char **start, off_t offset, int length, int *eof, void *data); | 93 | static int sysvipc_sem_proc_show(struct seq_file *s, void *it); |
| 93 | #endif | 94 | #endif |
| 94 | 95 | ||
| 95 | #define SEMMSL_FAST 256 /* 512 bytes on stack */ | 96 | #define SEMMSL_FAST 256 /* 512 bytes on stack */ |
| @@ -116,10 +117,10 @@ void __init sem_init (void) | |||
| 116 | { | 117 | { |
| 117 | used_sems = 0; | 118 | used_sems = 0; |
| 118 | ipc_init_ids(&sem_ids,sc_semmni); | 119 | ipc_init_ids(&sem_ids,sc_semmni); |
| 119 | 120 | ipc_init_proc_interface("sysvipc/sem", | |
| 120 | #ifdef CONFIG_PROC_FS | 121 | " key semid perms nsems uid gid cuid cgid otime ctime\n", |
| 121 | create_proc_read_entry("sysvipc/sem", 0, NULL, sysvipc_sem_read_proc, NULL); | 122 | &sem_ids, |
| 122 | #endif | 123 | sysvipc_sem_proc_show); |
| 123 | } | 124 | } |
| 124 | 125 | ||
| 125 | /* | 126 | /* |
| @@ -193,6 +194,7 @@ static int newary (key_t key, int nsems, int semflg) | |||
| 193 | } | 194 | } |
| 194 | used_sems += nsems; | 195 | used_sems += nsems; |
| 195 | 196 | ||
| 197 | sma->sem_id = sem_buildid(id, sma->sem_perm.seq); | ||
| 196 | sma->sem_base = (struct sem *) &sma[1]; | 198 | sma->sem_base = (struct sem *) &sma[1]; |
| 197 | /* sma->sem_pending = NULL; */ | 199 | /* sma->sem_pending = NULL; */ |
| 198 | sma->sem_pending_last = &sma->sem_pending; | 200 | sma->sem_pending_last = &sma->sem_pending; |
| @@ -201,7 +203,7 @@ static int newary (key_t key, int nsems, int semflg) | |||
| 201 | sma->sem_ctime = get_seconds(); | 203 | sma->sem_ctime = get_seconds(); |
| 202 | sem_unlock(sma); | 204 | sem_unlock(sma); |
| 203 | 205 | ||
| 204 | return sem_buildid(id, sma->sem_perm.seq); | 206 | return sma->sem_id; |
| 205 | } | 207 | } |
| 206 | 208 | ||
| 207 | asmlinkage long sys_semget (key_t key, int nsems, int semflg) | 209 | asmlinkage long sys_semget (key_t key, int nsems, int semflg) |
| @@ -1328,50 +1330,21 @@ next_entry: | |||
| 1328 | } | 1330 | } |
| 1329 | 1331 | ||
| 1330 | #ifdef CONFIG_PROC_FS | 1332 | #ifdef CONFIG_PROC_FS |
| 1331 | static int sysvipc_sem_read_proc(char *buffer, char **start, off_t offset, int length, int *eof, void *data) | 1333 | static int sysvipc_sem_proc_show(struct seq_file *s, void *it) |
| 1332 | { | 1334 | { |
| 1333 | off_t pos = 0; | 1335 | struct sem_array *sma = it; |
| 1334 | off_t begin = 0; | 1336 | |
| 1335 | int i, len = 0; | 1337 | return seq_printf(s, |
| 1336 | 1338 | "%10d %10d %4o %10lu %5u %5u %5u %5u %10lu %10lu\n", | |
| 1337 | len += sprintf(buffer, " key semid perms nsems uid gid cuid cgid otime ctime\n"); | 1339 | sma->sem_perm.key, |
| 1338 | down(&sem_ids.sem); | 1340 | sma->sem_id, |
| 1339 | 1341 | sma->sem_perm.mode, | |
| 1340 | for(i = 0; i <= sem_ids.max_id; i++) { | 1342 | sma->sem_nsems, |
| 1341 | struct sem_array *sma; | 1343 | sma->sem_perm.uid, |
| 1342 | sma = sem_lock(i); | 1344 | sma->sem_perm.gid, |
| 1343 | if(sma) { | 1345 | sma->sem_perm.cuid, |
| 1344 | len += sprintf(buffer + len, "%10d %10d %4o %10lu %5u %5u %5u %5u %10lu %10lu\n", | 1346 | sma->sem_perm.cgid, |
| 1345 | sma->sem_perm.key, | 1347 | sma->sem_otime, |
| 1346 | sem_buildid(i,sma->sem_perm.seq), | 1348 | sma->sem_ctime); |
| 1347 | sma->sem_perm.mode, | ||
| 1348 | sma->sem_nsems, | ||
| 1349 | sma->sem_perm.uid, | ||
| 1350 | sma->sem_perm.gid, | ||
| 1351 | sma->sem_perm.cuid, | ||
| 1352 | sma->sem_perm.cgid, | ||
| 1353 | sma->sem_otime, | ||
| 1354 | sma->sem_ctime); | ||
| 1355 | sem_unlock(sma); | ||
| 1356 | |||
| 1357 | pos += len; | ||
| 1358 | if(pos < offset) { | ||
| 1359 | len = 0; | ||
| 1360 | begin = pos; | ||
| 1361 | } | ||
| 1362 | if(pos > offset + length) | ||
| 1363 | goto done; | ||
| 1364 | } | ||
| 1365 | } | ||
| 1366 | *eof = 1; | ||
| 1367 | done: | ||
| 1368 | up(&sem_ids.sem); | ||
| 1369 | *start = buffer + (offset - begin); | ||
| 1370 | len -= (offset - begin); | ||
| 1371 | if(len > length) | ||
| 1372 | len = length; | ||
| 1373 | if(len < 0) | ||
| 1374 | len = 0; | ||
| 1375 | return len; | ||
| 1376 | } | 1349 | } |
| 1377 | #endif | 1350 | #endif |
| @@ -23,12 +23,12 @@ | |||
| 23 | #include <linux/init.h> | 23 | #include <linux/init.h> |
| 24 | #include <linux/file.h> | 24 | #include <linux/file.h> |
| 25 | #include <linux/mman.h> | 25 | #include <linux/mman.h> |
| 26 | #include <linux/proc_fs.h> | ||
| 27 | #include <linux/shmem_fs.h> | 26 | #include <linux/shmem_fs.h> |
| 28 | #include <linux/security.h> | 27 | #include <linux/security.h> |
| 29 | #include <linux/syscalls.h> | 28 | #include <linux/syscalls.h> |
| 30 | #include <linux/audit.h> | 29 | #include <linux/audit.h> |
| 31 | #include <linux/ptrace.h> | 30 | #include <linux/ptrace.h> |
| 31 | #include <linux/seq_file.h> | ||
| 32 | 32 | ||
| 33 | #include <asm/uaccess.h> | 33 | #include <asm/uaccess.h> |
| 34 | 34 | ||
| @@ -51,7 +51,7 @@ static int newseg (key_t key, int shmflg, size_t size); | |||
| 51 | static void shm_open (struct vm_area_struct *shmd); | 51 | static void shm_open (struct vm_area_struct *shmd); |
| 52 | static void shm_close (struct vm_area_struct *shmd); | 52 | static void shm_close (struct vm_area_struct *shmd); |
| 53 | #ifdef CONFIG_PROC_FS | 53 | #ifdef CONFIG_PROC_FS |
| 54 | static int sysvipc_shm_read_proc(char *buffer, char **start, off_t offset, int length, int *eof, void *data); | 54 | static int sysvipc_shm_proc_show(struct seq_file *s, void *it); |
| 55 | #endif | 55 | #endif |
| 56 | 56 | ||
| 57 | size_t shm_ctlmax = SHMMAX; | 57 | size_t shm_ctlmax = SHMMAX; |
| @@ -63,9 +63,10 @@ static int shm_tot; /* total number of shared memory pages */ | |||
| 63 | void __init shm_init (void) | 63 | void __init shm_init (void) |
| 64 | { | 64 | { |
| 65 | ipc_init_ids(&shm_ids, 1); | 65 | ipc_init_ids(&shm_ids, 1); |
| 66 | #ifdef CONFIG_PROC_FS | 66 | ipc_init_proc_interface("sysvipc/shm", |
| 67 | create_proc_read_entry("sysvipc/shm", 0, NULL, sysvipc_shm_read_proc, NULL); | 67 | " key shmid perms size cpid lpid nattch uid gid cuid cgid atime dtime ctime\n", |
| 68 | #endif | 68 | &shm_ids, |
| 69 | sysvipc_shm_proc_show); | ||
| 69 | } | 70 | } |
| 70 | 71 | ||
| 71 | static inline int shm_checkid(struct shmid_kernel *s, int id) | 72 | static inline int shm_checkid(struct shmid_kernel *s, int id) |
| @@ -869,63 +870,32 @@ asmlinkage long sys_shmdt(char __user *shmaddr) | |||
| 869 | } | 870 | } |
| 870 | 871 | ||
| 871 | #ifdef CONFIG_PROC_FS | 872 | #ifdef CONFIG_PROC_FS |
| 872 | static int sysvipc_shm_read_proc(char *buffer, char **start, off_t offset, int length, int *eof, void *data) | 873 | static int sysvipc_shm_proc_show(struct seq_file *s, void *it) |
| 873 | { | 874 | { |
| 874 | off_t pos = 0; | 875 | struct shmid_kernel *shp = it; |
| 875 | off_t begin = 0; | 876 | char *format; |
| 876 | int i, len = 0; | ||
| 877 | |||
| 878 | down(&shm_ids.sem); | ||
| 879 | len += sprintf(buffer, " key shmid perms size cpid lpid nattch uid gid cuid cgid atime dtime ctime\n"); | ||
| 880 | 877 | ||
| 881 | for(i = 0; i <= shm_ids.max_id; i++) { | ||
| 882 | struct shmid_kernel* shp; | ||
| 883 | |||
| 884 | shp = shm_lock(i); | ||
| 885 | if(shp!=NULL) { | ||
| 886 | #define SMALL_STRING "%10d %10d %4o %10u %5u %5u %5d %5u %5u %5u %5u %10lu %10lu %10lu\n" | 878 | #define SMALL_STRING "%10d %10d %4o %10u %5u %5u %5d %5u %5u %5u %5u %10lu %10lu %10lu\n" |
| 887 | #define BIG_STRING "%10d %10d %4o %21u %5u %5u %5d %5u %5u %5u %5u %10lu %10lu %10lu\n" | 879 | #define BIG_STRING "%10d %10d %4o %21u %5u %5u %5d %5u %5u %5u %5u %10lu %10lu %10lu\n" |
| 888 | char *format; | ||
| 889 | 880 | ||
| 890 | if (sizeof(size_t) <= sizeof(int)) | 881 | if (sizeof(size_t) <= sizeof(int)) |
| 891 | format = SMALL_STRING; | 882 | format = SMALL_STRING; |
| 892 | else | 883 | else |
| 893 | format = BIG_STRING; | 884 | format = BIG_STRING; |
| 894 | len += sprintf(buffer + len, format, | 885 | return seq_printf(s, format, |
| 895 | shp->shm_perm.key, | 886 | shp->shm_perm.key, |
| 896 | shm_buildid(i, shp->shm_perm.seq), | 887 | shp->id, |
| 897 | shp->shm_flags, | 888 | shp->shm_flags, |
| 898 | shp->shm_segsz, | 889 | shp->shm_segsz, |
| 899 | shp->shm_cprid, | 890 | shp->shm_cprid, |
| 900 | shp->shm_lprid, | 891 | shp->shm_lprid, |
| 901 | is_file_hugepages(shp->shm_file) ? (file_count(shp->shm_file) - 1) : shp->shm_nattch, | 892 | is_file_hugepages(shp->shm_file) ? (file_count(shp->shm_file) - 1) : shp->shm_nattch, |
| 902 | shp->shm_perm.uid, | 893 | shp->shm_perm.uid, |
| 903 | shp->shm_perm.gid, | 894 | shp->shm_perm.gid, |
| 904 | shp->shm_perm.cuid, | 895 | shp->shm_perm.cuid, |
| 905 | shp->shm_perm.cgid, | 896 | shp->shm_perm.cgid, |
| 906 | shp->shm_atim, | 897 | shp->shm_atim, |
| 907 | shp->shm_dtim, | 898 | shp->shm_dtim, |
| 908 | shp->shm_ctim); | 899 | shp->shm_ctim); |
| 909 | shm_unlock(shp); | ||
| 910 | |||
| 911 | pos += len; | ||
| 912 | if(pos < offset) { | ||
| 913 | len = 0; | ||
| 914 | begin = pos; | ||
| 915 | } | ||
| 916 | if(pos > offset + length) | ||
| 917 | goto done; | ||
| 918 | } | ||
| 919 | } | ||
| 920 | *eof = 1; | ||
| 921 | done: | ||
| 922 | up(&shm_ids.sem); | ||
| 923 | *start = buffer + (offset - begin); | ||
| 924 | len -= (offset - begin); | ||
| 925 | if(len > length) | ||
| 926 | len = length; | ||
| 927 | if(len < 0) | ||
| 928 | len = 0; | ||
| 929 | return len; | ||
| 930 | } | 900 | } |
| 931 | #endif | 901 | #endif |
diff --git a/ipc/util.c b/ipc/util.c index e00c35f7b2b8..10e836d0d89e 100644 --- a/ipc/util.c +++ b/ipc/util.c | |||
| @@ -24,11 +24,20 @@ | |||
| 24 | #include <linux/security.h> | 24 | #include <linux/security.h> |
| 25 | #include <linux/rcupdate.h> | 25 | #include <linux/rcupdate.h> |
| 26 | #include <linux/workqueue.h> | 26 | #include <linux/workqueue.h> |
| 27 | #include <linux/seq_file.h> | ||
| 28 | #include <linux/proc_fs.h> | ||
| 27 | 29 | ||
| 28 | #include <asm/unistd.h> | 30 | #include <asm/unistd.h> |
| 29 | 31 | ||
| 30 | #include "util.h" | 32 | #include "util.h" |
| 31 | 33 | ||
| 34 | struct ipc_proc_iface { | ||
| 35 | const char *path; | ||
| 36 | const char *header; | ||
| 37 | struct ipc_ids *ids; | ||
| 38 | int (*show)(struct seq_file *, void *); | ||
| 39 | }; | ||
| 40 | |||
| 32 | /** | 41 | /** |
| 33 | * ipc_init - initialise IPC subsystem | 42 | * ipc_init - initialise IPC subsystem |
| 34 | * | 43 | * |
| @@ -86,6 +95,43 @@ void __init ipc_init_ids(struct ipc_ids* ids, int size) | |||
| 86 | ids->entries->p[i] = NULL; | 95 | ids->entries->p[i] = NULL; |
| 87 | } | 96 | } |
| 88 | 97 | ||
| 98 | #ifdef CONFIG_PROC_FS | ||
| 99 | static struct file_operations sysvipc_proc_fops; | ||
| 100 | /** | ||
| 101 | * ipc_init_proc_interface - Create a proc interface for sysipc types | ||
| 102 | * using a seq_file interface. | ||
| 103 | * @path: Path in procfs | ||
| 104 | * @header: Banner to be printed at the beginning of the file. | ||
| 105 | * @ids: ipc id table to iterate. | ||
| 106 | * @show: show routine. | ||
| 107 | */ | ||
| 108 | void __init ipc_init_proc_interface(const char *path, const char *header, | ||
| 109 | struct ipc_ids *ids, | ||
| 110 | int (*show)(struct seq_file *, void *)) | ||
| 111 | { | ||
| 112 | struct proc_dir_entry *pde; | ||
| 113 | struct ipc_proc_iface *iface; | ||
| 114 | |||
| 115 | iface = kmalloc(sizeof(*iface), GFP_KERNEL); | ||
| 116 | if (!iface) | ||
| 117 | return; | ||
| 118 | iface->path = path; | ||
| 119 | iface->header = header; | ||
| 120 | iface->ids = ids; | ||
| 121 | iface->show = show; | ||
| 122 | |||
| 123 | pde = create_proc_entry(path, | ||
| 124 | S_IRUGO, /* world readable */ | ||
| 125 | NULL /* parent dir */); | ||
| 126 | if (pde) { | ||
| 127 | pde->data = iface; | ||
| 128 | pde->proc_fops = &sysvipc_proc_fops; | ||
| 129 | } else { | ||
| 130 | kfree(iface); | ||
| 131 | } | ||
| 132 | } | ||
| 133 | #endif | ||
| 134 | |||
| 89 | /** | 135 | /** |
| 90 | * ipc_findkey - find a key in an ipc identifier set | 136 | * ipc_findkey - find a key in an ipc identifier set |
| 91 | * @ids: Identifier set | 137 | * @ids: Identifier set |
| @@ -578,3 +624,113 @@ int ipc_parse_version (int *cmd) | |||
| 578 | } | 624 | } |
| 579 | 625 | ||
| 580 | #endif /* __ARCH_WANT_IPC_PARSE_VERSION */ | 626 | #endif /* __ARCH_WANT_IPC_PARSE_VERSION */ |
| 627 | |||
| 628 | #ifdef CONFIG_PROC_FS | ||
| 629 | static void *sysvipc_proc_next(struct seq_file *s, void *it, loff_t *pos) | ||
| 630 | { | ||
| 631 | struct ipc_proc_iface *iface = s->private; | ||
| 632 | struct kern_ipc_perm *ipc = it; | ||
| 633 | loff_t p; | ||
| 634 | |||
| 635 | /* If we had an ipc id locked before, unlock it */ | ||
| 636 | if (ipc && ipc != SEQ_START_TOKEN) | ||
| 637 | ipc_unlock(ipc); | ||
| 638 | |||
| 639 | /* | ||
| 640 | * p = *pos - 1 (because id 0 starts at position 1) | ||
| 641 | * + 1 (because we increment the position by one) | ||
| 642 | */ | ||
| 643 | for (p = *pos; p <= iface->ids->max_id; p++) { | ||
| 644 | if ((ipc = ipc_lock(iface->ids, p)) != NULL) { | ||
| 645 | *pos = p + 1; | ||
| 646 | return ipc; | ||
| 647 | } | ||
| 648 | } | ||
| 649 | |||
| 650 | /* Out of range - return NULL to terminate iteration */ | ||
| 651 | return NULL; | ||
| 652 | } | ||
| 653 | |||
| 654 | /* | ||
| 655 | * File positions: pos 0 -> header, pos n -> ipc id + 1. | ||
| 656 | * SeqFile iterator: iterator value locked shp or SEQ_TOKEN_START. | ||
| 657 | */ | ||
| 658 | static void *sysvipc_proc_start(struct seq_file *s, loff_t *pos) | ||
| 659 | { | ||
| 660 | struct ipc_proc_iface *iface = s->private; | ||
| 661 | struct kern_ipc_perm *ipc; | ||
| 662 | loff_t p; | ||
| 663 | |||
| 664 | /* | ||
| 665 | * Take the lock - this will be released by the corresponding | ||
| 666 | * call to stop(). | ||
| 667 | */ | ||
| 668 | down(&iface->ids->sem); | ||
| 669 | |||
| 670 | /* pos < 0 is invalid */ | ||
| 671 | if (*pos < 0) | ||
| 672 | return NULL; | ||
| 673 | |||
| 674 | /* pos == 0 means header */ | ||
| 675 | if (*pos == 0) | ||
| 676 | return SEQ_START_TOKEN; | ||
| 677 | |||
| 678 | /* Find the (pos-1)th ipc */ | ||
| 679 | for (p = *pos - 1; p <= iface->ids->max_id; p++) { | ||
| 680 | if ((ipc = ipc_lock(iface->ids, p)) != NULL) { | ||
| 681 | *pos = p + 1; | ||
| 682 | return ipc; | ||
| 683 | } | ||
| 684 | } | ||
| 685 | return NULL; | ||
| 686 | } | ||
| 687 | |||
| 688 | static void sysvipc_proc_stop(struct seq_file *s, void *it) | ||
| 689 | { | ||
| 690 | struct kern_ipc_perm *ipc = it; | ||
| 691 | struct ipc_proc_iface *iface = s->private; | ||
| 692 | |||
| 693 | /* If we had a locked segment, release it */ | ||
| 694 | if (ipc && ipc != SEQ_START_TOKEN) | ||
| 695 | ipc_unlock(ipc); | ||
| 696 | |||
| 697 | /* Release the lock we took in start() */ | ||
| 698 | up(&iface->ids->sem); | ||
| 699 | } | ||
| 700 | |||
| 701 | static int sysvipc_proc_show(struct seq_file *s, void *it) | ||
| 702 | { | ||
| 703 | struct ipc_proc_iface *iface = s->private; | ||
| 704 | |||
| 705 | if (it == SEQ_START_TOKEN) | ||
| 706 | return seq_puts(s, iface->header); | ||
| 707 | |||
| 708 | return iface->show(s, it); | ||
| 709 | } | ||
| 710 | |||
| 711 | static struct seq_operations sysvipc_proc_seqops = { | ||
| 712 | .start = sysvipc_proc_start, | ||
| 713 | .stop = sysvipc_proc_stop, | ||
| 714 | .next = sysvipc_proc_next, | ||
| 715 | .show = sysvipc_proc_show, | ||
| 716 | }; | ||
| 717 | |||
| 718 | static int sysvipc_proc_open(struct inode *inode, struct file *file) { | ||
| 719 | int ret; | ||
| 720 | struct seq_file *seq; | ||
| 721 | |||
| 722 | ret = seq_open(file, &sysvipc_proc_seqops); | ||
| 723 | if (!ret) { | ||
| 724 | seq = file->private_data; | ||
| 725 | seq->private = PDE(inode)->data; | ||
| 726 | } | ||
| 727 | return ret; | ||
| 728 | } | ||
| 729 | |||
| 730 | static struct file_operations sysvipc_proc_fops = { | ||
| 731 | .open = sysvipc_proc_open, | ||
| 732 | .read = seq_read, | ||
| 733 | .llseek = seq_lseek, | ||
| 734 | .release = seq_release, | ||
| 735 | }; | ||
| 736 | #endif /* CONFIG_PROC_FS */ | ||
diff --git a/ipc/util.h b/ipc/util.h index 44348ca5a707..fc9a28be0797 100644 --- a/ipc/util.h +++ b/ipc/util.h | |||
| @@ -30,7 +30,15 @@ struct ipc_ids { | |||
| 30 | struct ipc_id_ary* entries; | 30 | struct ipc_id_ary* entries; |
| 31 | }; | 31 | }; |
| 32 | 32 | ||
| 33 | struct seq_file; | ||
| 33 | void __init ipc_init_ids(struct ipc_ids* ids, int size); | 34 | void __init ipc_init_ids(struct ipc_ids* ids, int size); |
| 35 | #ifdef CONFIG_PROC_FS | ||
| 36 | void __init ipc_init_proc_interface(const char *path, const char *header, | ||
| 37 | struct ipc_ids *ids, | ||
| 38 | int (*show)(struct seq_file *, void *)); | ||
| 39 | #else | ||
| 40 | #define ipc_init_proc_interface(path, header, ids, show) do {} while (0) | ||
| 41 | #endif | ||
| 34 | 42 | ||
| 35 | /* must be called with ids->sem acquired.*/ | 43 | /* must be called with ids->sem acquired.*/ |
| 36 | int ipc_findkey(struct ipc_ids* ids, key_t key); | 44 | int ipc_findkey(struct ipc_ids* ids, key_t key); |
