lib_setlogmask.c 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /****************************************************************************
  2. * lib/syslog/lib_setlogmask.c
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. /****************************************************************************
  21. * Included Files
  22. ****************************************************************************/
  23. #include <nuttx/config.h>
  24. #include <stdint.h>
  25. #include <syslog.h>
  26. #include "syslog/syslog.h"
  27. /****************************************************************************
  28. * Public Data
  29. ****************************************************************************/
  30. /* The currently enabled set of syslog priorities */
  31. uint8_t g_syslog_mask = LOG_ALL;
  32. /****************************************************************************
  33. * Public Functions
  34. ****************************************************************************/
  35. /****************************************************************************
  36. * Name: setlogmask
  37. *
  38. * Description:
  39. * The setlogmask() function sets the logmask and returns the previous
  40. * mask. If the mask argument is 0, the current logmask is not modified.
  41. *
  42. * The SYSLOG priorities are: LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR,
  43. * LOG_WARNING, LOG_NOTICE, LOG_INFO, and LOG_DEBUG. The bit corresponding
  44. * to a priority p is LOG_MASK(p); LOG_UPTO(p) provides the mask of all
  45. * priorities in the above list up to and including p.
  46. *
  47. * Per OpenGroup.org "If the maskpri argument is 0, the current log mask
  48. * is not modified." In this implementation, the value zero is permitted
  49. * in order to disable all syslog levels.
  50. *
  51. * NOTE: setlogmask is not a thread-safe, re-entrant function. Concurrent
  52. * use of setlogmask() will have undefined behavior.
  53. *
  54. * REVISIT: Per POSIX the syslog mask should be a per-process value but in
  55. * NuttX, the scope of the mask is dependent on the nature of the build:
  56. *
  57. * Flat Build: There is one, global SYSLOG mask that controls all output.
  58. * Protected Build: There are two SYSLOG masks. One within the kernel
  59. * that controls only kernel output. And one in user-space that controls
  60. * only user SYSLOG output.
  61. * Kernel Build: The kernel build is compliant with the POSIX requirement:
  62. * There will be one mask for each user process, controlling the SYSLOG
  63. * output only form that process. There will be a separate mask
  64. * accessible only in the kernel code to control kernel SYSLOG output.
  65. *
  66. ****************************************************************************/
  67. int setlogmask(int mask)
  68. {
  69. uint8_t oldmask;
  70. oldmask = g_syslog_mask;
  71. g_syslog_mask = (uint8_t)mask;
  72. return oldmask;
  73. }