jack1 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
2.4KB

  1. /* -*- mode: c; c-file-style: "bsd"; -*- */
  2. /*
  3. Copyright (C) 2004 Paul Davis
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. #include <stdio.h>
  17. #include <unistd.h>
  18. #include <string.h>
  19. #include <limits.h>
  20. #include <sys/mman.h>
  21. #include "unlock.h"
  22. #include "internal.h"
  23. static char* blacklist[] = {
  24. "/libgtk",
  25. "/libqt",
  26. "/libfltk",
  27. "/wine/",
  28. NULL
  29. };
  30. static char* whitelist[] = {
  31. "/libc-",
  32. "/libardour",
  33. NULL
  34. };
  35. static char* library_roots[] = {
  36. "/lib",
  37. "/usr/lib",
  38. "/usr/local/lib",
  39. "/usr/X11R6/lib",
  40. "/opt/lib", /* solaris-y */
  41. "/opt/local/lib", /* common on OS X */
  42. NULL
  43. };
  44. void
  45. cleanup_mlock ()
  46. {
  47. FILE* map;
  48. size_t start;
  49. size_t end;
  50. char path[PATH_MAX+1];
  51. int unlock;
  52. int i;
  53. int whoknows;
  54. int looks_like_library;
  55. snprintf (path, sizeof(path), "/proc/%d/maps", getpid());
  56. if ((map = fopen (path, "r")) == NULL) {
  57. jack_error ("can't open map file");
  58. return;
  59. }
  60. while (!feof (map)) {
  61. unlock = 0;
  62. if (fscanf (map, "%zx-%zx %*s %*x %*d:%*d %d",
  63. &start, &end, &whoknows) != 3) {
  64. break;
  65. }
  66. if (!whoknows) {
  67. continue;
  68. }
  69. fscanf (map, " %[^\n]", path);
  70. /* if it doesn't look like a library, forget it */
  71. looks_like_library = 0;
  72. for (i = 0; library_roots[i]; ++i) {
  73. if ((looks_like_library = (strstr (path, library_roots[i]) == path))) {
  74. break;
  75. }
  76. }
  77. if (!looks_like_library) {
  78. continue;
  79. }
  80. for (i = 0; blacklist[i]; ++i) {
  81. if (strstr (path, blacklist[i])) {
  82. unlock = 1;
  83. break;
  84. }
  85. }
  86. if (end - start > 1048576) {
  87. unlock = 1;
  88. }
  89. for (i = 0; whitelist[i]; ++i) {
  90. if (strstr (path, whitelist[i])) {
  91. unlock = 0;
  92. break;
  93. }
  94. }
  95. if (unlock) {
  96. jack_info ("unlocking %s", path);
  97. munlock ((char *) start, end - start);
  98. }
  99. }
  100. fclose (map);
  101. }