obs-nix.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. Copyright (C) 2014 by Zachary Lund <[email protected]>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 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 General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. ******************************************************************************/
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include <unistd.h>
  18. #include <sys/sysinfo.h>
  19. #include <sys/utsname.h>
  20. #include "util/dstr.h"
  21. #include "obs-internal.h"
  22. const char *get_module_extension(void)
  23. {
  24. return ".so";
  25. }
  26. #ifdef __LP64__
  27. #define BIT_STRING "64bit"
  28. #else
  29. #define BIT_STRING "32bit"
  30. #endif
  31. static const char *module_bin[] = {
  32. "../../obs-plugins/" BIT_STRING,
  33. OBS_INSTALL_PREFIX "lib/obs-plugins",
  34. };
  35. static const char *module_data[] = {
  36. OBS_DATA_PATH "/obs-plugins/%module%",
  37. OBS_INSTALL_DATA_PATH "/obs-plugins/%module%",
  38. };
  39. static const int module_patterns_size =
  40. sizeof(module_bin)/sizeof(module_bin[0]);
  41. void add_default_module_paths(void)
  42. {
  43. for (int i = 0; i < module_patterns_size; i++)
  44. obs_add_module_path(module_bin[i], module_data[i]);
  45. }
  46. /*
  47. * /usr/local/share/libobs
  48. * /usr/share/libobs
  49. */
  50. char *find_libobs_data_file(const char *file)
  51. {
  52. struct dstr output;
  53. dstr_init(&output);
  54. if (check_path(file, OBS_DATA_PATH "/libobs/", &output))
  55. return output.array;
  56. if (OBS_INSTALL_PREFIX [0] != 0) {
  57. if (check_path(file, OBS_INSTALL_DATA_PATH "/libobs/",
  58. &output))
  59. return output.array;
  60. }
  61. dstr_free(&output);
  62. return NULL;
  63. }
  64. static void log_processor_info(void)
  65. {
  66. FILE *fp;
  67. int physical_id = -1;
  68. int last_physical_id = -1;
  69. char *line = NULL;
  70. size_t linecap = 0;
  71. struct dstr processor;
  72. blog(LOG_INFO, "Processor: %lu logical cores",
  73. sysconf(_SC_NPROCESSORS_ONLN));
  74. fp = fopen("/proc/cpuinfo", "r");
  75. if (!fp)
  76. return;
  77. dstr_init(&processor);
  78. while (getline(&line, &linecap, fp) != -1) {
  79. if (!strncmp(line, "model name", 10)) {
  80. char *start = strchr(line, ':');
  81. if (!start || *(++start) == '\0')
  82. continue;
  83. dstr_copy(&processor, start);
  84. dstr_resize(&processor, processor.len - 1);
  85. dstr_depad(&processor);
  86. }
  87. if (!strncmp(line, "physical id", 11)) {
  88. char *start = strchr(line, ':');
  89. if (!start || *(++start) == '\0')
  90. continue;
  91. physical_id = atoi(start);
  92. }
  93. if (*line == '\n' && physical_id != last_physical_id) {
  94. last_physical_id = physical_id;
  95. blog(LOG_INFO, "Processor: %s", processor.array);
  96. }
  97. }
  98. fclose(fp);
  99. dstr_free(&processor);
  100. free(line);
  101. }
  102. static void log_memory_info(void)
  103. {
  104. struct sysinfo info;
  105. if (sysinfo(&info) < 0)
  106. return;
  107. blog(LOG_INFO, "Physical Memory: %luMB Total",
  108. info.totalram / 1024 / 1024);
  109. }
  110. static void log_kernel_version(void)
  111. {
  112. struct utsname info;
  113. if (uname(&info) < 0)
  114. return;
  115. blog(LOG_INFO, "Kernel Version: %s %s", info.sysname, info.release);
  116. }
  117. static void log_distribution_info(void)
  118. {
  119. FILE *fp;
  120. char *line = NULL;
  121. size_t linecap = 0;
  122. struct dstr distro;
  123. struct dstr version;
  124. fp = fopen("/etc/os-release", "r");
  125. if (!fp) {
  126. blog(LOG_INFO, "Distribution: Missing /etc/os-release !");
  127. return;
  128. }
  129. dstr_init_copy(&distro, "Unknown");
  130. dstr_init_copy(&version, "Unknown");
  131. while (getline(&line, &linecap, fp) != -1) {
  132. if (!strncmp(line, "NAME", 4)) {
  133. char *start = strchr(line, '=');
  134. if (!start || *(++start) == '\0')
  135. continue;
  136. dstr_copy(&distro, start);
  137. dstr_resize(&distro, distro.len - 1);
  138. }
  139. if (!strncmp(line, "VERSION_ID", 10)) {
  140. char *start = strchr(line, '=');
  141. if (!start || *(++start) == '\0')
  142. continue;
  143. dstr_copy(&version, start);
  144. dstr_resize(&version, version.len - 1);
  145. }
  146. }
  147. blog(LOG_INFO, "Distribution: %s %s", distro.array, version.array);
  148. fclose(fp);
  149. dstr_free(&version);
  150. dstr_free(&distro);
  151. free(line);
  152. }
  153. void log_system_info(void)
  154. {
  155. log_processor_info();
  156. log_memory_info();
  157. log_kernel_version();
  158. log_distribution_info();
  159. }