Exemplo n.º 1
0
int posix_memalign (void **memptr, size_t align, size_t size)
{
	int ret;

	if (!real_malloc){
		/* for glibc, normally real_malloc should be already initialized */
		lmdbg_startup ();
	}

	if (log_enabled){
		disable_logging ();

		++alloc_count;

		ret = (*real_posix_memalign) (memptr, align, size);
		if (!ret)
			fprintf (log_fd, "posix_memalign ( %u , %u ) --> %p num: %u\n",
					 (unsigned) align, (unsigned) size, *memptr,
					 alloc_count);
		else
			fprintf (log_fd, "posix_memalign ( %u , %u ) --> NULL num: %u\n",
					 (unsigned) align, (unsigned) size,
					 alloc_count);

		log_stacktrace ();

		enable_logging ();
		return ret;
	}else{
		return (*real_posix_memalign) (memptr, align, size);
	}
}
Exemplo n.º 2
0
void * memalign (size_t align, size_t size)
{
	void *p;

	if (!real_malloc){
		/* for glibc, normally real_malloc should be already initialized */
		lmdbg_startup ();
	}

	if (log_enabled){
		disable_logging ();

		++alloc_count;

		p = (*real_memalign) (align, size);
		fprintf (log_fd, "memalign ( %u , %u ) --> %p num: %u\n",
				 (unsigned) align, (unsigned) size, p, alloc_count);
		log_stacktrace ();

		enable_logging ();
		return p;
	}else{
		return (*real_memalign) (align, size);
	}
}
Exemplo n.º 3
0
void free (void *p)
{
	if (!real_malloc){
		/* for glibc, normally real_malloc should be already initialized */
		lmdbg_startup ();
	}

	if (log_enabled){
		disable_logging ();

		++alloc_count;

		(*real_free) (p);
		if (p)
			fprintf (log_fd, "free ( %p ) num: %u\n", p, alloc_count);
		else
			fprintf (log_fd, "free ( NULL ) num: %u\n", alloc_count);

		log_stacktrace ();

		enable_logging ();
	}else{
		(*real_free) (p);
	}
}
Exemplo n.º 4
0
/* On glibc-based systems lmdbg doesn't work with calloc */
void * calloc (size_t number, size_t size)
{
	void *p;

	if (!real_malloc){
		/* for glibc, normally real_malloc should be already initialized */
		lmdbg_startup ();
	}

	if (log_enabled){
		disable_logging ();

		++alloc_count;

		p = (*real_calloc) (number, size);
		if (p)
			fprintf (log_fd, "calloc ( %u , %u ) --> %p num: %u\n",
					 (unsigned) number, (unsigned) size, p, alloc_count);
		else
			fprintf (log_fd, "calloc ( %u , %u ) --> NULL num: %u\n",
					 (unsigned) number, (unsigned) size, alloc_count);

		log_stacktrace ();

		enable_logging ();
		return p;
	}else{
		return (*real_calloc) (number, size);
	}
}
Exemplo n.º 5
0
void * realloc (void *p, size_t s)
{
	void *np;
	char np_buf [100];
	const char *np_ptr = "NULL";

	if (!real_malloc){
		/* for glibc, normally real_malloc should be already initialized */
		lmdbg_startup ();
	}

	if (log_enabled){
		disable_logging ();

		++alloc_count;

		np = (*real_realloc) (p, s);
		if (np){
			snprintf (np_buf, sizeof (np_buf), "%p", np);
			np_ptr = np_buf;
		}

		if (p){
			fprintf (log_fd, "realloc ( %p , %u ) --> %s num: %u\n",
					 p, (unsigned) s, np_ptr, alloc_count);
		}else{
			fprintf (log_fd, "realloc ( NULL , %u ) --> %s num: %u\n",
					 (unsigned) s, np_ptr, alloc_count);
		}

		log_stacktrace ();

		enable_logging ();
		return np;
	}else{
		return (*real_realloc) (p, s);
	}
}
Exemplo n.º 6
0
int AmBasicSipDialog::reply(const AmSipRequest& req,
			    unsigned int  code,
			    const string& reason,
			    const AmMimeBody* body,
			    const string& hdrs,
			    int flags)
{
  TransMap::const_iterator t_it = uas_trans.find(req.cseq);
  if(t_it == uas_trans.end()){
    ERROR("could not find any transaction matching request cseq\n");
    ERROR("request cseq=%i; reply code=%i; callid=%s; local_tag=%s; "
	  "remote_tag=%s\n",
	  req.cseq,code,callid.c_str(),
	  local_tag.c_str(),remote_tag.c_str());
    log_stacktrace(L_ERR);
    return -1;
  }
  DBG("reply: transaction found!\n");
    
  AmSipReply reply;

  reply.code = code;
  reply.reason = reason;
  reply.tt = req.tt;
  if((code > 100) && !(flags & SIP_FLAGS_NOTAG))
    reply.to_tag = ext_local_tag.empty() ? local_tag : ext_local_tag;
  reply.hdrs = hdrs;
  reply.cseq = req.cseq;
  reply.cseq_method = req.method;

  if(body != NULL)
    reply.body = *body;

  if(onTxReply(req,reply,flags)){
    DBG("onTxReply failed\n");
    return -1;
  }

  if (!(flags & SIP_FLAGS_VERBATIM)) {
    // add Signature
    if (AmConfig::Signature.length())
      reply.hdrs += SIP_HDR_COLSP(SIP_HDR_SERVER) + AmConfig::Signature + CRLF;
  }

  if ((code > 100 && code < 300) && !(flags & SIP_FLAGS_NOCONTACT)) {
    /* if 300<=code<400, explicit contact setting should be done */
    reply.contact = getContactHdr();
  }

  int ret = SipCtrlInterface::send(reply,local_tag,logger);
  if(ret){
    ERROR("Could not send reply: code=%i; reason='%s'; method=%s;"
	  " call-id=%s; cseq=%i\n",
	  reply.code,reply.reason.c_str(),reply.cseq_method.c_str(),
	  callid.c_str(),reply.cseq);

    return ret;
  }
  else {
    onReplyTxed(req,reply);
  }

  return ret;
}
Exemplo n.º 7
0
void
signal_handler(int signo)
{
    struct signal *sig;
    void (*action)(void);
    char *actionstr;
    bool done;

    for (sig = signals; sig->signo != 0; sig++) {
        if (sig->signo == signo) {
            break;
        }
    }
    ASSERT(sig->signo != 0);

    actionstr = "";
    action = NULL;
    done = false;

    switch (signo) {
    case SIGUSR1:
        actionstr = ", config reload";
        break;

    case SIGUSR2:
        break;

    case SIGTTIN:
        actionstr = ", up logging level";
        action = log_level_up;
        break;

    case SIGTTOU:
        actionstr = ", down logging level";
        action = log_level_down;
        break;

    case SIGHUP:
        actionstr = ", reopening log file";
        action = log_reopen;
        break;

    case SIGINT:
        done = true;
        actionstr = ", exiting";
        break;

    case SIGSEGV:
        log_stacktrace();
        actionstr = ", core dumping";
        raise(SIGSEGV);
        break;

    default:
        NOT_REACHED();
    }

    log_safe("signal %d (%s) received%s", signo, sig->signame, actionstr);

    if (action != NULL) {
        action();
    }

    if (done) {
        exit(1);
    }

    signal_report_to_channel(signo);
}
Exemplo n.º 8
0
void
signal_handler(int signo)
{
    struct signal *sig;
    void (*action)(void);
    char *actionstr;
    bool done;

    for (sig = signals; sig->signo != 0; sig++) {
        if (sig->signo == signo) {
            break;
        }
    }
    ASSERT(sig->signo != 0);

    actionstr = "";
    action = NULL;
    done = false;

    switch (signo) {
    case SIGUSR1:
#if 1 //shenzheng 2015-3-26 for debug
#ifdef NC_DEBUG_LOG
		actionstr = ", print timeout used msgs";
		action = print_timeout_used_msgs;
#endif
#endif //shenzheng 2015-3-26 for debug
        break;

    case SIGUSR2:
#if 1 //shenzheng 2015-3-26 for debug
#ifdef NC_DEBUG_LOG
		actionstr = ", print used msgs";
		action = print_used_msgs;
#endif
#endif //shenzheng 2015-3-26 for debug
        break;

    case SIGTTIN:
        actionstr = ", up logging level";
        action = log_level_up;
        break;

    case SIGTTOU:
        actionstr = ", down logging level";
        action = log_level_down;
        break;

    case SIGHUP:
        actionstr = ", reopening log file";
        action = log_reopen;
        break;

    case SIGINT:
        done = true;
        actionstr = ", exiting";
        break;

    case SIGSEGV:
        log_stacktrace();
        actionstr = ", core dumping";
        raise(SIGSEGV);
        break;

    default:
        NOT_REACHED();
    }

    log_safe("signal %d (%s) received%s", signo, sig->signame, actionstr);

    if (action != NULL) {
        action();
    }

    if (done) {
        exit(1);
    }
}
Exemplo n.º 9
0
/*------------------------------------------------------------------------------
 |    test_func2
 +-----------------------------------------------------------------------------*/
void test_func2(int i)
{
   (void)i;

   log_stacktrace(LC_LOG_INFO, 90);
}