util.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. /*
  2. * linux/ipc/util.c
  3. * Copyright (C) 1992 Krishna Balasubramanian
  4. *
  5. * Sep 1997 - Call suser() last after "normal" permission checks so we
  6. * get BSD style process accounting right.
  7. * Occurs in several places in the IPC code.
  8. * Chris Evans, <chris@ferret.lmh.ox.ac.uk>
  9. * Nov 1999 - ipc helper functions, unified SMP locking
  10. * Manfred Spraul <manfreds@colorfullife.com>
  11. * Oct 2002 - One lock per IPC id. RCU ipc_free for lock-free grow_ary().
  12. * Mingming Cao <cmm@us.ibm.com>
  13. */
  14. #include <linux/config.h>
  15. #include <linux/mm.h>
  16. #include <linux/shm.h>
  17. #include <linux/init.h>
  18. #include <linux/msg.h>
  19. #include <linux/smp_lock.h>
  20. #include <linux/vmalloc.h>
  21. #include <linux/slab.h>
  22. #include <linux/highuid.h>
  23. #include <linux/security.h>
  24. #include <linux/rcupdate.h>
  25. #include <linux/workqueue.h>
  26. #include <linux/seq_file.h>
  27. #include <linux/proc_fs.h>
  28. #include <asm/unistd.h>
  29. #include "util.h"
  30. struct ipc_proc_iface {
  31. const char *path;
  32. const char *header;
  33. struct ipc_ids *ids;
  34. int (*show)(struct seq_file *, void *);
  35. };
  36. /**
  37. * ipc_init - initialise IPC subsystem
  38. *
  39. * The various system5 IPC resources (semaphores, messages and shared
  40. * memory are initialised
  41. */
  42. static int __init ipc_init(void)
  43. {
  44. sem_init();
  45. msg_init();
  46. shm_init();
  47. return 0;
  48. }
  49. __initcall(ipc_init);
  50. /**
  51. * ipc_init_ids - initialise IPC identifiers
  52. * @ids: Identifier set
  53. * @size: Number of identifiers
  54. *
  55. * Given a size for the ipc identifier range (limited below IPCMNI)
  56. * set up the sequence range to use then allocate and initialise the
  57. * array itself.
  58. */
  59. void __init ipc_init_ids(struct ipc_ids* ids, int size)
  60. {
  61. int i;
  62. sema_init(&ids->sem,1);
  63. if(size > IPCMNI)
  64. size = IPCMNI;
  65. ids->in_use = 0;
  66. ids->max_id = -1;
  67. ids->seq = 0;
  68. {
  69. int seq_limit = INT_MAX/SEQ_MULTIPLIER;
  70. if(seq_limit > USHRT_MAX)
  71. ids->seq_max = USHRT_MAX;
  72. else
  73. ids->seq_max = seq_limit;
  74. }
  75. ids->entries = ipc_rcu_alloc(sizeof(struct kern_ipc_perm *)*size +
  76. sizeof(struct ipc_id_ary));
  77. if(ids->entries == NULL) {
  78. printk(KERN_ERR "ipc_init_ids() failed, ipc service disabled.\n");
  79. size = 0;
  80. ids->entries = &ids->nullentry;
  81. }
  82. ids->entries->size = size;
  83. for(i=0;i<size;i++)
  84. ids->entries->p[i] = NULL;
  85. }
  86. #ifdef CONFIG_PROC_FS
  87. static struct file_operations sysvipc_proc_fops;
  88. /**
  89. * ipc_init_proc_interface - Create a proc interface for sysipc types
  90. * using a seq_file interface.
  91. * @path: Path in procfs
  92. * @header: Banner to be printed at the beginning of the file.
  93. * @ids: ipc id table to iterate.
  94. * @show: show routine.
  95. */
  96. void __init ipc_init_proc_interface(const char *path, const char *header,
  97. struct ipc_ids *ids,
  98. int (*show)(struct seq_file *, void *))
  99. {
  100. struct proc_dir_entry *pde;
  101. struct ipc_proc_iface *iface;
  102. iface = kmalloc(sizeof(*iface), GFP_KERNEL);
  103. if (!iface)
  104. return;
  105. iface->path = path;
  106. iface->header = header;
  107. iface->ids = ids;
  108. iface->show = show;
  109. pde = create_proc_entry(path,
  110. S_IRUGO, /* world readable */
  111. NULL /* parent dir */);
  112. if (pde) {
  113. pde->data = iface;
  114. pde->proc_fops = &sysvipc_proc_fops;
  115. } else {
  116. kfree(iface);
  117. }
  118. }
  119. #endif
  120. /**
  121. * ipc_findkey - find a key in an ipc identifier set
  122. * @ids: Identifier set
  123. * @key: The key to find
  124. *
  125. * Requires ipc_ids.sem locked.
  126. * Returns the identifier if found or -1 if not.
  127. */
  128. int ipc_findkey(struct ipc_ids* ids, key_t key)
  129. {
  130. int id;
  131. struct kern_ipc_perm* p;
  132. int max_id = ids->max_id;
  133. /*
  134. * rcu_dereference() is not needed here
  135. * since ipc_ids.sem is held
  136. */
  137. for (id = 0; id <= max_id; id++) {
  138. p = ids->entries->p[id];
  139. if(p==NULL)
  140. continue;
  141. if (key == p->key)
  142. return id;
  143. }
  144. return -1;
  145. }
  146. /*
  147. * Requires ipc_ids.sem locked
  148. */
  149. static int grow_ary(struct ipc_ids* ids, int newsize)
  150. {
  151. struct ipc_id_ary* new;
  152. struct ipc_id_ary* old;
  153. int i;
  154. int size = ids->entries->size;
  155. if(newsize > IPCMNI)
  156. newsize = IPCMNI;
  157. if(newsize <= size)
  158. return newsize;
  159. new = ipc_rcu_alloc(sizeof(struct kern_ipc_perm *)*newsize +
  160. sizeof(struct ipc_id_ary));
  161. if(new == NULL)
  162. return size;
  163. new->size = newsize;
  164. memcpy(new->p, ids->entries->p, sizeof(struct kern_ipc_perm *)*size +
  165. sizeof(struct ipc_id_ary));
  166. for(i=size;i<newsize;i++) {
  167. new->p[i] = NULL;
  168. }
  169. old = ids->entries;
  170. /*
  171. * Use rcu_assign_pointer() to make sure the memcpyed contents
  172. * of the new array are visible before the new array becomes visible.
  173. */
  174. rcu_assign_pointer(ids->entries, new);
  175. ipc_rcu_putref(old);
  176. return newsize;
  177. }
  178. /**
  179. * ipc_addid - add an IPC identifier
  180. * @ids: IPC identifier set
  181. * @new: new IPC permission set
  182. * @size: new size limit for the id array
  183. *
  184. * Add an entry 'new' to the IPC arrays. The permissions object is
  185. * initialised and the first free entry is set up and the id assigned
  186. * is returned. The list is returned in a locked state on success.
  187. * On failure the list is not locked and -1 is returned.
  188. *
  189. * Called with ipc_ids.sem held.
  190. */
  191. int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size)
  192. {
  193. int id;
  194. size = grow_ary(ids,size);
  195. /*
  196. * rcu_dereference()() is not needed here since
  197. * ipc_ids.sem is held
  198. */
  199. for (id = 0; id < size; id++) {
  200. if(ids->entries->p[id] == NULL)
  201. goto found;
  202. }
  203. return -1;
  204. found:
  205. ids->in_use++;
  206. if (id > ids->max_id)
  207. ids->max_id = id;
  208. new->cuid = new->uid = current->euid;
  209. new->gid = new->cgid = current->egid;
  210. new->seq = ids->seq++;
  211. if(ids->seq > ids->seq_max)
  212. ids->seq = 0;
  213. spin_lock_init(&new->lock);
  214. new->deleted = 0;
  215. rcu_read_lock();
  216. spin_lock(&new->lock);
  217. ids->entries->p[id] = new;
  218. return id;
  219. }
  220. /**
  221. * ipc_rmid - remove an IPC identifier
  222. * @ids: identifier set
  223. * @id: Identifier to remove
  224. *
  225. * The identifier must be valid, and in use. The kernel will panic if
  226. * fed an invalid identifier. The entry is removed and internal
  227. * variables recomputed. The object associated with the identifier
  228. * is returned.
  229. * ipc_ids.sem and the spinlock for this ID is hold before this function
  230. * is called, and remain locked on the exit.
  231. */
  232. struct kern_ipc_perm* ipc_rmid(struct ipc_ids* ids, int id)
  233. {
  234. struct kern_ipc_perm* p;
  235. int lid = id % SEQ_MULTIPLIER;
  236. if(lid >= ids->entries->size)
  237. BUG();
  238. /*
  239. * do not need a rcu_dereference()() here to force ordering
  240. * on Alpha, since the ipc_ids.sem is held.
  241. */
  242. p = ids->entries->p[lid];
  243. ids->entries->p[lid] = NULL;
  244. if(p==NULL)
  245. BUG();
  246. ids->in_use--;
  247. if (lid == ids->max_id) {
  248. do {
  249. lid--;
  250. if(lid == -1)
  251. break;
  252. } while (ids->entries->p[lid] == NULL);
  253. ids->max_id = lid;
  254. }
  255. p->deleted = 1;
  256. return p;
  257. }
  258. /**
  259. * ipc_alloc - allocate ipc space
  260. * @size: size desired
  261. *
  262. * Allocate memory from the appropriate pools and return a pointer to it.
  263. * NULL is returned if the allocation fails
  264. */
  265. void* ipc_alloc(int size)
  266. {
  267. void* out;
  268. if(size > PAGE_SIZE)
  269. out = vmalloc(size);
  270. else
  271. out = kmalloc(size, GFP_KERNEL);
  272. return out;
  273. }
  274. /**
  275. * ipc_free - free ipc space
  276. * @ptr: pointer returned by ipc_alloc
  277. * @size: size of block
  278. *
  279. * Free a block created with ipc_alloc. The caller must know the size
  280. * used in the allocation call.
  281. */
  282. void ipc_free(void* ptr, int size)
  283. {
  284. if(size > PAGE_SIZE)
  285. vfree(ptr);
  286. else
  287. kfree(ptr);
  288. }
  289. /*
  290. * rcu allocations:
  291. * There are three headers that are prepended to the actual allocation:
  292. * - during use: ipc_rcu_hdr.
  293. * - during the rcu grace period: ipc_rcu_grace.
  294. * - [only if vmalloc]: ipc_rcu_sched.
  295. * Their lifetime doesn't overlap, thus the headers share the same memory.
  296. * Unlike a normal union, they are right-aligned, thus some container_of
  297. * forward/backward casting is necessary:
  298. */
  299. struct ipc_rcu_hdr
  300. {
  301. int refcount;
  302. int is_vmalloc;
  303. void *data[0];
  304. };
  305. struct ipc_rcu_grace
  306. {
  307. struct rcu_head rcu;
  308. /* "void *" makes sure alignment of following data is sane. */
  309. void *data[0];
  310. };
  311. struct ipc_rcu_sched
  312. {
  313. struct work_struct work;
  314. /* "void *" makes sure alignment of following data is sane. */
  315. void *data[0];
  316. };
  317. #define HDRLEN_KMALLOC (sizeof(struct ipc_rcu_grace) > sizeof(struct ipc_rcu_hdr) ? \
  318. sizeof(struct ipc_rcu_grace) : sizeof(struct ipc_rcu_hdr))
  319. #define HDRLEN_VMALLOC (sizeof(struct ipc_rcu_sched) > HDRLEN_KMALLOC ? \
  320. sizeof(struct ipc_rcu_sched) : HDRLEN_KMALLOC)
  321. static inline int rcu_use_vmalloc(int size)
  322. {
  323. /* Too big for a single page? */
  324. if (HDRLEN_KMALLOC + size > PAGE_SIZE)
  325. return 1;
  326. return 0;
  327. }
  328. /**
  329. * ipc_rcu_alloc - allocate ipc and rcu space
  330. * @size: size desired
  331. *
  332. * Allocate memory for the rcu header structure + the object.
  333. * Returns the pointer to the object.
  334. * NULL is returned if the allocation fails.
  335. */
  336. void* ipc_rcu_alloc(int size)
  337. {
  338. void* out;
  339. /*
  340. * We prepend the allocation with the rcu struct, and
  341. * workqueue if necessary (for vmalloc).
  342. */
  343. if (rcu_use_vmalloc(size)) {
  344. out = vmalloc(HDRLEN_VMALLOC + size);
  345. if (out) {
  346. out += HDRLEN_VMALLOC;
  347. container_of(out, struct ipc_rcu_hdr, data)->is_vmalloc = 1;
  348. container_of(out, struct ipc_rcu_hdr, data)->refcount = 1;
  349. }
  350. } else {
  351. out = kmalloc(HDRLEN_KMALLOC + size, GFP_KERNEL);
  352. if (out) {
  353. out += HDRLEN_KMALLOC;
  354. container_of(out, struct ipc_rcu_hdr, data)->is_vmalloc = 0;
  355. container_of(out, struct ipc_rcu_hdr, data)->refcount = 1;
  356. }
  357. }
  358. return out;
  359. }
  360. void ipc_rcu_getref(void *ptr)
  361. {
  362. container_of(ptr, struct ipc_rcu_hdr, data)->refcount++;
  363. }
  364. /**
  365. * ipc_schedule_free - free ipc + rcu space
  366. * @head: RCU callback structure for queued work
  367. *
  368. * Since RCU callback function is called in bh,
  369. * we need to defer the vfree to schedule_work
  370. */
  371. static void ipc_schedule_free(struct rcu_head *head)
  372. {
  373. struct ipc_rcu_grace *grace =
  374. container_of(head, struct ipc_rcu_grace, rcu);
  375. struct ipc_rcu_sched *sched =
  376. container_of(&(grace->data[0]), struct ipc_rcu_sched, data[0]);
  377. INIT_WORK(&sched->work, vfree, sched);
  378. schedule_work(&sched->work);
  379. }
  380. /**
  381. * ipc_immediate_free - free ipc + rcu space
  382. * @head: RCU callback structure that contains pointer to be freed
  383. *
  384. * Free from the RCU callback context
  385. */
  386. static void ipc_immediate_free(struct rcu_head *head)
  387. {
  388. struct ipc_rcu_grace *free =
  389. container_of(head, struct ipc_rcu_grace, rcu);
  390. kfree(free);
  391. }
  392. void ipc_rcu_putref(void *ptr)
  393. {
  394. if (--container_of(ptr, struct ipc_rcu_hdr, data)->refcount > 0)
  395. return;
  396. if (container_of(ptr, struct ipc_rcu_hdr, data)->is_vmalloc) {
  397. call_rcu(&container_of(ptr, struct ipc_rcu_grace, data)->rcu,
  398. ipc_schedule_free);
  399. } else {
  400. call_rcu(&container_of(ptr, struct ipc_rcu_grace, data)->rcu,
  401. ipc_immediate_free);
  402. }
  403. }
  404. /**
  405. * ipcperms - check IPC permissions
  406. * @ipcp: IPC permission set
  407. * @flag: desired permission set.
  408. *
  409. * Check user, group, other permissions for access
  410. * to ipc resources. return 0 if allowed
  411. */
  412. int ipcperms (struct kern_ipc_perm *ipcp, short flag)
  413. { /* flag will most probably be 0 or S_...UGO from <linux/stat.h> */
  414. int requested_mode, granted_mode;
  415. requested_mode = (flag >> 6) | (flag >> 3) | flag;
  416. granted_mode = ipcp->mode;
  417. if (current->euid == ipcp->cuid || current->euid == ipcp->uid)
  418. granted_mode >>= 6;
  419. else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
  420. granted_mode >>= 3;
  421. /* is there some bit set in requested_mode but not in granted_mode? */
  422. if ((requested_mode & ~granted_mode & 0007) &&
  423. !capable(CAP_IPC_OWNER))
  424. return -1;
  425. return security_ipc_permission(ipcp, flag);
  426. }
  427. /*
  428. * Functions to convert between the kern_ipc_perm structure and the
  429. * old/new ipc_perm structures
  430. */
  431. /**
  432. * kernel_to_ipc64_perm - convert kernel ipc permissions to user
  433. * @in: kernel permissions
  434. * @out: new style IPC permissions
  435. *
  436. * Turn the kernel object 'in' into a set of permissions descriptions
  437. * for returning to userspace (out).
  438. */
  439. void kernel_to_ipc64_perm (struct kern_ipc_perm *in, struct ipc64_perm *out)
  440. {
  441. out->key = in->key;
  442. out->uid = in->uid;
  443. out->gid = in->gid;
  444. out->cuid = in->cuid;
  445. out->cgid = in->cgid;
  446. out->mode = in->mode;
  447. out->seq = in->seq;
  448. }
  449. /**
  450. * ipc64_perm_to_ipc_perm - convert old ipc permissions to new
  451. * @in: new style IPC permissions
  452. * @out: old style IPC permissions
  453. *
  454. * Turn the new style permissions object in into a compatibility
  455. * object and store it into the 'out' pointer.
  456. */
  457. void ipc64_perm_to_ipc_perm (struct ipc64_perm *in, struct ipc_perm *out)
  458. {
  459. out->key = in->key;
  460. SET_UID(out->uid, in->uid);
  461. SET_GID(out->gid, in->gid);
  462. SET_UID(out->cuid, in->cuid);
  463. SET_GID(out->cgid, in->cgid);
  464. out->mode = in->mode;
  465. out->seq = in->seq;
  466. }
  467. /*
  468. * So far only shm_get_stat() calls ipc_get() via shm_get(), so ipc_get()
  469. * is called with shm_ids.sem locked. Since grow_ary() is also called with
  470. * shm_ids.sem down(for Shared Memory), there is no need to add read
  471. * barriers here to gurantee the writes in grow_ary() are seen in order
  472. * here (for Alpha).
  473. *
  474. * However ipc_get() itself does not necessary require ipc_ids.sem down. So
  475. * if in the future ipc_get() is used by other places without ipc_ids.sem
  476. * down, then ipc_get() needs read memery barriers as ipc_lock() does.
  477. */
  478. struct kern_ipc_perm* ipc_get(struct ipc_ids* ids, int id)
  479. {
  480. struct kern_ipc_perm* out;
  481. int lid = id % SEQ_MULTIPLIER;
  482. if(lid >= ids->entries->size)
  483. return NULL;
  484. out = ids->entries->p[lid];
  485. return out;
  486. }
  487. struct kern_ipc_perm* ipc_lock(struct ipc_ids* ids, int id)
  488. {
  489. struct kern_ipc_perm* out;
  490. int lid = id % SEQ_MULTIPLIER;
  491. struct ipc_id_ary* entries;
  492. rcu_read_lock();
  493. entries = rcu_dereference(ids->entries);
  494. if(lid >= entries->size) {
  495. rcu_read_unlock();
  496. return NULL;
  497. }
  498. out = entries->p[lid];
  499. if(out == NULL) {
  500. rcu_read_unlock();
  501. return NULL;
  502. }
  503. spin_lock(&out->lock);
  504. /* ipc_rmid() may have already freed the ID while ipc_lock
  505. * was spinning: here verify that the structure is still valid
  506. */
  507. if (out->deleted) {
  508. spin_unlock(&out->lock);
  509. rcu_read_unlock();
  510. return NULL;
  511. }
  512. return out;
  513. }
  514. void ipc_lock_by_ptr(struct kern_ipc_perm *perm)
  515. {
  516. rcu_read_lock();
  517. spin_lock(&perm->lock);
  518. }
  519. void ipc_unlock(struct kern_ipc_perm* perm)
  520. {
  521. spin_unlock(&perm->lock);
  522. rcu_read_unlock();
  523. }
  524. int ipc_buildid(struct ipc_ids* ids, int id, int seq)
  525. {
  526. return SEQ_MULTIPLIER*seq + id;
  527. }
  528. int ipc_checkid(struct ipc_ids* ids, struct kern_ipc_perm* ipcp, int uid)
  529. {
  530. if(uid/SEQ_MULTIPLIER != ipcp->seq)
  531. return 1;
  532. return 0;
  533. }
  534. #ifdef __ARCH_WANT_IPC_PARSE_VERSION
  535. /**
  536. * ipc_parse_version - IPC call version
  537. * @cmd: pointer to command
  538. *
  539. * Return IPC_64 for new style IPC and IPC_OLD for old style IPC.
  540. * The cmd value is turned from an encoding command and version into
  541. * just the command code.
  542. */
  543. int ipc_parse_version (int *cmd)
  544. {
  545. if (*cmd & IPC_64) {
  546. *cmd ^= IPC_64;
  547. return IPC_64;
  548. } else {
  549. return IPC_OLD;
  550. }
  551. }
  552. #endif /* __ARCH_WANT_IPC_PARSE_VERSION */
  553. #ifdef CONFIG_PROC_FS
  554. static void *sysvipc_proc_next(struct seq_file *s, void *it, loff_t *pos)
  555. {
  556. struct ipc_proc_iface *iface = s->private;
  557. struct kern_ipc_perm *ipc = it;
  558. loff_t p;
  559. /* If we had an ipc id locked before, unlock it */
  560. if (ipc && ipc != SEQ_START_TOKEN)
  561. ipc_unlock(ipc);
  562. /*
  563. * p = *pos - 1 (because id 0 starts at position 1)
  564. * + 1 (because we increment the position by one)
  565. */
  566. for (p = *pos; p <= iface->ids->max_id; p++) {
  567. if ((ipc = ipc_lock(iface->ids, p)) != NULL) {
  568. *pos = p + 1;
  569. return ipc;
  570. }
  571. }
  572. /* Out of range - return NULL to terminate iteration */
  573. return NULL;
  574. }
  575. /*
  576. * File positions: pos 0 -> header, pos n -> ipc id + 1.
  577. * SeqFile iterator: iterator value locked shp or SEQ_TOKEN_START.
  578. */
  579. static void *sysvipc_proc_start(struct seq_file *s, loff_t *pos)
  580. {
  581. struct ipc_proc_iface *iface = s->private;
  582. struct kern_ipc_perm *ipc;
  583. loff_t p;
  584. /*
  585. * Take the lock - this will be released by the corresponding
  586. * call to stop().
  587. */
  588. down(&iface->ids->sem);
  589. /* pos < 0 is invalid */
  590. if (*pos < 0)
  591. return NULL;
  592. /* pos == 0 means header */
  593. if (*pos == 0)
  594. return SEQ_START_TOKEN;
  595. /* Find the (pos-1)th ipc */
  596. for (p = *pos - 1; p <= iface->ids->max_id; p++) {
  597. if ((ipc = ipc_lock(iface->ids, p)) != NULL) {
  598. *pos = p + 1;
  599. return ipc;
  600. }
  601. }
  602. return NULL;
  603. }
  604. static void sysvipc_proc_stop(struct seq_file *s, void *it)
  605. {
  606. struct kern_ipc_perm *ipc = it;
  607. struct ipc_proc_iface *iface = s->private;
  608. /* If we had a locked segment, release it */
  609. if (ipc && ipc != SEQ_START_TOKEN)
  610. ipc_unlock(ipc);
  611. /* Release the lock we took in start() */
  612. up(&iface->ids->sem);
  613. }
  614. static int sysvipc_proc_show(struct seq_file *s, void *it)
  615. {
  616. struct ipc_proc_iface *iface = s->private;
  617. if (it == SEQ_START_TOKEN)
  618. return seq_puts(s, iface->header);
  619. return iface->show(s, it);
  620. }
  621. static struct seq_operations sysvipc_proc_seqops = {
  622. .start = sysvipc_proc_start,
  623. .stop = sysvipc_proc_stop,
  624. .next = sysvipc_proc_next,
  625. .show = sysvipc_proc_show,
  626. };
  627. static int sysvipc_proc_open(struct inode *inode, struct file *file) {
  628. int ret;
  629. struct seq_file *seq;
  630. ret = seq_open(file, &sysvipc_proc_seqops);
  631. if (!ret) {
  632. seq = file->private_data;
  633. seq->private = PDE(inode)->data;
  634. }
  635. return ret;
  636. }
  637. static struct file_operations sysvipc_proc_fops = {
  638. .open = sysvipc_proc_open,
  639. .read = seq_read,
  640. .llseek = seq_lseek,
  641. .release = seq_release,
  642. };
  643. #endif /* CONFIG_PROC_FS */