This source file includes following definitions.
- attrd_shutting_down
 
- attrd_shutdown
 
- attrd_init_mainloop
 
- attrd_run_mainloop
 
- attrd_mainloop_running
 
- attrd_quit_mainloop
 
- attrd_ipc_accept
 
- attrd_ipc_created
 
- attrd_ipc_closed
 
- attrd_ipc_destroy
 
- attrd_init_ipc
 
- attrd_cib_disconnect
 
- attrd_value_needs_expansion
 
- attrd_expand_value
 
- attrd_failure_regex
 
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 #include <crm_internal.h>
   9 
  10 #include <stdio.h>
  11 #include <errno.h>
  12 #include <glib.h>
  13 #include <regex.h>
  14 #include <sys/types.h>
  15 
  16 #include <crm/crm.h>
  17 #include <crm/common/ipcs.h>
  18 #include <crm/common/mainloop.h>
  19 
  20 #include <attrd_common.h>
  21 
  22 cib_t *the_cib = NULL;
  23 
  24 static gboolean shutting_down = FALSE;
  25 static GMainLoop *mloop = NULL;
  26 
  27 
  28 
  29 
  30 
  31 
  32 
  33 gboolean
  34 attrd_shutting_down()
     
  35 {
  36     return shutting_down;
  37 }
  38 
  39 
  40 
  41 
  42 
  43 
  44 
  45 void
  46 attrd_shutdown(int nsig) {
     
  47     crm_info("Shutting down");
  48 
  49     shutting_down = TRUE;
  50 
  51     if ((mloop != NULL) && g_main_is_running(mloop)) {
  52         g_main_quit(mloop);
  53     } else {
  54         crm_exit(pcmk_ok);
  55     }
  56 }
  57 
  58 
  59 
  60 
  61 
  62 void
  63 attrd_init_mainloop()
     
  64 {
  65     mloop = g_main_new(FALSE);
  66 }
  67 
  68 
  69 
  70 
  71 
  72 void
  73 attrd_run_mainloop()
     
  74 {
  75     g_main_run(mloop);
  76 }
  77 
  78 
  79 
  80 
  81 
  82 
  83 
  84 gboolean
  85 attrd_mainloop_running()
     
  86 {
  87     return (mloop != NULL) && g_main_is_running(mloop);
  88 }
  89 
  90 
  91 
  92 
  93 
  94 void
  95 attrd_quit_mainloop()
     
  96 {
  97     g_main_quit(mloop);
  98 }
  99 
 100 
 101 
 102 
 103 
 104 
 105 
 106 
 107 
 108 
 109 
 110 static int32_t
 111 attrd_ipc_accept(qb_ipcs_connection_t *c, uid_t uid, gid_t gid)
     
 112 {
 113     crm_trace("New client connection %p", c);
 114     if (shutting_down) {
 115         crm_info("Ignoring new connection from pid %d during shutdown",
 116                  crm_ipcs_client_pid(c));
 117         return -EPERM;
 118     }
 119 
 120     if (crm_client_new(c, uid, gid) == NULL) {
 121         return -EIO;
 122     }
 123     return pcmk_ok;
 124 }
 125 
 126 
 127 
 128 
 129 
 130 
 131 
 132 static void
 133 attrd_ipc_created(qb_ipcs_connection_t *c)
     
 134 {
 135     crm_trace("Client connection %p accepted", c);
 136 }
 137 
 138 
 139 
 140 
 141 
 142 
 143 
 144 
 145 
 146 static int32_t
 147 attrd_ipc_closed(qb_ipcs_connection_t *c)
     
 148 {
 149     crm_client_t *client = crm_client_get(c);
 150 
 151     if (client == NULL) {
 152         crm_trace("Ignoring request to clean up unknown connection %p", c);
 153     } else {
 154         crm_trace("Cleaning up closed client connection %p", c);
 155         crm_client_destroy(client);
 156     }
 157     return FALSE;
 158 }
 159 
 160 
 161 
 162 
 163 
 164 
 165 
 166 
 167 
 168 
 169 static void
 170 attrd_ipc_destroy(qb_ipcs_connection_t *c)
     
 171 {
 172     crm_trace("Destroying client connection %p", c);
 173     attrd_ipc_closed(c);
 174 }
 175 
 176 
 177 
 178 
 179 
 180 
 181 
 182 
 183 void
 184 attrd_init_ipc(qb_ipcs_service_t **ipcs, qb_ipcs_msg_process_fn dispatch_fn)
     
 185 {
 186 
 187     static struct qb_ipcs_service_handlers ipc_callbacks = {
 188         .connection_accept = attrd_ipc_accept,
 189         .connection_created = attrd_ipc_created,
 190         .msg_process = NULL,
 191         .connection_closed = attrd_ipc_closed,
 192         .connection_destroyed = attrd_ipc_destroy
 193     };
 194 
 195     ipc_callbacks.msg_process = dispatch_fn;
 196     attrd_ipc_server_init(ipcs, &ipc_callbacks);
 197 }
 198 
 199 void
 200 attrd_cib_disconnect()
     
 201 {
 202     if (the_cib) {
 203         the_cib->cmds->signoff(the_cib);
 204         cib_delete(the_cib);
 205         the_cib = NULL;
 206     }
 207 }
 208 
 209 
 210 #define plus_plus_len (5)
 211 
 212 
 213 
 214 
 215 
 216 
 217 
 218 
 219 
 220 gboolean
 221 attrd_value_needs_expansion(const char *value)
     
 222 {
 223     return ((strlen(value) >= (plus_plus_len + 2))
 224            && (value[plus_plus_len] == '+')
 225            && ((value[plus_plus_len + 1] == '+')
 226                || (value[plus_plus_len + 1] == '=')));
 227 }
 228 
 229 
 230 
 231 
 232 
 233 
 234 
 235 
 236 
 237 
 238 int
 239 attrd_expand_value(const char *value, const char *old_value)
     
 240 {
 241     int offset = 1;
 242     int int_value = char2score(old_value);
 243 
 244     if (value[plus_plus_len + 1] != '+') {
 245         const char *offset_s = value + (plus_plus_len + 2);
 246 
 247         offset = char2score(offset_s);
 248     }
 249     int_value += offset;
 250 
 251     if (int_value > INFINITY) {
 252         int_value = INFINITY;
 253     }
 254     return int_value;
 255 }
 256 
 257 
 258 
 259 
 260 
 261 
 262 
 263 
 264 
 265 
 266 
 267 
 268 
 269 
 270 int
 271 attrd_failure_regex(regex_t *regex, const char *rsc, const char *op,
     
 272                     int interval)
 273 {
 274     char *pattern = NULL;
 275     int rc;
 276 
 277     
 278 
 279     if (rsc == NULL) {
 280         pattern = strdup(ATTRD_RE_CLEAR_ALL);
 281     } else if (op == NULL) {
 282         pattern = crm_strdup_printf(ATTRD_RE_CLEAR_ONE, rsc);
 283     } else {
 284         pattern = crm_strdup_printf(ATTRD_RE_CLEAR_OP,
 285                                     rsc, op, interval);
 286     }
 287 
 288     
 289     crm_trace("Clearing attributes matching %s", pattern);
 290     rc = regcomp(regex, pattern, REG_EXTENDED|REG_NOSUB);
 291     free(pattern);
 292 
 293     return (rc == 0)? pcmk_ok : -EINVAL;
 294 }