2
0

shm_init.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2010 iptelorg GmbH
  5. *
  6. * Permission to use, copy, modify, and distribute this software for any
  7. * purpose with or without fee is hereby granted, provided that the above
  8. * copyright notice and this permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. /*
  19. * shm_init.c
  20. */
  21. /*
  22. * History:
  23. * --------
  24. * 2010-01-10 initial version (andrei)
  25. */
  26. #include "shm_init.h"
  27. #include "mem/mem.h"
  28. #include "globals.h"
  29. static int shm_init = 0;
  30. /** check if shm is initialized.
  31. * @return 1 if initialized, 0 if not
  32. */
  33. int shm_initialized()
  34. {
  35. return shm_init;
  36. }
  37. #ifdef SHM_MEM
  38. /** init shm mem.
  39. * @return 0 on success, < 0 on error
  40. * it _must_ be called:
  41. * - after the shm_mem_size is known
  42. * - after shm_force_alloc is known (mlock_pages should happen at a later
  43. * point so it's not yet needed here)
  44. * - after the user is known (so that in the SYSV sems case the sems will
  45. * have the correct euid)
  46. * - before init_timer and init_tcp
  47. * --andrei
  48. *
  49. * Global vars used: shm_mem_size, shm_force_alloc, user & uid.
  50. * Side effects: it might set uid, gid and shm_mem_size.
  51. */
  52. int init_shm()
  53. {
  54. /* set uid if user is set */
  55. if (user && uid == 0){
  56. if (user2uid(&uid, &gid, user)<0){
  57. fprintf(stderr, "bad user name/uid number: -u %s\n", user);
  58. goto error;
  59. }
  60. }
  61. if (shm_mem_size == 0)
  62. shm_mem_size=SHM_MEM_SIZE * 1024 * 1024;
  63. if (init_shm_mallocs(shm_force_alloc)==-1)
  64. goto error;
  65. shm_init=1;
  66. return 0;
  67. error:
  68. return -1;
  69. }
  70. #endif /* SHM_MEM */
  71. /* vi: set ts=4 sw=4 tw=79:ai:cindent: */