instance.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
  3. * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License version 2.1
  7. * as published by the Free Software Foundation
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #ifndef __PROCD_INSTANCE_H
  15. #define __PROCD_INSTANCE_H
  16. #include <libubox/vlist.h>
  17. #include <libubox/uloop.h>
  18. #include <libubox/ustream.h>
  19. #include "../utils/utils.h"
  20. #define RESPAWN_ERROR (5 * 60)
  21. #define SIGNALLED_OFFSET 128
  22. struct jail {
  23. bool procfs;
  24. bool sysfs;
  25. bool ubus;
  26. bool log;
  27. bool ronly;
  28. bool netns;
  29. bool userns;
  30. bool cgroupsns;
  31. bool console;
  32. char *name;
  33. char *hostname;
  34. struct blobmsg_list mount;
  35. int argc;
  36. };
  37. typedef enum instance_watchdog {
  38. INSTANCE_WATCHDOG_MODE_DISABLED,
  39. INSTANCE_WATCHDOG_MODE_PASSIVE,
  40. INSTANCE_WATCHDOG_MODE_ACTIVE,
  41. __INSTANCE_WATCHDOG_MODE_MAX,
  42. } instance_watchdog_mode_t;
  43. struct watchdog {
  44. instance_watchdog_mode_t mode;
  45. uint32_t freq;
  46. struct uloop_timeout timeout;
  47. };
  48. struct service_instance {
  49. struct vlist_node node;
  50. struct service *srv;
  51. const char *name;
  52. int8_t nice;
  53. bool valid;
  54. char *user;
  55. uid_t uid;
  56. gid_t pw_gid;
  57. char *group;
  58. gid_t gr_gid;
  59. bool halt;
  60. bool restart;
  61. bool respawn;
  62. int respawn_count;
  63. int reload_signal;
  64. struct timespec start;
  65. bool trace;
  66. bool has_jail;
  67. bool require_jail;
  68. bool immediately;
  69. bool no_new_privs;
  70. struct jail jail;
  71. char *seccomp;
  72. char *pidfile;
  73. char *extroot;
  74. char *overlaydir;
  75. char *tmpoverlaysize;
  76. char *bundle;
  77. int syslog_facility;
  78. int exit_code;
  79. uint32_t term_timeout;
  80. uint32_t respawn_timeout;
  81. uint32_t respawn_threshold;
  82. uint32_t respawn_retry;
  83. struct blob_attr *config;
  84. struct uloop_process proc;
  85. struct uloop_timeout timeout;
  86. struct ustream_fd _stdout;
  87. struct ustream_fd _stderr;
  88. struct ustream_fd console;
  89. struct ustream_fd console_client;
  90. struct blob_attr *command;
  91. struct blob_attr *trigger;
  92. struct blobmsg_list env;
  93. struct blobmsg_list data;
  94. struct blobmsg_list netdev;
  95. struct blobmsg_list file;
  96. struct blobmsg_list limits;
  97. struct blobmsg_list errors;
  98. struct watchdog watchdog;
  99. };
  100. void instance_start(struct service_instance *in);
  101. void instance_stop(struct service_instance *in, bool halt);
  102. void instance_update(struct service_instance *in, struct service_instance *in_new);
  103. void instance_init(struct service_instance *in, struct service *s, struct blob_attr *config);
  104. void instance_free(struct service_instance *in);
  105. void instance_dump(struct blob_buf *b, struct service_instance *in, int debug);
  106. #endif