syslogd_and_logger.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * prioritynames[] and facilitynames[]
  4. *
  5. * Copyright (C) 2008 by Denys Vlasenko <vda.linux@gmail.com>
  6. *
  7. * Licensed under GPLv2, see file LICENSE in this source tree.
  8. */
  9. #include "libbb.h"
  10. #include "common_bufsiz.h"
  11. #define SYSLOG_NAMES
  12. #define SYSLOG_NAMES_CONST
  13. #include <syslog.h>
  14. #if 0
  15. /* For the record: with SYSLOG_NAMES <syslog.h> defines
  16. * (not declares) the following:
  17. */
  18. typedef struct _code {
  19. /*const*/ char *c_name;
  20. int c_val;
  21. } CODE;
  22. /*const*/ CODE prioritynames[] = {
  23. { "alert", LOG_ALERT },
  24. ...
  25. { NULL, -1 }
  26. };
  27. /* same for facilitynames[] */
  28. /* This MUST occur only once per entire executable,
  29. * therefore we can't just do it in syslogd.c and logger.c -
  30. * there will be two copies of it.
  31. *
  32. * We cannot even do it in separate file and then just reference
  33. * prioritynames[] from syslogd.c and logger.c - bare <syslog.h>
  34. * will not emit extern decls for prioritynames[]! Attempts to
  35. * emit "matching" struct _code declaration defeat the whole purpose
  36. * of <syslog.h>.
  37. *
  38. * For now, syslogd.c and logger.c are simply compiled into
  39. * one object file.
  40. */
  41. #endif
  42. /* musl decided to be funny and it implements these as giant defines
  43. * of the form: ((CODE *)(const CODE []){ ... })
  44. * Which works, but causes _every_ function using them
  45. * to have a copy on stack (at least with gcc-6.3.0).
  46. * If we reference them just once, this saves 150 bytes.
  47. * The pointers themselves are optimized out
  48. * (no size change on uclibc).
  49. */
  50. static const CODE *const bb_prioritynames = prioritynames;
  51. static const CODE *const bb_facilitynames = facilitynames;
  52. #if ENABLE_SYSLOGD
  53. #include "syslogd.c"
  54. #endif
  55. #if ENABLE_LOGGER
  56. #include "logger.c"
  57. #endif