runit_lib.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. Copyright (c) 2001-2006, Gerrit Pape
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. 1. Redistributions of source code must retain the above copyright notice,
  7. this list of conditions and the following disclaimer.
  8. 2. Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. 3. The name of the author may not be used to endorse or promote products
  12. derived from this software without specific prior written permission.
  13. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  14. WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  15. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  16. EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  17. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  19. OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  20. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  21. OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  22. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. extern unsigned byte_chr(char *s,unsigned n,int c);
  25. extern int coe(int);
  26. #define direntry struct dirent
  27. //struct tai {
  28. // uint64_t x;
  29. //};
  30. //
  31. //#define tai_unix(t,u) ((void) ((t)->x = 0x400000000000000aULL + (uint64_t) (u)))
  32. //
  33. //#define TAI_PACK 8
  34. //extern void tai_unpack(const char *,struct tai *);
  35. //
  36. //extern void tai_uint(struct tai *,unsigned);
  37. //
  38. //struct taia {
  39. // struct tai sec;
  40. // unsigned long nano; /* 0...999999999 */
  41. // unsigned long atto; /* 0...999999999 */
  42. //};
  43. //
  44. //extern void taia_now(struct taia *);
  45. //
  46. //extern void taia_add(struct taia *,const struct taia *,const struct taia *);
  47. //extern void taia_addsec(struct taia *,const struct taia *,int);
  48. //extern void taia_sub(struct taia *,const struct taia *,const struct taia *);
  49. //extern void taia_half(struct taia *,const struct taia *);
  50. //extern int taia_less(const struct taia *,const struct taia *);
  51. //
  52. //#define TAIA_PACK 16
  53. //extern void taia_pack(char *,const struct taia *);
  54. //
  55. //extern void taia_uint(struct taia *,unsigned);
  56. //
  57. //typedef struct pollfd iopause_fd;
  58. //#define IOPAUSE_READ POLLIN
  59. //#define IOPAUSE_WRITE POLLOUT
  60. //
  61. //extern void iopause(iopause_fd *,unsigned,struct taia *,struct taia *);
  62. extern int lock_ex(int);
  63. extern int lock_un(int);
  64. extern int lock_exnb(int);
  65. extern int open_read(const char *);
  66. extern int open_excl(const char *);
  67. extern int open_append(const char *);
  68. extern int open_trunc(const char *);
  69. extern int open_write(const char *);
  70. extern unsigned pmatch(const char *, const char *, unsigned);
  71. #define str_diff(s,t) strcmp((s), (t))
  72. #define str_equal(s,t) (!strcmp((s), (t)))
  73. /*
  74. * runsv / supervise / sv stuff
  75. */
  76. typedef struct svstatus_t {
  77. uint64_t time_be64 ATTRIBUTE_PACKED;
  78. uint32_t time_nsec_be32 ATTRIBUTE_PACKED;
  79. uint32_t pid_le32 ATTRIBUTE_PACKED;
  80. uint8_t paused;
  81. uint8_t want;
  82. uint8_t got_term;
  83. uint8_t run_or_finish;
  84. } svstatus_t;
  85. struct ERR_svstatus_must_be_20_bytes {
  86. char ERR_svstatus_must_be_20_bytes[sizeof(svstatus_t) == 20 ? 1 : -1];
  87. };