예제 #1
0
storaged_init(storaged_instance *si){
    connectionadaptorinit(&si->adaptor, 8);

        listenon(&si->adaptor, STORAGED_PORT);

        addpacketoperation(&si->adaptor, STORAGE_PROTO_REQ_UPLOAD_FILE, handle_upload);
	L_DEBUG("add packetoperation on type %u\n", STORAGE_PROTO_REQ_UPLOAD_FILE);
        addpacketoperation(&si->adaptor, STORAGE_PROTO_REQ_DOWNLOAD_FILE, handle_download);
	L_DEBUG("add packetoperation on type %u\n", STORAGE_PROTO_REQ_DOWNLOAD_FILE);

    connectionadaptorstart(&si->adaptor);
}
예제 #2
0
void check_test_string(const char *s, int es, int es2)
{
  int j, k, r;
  uint8_t buf[128];
  char buf2[128];

  L_DEBUG("check_test_string %s => %d => %d", s, es, es2);
  for (j = -1 ; j < es + 2 ; j++)
    {
      buf[j+1] = 42;
      r = escaped2ll(s, j ? buf : NULL, j);
      L_DEBUG("j:%d got %d", j, r);
      sput_fail_unless(buf[j+1] == 42, "canary died");
      if (j < es)
        {
          sput_fail_unless(r < 0, "not error with insufficient buffer");
        }
      else if (r != es)
        {
          sput_fail_unless(false, "wrong result value");
        }
      else
        {
          int or = r;
          for (k = -1 ; k < es2 + 2 ; k++)
            {
              /* Try to re-encode it to buf2. */
              buf2[k+1] = 42;
              r = ll2escaped(NULL, buf, or, k ? buf2 : NULL, k);
              L_DEBUG("k:%d got %d", k, r);
              sput_fail_unless(buf2[k+1] == 42, "canary died");
              if (k < es2)
                {
                  sput_fail_unless(r < 0,
                                   "not error with insufficient buffer");
                }
              else
                {
                  if (r > 0)
                    L_DEBUG("escaped->ll->escaped:'%s'<>'%s'", s, buf2);
                  sput_fail_unless(r == es,
                                   "wrong number of bytes consumed");
                  sput_fail_unless((int)strlen(buf2) == es2 - 1,
                                   "wrong strlen");
                  sput_fail_unless(strncmp(s, buf2, strlen(s)) == 0,
                                   "strncmp fail");

                }
            }
        }
    }
}
예제 #3
0
int handle_lsync(connection *con, uint32_t size, void* data) {
    learner_sync_msg* msg = (learner_sync_msg*)data;
    char ipstr[32];

    acceptor_record* rec;
    int i;
    for(i=0; i<msg->count ;i++){

    	uint32_t instance_id = msg->ids[i];
        //Lookup
        rec = &acc.instance_cache[GET_ACC_INDEX(instance_id)];
    
        //Found record in memory
        if (instance_id == rec->iid) {
            //A value was accepted
            if (rec->value != NULL) {
                L_DEBUG("answering to lsync for instance %d\n", instance_id);
                return send_learn_message(addr2str(ipstr, con->remoteaddr), con->remoteport, rec);
            }
            //No value was accepted
            L_DEBUG("ignoring lsync for instance %d, record present but no value accepted\n", instance_id);
            return 0;
        }
    
        //Record was overwritten in acceptor array
        //We must scan the logfile before answering
        if (instance_id < rec->iid) {
            rec = stablestorage_get_record(instance_id);

            //A record was found, we accepted something
            if (rec != NULL) {
                L_DEBUG("answering to lsync for instance %d [info from disk]\n", instance_id);
                send_learn_message(addr2str(ipstr, con->remoteaddr), con->remoteport, rec);
                free(rec->value);
                free(rec);
            } else {
                //Nothing from disk, nothing accepted
                L_DEBUG("ignoring lsync for instance %d, no value accepted [info from disk]\n", instance_id);
            }
    
            return 0;
        }
    
        //Record not found in acceptor array
        //Nothing was accepted
        L_DEBUG("ignoring lsync for instance %d, no info is available\n", instance_id);
        return 0;

    }

}
예제 #4
0
void DocumentView::connect_file_monitor() {
    if(!file_monitor_) {
        L_DEBUG("Connecting file monitor");
        file_monitor_ = file_->monitor_file();
        file_monitor_->signal_changed().connect(sigc::mem_fun(this, &DocumentView::file_changed));
    }
}
예제 #5
0
void DocumentView::disconnect_file_monitor() {
    if(file_monitor_) {
        L_DEBUG("Disconnecting existing file monitor");
        file_monitor_->cancel();
        file_monitor_.reset();
    }
}
예제 #6
0
void IdleTaskManager::execute() {
    {
        //FIXME: If (*it).second tries to queue on idle this will deadlock
        std::lock_guard<std::mutex> lock(signals_mutex_);
        for(auto it = signals_.begin(); it != signals_.end();) {
            bool result = (*it).second();
            if(!result) {
                L_DEBUG("Idle task returned false. Removing.");
                it = signals_.erase(it);
            } else {
                ++it;
            }
        }
    }

    SignalOnceMap to_iter; //Create an empty map
    {
        //Lock the signals once mutex and then swap to clear
        std::lock_guard<std::mutex> lock(signals_once_mutex_);
        std::swap(to_iter, signals_once_);
    }

    //Iterate over the copy
    for(auto p: to_iter) {
        p.second();
    }

    cv_.notify_all(); //Unblock any threads waiting
}
예제 #7
0
파일: test_dummy.c 프로젝트: dtaht/hnetd
void sample(void)
{
  int r;

  L_DEBUG("debug");
  L_INFO("info");
  L_NOTICE("notice");
  L_WARN("warn");
  L_ERR("err");

  sput_fail_if(0, "0 isn't false!");
  sput_fail_unless(1, "1 isn't true!");

  /* Play with smock */
  sput_fail_unless(smock_empty(), "smock empty");
  smock_push_int("in", 1);
  sput_fail_unless(!smock_empty(), "smock not empty");
  smock_push_int("out", 2);
  smock_push_int("in", 3);
  smock_push_int("out", 6);
  r = dummy_callback(1);
  sput_fail_unless(r == 2, "dummy_callback broken");
  r = dummy_callback(3);
  sput_fail_unless(r == 6, "dummy_callback broken");
  /* In the end, we should be again gone. */
  sput_fail_unless(smock_empty(), "smock empty");
}
예제 #8
0
void DocumentView::save(const unicode& path) {
    L_DEBUG("Saving file: " + path.encode());
    trim_trailing_newlines();
    trim_trailing_whitespace();

    Glib::ustring text = buffer()->get_text();

    if(file_->get_path() == path.encode()) {
        //FIXME: Use entity tag arguments to make sure that the file
        //didn't change since the last time we saved
        file_->replace_contents(std::string(text.c_str()), "", file_etag_);
        connect_file_monitor();
    } else {
        auto file = Gio::File::create_for_path(path.encode());
        if(!os::path::exists(path)) {
            file->create_file();
        }
        file->replace_contents(text, "", file_etag_);
        connect_file_monitor();
    }

    buffer()->set_modified(false);

    apply_settings(guess_mimetype()); //Make sure we update the settings when we've saved the file

    window_.rebuild_open_list();
    run_linters_and_stuff();
}
예제 #9
0
void Task::init()
{
  L_FUNC("");

  L_INFO("+++ test Logger");
  L_FATAL("L_FATAL");
  L_ERROR("L_ERROR");
  L_WARN("L_WARN");
  L_INFO("L_INFO");
  L_DEBUG("L_DEBUG");
  L_INFO("--- test Logger");

  L_INFO(QString()); // --> "?"
  L_INFO(" \n Trimmed \n\n"); // --> whitespace removed from start and end
  L_INFO("UTF-8 Unicode text: äöü àéè");

  QString formattedOutput1 = "JSON output 1:\n"
    "{\n"
    "  \"firstName\": \"Mario\",\n"
    "  \"age\": 44\n"
    "}"
  ;
  L_INFO(formattedOutput1);

  QString formattedOutput2 = "{<br>  \"firstName\": \"Mario\",<br>  \"age\": 44<br>}";
  L_INFO(formattedOutput2.prepend("JSON output 2:<br>").replace("<br>", "\n"));

  QTimer::singleShot(1000, this, SLOT(slotRun()));
  QTimer::singleShot(1000, this, SLOT(slotRun()));
  QTimer::singleShot(3000, this, SLOT(slotRun()));
  QTimer::singleShot(6000, this, SLOT(theEnd()));
}
예제 #10
0
void FindBar::on_document_switched(DocumentView& buffer)  {
    //Create the buffer tag if necessary
    if(!buffer.buffer()->get_tag_table()->lookup(SEARCH_HIGHLIGHT_TAG)) {
        L_DEBUG("Creating search highlight tag");
        auto tag = buffer.buffer()->create_tag (SEARCH_HIGHLIGHT_TAG);
        tag->property_background() = "#1EBCFF";
    }
}
예제 #11
0
파일: logger.c 프로젝트: gencer/memcached
/* Called with logger stack locked.
 * Releases every chunk associated with a watcher and closes the connection.
 * We can't presently send a connection back to the worker for further
 * processing.
 */
