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 <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. *
  367. * Since RCU callback function is called in bh,
  368. * we need to defer the vfree to schedule_work
  369. */
  370. static void ipc_schedule_free(struct rcu_head *head)
  371. {
  372. struct ipc_rcu_grace *grace =
  373. container_of(head, struct ipc_rcu_grace, rcu);
  374. struct ipc_rcu_sched *sched =
  375. container_of(&(grace->data[0]), struct ipc_rcu_sched, data[0]);
  376. INIT_WORK(&sched->work, vfree, sched);
  377. schedule_work(&sched->work);
  378. }
  379. /**
  380. * ipc_immediate_free - free ipc + rcu space
  381. *
  382. * Free from the RCU callback context
  383. *
  384. */
  385. static void ipc_immediate_free(struct rcu_head *head)
  386. {
  387. struct ipc_rcu_grace *free =
  388. container_of(head, struct ipc_rcu_grace, rcu);
  389. kfree(free);
  390. }
  391. void ipc_rcu_putref(void *ptr)
  392. {
  393. if (--container_of(ptr, struct ipc_rcu_hdr, data)->refcount > 0)
  394. return;
  395. if (container_of(ptr, struct ipc_rcu_hdr, data)->is_vmalloc) {
  396. call_rcu(&container_of(ptr, struct ipc_rcu_grace, data)->rcu,
  397. ipc_schedule_free);
  398. } else {
  399. call_rcu(&container_of(ptr, struct ipc_rcu_grace, data)->rcu,
  400. ipc_immediate_free);
  401. }
  402. }
  403. /**
  404. * ipcperms - check IPC permissions
  405. * @ipcp: IPC permission set
  406. * @flag: desired permission set.
  407. *
  408. * Check user, group, other permissions for access
  409. * to ipc resources. return 0 if allowed
  410. */
  411. int ipcperms (struct kern_ipc_perm *ipcp, short flag)
  412. { /* flag will most probably be 0 or S_...UGO from <linux/stat.h> */
  413. int requested_mode, granted_mode;
  414. requested_mode = (flag >> 6) | (flag >> 3) | flag;
  415. granted_mode = ipcp->mode;
  416. if (current->euid == ipcp->cuid || current->euid == ipcp->uid)
  417. granted_mode >>= 6;
  418. else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
  419. granted_mode >>= 3;
  420. /* is there some bit set in requested_mode but not in granted_mode? */
  421. if ((requested_mode & ~granted_mode & 0007) &&
  422. !capable(CAP_IPC_OWNER))
  423. return -1;
  424. return security_ipc_permission(ipcp, flag);
  425. }
  426. /*
  427. * Functions to convert between the kern_ipc_perm structure and the
  428. * old/new ipc_perm structures
  429. */
  430. /**
  431. * kernel_to_ipc64_perm - convert kernel ipc permissions to user
  432. * @in: kernel permissions
  433. * @out: new style IPC permissions
  434. *
  435. * Turn the kernel object 'in' into a set of permissions descriptions
  436. * for returning to userspace (out).
  437. */
  438. void kernel_to_ipc64_perm (struct kern_ipc_perm *in, struct ipc64_perm *out)
  439. {
  440. out->key = in->key;
  441. out->uid = in->uid;
  442. out->gid = in->gid;
  443. out->cuid = in->cuid;
  444. out->cgid = in->cgid;
  445. out->mode = in->mode;
  446. out->seq = in->seq;
  447. }
  448. /**
  449. * ipc64_perm_to_ipc_perm - convert old ipc permissions to new
  450. * @in: new style IPC permissions
  451. * @out: old style IPC permissions
  452. *
  453. * Turn the new style permissions object in into a compatibility
  454. * object and store it into the 'out' pointer.
  455. */
  456. void ipc64_perm_to_ipc_perm (struct ipc64_perm *in, struct ipc_perm *out)
  457. {
  458. out->key = in->key;
  459. SET_UID(out->uid, in->uid);
  460. SET_GID(out->gid, in->gid);
  461. SET_UID(out->cuid, in->cuid);
  462. SET_GID(out->cgid, in->cgid);
  463. out->mode = in->mode;
  464. out->seq = in->seq;
  465. }
  466. /*
  467. * So far only shm_get_stat() calls ipc_get() via shm_get(), so ipc_get()
  468. * is called with shm_ids.sem locked. Since grow_ary() is also called with
  469. * shm_ids.sem down(for Shared Memory), there is no need to add read
  470. * barriers here to gurantee the writes in grow_ary() are seen in order
  471. * here (for Alpha).
  472. *
  473. * However ipc_get() itself does not necessary require ipc_ids.sem down. So
  474. * if in the future ipc_get() is used by other places without ipc_ids.sem
  475. * down, then ipc_get() needs read memery barriers as ipc_lock() does.
  476. */
  477. struct kern_ipc_perm* ipc_get(struct ipc_ids* ids, int id)
  478. {
  479. struct kern_ipc_perm* out;
  480. int lid = id % SEQ_MULTIPLIER;
  481. if(lid >= ids->entries->size)
  482. return NULL;
  483. out = ids->entries->p[lid];
  484. return out;
  485. }
  486. struct kern_ipc_perm* ipc_lock(struct ipc_ids* ids, int id)
  487. {
  488. struct kern_ipc_perm* out;
  489. int lid = id % SEQ_MULTIPLIER;
  490. struct ipc_id_ary* entries;
  491. rcu_read_lock();
  492. entries = rcu_dereference(ids->entries);
  493. if(lid >= entries->size) {
  494. rcu_read_unlock();
  495. return NULL;
  496. }
  497. out = entries->p[lid];
  498. if(out == NULL) {
  499. rcu_read_unlock();
  500. return NULL;
  501. }
  502. spin_lock(&out->lock);
  503. /* ipc_rmid() may have already freed the ID while ipc_lock
  504. * was spinning: here verify that the structure is still valid
  505. */
  506. if (out->deleted) {
  507. spin_unlock(&out->lock);
  508. rcu_read_unlock();
  509. return NULL;
  510. }
  511. return out;
  512. }
  513. void ipc_lock_by_ptr(struct kern_ipc_perm *perm)
  514. {
  515. rcu_read_lock();
  516. spin_lock(&perm->lock);
  517. }
  518. void ipc_unlock(struct kern_ipc_perm* perm)
  519. {
  520. spin_unlock(&perm->lock);
  521. rcu_read_unlock();
  522. }
  523. int ipc_buildid(struct ipc_ids* ids, int id, int seq)
  524. {
  525. return SEQ_MULTIPLIER*seq + id;
  526. }
  527. int ipc_checkid(struct ipc_ids* ids, struct kern_ipc_perm* ipcp, int uid)
  528. {
  529. if(uid/SEQ_MULTIPLIER != ipcp->seq)
  530. return 1;
  531. return 0;
  532. }
  533. #ifdef __ARCH_WANT_IPC_PARSE_VERSION
  534. /**
  535. * ipc_parse_version - IPC call version
  536. * @cmd: pointer to command
  537. *
  538. * Return IPC_64 for new style IPC and IPC_OLD for old style IPC.
  539. * The cmd value is turned from an encoding command and version into
  540. * just the command code.
  541. */
  542. int ipc_parse_version (int *cmd)
  543. {
  544. if (*cmd & IPC_64) {
  545. *cmd ^= IPC_64;
  546. return IPC_64;
  547. } else {
  548. return IPC_OLD;
  549. }
  550. }
  551. #endif /* __ARCH_WANT_IPC_PARSE_VERSION */
  552. #ifdef CONFIG_PROC_FS
  553. static void *sysvipc_proc_next(struct seq_file *s, void *it, loff_t *pos)
  554. {
  555. struct ipc_proc_iface *iface = s->private;
  556. struct kern_ipc_perm *ipc = it;
  557. loff_t p;
  558. /* If we had an ipc id locked before, unlock it */
  559. if (ipc && ipc != SEQ_START_TOKEN)
  560. ipc_unlock(ipc);
  561. /*
  562. * p = *pos - 1 (because id 0 starts at position 1)
  563. * + 1 (because we increment the position by one)
  564. */
  565. for (p = *pos; p <= iface->ids->max_id; p++) {
  566. if ((ipc = ipc_lock(iface->ids, p)) != NULL) {
  567. *pos = p + 1;
  568. return ipc;
  569. }
  570. }
  571. /* Out of range - return NULL to terminate iteration */
  572. return NULL;
  573. }
  574. /*
  575. * File positions: pos 0 -> header, pos n -> ipc id + 1.
  576. * SeqFile iterator: iterator value locked shp or SEQ_TOKEN_START.
  577. */
  578. static void *sysvipc_proc_start(struct seq_file *s, loff_t *pos)
  579. {
  580. struct ipc_proc_iface *iface = s->private;
  581. struct kern_ipc_perm *ipc;
  582. loff_t p;
  583. /*
  584. * Take the lock - this will be released by the corresponding
  585. * call to stop().
  586. */
  587. down(&iface->ids->sem);
  588. /* pos < 0 is invalid */
  589. if (*pos < 0)
  590. return NULL;
  591. /* pos == 0 means header */
  592. if (*pos == 0)
  593. return SEQ_START_TOKEN;
  594. /* Find the (pos-1)th ipc */
  595. for (p = *pos - 1; p <= iface->ids->max_id; p++) {
  596. if ((ipc = ipc_lock(iface->ids, p)) != NULL) {
  597. *pos = p + 1;
  598. return ipc;
  599. }
  600. }
  601. return NULL;
  602. }
  603. static void sysvipc_proc_stop(struct seq_file *s, void *it)
  604. {
  605. struct kern_ipc_perm *ipc = it;
  606. struct ipc_proc_iface *iface = s->private;
  607. /* If we had a locked segment, release it */
  608. if (ipc && ipc != SEQ_START_TOKEN)
  609. ipc_unlock(ipc);
  610. /* Release the lock we took in start() */
  611. up(&iface->ids->sem);
  612. }
  613. static int sysvipc_proc_show(struct seq_file *s, void *it)
  614. {
  615. struct ipc_proc_iface *iface = s->private;
  616. if (it == SEQ_START_TOKEN)
  617. return seq_puts(s, iface->header);
  618. return iface->show(s, it);
  619. }
  620. static struct seq_operations sysvipc_proc_seqops = {
  621. .start = sysvipc_proc_start,
  622. .stop = sysvipc_proc_stop,
  623. .next = sysvipc_proc_next,
  624. .show = sysvipc_proc_show,
  625. };
  626. static int sysvipc_proc_open(struct inode *inode, struct file *file) {
  627. int ret;
  628. struct seq_file *seq;
  629. ret = seq_open(file, &sysvipc_proc_seqops);
  630. if (!ret) {
  631. seq = file->private_data;
  632. seq->private = PDE(inode)->data;
  633. }
  634. return ret;
  635. }
  636. static struct file_operations sysvipc_proc_fops = {
  637. .open = sysvipc_proc_open,
  638. .read = seq_read,
  639. .llseek = seq_lseek,
  640. .release = seq_release,
  641. };
  642. #endif /* CONFIG_PROC_FS */