/** * Post a new Event * @param service The Service the event belongs to * @param id The event identification * @param state The event state * @param action Description of the event action * @param s Optional message describing the event */ void Event_post(Service_T service, long id, State_Type state, EventAction_T action, char *s, ...) { ASSERT(service); ASSERT(action); ASSERT(s); ASSERT(state == State_Failed || state == State_Succeeded || state == State_Changed || state == State_ChangedNot); va_list ap; va_start(ap, s); char *message = Str_vcat(s, ap); va_end(ap); Event_T e = service->eventlist; while (e) { if (e->action == action && e->id == id) { gettimeofday(&e->collected, NULL); /* Shift the existing event flags to the left and set the first bit based on actual state */ e->state_map <<= 1; e->state_map |= ((state == State_Succeeded || state == State_ChangedNot) ? 0 : 1); /* Update the message */ FREE(e->message); e->message = message; break; } e = e->next; } if (! e) { /* Only first failed/changed event can initialize the queue for given event type, thus succeeded events are ignored until first error. */ if (state == State_Succeeded || state == State_ChangedNot) { DEBUG("'%s' %s\n", service->name, message); FREE(message); return; } /* Initialize the event. The mandatory informations are cloned so the event is as standalone as possible and may be saved * to the queue without the dependency on the original service, thus persistent and managable across monit restarts */ NEW(e); e->id = id; gettimeofday(&e->collected, NULL); e->source = service; e->mode = service->mode; e->type = service->type; e->state = State_Init; e->state_map = 1; e->action = action; e->message = message; e->next = service->eventlist; service->eventlist = e; } e->state_changed = _checkState(e, state); /* In the case that the state changed, update it and reset the counter */ if (e->state_changed) { e->state = state; e->count = 1; } else { e->count++; } _handleEvent(service, e); }
char *Str_cat(const char *s, ...) { char *t = NULL; if (s) { va_list ap; va_start(ap, s); t = Str_vcat(s, ap); va_end(ap); } return t; }
void do_send(SendMail_T *S, const char *s, ...) { va_list ap; va_start(ap,s); char *msg = Str_vcat(s, ap); va_end(ap); int rv = Socket_write(S->socket, msg, strlen(msg)); FREE(msg); if (rv <= 0) THROW(IOException, "Error sending data to the server '%s' -- %s", S->server, STRERROR); }
static void _send(T S, const char *data, ...) { va_list ap; va_start(ap, data); char *msg = Str_vcat(data, ap); va_end(ap); int rv = Socket_write(S->socket, msg, strlen(msg)); FREE(msg); if (rv <= 0) THROW(IOException, "Error sending data to the mailserver -- %s", STRERROR); }
T URL_create(const char *url, ...) { if (STR_UNDEF(url)) return NULL; Exception_init(); va_list ap; va_start(ap, url); T U = ctor((uchar_t*)Str_vcat(url, ap)); va_end(ap); return U; }
void System_abort(const char *e, ...) { va_list ap; va_start(ap, e); if (AbortHandler) { char *t = Str_vcat(e, ap); AbortHandler(t); FREE(t); } else { vfprintf(stderr, e, ap); if (ZBDEBUG) abort(); else exit(1); } va_end(ap); }
void do_send(SendMail_T *S, const char *s, ...) { va_list ap; char *msg= NULL; va_start(ap,s); msg= Str_vcat(s, ap); va_end(ap); if (socket_write(S->socket, msg, strlen(msg)) <= 0) { FREE(msg); LogError("Sendmail: error sending data to the server '%s' -- %s\n", S->server, STRERROR); siglongjmp(S->error, TRUE); } FREE(msg); }
void Box_setColumn(T t, int index, const char *format, ...) { ASSERT(t); ASSERT(index > 0); ASSERT(index <= t->columnsCount); int _index = index - 1; _resetColumn(&(t->columns[_index])); if (format) { va_list ap; va_start(ap, format); t->columns[_index].value = Str_vcat(format, ap); va_end(ap); if ((t->columns[_index]._colorLength = Color_length(t->columns[_index].value))) { _cacheColor(&(t->columns[_index])); Color_strip(t->columns[_index].value); // Strip the escape sequences, so we can safely break the line } t->columns[_index]._valueLength = strlen(t->columns[_index].value); } }
void Command_vSetEnv(T C, const char *env, ...) { assert(C); if (STR_DEF(env)) { va_list ap; char *s, *n, *v, *t; va_start(ap, env); n = s = Str_vcat(env, ap); va_end(ap); while ((v = strchr(n, '='))) { *(v++) = 0; t = strchr(v, ';'); if (t) *(t++) = 0; Command_setEnv(C, Str_trim(n), Str_trim(v)); if (t) n = t; else break; } FREE(s); } }