log.c 674 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // SPDX-License-Identifier: LGPL-2.1-or-later
  2. /*
  3. *
  4. * BlueZ - Bluetooth protocol stack for Linux
  5. *
  6. * Copyright (C) 2015 Intel Corporation. All rights reserved.
  7. *
  8. *
  9. */
  10. #ifdef HAVE_CONFIG_H
  11. #include <config.h>
  12. #endif
  13. #define _GNU_SOURCE
  14. #include <stdio.h>
  15. #include <errno.h>
  16. #include <fcntl.h>
  17. #include <unistd.h>
  18. #include "peripheral/log.h"
  19. static int kmsg_fd = -1;
  20. void log_open(void)
  21. {
  22. if (kmsg_fd >= 0)
  23. return;
  24. kmsg_fd = open("/dev/kmsg", O_WRONLY | O_NOCTTY | O_CLOEXEC);
  25. if (kmsg_fd < 0) {
  26. fprintf(stderr, "Failed to open kernel logging: %m\n");
  27. return;
  28. }
  29. }
  30. void log_close(void)
  31. {
  32. if (kmsg_fd < 0)
  33. return;
  34. close(kmsg_fd);
  35. kmsg_fd = -1;
  36. }