Esempio n. 1
0
void test_logging()
{
    ILOG(logfmt("thread(%1%) begin.") % boost::this_thread::get_id());

    for(int i=0; i<2; i++) {
        FLOG(logfmt("%1%, %2%") % 1 % 2);
        VLOG(logfmt("%1%, %2%") % 1 % 2);
        LOG_ASSERT(1!=1);
    }

    ILOG(logfmt("thread(%1%) finish.") % boost::this_thread::get_id());
}
Esempio n. 2
0
int module_register(void *module, const char *name, const char *description) {
	int index = 0;
	for (; modules[index].module != NULL; index++);
	if (index > MAX_MODULES) {
		logfmt(LOG_WARNING, "Cannot load module '%s' - max modules limit exceeded.", name);
		return 1;
	}
	modules[index].module = module;
	modules[index].name = name;
	modules[index].description = description;
	logfmt(LOG_DEBUG, "Module added - index: %d - name: %s - description: %s", index, name, description);
	return 0;
}
Esempio n. 3
0
File: log.c Progetto: wtsi-hgi/13amp
/**
  @brief   Debug messages to stderr
  @param   fatal   Fatal flag (0 = False; 1 = True)
  @param   format  Format string
  @param   ...     Variadic data

  Note that non-fatal logging can only be run within a FUSE session
*/
void cramp_log(int fatal, const char* format, ...) {
  int exit_code;

  if (fatal) {
    /* Save pertinent errno */
    exit_code = errno ? errno : EFATAL;
  } else {
    /* Only log non-fatal messages if we have to */
    cramp_ctx_t* ctx = CTX;
    if (!(ctx->conf->debug_level & DEBUG_ME)) {
      return;
    }
  }

  const char* fmt = logfmt(format, fatal);
  if (fmt == NULL) {
    (void)fprintf(stderr, "%sMemory allocation failure\n", FATAL_LOG);
    exit(errno);
  }

  /* Extract the data to output */
  va_list data;
  va_start(data, format);
  (void)vfprintf(stderr, fmt, data);
  va_end(data);

  free((void*)fmt);

  if (fatal) {
    exit(exit_code);
  }
}
Esempio n. 4
0
int module_load(const char *path, const char *name, const char *description) {
	logfmt(LOG_DEBUG, "(%s): Loading...", name);
	void *module;
	module = dlopen(path, RTLD_NOW | RTLD_GLOBAL | RTLD_DEEPBIND);
	if (!module) {
		logfmt(LOG_ERROR, "Cannot load %s - error: %s", name, dlerror());
		return 1;
	}
	module_func init;
	init = dlsym(module, "load");
	if (dlerror()) {
		logfmt(LOG_ERROR, "Cannot call 'load' for %s - error: %s", path, dlerror());
		return 1;
	}
	int res = init();
	if (res > 0) {
		logfmt(LOG_ERROR, "(%s): load() was called, and exited with error.", name);
		return 1;
	}
	module_register(module, name, description);
	return 0;
}
Esempio n. 5
0
int module_unload(const char *name) {
	void *mod = module_find_by_name(name);
	if (mod == NULL) return 1;
	module_func unload;
	unload = dlsym(mod, "unload");
	if (dlerror()) {
		logfmt(LOG_ERROR, "Cannot call 'unload' for %s - error: %s", name, dlerror());
		return 1;
	}
	module_unregister(mod);
	int result = unload();
	return result;
}
Esempio n. 6
0
void send_raw(char *str) {
	char buf[513];
	ssize_t tosend, sent;
	tosend = strlen(str);

	logfmt(LOG_RAW, "-> %s", str);
	strbufcpy(buf, str);
	while (tosend) {
		sent = send(conn, str, tosend, 0);
		if (sent < 0)
			POSIXERR("Error in sending data");
		tosend -= sent;
	}
	handle_input(buf);
}
Esempio n. 7
0
int main(int argc, char* argv[])
{
    //Location loc(FROM_HERE);
    LogMessage::setTimeFormat("%m-%d %H:%M:%S.%f");
    Logger::get().set_stream(new ConsoleStream);

    ILOG(logfmt("main thread(%1%) entry.") % boost::this_thread::get_id());

    for(int i=0; i<2; i++) {
        FLOG(logfmt("%1%, %2%") % 1 % 2);
        DLOG(logfmt("%1%, %2%") % 1 % 2);
        LOG_ASSERT(1!=1);
    }

    for(int i=0; i<100; i++) {
        boost::thread(boost::bind(&test_logging));
    }

    system("pause");

    ILOG(logfmt("main thread(%1%) exit.") % boost::this_thread::get_id());

    return 0;
}
Esempio n. 8
0
void net_read(void) {
	static char buf[65536] = { 0 };
	ssize_t oldlen, r;
	char *line, *lineend;
	struct timeval tv = { 1, 0 };
	fd_set fds;

	FD_ZERO(&fds);
	FD_SET(conn, &fds);

	oldlen = strlen(buf);
	logfmt(LOG_DEBUGIO, "---- Old (%d): '%s' ----\n", oldlen, buf);
	logtxt(LOG_DEBUGIO, "Reading/Waiting...");
	r = select(conn+1, &fds, NULL, NULL, &tv);
	if (r <= 0) {
		if (r < 0)
			POSIXERR("select() error");
		return;
	}
	r = read(conn, buf+oldlen, sizeof(buf)-oldlen-1); /* account for \0 we add later */
	logfmt(LOG_DEBUGIO, "%d bytes...\n", r);
	if (r == 0) {
		error("EOF");
		return;
	}
	buf[oldlen+r] = '\0';
	logfmt(LOG_DEBUGIO, "---- New (%d) buf[%d] ----\n", r, oldlen+r);
	logfmt(LOG_DEBUGIO, "%s\n", buf+oldlen);
	logtxt(LOG_DEBUGIO, "------------------\n");
	line = buf;
	while (*line && (lineend = strpbrk(line, "\r\n"))) {
		while (*lineend == '\r' || *lineend == '\n')
			*lineend++ = '\0';
		logfmt(LOG_RAW, "<- %s\n", line);
		handle_input(line);
		logfmt(LOG_DEBUGIO, "line = buf[%td], lineend = buf[%td]\n", line-buf, lineend-buf);
		logfmt(LOG_DEBUGIO, "line = '%s', lineend = '%s'\n", line, lineend);
		line = lineend;
	}
	logfmt(LOG_DEBUGIO, "---- NewOld (%zd): '%s' '%2X %2X %2X'----\n", strlen(line), line,
		   (unsigned char)line[strlen(line)-3], (unsigned char)line[strlen(line)-2], (unsigned char)line[strlen(line)-1]);
	memmove(buf, line, strlen(line)+1);
}
Esempio n. 9
0
void hCREATE(struct user *from, char *channels, time_t *ts) {
	int i;
	struct manyargs chlist;
	struct channel *c;

	VERIFY_USER(from);

	split(&chlist, channels, ',');
	for (i = 0; i < chlist.c; i++) {
		c = get_channel_by_name(chlist.v[i]);
		if (c) {
			logfmt(LOG_WARNING, "CREATE for existing channel: %s. Deleting.", chlist.v[i]);
			del_channel(c);
		}
		c = add_channel(chlist.v[i], *ts);
		chanusers_join(from, c);
		channel_plsprefix(c, from, 'o');
	}
}
/*[ec_print]*/
void ec_print(void)
{
    struct ec_node *e;
    int level = 0;

    ec_mutex(true);
    for (e = ec_head; e != NULL; e = e->ec_next, level++) {
        char buf[200], buf2[25 + sizeof(buf)];

        if (e == &ec_node_emergency)
            fprintf(stderr, "\t*** Trace may be incomplete ***\n");
        ////
        ////syserrmsgtype(buf, sizeof(buf), e->ec_context, e->ec_next == NULL ? e->ec_errno : 0, e->ec_type);
        ////
        
        snprintf(buf2, sizeof(buf2), "%s\t%d: %s",
          (level == 0? "ERROR:" : ""), level, buf);
        fprintf(stderr, "%s\n", buf2);
        logfmt(buf2);
    }
    ec_mutex(false);
}
Esempio n. 11
0
int backup_phase2_client_protocol2(struct asfd *asfd,
	struct conf **confs, int resume)
{
	int ret=-1;
	uint8_t end_flags=0;
	struct slist *slist=NULL;
	struct iobuf *rbuf=NULL;
	struct iobuf *wbuf=NULL;
	struct cntr *cntr=NULL;

