Exemple #1
0
static int rotate(const char *name)
{
	int fd;
	int i;
	char buf[PATH_MAX];
	char buf2[PATH_MAX];

	fd = open(LOG_DIR, O_RDONLY);
	if(fd < 0) {
		/* No log directory, so there's nothing to rotate. */
		return 0;
	}

	if(get_log(name, buf, PATH_MAX, NUM_LOGS-1) < 0)
		return -1;
	if(unlinkat(fd, buf, 0) < 0) {
		if(errno != ENOENT) {
			perror(buf);
			fprintf(stderr, "tup error: Unable to unlink log file: %s\n", buf);
			return -1;
		}
	}
	for(i=NUM_LOGS-1; i>0; i--) {
		get_log(name, buf, PATH_MAX, i);
		get_log(name, buf2, PATH_MAX, i-1);
		if(renameat(fd, buf2, fd, buf) < 0) {
			if(errno != ENOENT) {
				perror("renameat");
				fprintf(stderr, "tup error: Unable to rotate logs.\n");
				return -1;
			}
		}
	}
	return 0;
}
Exemple #2
0
uint8_t octet_ops::product(uint8_t u, uint8_t v)
{
    if (u == 0 || v == 0) {
        return 0;
    }
    return (uint8_t)get_exp(get_log(u) + get_log(v));
}
Exemple #3
0
uint8_t octet_ops::division(uint8_t u, uint8_t v)
{
    if (v == 0) {
        throw std::invalid_argument("Denominator cannot be 0.");
    }
    if (u == 0) {
        return 0;
    }
    return (uint8_t)get_exp((get_log(u) - get_log(v)) + 255);
}
Exemple #4
0
IDX_T pantech_logfile_get_prev_log( IDX_T idx, char* log_buf )
{
    if( g_head.inited_ == FALSE || idx == NULL_IDX )
    {
        return NULL_IDX;
    }

    if( g_head.prev_[ idx ] == NULL_IDX )
    {
        idx         = g_head.tail_;
        g_head.pos_ = g_head.count_ - 1;
    }
    else
    {
        idx = g_head.prev_[ idx ];
        g_head.pos_--;
    }

    if( get_log( idx, log_buf ) == FALSE )
    {
        return NULL_IDX;
    }

    return idx;
}
Exemple #5
0
bool GLShaderImpl::Recompile() {
  if (!m_need_recompile)
    return false;
  m_need_recompile = false;

  if (fs::exists(m_shader_filename) && fs::is_regular(m_shader_filename)) {
    if (!CompileSourceFile(m_shader_filename)) {
#ifndef GL_ES
      ShaderErrorDialog::ShowErrors(m_shader_filename,
                                    QString::fromStdString(get_log()));
#endif
      return false;
    } else {
#ifndef GL_ES
      ShaderErrorDialog::ShowErrors(m_shader_filename, QString(""));
#endif
      return true;
    }
  } else {
#ifndef GL_ES
    ShaderErrorDialog::ShowErrors(m_shader_filename,
                                  QString("File %1 doesn't exists ").arg(
                                      QString::fromStdString(m_shader_filename)));
#endif
    return false;
  }
}
void HuffmanEncoder::encode(dict d)
{
	ofstream out;
	out.open((path + ".ashf").c_str());

	vector < Code > word_concat;
	for (int i = 0; i < d.size(); i++)
	{
		if (d[i].c.q == -1 || d[i].c.r == -1)
			continue;
		word_concat.push_back(d[i].c);
	}

	// coding of min(i1, i2)
	vector < string > r_s;
	int k = 0;
	for (int i = 0; i < word_concat.size(); i++)
	{
		int q_log = get_log(word_concat[i].q);
		string kemp = "";
		for (int i = 0; i <= q_log; i++)
		{
			kemp += (1 << i) & word_concat[i].r ? "1" : "0";
		}
		reverse(kemp.begin(), kemp.end());
		r_s.push_back(kemp);

		int r = word_concat[i].q;
		word_concat[i].q -= k;
		k = r;
	}

	root = build_tree(word_concat);
	get_codes(root);
	print_tree(root);

	string long_string = "";
	int q = 0;
	for (int i = 0; i < word_concat.size(); i++)
	{
		string tempor = get_code(word_concat[i].q) + r_s[i] + (word_concat[i].d == true ? "1" : "0");
		long_string = long_string + tempor;
	}

	int l_str_size = long_string.size();
	int cur_p = 0;
	while (cur_p < l_str_size)
	{
		unsigned char c = 0;
		for (int i = 0; i < min(8, l_str_size - cur_p); i++)
		{
			int t = long_string[i + cur_p] == '0' ? 0 : 1;
			c += (t << i);
		}
		cur_p += 8;
		out << c;
	}

	out.close();
}
Exemple #7
0
IDX_T pantech_logfile_get_next_log( IDX_T idx, char* log_buf )
{
    if( g_head.inited_ == FALSE || idx == NULL_IDX )
    {
        return NULL_IDX;
    }

    if( g_head.next_[ idx ] == NULL_IDX )
    {
        idx         = g_head.head_;
        g_head.pos_ = 0;
    }
    else
    {
        idx = g_head.next_[ idx ];
        g_head.pos_++;
    }

    if( get_log( idx, log_buf ) == FALSE )
    {
        return NULL_IDX;
    }

    return idx;
}
Exemple #8
0
int
main(int argc, char** argv)
{
	const char* command = "list";
	bool verbose = false;

	int c;
	while ((c = getopt_long(argc, argv, "+hv", kLongOptions, NULL)) != -1) {
		switch (c) {
			case 0:
				break;
			case 'h':
				usage(0);
				break;
			case 'v':
				verbose = true;
				break;
			default:
				usage(1);
				break;
		}
	}

	if (argc - optind >= 1)
		command = argv[optind];

	if (strcmp(command, "list") == 0) {
		list_jobs(verbose);
	} else if (strcmp(command, "list-targets") == 0) {
		list_targets(verbose);
	} else if (strcmp(command, "log") == 0) {
		get_log(argc - optind, &argv[optind]);
	} else if (argc == optind + 1) {
		// For convenience (the "info" command can be omitted)
		get_info(command);
	} else {
		// All commands that need a name following

		const char* name = argv[argc - 1];

		if (strcmp(command, "info") == 0) {
			get_info(name);
		} else if (strcmp(command, "start") == 0) {
			start_job(name);
		} else if (strcmp(command, "stop") == 0) {
			stop_job(name);
		} else if (strcmp(command, "restart") == 0) {
			restart_job(name);
		} else if (strcmp(command, "enable") == 0) {
			enable_job(name, true);
		} else if (strcmp(command, "disable") == 0) {
			enable_job(name, false);
		} else {
			fprintf(stderr, "%s: Unknown command \"%s\".\n", kProgramName,
				command);
		}
	}
	return 0;
}
Exemple #9
0
void Watch::log_read(const FILE_NOTIFY_INFORMATION& file_notify_info) {
  if (get_log() != NULL) {
    get_log()->get_stream(Log::Level::DEBUG) <<
        "yield::fs::poll::win32::Watch(" <<
        "path=" << get_path() <<
        ")" <<
        ": read FILE_NOTIFY_INFORMATION(" <<
        "Action=" << file_notify_info.Action <<
        ", "
        "FileName=" <<
        Path(
          file_notify_info.FileName,
          file_notify_info.FileNameLength / sizeof(wchar_t)
        ) <<
        ")";
  }
}
Exemple #10
0
void print_log(GLuint object) {
  char* log;
  if ((log = get_log(object))) {
    fprintf(stderr, "%s", log);
    free(log);
  }else {
    fprintf(stderr, "Unable to retrieve log.\n");
  }
}
Exemple #11
0
bool rssconwindowsFree(Rsscon* rsscon) {
	LOG4C_CATEGORY log = get_log(LOG_CATEGORY);
	log_debug(log, "free all windows data structures for rsscon %d.", rsscon);

	assert(rsscon != NULL);
	assert(rsscon->portdata != NULL);
	free(rsscon->portdata);
	rsscon->portdata = NULL;
	return true;
}
Exemple #12
0
bool writeCommand(Rsscon* rsscon, const void* command, size_t size) {
	LOG4C_CATEGORY log = get_log(LOG_CATEGORY);
	log_info(log, "write command %d bytes.", size);

	size_t wrote;
	bool ret = rssconWrite(rsscon, command, size, &wrote);

	log_info(log, "wrote %d bytes.", wrote);
	free_log();
	return ret;
}
Exemple #13
0
void BaseContainer::tx_commit() {
    Log* undo_log = get_log();
    if (undo_log) {
        undo_log->clear();
    }

    //    LogMap::accessor writer;
    //    if (undo_logs.find(writer, thread_getId())) {
    //        assert(undo_logs.erase(writer));
    //    }
    locks.release_locks();
}
Exemple #14
0
bool rssconwindowsOpen(Rsscon* rsscon) {
	bool createFile(const char* device, RssconwindowsPortdata* pdata);
	bool setCommConfiguration(const char*, RssconwindowsPortdata*, DCB*);
	bool setCommState(const char*, RssconwindowsPortdata*, DCB*);
	bool handshakeOff(RssconwindowsPortdata* portdata);
	bool readTimeoutBlocking(RssconwindowsPortdata* pdata);
	bool readTimeoutNonblocking(RssconwindowsPortdata* pdata);

	assert(rsscon != NULL);
	assert(rsscon->portdata != NULL);
	RssconwindowsPortdata* pdata = (RssconwindowsPortdata*) rsscon->portdata;

	LOG4C_CATEGORY log = get_log(LOG_CATEGORY);
	log_debug(log, "open windows device for rsscon %d.", rsscon);

	rssconSetLastError(rsscon, RSSCON_ERROR_NOERROR);

	const char* device = rssconGetDevice(rsscon);
	log_debug(log, "create file for device %s.", device);
	if (!createFile(device, pdata)) {
		rssconSetLastError(rsscon, RSSCON_ERROR_OPENDEVICE);
		return false;
	}

	DCB port = {0};
	port.DCBlength = sizeof(DCB);

	log_debug(log, "set comm configuration for device %s.", device);
	if (!setCommConfiguration(device, pdata, &port)) {
		rssconSetLastError(rsscon, RSSCON_ERROR_SETUPDEVICE);
		return false;
	}

	log_debug(log, "set the comm state for the port handler %d.", pdata->portHandle);
	if (!setCommState(device, pdata, &port)) {
		rssconSetLastError(rsscon, RSSCON_ERROR_SETUPDEVICE);
		return false;
	}

	log_debug(log, "set the handshake for the port handler %d.", pdata->portHandle);
	if (!handshakeOff(pdata)) {
		rssconSetLastError(rsscon, RSSCON_ERROR_SETUPDEVICE);
		return false;
	}

	log_debug(log, "set the timeout blocking for the port handler %d.", pdata->portHandle);
	if (!readTimeoutBlocking(pdata)) {
		rssconSetLastError(rsscon, RSSCON_ERROR_SETUPDEVICE);
		return false;
	}

	return true;
}
Exemple #15
0
/* attack a position */
int hit_pos(int index, int x, int y)
{
  Players player1, player2;
  int ind;

  get_log(&player1, index);

  if (player1.map[y][x].presentation != EMPTY && player1.map[y][x].isVisible == 0) {
    if (index == 0)
      ind = 1;
    else
      ind = 0;

    get_log(&player2, ind);
    player2.score++;
    create_log(&player2, ind, player2.name);
    if (player2.score >= TOTAL_SLOTS)
      printf("<meta http-equiv=\"refresh\" content=0;url=\"?mode=5\">");
  }

  player1.map[y][x].isVisible = 1;
  create_log(&player1, index, player1.name);
}
Exemple #16
0
void BaseContainer::tx_start() {
    //    LogMap::accessor writer;
    //    assert(undo_logs.insert(writer, thread_getId()));
    auto undo_log = get_log();
    if (undo_log) {
        undo_log->clear();
    } else {
        if (THREAD_LOCAL_SET(key, new Log())) {
            //        fprintf(stderr, "fail to set key at address %ld.\n", (long) &key);
        } else {
            //        fprintf(stderr, "able to set key at address %ld.\n", (long) &key);
        }
    }
    return;
}
Exemple #17
0
/* ai hit user positions */
void ai_hit_pos()
{
  Players player1, player2;
  int x, y, around[2] = {1, -1};
  char *query;


  query = getenv("QUERY_STRING");

  if ((sscanf(query, "mode=4&player=0&posx=%d&posy=%d", &x, &y) == 2)) {
    x += around[rand() % 2];
    y += around[rand() % 2];

    while (x >= MAP_SIZE || x < 0 || y < 0 || y >= MAP_SIZE) {
      x = rand() % MAP_SIZE;
      y = rand() % MAP_SIZE;
    }

  } else {
    x = rand() % MAP_SIZE;
    y = rand() % MAP_SIZE;
  }

  get_log(&player1, 0);

  if (player1.map[y][x].presentation != EMPTY && player1.map[y][x].isVisible == 0) {
    get_log(&player2, 1);
    player2.score++;
    create_log(&player2, 1, AI_NAME);
    if (player2.score >= TOTAL_SLOTS)
      printf("<meta http-equiv=\"refresh\" content=0;url=\"?mode=5\">");
  }

  player1.map[y][x].isVisible = 1;
  create_log(&player1, 0, player1.name);
}
Exemple #18
0
// interface to bison:
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void  jacc::parse_grammar(std::istream& grm_file, const char* grm_file_name)
{
  current.lexer       =  this;  // jacc subclasses jamp subclasses lexer !
  current.grammar     = &grammar;
  current.properties  = &macros;
 (current.symtype_mgr = &symtype_mgr)->set_log(get_log());

  current.rhs.reset();
  current.n_mra = 0;
  current.prec  = 0;

  jacc_source  grm_source(grm_file, grm_file_name);
  push_source(&grm_source);
  yyparse();
  pop_source();
}
Exemple #19
0
IDX_T pantech_logfile_get_first_log( char* log_buf )
{
    init_log();
    g_head.pos_ = 0;

    if( g_head.head_ == NULL_IDX )
    {
        return NULL_IDX;
    }

    if( get_log( g_head.head_, log_buf ) == FALSE )
    {
        return NULL_IDX;
    }

    return g_head.head_;
}
Exemple #20
0
bool rssconInit(Rsscon* rsscon) {
	assert(rsscon != NULL);

	LOG4C_CATEGORY log = get_log(LOG_CATEGORY);
	log_debug(log, "setup windows interface for rsscon %d.", rsscon);

	RssconwindowsPortdata* portdata = malloc(sizeof(RssconwindowsPortdata));
	rsscon->portdata = portdata;
	rsscon->rssconInit = rssconwindowsInit;
	rsscon->rssconFree = rssconwindowsFree;
	rsscon->rssconOpen = rssconwindowsOpen;
	rsscon->rssconClose = rssconwindowsClose;
	rsscon->rssconWrite = rssconwindowsWrite;
	rsscon->rssconRead = rssconwindowsRead;

	return rsscon->rssconInit(rsscon);
}
Exemple #21
0
int main() {
#ifdef __linux
	const char* device = "/dev/ttyUSB3";
#endif
#ifdef RSSCON_WINDOWS
	const char* device = "COM:5";
#endif
	LOG4C_CATEGORY log = get_log(LOG_CATEGORY);

	log_info(log, "create rsscon");
	unsigned int baudrate = RSSCON_BAUDRATE_921600;
	Rsscon* rsscon = rssconCreate(device, baudrate);
	printErrorUnless(rsscon != NULL, "rsscon is null.");
	exitUnless(rsscon != NULL );

	log_info(log, "init rsscon");
	bool ret = rssconInit(rsscon);
	printErrorUnless(ret, "rsscon init.");
	printRssconError(rsscon);
	cleanupUnless(ret, rsscon);
	exitUnless(ret);

	ret = rssconSetBlocking(rsscon, true);
	ret = rssconSetWait(rsscon, false);

	log_info(log, "open rsscon");
	ret = rssconOpen(rsscon);
	printErrorUnless(ret, "rsscon open.");
	printRssconError(rsscon);
	cleanupUnless(ret, rsscon);

//	ret = readInfo(rsscon);
//	printErrorUnless(ret, "read info.");
//	printRssconError(rsscon);
//	cleanupUnless(ret, rsscon);

	log_info(log, "read data");
	ret = readData(rsscon);
	printErrorUnless(ret, "read data.");
	printRssconError(rsscon);
	cleanupUnless(ret, rsscon);

	free_log();
	return 0;
}
Exemple #22
0
 void shader::compile()
 {
     if(!m_have_src)
     throw std::runtime_error("No source code to compile.");
     m_handle = glCreateShader(m_type);
     const GLchar* csrc = m_src.c_str();
     glShaderSource(m_handle, 1, &csrc, nullptr);
     glCompileShader(m_handle);
     GLint compile_status = 0;
     glGetShaderiv(m_handle, GL_COMPILE_STATUS, &compile_status);
     get_log();
     if(compile_status == GL_FALSE)
     {
         glDeleteShader(m_handle);
         throw runtime_error("Unable to compile shader: " + m_log);
     }
     m_compiled = true;
 }
