utsname_sysctl.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright (C) 2007
  3. *
  4. * Author: Eric Biederman <ebiederm@xmision.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation, version 2 of the
  9. * License.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/uts.h>
  13. #include <linux/utsname.h>
  14. #include <linux/sysctl.h>
  15. static void *get_uts(ctl_table *table, int write)
  16. {
  17. char *which = table->data;
  18. struct uts_namespace *uts_ns;
  19. uts_ns = current->nsproxy->uts_ns;
  20. which = (which - (char *)&init_uts_ns) + (char *)uts_ns;
  21. if (!write)
  22. down_read(&uts_sem);
  23. else
  24. down_write(&uts_sem);
  25. return which;
  26. }
  27. static void put_uts(ctl_table *table, int write, void *which)
  28. {
  29. if (!write)
  30. up_read(&uts_sem);
  31. else
  32. up_write(&uts_sem);
  33. }
  34. #ifdef CONFIG_PROC_SYSCTL
  35. /*
  36. * Special case of dostring for the UTS structure. This has locks
  37. * to observe. Should this be in kernel/sys.c ????
  38. */
  39. static int proc_do_uts_string(ctl_table *table, int write,
  40. void __user *buffer, size_t *lenp, loff_t *ppos)
  41. {
  42. struct ctl_table uts_table;
  43. int r;
  44. memcpy(&uts_table, table, sizeof(uts_table));
  45. uts_table.data = get_uts(table, write);
  46. r = proc_dostring(&uts_table,write,buffer,lenp, ppos);
  47. put_uts(table, write, uts_table.data);
  48. return r;
  49. }
  50. #else
  51. #define proc_do_uts_string NULL
  52. #endif
  53. static struct ctl_table uts_kern_table[] = {
  54. {
  55. .procname = "ostype",
  56. .data = init_uts_ns.name.sysname,
  57. .maxlen = sizeof(init_uts_ns.name.sysname),
  58. .mode = 0444,
  59. .proc_handler = proc_do_uts_string,
  60. },
  61. {
  62. .procname = "osrelease",
  63. .data = init_uts_ns.name.release,
  64. .maxlen = sizeof(init_uts_ns.name.release),
  65. .mode = 0444,
  66. .proc_handler = proc_do_uts_string,
  67. },
  68. {
  69. .procname = "version",
  70. .data = init_uts_ns.name.version,
  71. .maxlen = sizeof(init_uts_ns.name.version),
  72. .mode = 0444,
  73. .proc_handler = proc_do_uts_string,
  74. },
  75. {
  76. .procname = "hostname",
  77. .data = init_uts_ns.name.nodename,
  78. .maxlen = sizeof(init_uts_ns.name.nodename),
  79. .mode = 0644,
  80. .proc_handler = proc_do_uts_string,
  81. },
  82. {
  83. .procname = "domainname",
  84. .data = init_uts_ns.name.domainname,
  85. .maxlen = sizeof(init_uts_ns.name.domainname),
  86. .mode = 0644,
  87. .proc_handler = proc_do_uts_string,
  88. },
  89. {}
  90. };
  91. static struct ctl_table uts_root_table[] = {
  92. {
  93. .procname = "kernel",
  94. .mode = 0555,
  95. .child = uts_kern_table,
  96. },
  97. {}
  98. };
  99. static int __init utsname_sysctl_init(void)
  100. {
  101. register_sysctl_table(uts_root_table);
  102. return 0;
  103. }
  104. __initcall(utsname_sysctl_init);