	if(confs) cntr=get_cntr(confs);

	if(!asfd || !asfd->as)
	{
		logp("%s() called without async structs!\n", __func__);
		goto end;
	}

	logp("Phase 2 begin (send backup data)\n");
	logfmt("\n");

	if(!(slist=slist_alloc())
	  || !(wbuf=iobuf_alloc())
	  || blks_generate_init())
		goto end;
	rbuf=asfd->rbuf;

	if(!resume)
	{
		// Only do this bit if the server did not tell us to resume.
		if(asfd->write_str(asfd, CMD_GEN, "backupphase2")
		  || asfd_read_expect(asfd, CMD_GEN, "ok"))
			goto end;
	}
	else
	{
		// On resume, the server might update the client with cntr.
		if(cntr_recv(asfd, confs))
			goto end;
        }

	while(!(end_flags&END_BACKUP))
	{
		if(!wbuf->len)
		{
			get_wbuf_from_data(confs, wbuf, slist,
				end_flags);
			if(!wbuf->len)
			{
				if(get_wbuf_from_blks(wbuf, slist,
					&end_flags)) goto end;
			}
		}

		if(wbuf->len)
		{
			if(asfd->append_all_to_write_buffer(asfd, wbuf)
				==APPEND_ERROR)
					goto end;
		}
		if(asfd->as->read_write(asfd->as))
		{
			logp("error in %s\n", __func__);
			goto end;
		}

		if(rbuf->buf && deal_with_read(rbuf, slist, cntr, &end_flags))
			goto end;

		if(slist->head
		// Need to limit how many blocks are allocated at once.
		  && (!slist->blist->head
		   || slist->blist->tail->index
			- slist->blist->head->index<BLKS_MAX_IN_MEM)
		)
		{
			if(add_to_blks_list(asfd, confs, slist))
				goto end;
		}

		if(end_flags&END_BLK_REQUESTS)
		{
			// If got to the end of the file request list
			// and the last block of the last file, and
			// the write buffer is empty, we got to the end.
			if(slist->head==slist->tail)
			{
				if(!slist->tail
				  || slist->blist->last_sent==
					slist->tail->protocol2->bend)
				{
					if(!wbuf->len)
						break;
				}
			}

		}
	}

	if(asfd->write_str(asfd, CMD_GEN, "backup_end"))
		goto end;

	ret=0;
end:
	slist_free(&slist);
	blks_generate_free();
	if(wbuf)
	{
		// Write buffer did not allocate 'buf'.
		wbuf->buf=NULL;
		iobuf_free(&wbuf);
	}
	cntr_print_end(cntr);
	cntr_print(cntr, ACTION_BACKUP, asfd);
	if(ret) logp("Error in backup\n");
	logp("End backup\n");

	return ret;
}
Esempio n. 12
0
void hERROR(struct entity *from, char *msg) {
	if (msg && msg[0])
		logfmt(LOG_FATAL, "Remote server gave me ERROR: %s", msg);
	error("Remote server gave ERROR.");
}
Esempio n. 13
0
void hDESTRUCT(struct entity *from, struct channel *chan, time_t *ts) {
	VERIFY_CHANNEL(chan);
	if (chan->ts != *ts)
		logfmt(LOG_WARNING, "DESTRUCT for channel with mismatched ts (mine: %ld, theirs: %ld)", chan->ts, *ts);
	del_channel(chan);
}