Exemple #23
0
int natv_logger_init() {
    natv_logger_t *nl = get_log();

    if(swapi_queue_create(sizeof(swapi_message_t), knatv_logger_PENDINGS,
                          &nl->nl_queue) != 0) {
        return -1;
    }

    if(swapi_thread_create(&nl->nl_thread, logger_routine, nl) != 0) {
        return -1;
    }

    nl->nl_fd = fopen("natv.log", "w");

    nl->nl_init = 1;

    return 0;
}
Exemple #24
0
void
ShaderAPITest::check_status(GLuint id, GLenum pname,
			    void (APIENTRY *query)(GLuint, GLenum, GLint *),
			    void (APIENTRY *get_log)(GLuint, GLsizei, GLsizei *, GLchar *))
{
	GLint status;

	query(id, pname, &status);
	if (!status) {
		char info[65536];

		fprintf(stderr, "Compilation/link failure:\n");
		get_log(id, sizeof(info), NULL, info);
		fprintf(stderr, "%s\n", info);

		error = true;
	}
}
Exemple #25
0
bool rssconwindowsClose(Rsscon* rsscon) {
	assert(rsscon != NULL);
	RssconwindowsPortdata* pdata = (RssconwindowsPortdata*) rsscon->portdata;
	assert(pdata != NULL);
	assert(pdata->portHandle != INVALID_HANDLE_VALUE);

	rssconSetLastError(rsscon, RSSCON_ERROR_NOERROR);

	LOG4C_CATEGORY log = get_log(LOG_CATEGORY);
	log_debug(log, "close windows device for rsscon %d.", rsscon);

	if (!CloseHandle(pdata->portHandle)) {
		fputs("Failed to close the handle from port.\n", stderr);
		rssconSetLastError(rsscon, RSSCON_ERROR_CLOSEDEVICE);
		pdata->lastError = GetLastError();
		return false;
	}
	return true;
}
Exemple #26
0
bool rssconwindowsInit(Rsscon* rsscon) {
	LOG4C_CATEGORY log = get_log(LOG_CATEGORY);
	log_debug(log, "setup windows settings for rsscon %d.", rsscon);

	assert(rsscon != NULL);
	assert(rsscon->portdata != NULL);
	RssconwindowsPortdata* pdata = (RssconwindowsPortdata*) rsscon->portdata;

	pdata->portHandle = INVALID_HANDLE_VALUE;
#ifndef NOISEREAD_3
	pdata->baudRate = CBR_115200;
#endif
#ifdef NOISEREAD_3
	pdata->baudRate = 921600;
#endif
	pdata->parityon = FALSE;
	pdata->parity = NOPARITY;
	pdata->stopBits = ONESTOPBIT;
	pdata->byteSize = 8;
	return true;
}
Exemple #27
0
void BaseContainer::tx_abort() {
    Log* undo_log = get_log();
    if (undo_log) {
        for (auto op = undo_log->rbegin(); op != undo_log->rend(); op++) {
            //invoke callbacks in reverse order
            assert((*op)());
        }
        undo_log->clear();
    }

    //    LogMap::accessor writer;
    //    if (undo_logs.find(writer, thread_getId())) {
    //        auto& undo_log = writer->second;
    //        for (auto op = undo_log.rbegin(); op != undo_log.rend(); op++) {
    //            //invoke callbacks in reverse order
    //            assert((*op)());
    //        }
    //        assert(undo_logs.erase(writer));
    //    }
    locks.release_locks();
}
Exemple #28
0
int natv_logger_output(const char *log, int size) {
    natv_logger_t		*nl =  get_log();
    swapi_message_t		msg;

    if(nl->nl_init == 0) {
        return -1;
    }

    msg.sm_ptr = malloc(knatv_logger_LOGSIZE);
    if(msg.sm_ptr == NULL) {
        return -1;
    }
    memset(msg.sm_ptr, 0, knatv_logger_LOGSIZE);

    if(size >= (knatv_logger_LOGSIZE-1))
        size = knatv_logger_LOGSIZE - 1;

    strncpy((char *)msg.sm_ptr, log, size);
    msg.sm_size = size;

    return swapi_queue_post(nl->nl_queue, &msg);
}
Exemple #29
0
/*******************************************************************************
 * inst_release_thread - probe for release_thread
 * @t - the task which is getting released (murder!)
 * @return - None
 * @Side Effect - If debug has started, then pid is logged.
 *
 * Logs the pids and command names of threads when they die
 *******************************************************************************/