static void logger_thread_close_watcher(logger_watcher *w) {
    L_DEBUG("LOGGER: Closing dead watcher\n");
    watchers[w->id] = NULL;
    sidethread_conn_close(w->c);
    watcher_count--;
    bipbuf_free(w->buf);
    free(w);
    logger_set_flags();
}
예제 #12
0
파일: logger.c 프로젝트: gencer/memcached
/* Writes flattened entry to available watchers */
static void logger_thread_write_entry(logentry *e, struct logger_stats *ls,
        char *scratch, int scratch_len) {
    int x, total;
    /* Write the line into available watchers with matching flags */
    for (x = 0; x < WATCHER_LIMIT; x++) {
        logger_watcher *w = watchers[x];
        char *skip_scr = NULL;
        if (w == NULL || (e->eflags & w->eflags) == 0)
            continue;

         /* Avoid poll()'ing constantly when buffer is full by resetting a
         * flag periodically.
         */
        while (!w->failed_flush &&
                (skip_scr = (char *) bipbuf_request(w->buf, scratch_len + 128)) == NULL) {
            if (logger_thread_poll_watchers(0, x) <= 0) {
                L_DEBUG("LOGGER: Watcher had no free space for line of size (%d)\n", scratch_len + 128);
                w->failed_flush = true;
            }
        }

        if (w->failed_flush) {
            L_DEBUG("LOGGER: Fast skipped for watcher [%d] due to failed_flush\n", w->sfd);
            w->skipped++;
            ls->watcher_skipped++;
            continue;
        }

        if (w->skipped > 0) {
            total = snprintf(skip_scr, 128, "skipped=%llu\n", (unsigned long long) w->skipped);
            if (total >= 128 || total <= 0) {
                L_DEBUG("LOGGER: Failed to flatten skipped message into watcher [%d]\n", w->sfd);
                w->skipped++;
                ls->watcher_skipped++;
                continue;
            }
            bipbuf_push(w->buf, total);
            w->skipped = 0;
        }
        /* Can't fail because bipbuf_request succeeded. */
        bipbuf_offer(w->buf, (unsigned char *) scratch, scratch_len);
        ls->watcher_sent++;
    }
}
예제 #13
0
void DocumentView::run_linters_and_stuff(bool force) {
    L_DEBUG("DocumentView::run_linters_and_stuff");

    if(!force && window().current_buffer().get() != this) {
        //Only run linters on the active document
        L_DEBUG("Document is not active, not running");
        return;
    }

    L_DEBUG("Detecting language");
    apply_language_to_buffer(guess_language_from_file(file_));

    L_DEBUG("Applying settings");
    apply_settings(guess_mimetype()); //Make sure we update the settings when we've reloaded the file

    //Check for coverage stats
    auto language = buffer()->get_language();
    unicode name = (language) ? unicode(language->get_name()) : "";
    if(name == "Python") {
        if(!coverage_) {
            std::cout << "COVERAGE: Creating coverage" << std::endl;
            coverage_ = std::make_shared<coverage::PythonCoverage>();
            //Connect to the coverage updated signal and re-run this function if that happens
            coverage_->signal_coverage_updated().connect(std::bind(&DocumentView::run_linters_and_stuff, this, false));
        }
        coverage_->apply_to_document(this);

        linter_ = std::make_shared<linter::PythonLinter>();
        linter_->apply_to_document(this);
    } else if(name == "JavaScript") {
        linter_ = std::make_shared<linter::JavascriptLinter>();
        linter_->apply_to_document(this);
    } else {
        if(coverage_) {
           coverage_->clear_document(this);
           coverage_.reset();
        }

        if(linter_) {
           linter_->clear_document(this);
           linter_.reset();
        }
    }
}
예제 #14
0
static inline char* concatpath(char* realpath, char* path_ptr, size_t filename_len){
	if(scontent_len + filename_len >= MAX_STORAGED_PATH_LEN){
		L_DEBUG("filename to long");
		return NULL;
	}	
	memcpy(realpath, scontent, scontent_len);
	memcpy(&realpath[scontent_len], path_ptr, filename_len);
	realpath[scontent_len + filename_len] = '\0';
	return realpath;
}
예제 #15
0
int handle_upload(connection *con, uint32_t size, void* data) {
	uploadfilemsg_req *msg = (uploadfilemsg_req*)data;

	//cat & validate filename
	char realpath[MAX_STORAGED_PATH_LEN+1];
	assert(NULL != concatpath(realpath, msg->data, msg->filename_len));

	char *err;
        bool r = isvalidfile(&realpath[scontent_len], &err);
	if(!r){
		L_DEBUG("refuse invalid filename");
		return false;
	}
	
	L_DEBUG("recv upload file req %s\n", realpath);
	//lock file then write
	lockfile(realpath, scontent_len + msg->filename_len);
	
	//TODO
	assert(true == mkdirs(realpath));
	int fd = open(realpath ,O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
	//TODO deal with write result
	int w_len = write(fd, (void*)&msg->data[msg->filename_len], msg->data_len);
	fsync(fd);
	close(fd);

	unlockfile(realpath, scontent_len + msg->filename_len);
	

	//send res packet
	int rp_size =msg->filename_len + uploadfilemsg_res_packetsize;
	packet_header *head = generatebuffer(rp_size, CLIENT_PROTO_RES_UPLOAD_FILE);
	//TODO
	assert(NULL != head);
	uploadfilemsg_res *rp = (uploadfilemsg_res *)head->data;
	rp->filename_len = msg->filename_len;
	//TODO define result value
	rp->result = 0;
	memcpy(rp->data, msg->data, msg->filename_len);
	//TODO deal with send result
	sendpacket(con, head);
}
예제 #16
0
void IdleTaskManager::execute() {
    std::map<ConnectionID, std::tr1::function<bool ()> > signals = signals_;
    
    std::map<ConnectionID, std::tr1::function<bool ()> >::iterator it = signals.begin();
    
    for(; it != signals.end(); ++it) {
        L_DEBUG("Executing idle task");
        bool result = (*it).second();
        if(!result) {
            L_DEBUG("Idle task returned false. Removing.");
            signals_.erase((*it).first);
        }
    }
    
    for(std::pair<ConnectionID, std::tr1::function<void ()> > p: signals_once_) {
        L_DEBUG("Executing one-off idle task");
        p.second();
    }
    signals_once_.clear();
}
예제 #17
0
void ResourceManagerImpl::update() {
    static datetime::DateTime last_collection = datetime::now();

    if(datetime::timedelta_in_seconds(datetime::now() - last_collection) >= 5) {
        //Garbage collect all the things
        L_DEBUG("Collecting meshes");
        MeshManager::garbage_collect();

        L_DEBUG("Collecting materials");
        MaterialManager::garbage_collect();

        L_DEBUG("Collecting textures");
        TextureManager::garbage_collect();

        L_DEBUG("Collecting sounds");
        SoundManager::garbage_collect();

        last_collection = datetime::now();
    }
}
예제 #18
0
int handle_download(connection *con, uint32_t size, void* data) {
	downloadfilemsg_req *msg = (downloadfilemsg_req *)data;
	
	//cat & validate filename
	char realpath[MAX_STORAGED_PATH_LEN+1];
	assert(NULL != concatpath(realpath, msg->data, msg->filename_len));

	char *err;
        bool r = isvalidfile(&realpath[scontent_len],&err);
	if(!r){
		L_DEBUG("refuse invalid filename");
		return false;
	}

	L_DEBUG("recv download file req %s\n", realpath);
	//get file length
	lockfile(realpath, scontent_len + msg->filename_len);
	int fd = open(realpath ,O_RDONLY);
	int rpdata_len = lseek(fd, 0, SEEK_END);
	//TODO
	assert(rpdata_len >= 0);

	//send res packet
	int rp_size =rpdata_len + downloadfilemsg_res_packetsize;
	packet_header *head = generatebuffer(rp_size, CLIENT_PROTO_RES_DOWNLOAD_FILE);
	//TODO
        assert(NULL != head);
	uploadfilemsg_res *rp = (downloadfilemsg_res *)head->data;
	rp->filename_len = msg->filename_len;
	memcpy(rp->data, msg->data, msg->filename_len);

	int r_len = read(fd, (void *)&rp->data[msg->filename_len], rpdata_len);	
	//TODO
	assert(r_len >= 0);
	close(fd);

	//TODO deal with send result
        sendpacket(con, head);

	unlockfile(realpath, scontent_len + msg->filename_len);
}
예제 #19
0
파일: pa_timer.c 프로젝트: dtaht/hnetd
void pa_timer_init(struct pa_timer *t, void (*cb)(struct pa_timer *), const char *name)
{
	L_DEBUG("Initialize timer %s", name);
	t->t.pending = false;
	t->t.cb = pa_timer_cb;
	t->enabled = false;
	t->cb = cb;
	t->when = -1;
	t->name = name;
	t->min_delay = 0;
	t->not_before = 0;
}
예제 #20
0
파일: pedcnf.cpp 프로젝트: yp/reHCstar
bool
pedcnf_t::is_satisfying_assignment() const {
  L_DEBUG("Checking if value assignment satisfies the or-clauses...");
  MY_ASSERT_DBG( _vars.size() == _vals.size() );
  bool ris= true;
  BOOST_FOREACH(const clause_t& clause, _clauses) {
	 if (ris) {
		bool intris= false;
		BOOST_FOREACH(const lit_t& var, clause) {
		  MY_ASSERT( var != 0 );
		  MY_ASSERT( (size_t)abs(var) <= _vars.size() );
		  if (var>0) {
			 intris= intris || _vals[var-1];
		  } else {
			 intris= intris || !_vals[-var-1];
		  }
		}
		if (!intris) {
		  L_DEBUG("Clause " << tostr(clause) << " is not satisfied.");
		}
		ris= ris && intris;
	 }
  }
예제 #21
0
파일: io.c 프로젝트: dot-Sean/ohybridproxy
/* Stop processing a query; if it returns false, it killed it's friends too. */
bool io_query_stop(io_query q)
{
  if (q->stopped)
    return true;
  L_DEBUG("io_query_stop %s", q->query);
  q->stopped = true;
  b_query_stop(q);
  if (!(--q->request->running))
    {
      cache_entry_completed(q->request->e);
      return false;
    }
  return true;
}
예제 #22
0
파일: hncp_io.c 프로젝트: dtaht/hnetd
ssize_t hncp_io_recvfrom(hncp o, void *buf, size_t len,
                         char *ifname,
                         struct in6_addr *src,
                         struct in6_addr *dst)
{
  struct sockaddr_in6 srcsa;
  struct iovec iov = {buf, len};
  unsigned char cmsg_buf[256];
  struct msghdr msg = {&srcsa, sizeof(srcsa), &iov, 1,
                       cmsg_buf, sizeof(cmsg_buf), 0};
  ssize_t l;
  struct cmsghdr *h;
  struct in6_pktinfo *ipi6;

  l = recvmsg(o->udp_socket, &msg, MSG_DONTWAIT);
  if (l > 0)
    {
      *ifname = 0;
      *src = srcsa.sin6_addr;
      for (h = CMSG_FIRSTHDR(&msg); h ;
           h = CMSG_NXTHDR(&msg, h))
        if (h->cmsg_level == IPPROTO_IPV6
            && h->cmsg_type == IPV6_PKTINFO)
          {
            ipi6 = (struct in6_pktinfo *)CMSG_DATA(h);
            if (!if_indextoname(ipi6->ipi6_ifindex, ifname))
              {
                *ifname = 0;
                L_ERR("unable to receive - if_indextoname:%s",
                      strerror(errno));
              }
            *dst = ipi6->ipi6_addr;
          }
      if (!*ifname)
        {
          L_ERR("unable to receive - no ifname");
          return -1;
        }
    }
  else
    {
      *ifname = 0;
      if (l < 0 && errno != EWOULDBLOCK)
        {
          L_DEBUG("unable to receive - recvmsg:%s", strerror(errno));
        }
    }
  return l;
}
예제 #23
0
int acceptor_init(int id, acceptor_instance *acc) {

    L_DEBUG("Acceptor starting, self=%d, acceptors:%d, majority:%d\n", id, N_OF_ACCEPTORS, N_OF_MAJORITY);


    connectionadaptorinit(&acc->adaptor, 8);

        listenon(&acc->adaptor, PAXOS_ACCEPTORS_PORT);
	
        addpacketoperation(&acc->adaptor, prepare_reqs, handle_prepare);
        addpacketoperation(&acc->adaptor, accept_reqs, handle_accept);
        addpacketoperation(&acc->adaptor, repeat_reqs, handle_lsync);

    connectionadaptorstart(&acc->adaptor);
}
예제 #24
0
파일: logger.c 프로젝트: gencer/memcached
/* Reads a particular worker thread's available bipbuf bytes. Parses each log
 * entry into the watcher buffers.
 */
static int logger_thread_read(logger *l, struct logger_stats *ls) {
    unsigned int size;
    unsigned int pos = 0;
    unsigned char *data;
    char scratch[LOGGER_PARSE_SCRATCH];
    logentry *e;
    pthread_mutex_lock(&l->mutex);
    data = bipbuf_peek_all(l->buf, &size);
    pthread_mutex_unlock(&l->mutex);

    if (data == NULL) {
        return 0;
    }
    L_DEBUG("LOGGER: Got %d bytes from bipbuffer\n", size);

    /* parse buffer */
    while (pos < size && watcher_count > 0) {
        enum logger_parse_entry_ret ret;
        int scratch_len = 0;
        e = (logentry *) (data + pos);
        ret = logger_thread_parse_entry(e, ls, scratch, &scratch_len);
        if (ret != LOGGER_PARSE_ENTRY_OK) {
            /* TODO: stats counter */
            fprintf(stderr, "LOGGER: Failed to parse log entry\n");
        } else {
            logger_thread_write_entry(e, ls, scratch, scratch_len);
        }
        pos += sizeof(logentry) + e->size;
    }
    assert(pos <= size);

    pthread_mutex_lock(&l->mutex);
    data = bipbuf_poll(l->buf, size);
    ls->worker_written += l->written;
    ls->worker_dropped += l->dropped;
    l->written = 0;
    l->dropped = 0;
    pthread_mutex_unlock(&l->mutex);
    if (data == NULL) {
        fprintf(stderr, "LOGGER: unexpectedly couldn't advance buf pointer\n");
        assert(0);
    }
    return size; /* maybe the count of objects iterated? */
}
예제 #25
0
void DocumentView::handle_file_deleted() {
    L_DEBUG("Processing deleted file");

    if(!os::path::exists(path())) {
        Gtk::MessageDialog dialog(window_._gtk_window(), "File Deleted", true, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO, true);
        dialog.set_message(_u("The file <i>{0}</i> has been deleted").format(name()).encode(), true);
        dialog.set_secondary_text("Do you want to close this file?");
        int response = dialog.run();
        switch(response) {
            case Gtk::RESPONSE_YES:
                close();
            break;
            case Gtk::RESPONSE_NO:
                //If they didn't want to close the file, mark this file as modified from on disk
                buffer()->set_modified(true);
            break;
            default:
                return;
        }
    }
}
예제 #26
0
void check_test_ipv6(void)
{
  int i;
  struct in6_addr a;
  char tbuf[DNS_MAX_ESCAPED_LEN];
  const char *s;

  for (i = 0 ; (s=test_ipv6_strings[i]) ; i++)
    {
      L_DEBUG("iteration #%d: %s", i, s);
      if (escaped2ipv6(s, &a))
        {
          sput_fail_unless(i == 0, "_first_ succeeds");
          ipv62escaped(&a, tbuf);
          sput_fail_unless(strcmp(s, tbuf) == 0, "ipv62escaped failed");
        }
      else
        {
          sput_fail_unless(i != 0, "non-first fails");
        }
    }
}
예제 #27
0
파일: logger.c 프로젝트: gencer/memcached
/* called *from* the thread using a logger.
 * initializes the per-thread bipbuf, links it into the list of loggers
 */
logger *logger_create(void) {
    L_DEBUG("LOGGER: Creating and linking new logger instance\n");
    logger *l = calloc(1, sizeof(logger));
    if (l == NULL) {
        return NULL;
    }

    l->buf = bipbuf_new(settings.logger_buf_size);
    if (l->buf == NULL) {
        free(l);
        return NULL;
    }

    l->entry_map = default_entries;

    pthread_mutex_init(&l->mutex, NULL);
    pthread_setspecific(logger_key, l);

    /* add to list of loggers */
    logger_link_q(l);
    return l;
}
예제 #28
0
파일: logger.c 프로젝트: gencer/memcached
/* Primary logger thread routine */
static void *logger_thread(void *arg) {
    useconds_t to_sleep = MIN_LOGGER_SLEEP;
    L_DEBUG("LOGGER: Starting logger thread\n");
    while (do_run_logger_thread) {
        int found_logs = 0;
        logger *l;
        struct logger_stats ls;
        memset(&ls, 0, sizeof(struct logger_stats));

        /* only sleep if we're *above* the minimum */
        if (to_sleep > MIN_LOGGER_SLEEP)
            usleep(to_sleep);

        /* Call function to iterate each logger. */
        pthread_mutex_lock(&logger_stack_lock);
        for (l = logger_stack_head; l != NULL; l=l->next) {
            /* lock logger, call function to manipulate it */
            found_logs += logger_thread_read(l, &ls);
        }

        logger_thread_poll_watchers(1, WATCHER_ALL);
        pthread_mutex_unlock(&logger_stack_lock);

        /* TODO: abstract into a function and share with lru_crawler */
        if (!found_logs) {
            if (to_sleep < MAX_LOGGER_SLEEP)
                to_sleep += to_sleep / 8;
            if (to_sleep > MAX_LOGGER_SLEEP)
                to_sleep = MAX_LOGGER_SLEEP;
        } else {
            to_sleep /= 2;
            if (to_sleep < MIN_LOGGER_SLEEP)
                to_sleep = MIN_LOGGER_SLEEP;
        }
        logger_thread_sum_stats(&ls);
    }

    return NULL;
}
예제 #29
0
Dialog::Dialog(QWidget *parent)
  : QDialog(parent)
  , ui(new Ui::Dialog)
{
  L_FUNC("");
  // qDebug("Dialog::Dialog");
  ui->setupUi(this);

  EventLog *eventLog = new EventLog(this);
  QObject::connect(eventLog, SIGNAL(eventInfo(const QString&)), this, SLOT(eventInfo(const QString&)), Qt::QueuedConnection); // Qt::QueuedConnection: Qt 5.4.x Debian
  installEventFilter(eventLog);

  L_INFO("+++ test Logger");
  L_FATAL("L_FATAL");
  L_ERROR("L_ERROR");
  L_WARN("L_WARN");
  L_NOTE("L_NOTE");
  L_INFO("L_INFO");
  L_DEBUG("L_DEBUG");
  L_INFO("--- test Logger");

  L_NOTE("Start");
}
예제 #30
0
void DocumentView::close() {
    //Display a prompt encourage saving unless the file is new and empty
    if(buffer() && buffer()->get_modified() && !(is_new_file() && buffer_->get_text().size() == 0)) {
        Gtk::MessageDialog dialog(window_._gtk_window(), "Do you want to save your work?", true, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO, true);
        dialog.set_message(_u("The file <i>{0}</i> has been changed since it was last saved.").format(name()).encode(), true);
        dialog.set_secondary_text("Do you want to save the file?");
        int response = dialog.run();
        switch(response) {
            case Gtk::RESPONSE_YES: {
                bool was_saved = window_.toolbutton_save_clicked();
                if(!was_saved) {
                    L_DEBUG("User cancelled saving a file, so we won't close the buffer");
                    return;
                }
            }
            break;
            default:
                break;
        }
    }

    disconnect_file_monitor();
    signal_closed_(*this);
}