util.c 17 KB

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