Пример #1
0
static int tcsv_read(user_data_t *ud) {
  instance_definition_t *id;
  id = ud->data;

  if (id->tail == NULL) {
    id->tail = cu_tail_create(id->path);
    if (id->tail == NULL) {
      ERROR("tail_csv plugin: cu_tail_create (\"%s\") failed.", id->path);
      return (-1);
    }
  }

  while (42) {
    char buffer[1024];
    size_t buffer_len;
    int status;

    status = cu_tail_readline(id->tail, buffer, (int)sizeof(buffer));
    if (status != 0) {
      ERROR("tail_csv plugin: File \"%s\": cu_tail_readline failed "
            "with status %i.",
            id->path, status);
      return (-1);
    }

    buffer_len = strlen(buffer);
    if (buffer_len == 0)
      break;

    tcsv_read_buffer(id, buffer, buffer_len);
  }

  return (0);
}
Пример #2
0
int cu_tail_read (cu_tail_t *obj, char *buf, int buflen, tailfunc_t *callback,
		void *data)
{
	int status;

	while (42)
	{
		size_t len;

		status = cu_tail_readline (obj, buf, buflen);
		if (status != 0)
		{
			ERROR ("utils_tail: cu_tail_read: cu_tail_readline "
					"failed.");
			break;
		}

		/* check for EOF */
		if (buf[0] == 0)
			break;

		len = strlen (buf);
		while (len > 0) {
			if (buf[len - 1] != '\n')
				break;
			buf[len - 1] = '\0';
			len--;
		}

		status = callback (data, buf, buflen);
		if (status != 0)
		{
			ERROR ("utils_tail: cu_tail_read: callback returned "
					"status %i.", status);
			break;
		}
	}

	return status;
} /* int cu_tail_read */