util.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  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. mutex_init(&ids->mutex);
  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.mutex 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.mutex 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.mutex 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. 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.mutex 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.mutex 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.mutex 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. BUG_ON(lid >= ids->entries->size);
  237. /*
  238. * do not need a rcu_dereference()() here to force ordering
  239. * on Alpha, since the ipc_ids.mutex is held.
  240. */
  241. p = ids->entries->p[lid];
  242. ids->entries->p[lid] = NULL;
  243. BUG_ON(p==NULL);
  244. ids->in_use--;
  245. if (lid == ids->max_id) {
  246. do {
  247. lid--;
  248. if(lid == -1)
  249. break;
  250. } while (ids->entries->p[lid] == NULL);
  251. ids->max_id = lid;
  252. }
  253. p->deleted = 1;
  254. return p;
  255. }
  256. /**
  257. * ipc_alloc - allocate ipc space
  258. * @size: size desired
  259. *
  260. * Allocate memory from the appropriate pools and return a pointer to it.
  261. * NULL is returned if the allocation fails
  262. */
  263. void* ipc_alloc(int size)
  264. {
  265. void* out;
  266. if(size > PAGE_SIZE)
  267. out = vmalloc(size);
  268. else
  269. out = kmalloc(size, GFP_KERNEL);
  270. return out;
  271. }
  272. /**
  273. * ipc_free - free ipc space
  274. * @ptr: pointer returned by ipc_alloc
  275. * @size: size of block
  276. *
  277. * Free a block created with ipc_alloc. The caller must know the size
  278. * used in the allocation call.
  279. */
  280. void ipc_free(void* ptr, int size)
  281. {
  282. if(size > PAGE_SIZE)
  283. vfree(ptr);
  284. else
  285. kfree(ptr);
  286. }
  287. /*
  288. * rcu allocations:
  289. * There are three headers that are prepended to the actual allocation:
  290. * - during use: ipc_rcu_hdr.
  291. * - during the rcu grace period: ipc_rcu_grace.
  292. * - [only if vmalloc]: ipc_rcu_sched.
  293. * Their lifetime doesn't overlap, thus the headers share the same memory.
  294. * Unlike a normal union, they are right-aligned, thus some container_of
  295. * forward/backward casting is necessary:
  296. */
  297. struct ipc_rcu_hdr
  298. {
  299. int refcount;
  300. int is_vmalloc;
  301. void *data[0];
  302. };
  303. struct ipc_rcu_grace
  304. {
  305. struct rcu_head rcu;
  306. /* "void *" makes sure alignment of following data is sane. */
  307. void *data[0];
  308. };
  309. struct ipc_rcu_sched
  310. {
  311. struct work_struct work;
  312. /* "void *" makes sure alignment of following data is sane. */
  313. void *data[0];
  314. };
  315. #define HDRLEN_KMALLOC (sizeof(struct ipc_rcu_grace) > sizeof(struct ipc_rcu_hdr) ? \
  316. sizeof(struct ipc_rcu_grace) : sizeof(struct ipc_rcu_hdr))
  317. #define HDRLEN_VMALLOC (sizeof(struct ipc_rcu_sched) > HDRLEN_KMALLOC ? \
  318. sizeof(struct ipc_rcu_sched) : HDRLEN_KMALLOC)
  319. static inline int rcu_use_vmalloc(int size)
  320. {
  321. /* Too big for a single page? */
  322. if (HDRLEN_KMALLOC + size > PAGE_SIZE)
  323. return 1;
  324. return 0;
  325. }
  326. /**
  327. * ipc_rcu_alloc - allocate ipc and rcu space
  328. * @size: size desired
  329. *
  330. * Allocate memory for the rcu header structure + the object.
  331. * Returns the pointer to the object.
  332. * NULL is returned if the allocation fails.
  333. */
  334. void* ipc_rcu_alloc(int size)
  335. {
  336. void* out;
  337. /*
  338. * We prepend the allocation with the rcu struct, and
  339. * workqueue if necessary (for vmalloc).
  340. */
  341. if (rcu_use_vmalloc(size)) {
  342. out = vmalloc(HDRLEN_VMALLOC + size);
  343. if (out) {
  344. out += HDRLEN_VMALLOC;
  345. container_of(out, struct ipc_rcu_hdr, data)->is_vmalloc = 1;
  346. container_of(out, struct ipc_rcu_hdr, data)->refcount = 1;
  347. }
  348. } else {
  349. out = kmalloc(HDRLEN_KMALLOC + size, GFP_KERNEL);
  350. if (out) {
  351. out += HDRLEN_KMALLOC;
  352. container_of(out, struct ipc_rcu_hdr, data)->is_vmalloc = 0;
  353. container_of(out, struct ipc_rcu_hdr, data)->refcount = 1;
  354. }
  355. }
  356. return out;
  357. }
  358. void ipc_rcu_getref(void *ptr)
  359. {
  360. container_of(ptr, struct ipc_rcu_hdr, data)->refcount++;
  361. }
  362. /**
  363. * ipc_schedule_free - free ipc + rcu space
  364. * @head: RCU callback structure for queued work
  365. *
  366. * Since RCU callback function is called in bh,
  367. * we need to defer the vfree to schedule_work
  368. */
  369. static void ipc_schedule_free(struct rcu_head *head)
  370. {
  371. struct ipc_rcu_grace *grace =
  372. container_of(head, struct ipc_rcu_grace, rcu);
  373. struct ipc_rcu_sched *sched =
  374. container_of(&(grace->data[0]), struct ipc_rcu_sched, data[0]);
  375. INIT_WORK(&sched->work, vfree, sched);
  376. schedule_work(&sched->work);
  377. }
  378. /**
  379. * ipc_immediate_free - free ipc + rcu space
  380. * @head: RCU callback structure that contains pointer to be freed
  381. *
  382. * Free from the RCU callback context
  383. */
  384. static void ipc_immediate_free(struct rcu_head *head)
  385. {
  386. struct ipc_rcu_grace *free =
  387. container_of(head, struct ipc_rcu_grace, rcu);
  388. kfree(free);
  389. }
  390. void ipc_rcu_putref(void *ptr)
  391. {
  392. if (--container_of(ptr, struct ipc_rcu_hdr, data)->refcount > 0)
  393. return;
  394. if (container_of(ptr, struct ipc_rcu_hdr, data)->is_vmalloc) {
  395. call_rcu(&container_of(ptr, struct ipc_rcu_grace, data)->rcu,
  396. ipc_schedule_free);
  397. } else {
  398. call_rcu(&container_of(ptr, struct ipc_rcu_grace, data)->rcu,
  399. ipc_immediate_free);
  400. }
  401. }
  402. /**
  403. * ipcperms - check IPC permissions
  404. * @ipcp: IPC permission set
  405. * @flag: desired permission set.
  406. *
  407. * Check user, group, other permissions for access
  408. * to ipc resources. return 0 if allowed
  409. */
  410. int ipcperms (struct kern_ipc_perm *ipcp, short flag)
  411. { /* flag will most probably be 0 or S_...UGO from <linux/stat.h> */
  412. int requested_mode, granted_mode;
  413. requested_mode = (flag >> 6) | (flag >> 3) | flag;
  414. granted_mode = ipcp->mode;
  415. if (current->euid == ipcp->cuid || current->euid == ipcp->uid)
  416. granted_mode >>= 6;
  417. else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
  418. granted_mode >>= 3;
  419. /* is there some bit set in requested_mode but not in granted_mode? */
  420. if ((requested_mode & ~granted_mode & 0007) &&
  421. !capable(CAP_IPC_OWNER))
  422. return -1;
  423. return security_ipc_permission(ipcp, flag);
  424. }
  425. /*
  426. * Functions to convert between the kern_ipc_perm structure and the
  427. * old/new ipc_perm structures
  428. */
  429. /**
  430. * kernel_to_ipc64_perm - convert kernel ipc permissions to user
  431. * @in: kernel permissions
  432. * @out: new style IPC permissions
  433. *
  434. * Turn the kernel object 'in' into a set of permissions descriptions
  435. * for returning to userspace (out).
  436. */
  437. void kernel_to_ipc64_perm (struct kern_ipc_perm *in, struct ipc64_perm *out)
  438. {
  439. out->key = in->key;
  440. out->uid = in->uid;
  441. out->gid = in->gid;
  442. out->cuid = in->cuid;
  443. out->cgid = in->cgid;
  444. out->mode = in->mode;
  445. out->seq = in->seq;
  446. }
  447. /**
  448. * ipc64_perm_to_ipc_perm - convert old ipc permissions to new
  449. * @in: new style IPC permissions
  450. * @out: old style IPC permissions
  451. *
  452. * Turn the new style permissions object in into a compatibility
  453. * object and store it into the 'out' pointer.
  454. */
  455. void ipc64_perm_to_ipc_perm (struct ipc64_perm *in, struct ipc_perm *out)
  456. {
  457. out->key = in->key;
  458. SET_UID(out->uid, in->uid);
  459. SET_GID(out->gid, in->gid);
  460. SET_UID(out->cuid, in->cuid);
  461. SET_GID(out->cgid, in->cgid);
  462. out->mode = in->mode;
  463. out->seq = in->seq;
  464. }
  465. /*
  466. * So far only shm_get_stat() calls ipc_get() via shm_get(), so ipc_get()
  467. * is called with shm_ids.mutex locked. Since grow_ary() is also called with
  468. * shm_ids.mutex down(for Shared Memory), there is no need to add read
  469. * barriers here to gurantee the writes in grow_ary() are seen in order
  470. * here (for Alpha).
  471. *
  472. * However ipc_get() itself does not necessary require ipc_ids.mutex down. So
  473. * if in the future ipc_get() is used by other places without ipc_ids.mutex
  474. * down, then ipc_get() needs read memery barriers as ipc_lock() does.
  475. */
  476. struct kern_ipc_perm* ipc_get(struct ipc_ids* ids, int id)
  477. {
  478. struct kern_ipc_perm* out;
  479. int lid = id % SEQ_MULTIPLIER;
  480. if(lid >= ids->entries->size)
  481. return NULL;
  482. out = ids->entries->p[lid];
  483. return out;
  484. }
  485. struct kern_ipc_perm* ipc_lock(struct ipc_ids* ids, int id)
  486. {
  487. struct kern_ipc_perm* out;
  488. int lid = id % SEQ_MULTIPLIER;
  489. struct ipc_id_ary* entries;
  490. rcu_read_lock();
  491. entries = rcu_dereference(ids->entries);
  492. if(lid >= entries->size) {
  493. rcu_read_unlock();
  494. return NULL;
  495. }
  496. out = entries->p[lid];
  497. if(out == NULL) {
  498. rcu_read_unlock();
  499. return NULL;
  500. }
  501. spin_lock(&out->lock);
  502. /* ipc_rmid() may have already freed the ID while ipc_lock
  503. * was spinning: here verify that the structure is still valid
  504. */
  505. if (out->deleted) {
  506. spin_unlock(&out->lock);
  507. rcu_read_unlock();
  508. return NULL;
  509. }
  510. return out;
  511. }
  512. void ipc_lock_by_ptr(struct kern_ipc_perm *perm)
  513. {
  514. rcu_read_lock();
  515. spin_lock(&perm->lock);
  516. }
  517. void ipc_unlock(struct kern_ipc_perm* perm)
  518. {
  519. spin_unlock(&perm->lock);
  520. rcu_read_unlock();
  521. }
  522. int ipc_buildid(struct ipc_ids* ids, int id, int seq)
  523. {
  524. return SEQ_MULTIPLIER*seq + id;
  525. }
  526. int ipc_checkid(struct ipc_ids* ids, struct kern_ipc_perm* ipcp, int uid)
  527. {
  528. if(uid/SEQ_MULTIPLIER != ipcp->seq)
  529. return 1;
  530. return 0;
  531. }
  532. #ifdef __ARCH_WANT_IPC_PARSE_VERSION
  533. /**
  534. * ipc_parse_version - IPC call version
  535. * @cmd: pointer to command
  536. *
  537. * Return IPC_64 for new style IPC and IPC_OLD for old style IPC.
  538. * The cmd value is turned from an encoding command and version into
  539. * just the command code.
  540. */
  541. int ipc_parse_version (int *cmd)
  542. {
  543. if (*cmd & IPC_64) {
  544. *cmd ^= IPC_64;
  545. return IPC_64;
  546. } else {
  547. return IPC_OLD;
  548. }
  549. }
  550. #endif /* __ARCH_WANT_IPC_PARSE_VERSION */
  551. #ifdef CONFIG_PROC_FS
  552. static void *sysvipc_proc_next(struct seq_file *s, void *it, loff_t *pos)
  553. {
  554. struct ipc_proc_iface *iface = s->private;
  555. struct kern_ipc_perm *ipc = it;
  556. loff_t p;
  557. /* If we had an ipc id locked before, unlock it */
  558. if (ipc && ipc != SEQ_START_TOKEN)
  559. ipc_unlock(ipc);
  560. /*
  561. * p = *pos - 1 (because id 0 starts at position 1)
  562. * + 1 (because we increment the position by one)
  563. */
  564. for (p = *pos; p <= iface->ids->max_id; p++) {
  565. if ((ipc = ipc_lock(iface->ids, p)) != NULL) {
  566. *pos = p + 1;
  567. return ipc;
  568. }
  569. }
  570. /* Out of range - return NULL to terminate iteration */
  571. return NULL;
  572. }
  573. /*
  574. * File positions: pos 0 -> header, pos n -> ipc id + 1.
  575. * SeqFile iterator: iterator value locked shp or SEQ_TOKEN_START.
  576. */
  577. static void *sysvipc_proc_start(struct seq_file *s, loff_t *pos)
  578. {
  579. struct ipc_proc_iface *iface = s->private;
  580. struct kern_ipc_perm *ipc;
  581. loff_t p;
  582. /*
  583. * Take the lock - this will be released by the corresponding
  584. * call to stop().
  585. */
  586. mutex_lock(&iface->ids->mutex);
  587. /* pos < 0 is invalid */
  588. if (*pos < 0)
  589. return NULL;
  590. /* pos == 0 means header */
  591. if (*pos == 0)
  592. return SEQ_START_TOKEN;
  593. /* Find the (pos-1)th ipc */
  594. for (p = *pos - 1; p <= iface->ids->max_id; p++) {
  595. if ((ipc = ipc_lock(iface->ids, p)) != NULL) {
  596. *pos = p + 1;
  597. return ipc;
  598. }
  599. }
  600. return NULL;
  601. }
  602. static void sysvipc_proc_stop(struct seq_file *s, void *it)
  603. {
  604. struct kern_ipc_perm *ipc = it;
  605. struct ipc_proc_iface *iface = s->private;
  606. /* If we had a locked segment, release it */
  607. if (ipc && ipc != SEQ_START_TOKEN)
  608. ipc_unlock(ipc);
  609. /* Release the lock we took in start() */
  610. mutex_unlock(&iface->ids->mutex);
  611. }
  612. static int sysvipc_proc_show(struct seq_file *s, void *it)
  613. {
  614. struct ipc_proc_iface *iface = s->private;
  615. if (it == SEQ_START_TOKEN)
  616. return seq_puts(s, iface->header);
  617. return iface->show(s, it);
  618. }
  619. static struct seq_operations sysvipc_proc_seqops = {
  620. .start = sysvipc_proc_start,
  621. .stop = sysvipc_proc_stop,
  622. .next = sysvipc_proc_next,
  623. .show = sysvipc_proc_show,
  624. };
  625. static int sysvipc_proc_open(struct inode *inode, struct file *file) {
  626. int ret;
  627. struct seq_file *seq;
  628. ret = seq_open(file, &sysvipc_proc_seqops);
  629. if (!ret) {
  630. seq = file->private_data;
  631. seq->private = PDE(inode)->data;
  632. }
  633. return ret;
  634. }
  635. static struct file_operations sysvipc_proc_fops = {
  636. .open = sysvipc_proc_open,
  637. .read = seq_read,
  638. .llseek = seq_lseek,
  639. .release = seq_release,
  640. };
  641. #endif /* CONFIG_PROC_FS */