void inst_release_thread(struct task_struct *t)
{
	struct log_block *p = NULL;
	if (TS_MEMBER(t, seeker_scheduled) != SEEKER_MAGIC_NUMBER)
		goto out;
	if (is_blacklist_task(t))
		goto out;
	p = get_log();
	if (p) {
		p->entry.type = LOG_PID;
		p->entry.u.tpid.pid = (u32) (t->pid);
		memcpy(&(p->entry.u.tpid.name[0]), t->comm, 16);
	}

	put_log(p);

	/* Make sure there is no pending work on this task */
	cancel_task_work(t);
out:
	jprobe_return();

}
Exemple #30
0
void process_begin_end( L get_log, O output )
{
//     static comma::csv::input_stream< T > istream( std::cin );
    static comma::csv::output_stream< T > estream( std::cerr );
    std::deque< T > stack; 
    while( std::cin.good() && !std::cin.eof() )
    {
        const T* plog = get_log();
        if( plog == NULL ) { break; }
        const T& message = *plog;
        
        
        if( stack.empty() ) {
            stack.push_back( message );
        }
        else
        {
            if( stack.empty() ) {
                std::cerr << name() << ": failed on "; estream.write( message );
                COMMA_THROW( comma::exception, "'end' must have a 'start' log entry" );
            }
            
            if( message.is_begin ) 
            {
                stack.push_back( message );
            }
            else 
            {
                if( stack.back().name != message.name ) {
                    std::cerr << name() << ": failed on "; estream.write( message );
                    COMMA_THROW( comma::exception, "found 'end' but missing FIFO entry 'begin' log entry with that name" );
                }
                const T& begin = stack.back();
                output( begin, message, comma::join( stack, stack.size()-1, '/' ) );
                stack.pop_back();
            }
        }
    }
}