Exemplo n.º 1
0
int main(int argc, char *argv[])
{
  assert(sizeof(localbuf) >= getpagesize());

  close(STDIN_FILENO);
  setlocale(LC_ALL, "C");

  if (!configure(argc, argv)) return EXIT_FAILURE;

  if (unlikely(!read_proc_swaps()) ||
      unlikely(!activate_old_swaps()) ||
      unlikely(!check_memory_status()))
    return EXIT_FAILURE;

  if (erase) return retire_all() ? EXIT_SUCCESS : EXIT_FAILURE;

  install_sigs();

  if (unlikely(!startpidfile())) return EXIT_FAILURE;

  /* Do a first iteration here so we can report any startup errors, and if we're
   * going to run as a daemon, we can do so in a steady state.
   */
  handle_requirements();

  /* If we're going to fork(), this is the last chance to read /proc/swaps in a
   * nonempty state before we do so.  Make one last attempt to check its format.
   */
  if (!proc_swaps_parsed())
  {
    if (!read_proc_swaps()) return EXIT_FAILURE;
#ifndef NO_CONFIG
    if (!quiet && !proc_swaps_parsed())
      fputs("[/proc/swaps is empty, so cannot check its format]\n", stderr);
#endif
  }

  if (godaemon)
  {
#ifndef NO_CONFIG
    if (verbose) logm(LOG_DEBUG, "daemonizing...");
#endif
    const pid_t pid = daemonize();
    if (unlikely(pid < 0))
    {
      rmpidfile();
      return EXIT_FAILURE;
    }
    if (pid > 0)
    {
      /* New process, so new pid.  Parent process rewrites pidfile.  We do this
       * from the parent, not the child process so that we're sure that the
       * pidfile is in a stable state when the parent exits.
       */
      lseek(pidfd, 0, SEEK_SET);
#ifndef NO_CONFIG
      if (verbose) logm(LOG_DEBUG, "got process id %d", pid);
#endif
      return writepid(pid) ? EXIT_SUCCESS : EXIT_FAILURE;
    }
  }

  finishpidfile();

  if (godaemon)
  {
    close(STDERR_FILENO);
    close(STDOUT_FILENO);

    // From here on std output is pointless in daemon mode.  Use syslog instead.
    log_start(argv[0]);
  }

  // Central loop
  for (++runclock; !stop; ++runclock)
  {
    if (unlikely(print_status))		print_status = false,	dump_stats();
    else if (unlikely(adjust_swap))	adjust_swap = false,	request_diet();
    else 			        handle_requirements();

    sleep(1);
  }

  int result = EXIT_SUCCESS;

#ifndef NO_CONFIG
  /* If we're worried about attackers getting unguarded access to the disk, we
   * need to retire and erase all swap files to keep them secret.
   */
  if (paranoid && !retire_all()) result = EXIT_FAILURE;
#endif

  rmpidfile();
  log_close();

  return result;
}
Exemplo n.º 2
0
int
cliprdr_init()
{
  char filename[256];
  struct list* names;
  struct list* values;
  char* name;
  char* value;
  int index;
  int display_num;

  display_num = g_get_display_num_from_display(g_getenv("DISPLAY"));
	if(display_num == 0)
	{
		g_printf("cliprdr[cliprdr_init]: Display must be different of 0\n");
		return ERROR;
	}
	l_config = g_malloc(sizeof(struct log_config), 1);
	l_config->program_name = "cliprdr";
	l_config->log_file = 0;
	l_config->fd = 0;
	l_config->log_level = LOG_LEVEL_DEBUG;
	l_config->enable_syslog = 0;
	l_config->syslog_level = LOG_LEVEL_DEBUG;

  names = list_create();
  names->auto_free = 1;
  values = list_create();
  values->auto_free = 1;
  g_snprintf(filename, 255, "%s/cliprdr.conf", XRDP_CFG_PATH);
  if (file_by_name_read_section(filename, CLIPRDR_CFG_GLOBAL, names, values) == 0)
  {
    for (index = 0; index < names->count; index++)
    {
      name = (char*)list_get_item(names, index);
      value = (char*)list_get_item(values, index);
      if (0 == g_strcasecmp(name, CLIPRDR_CFG_NAME))
      {
        if( g_strlen(value) > 1)
        {
        	l_config->program_name = (char*)g_strdup(value);
        }
      }
    }
  }
  if (file_by_name_read_section(filename, CLIPRDR_CFG_LOGGING, names, values) == 0)
  {
    for (index = 0; index < names->count; index++)
    {
      name = (char*)list_get_item(names, index);
      value = (char*)list_get_item(values, index);
      if (0 == g_strcasecmp(name, CLIPRDR_CFG_LOG_LEVEL))
      {
      	l_config->log_level = log_text2level(value);
      }
    }
  }
  list_delete(names);
  list_delete(values);

	if(log_start(l_config) != LOG_STARTUP_OK)
	{
		g_printf("vchannel[vchannel_init]: Unable to start log system\n");
		return ERROR;
	}
  else
  {
  	return LOG_STARTUP_OK;
  }
  return 0;
}
Exemplo n.º 3
0
void test_mask1blit(Raster *r)
/*****************************************************************************
 *
 ****************************************************************************/
{
Rastlib		*rlib = r->lib;
Raster		*vbr = &tcb.verification_raster;
Coor		x;
Coor		y;
Coor		xstart;
Coor		width;
Coor		height;
Pixel		color;
short		iteration_count;
short		iteration_limit;

	width = r->width;
	height = r->height;

	/*-----------------------------------------------------------------------
	 * mask1blit testing...
	 *   if the driver didn't provide a routine, and we're not testing via
	 *   generics, skip the testing.
	 *---------------------------------------------------------------------*/
	
	if (is_generic(rlib,mask1blit) && !tcb.test_via_generics)
		{
		log_bypass("mask1blit()");
		goto M1BLIT_DONE;
		}

	/*-----------------------------------------------------------------------
	 * test mask1blit...
	 *---------------------------------------------------------------------*/

	iteration_limit = (tcb.timing_only_run) ? MASK1_TIME_ITCOUNT : 1;

	log_start("Testing mask1blit()...\n");

	iteration_count = iteration_limit;

	pj_set_rast(r,  0);
	pj_set_rast(vbr,0);
	for (x = 0; x+MBPW/3 <= width; x += 2*(MBPW/3))
		{
		pj_set_rect(r,   1, x, 0, MBPW/3, height);
		pj_set_rect(vbr, 1, x, 0, MBPW/3, height);
		}

	rlib->wait_vsync(r);
	time_start();
	while (iteration_count--)
		{
		color = iteration_count * 3;
		for (y = -MBPH+3, xstart = -MBPW; y < height+MBPH; y += MBPH, xstart +=1)
			{
			for (x=xstart; x < width+MBPW; x+=MBPW)
				{
				++color;
				pj_mask1blit(markBitmap,  MBPR,
							 0, 0, r, x, y, MBPW, MBPH, color);
				}
			}
		}
	time_end();

	/* build the verification raster... */

	color = 0;
	for (y = -MBPH+3, xstart = -MBPW; y < height+MBPH; y += MBPH, xstart +=1)
		{
		for (x=xstart; x < width+MBPW; x+=MBPW)
			{
			++color;
			pj_mask1blit(markBitmap, MBPR,
						 0, 0, vbr, x, y, MBPW, MBPH, color);
			}
		}

	verify_raster(r, vbr, TRUE);

M1BLIT_EXIT:

	log_end("...testing of mask1blit() complete.\n\n");

	single_step();

M1BLIT_DONE:

	return;

}
Exemplo n.º 4
0
/**
 * Sets a system error-message as the first error-message for the current
 * thread.
 */
void log_errno(void)
{
    log_start("%s", strerror(errno));
}
Exemplo n.º 5
0
int DEFAULT_CC
printerd_init()
{
	char filename[256];
	struct list *names;
	struct list *values;
	char *name;
	char *value;
	int index;
	int res;

	l_config = g_malloc(sizeof(struct log_config), 1);
	l_config->program_name = g_strdup("printerd");
	l_config->log_file = 0;
	l_config->fd = 0;
	l_config->log_level = LOG_LEVEL_DEBUG;
	l_config->enable_syslog = 0;
	l_config->syslog_level = LOG_LEVEL_DEBUG;

	names = list_create();
	names->auto_free = 1;
	values = list_create();
	values->auto_free = 1;
	g_snprintf(filename, 255, "%s/printerd.ini", XRDP_CFG_PATH);

	if (file_by_name_read_section (filename, PRINTERD_CFG_LOGGING, names, values) == 0) {
		for (index = 0; index < names->count; index++) {
			name = (char *)list_get_item(names, index);
			value = (char *)list_get_item(values, index);
			if (0 == g_strcasecmp(name, PRINTERD_CFG_LOG_DIR)) {
				l_config->log_file = (char *)g_strdup(value);
			}
			if (0 == g_strcasecmp(name, PRINTERD_CFG_LOG_LEVEL)) {
				l_config->log_level = log_text2level(value);
			}
			if (0 ==
			    g_strcasecmp(name, PRINTERD_CFG_LOG_ENABLE_SYSLOG)) {
				l_config->enable_syslog = log_text2bool(value);
			}
			if (0 == g_strcasecmp(name, PRINTERD_CFG_LOG_SYSLOG_LEVEL)) {
				l_config->syslog_level = log_text2level(value);
			}
		}
	}

	if (file_by_name_read_section
	    (filename, PRINTERD_CFG_GLOBAL, names, values) == 0) {
		for (index = 0; index < names->count; index++) {
			name = (char *)list_get_item(names, index);
			value = (char *)list_get_item(values, index);
			if (0 == g_strcasecmp(name, PRINTERD_CFG_GLOBAL_THREAD_COUNT)) {
				thread_count = g_atoi(value);
			}
		}
	}
	list_delete(names);
	list_delete(values);
	res = log_start(l_config);

	if (res != LOG_STARTUP_OK)
	{
		g_printf("xrdp-printerd[printerd_init]: Unable to start log system[%i]\n", res);
		return res;
	}
	else
	{
		return LOG_STARTUP_OK;
	}
}
Exemplo n.º 6
0
void accounting(tac_session * session, tac_pak_hdr * hdr)
{
    rb_tree_t *rbt = session->ctx->aaa_realm->acct;
    report(session, LOG_DEBUG, DEBUG_ACCT_FLAG, "Start accounting request");

    if (rbt) {
	struct acct *acct = tac_payload(hdr, struct acct *);
	int i;
	char *acct_type, *username, *portname, *argstart, *msgid;
	u_char *argsizep;
	u_char *p = (u_char *) acct + TAC_ACCT_REQ_FIXED_FIELDS_SIZE + acct->arg_cnt;

	if (acct->flags & TAC_PLUS_ACCT_FLAG_STOP)
	    acct_type = "stop", msgid = "ACCTSTOP";
	else if (acct->flags & TAC_PLUS_ACCT_FLAG_START)
	    acct_type = "start", msgid = "ACCTSTART";
	else if (acct->flags & TAC_PLUS_ACCT_FLAG_WATCHDOG)
	    acct_type = "update", msgid = "ACCTUPDATE";
	else
	    acct_type = "unknown", msgid = "ACCTUNKNOWN";

	log_start(rbt, session->ctx->nas_address_ascii, msgid);

	log_write(rbt, (char *) p, acct->user_len);
	username = (char *) p;
	p += acct->user_len;

	log_write_separator(rbt);
	log_write(rbt, (char *) p, acct->port_len);
	portname = (char *) p;
	p += acct->port_len;

	log_write_separator(rbt);
	log_write(rbt, (char *) p, acct->rem_addr_len);
	p += acct->rem_addr_len;

	log_write_separator(rbt);
	log_write(rbt, acct_type, strlen(acct_type));

	argsizep = (u_char *) acct + TAC_ACCT_REQ_FIXED_FIELDS_SIZE;
	argstart = (char *) p;

	for (i = 0; i < (int) acct->arg_cnt; i++) {
	    log_write_separator(rbt);
	    log_write(rbt, (char *) p, *argsizep);
	    p += *argsizep++;
	}

	log_flush(rbt);

	if (acct->flags & TAC_PLUS_ACCT_FLAG_STOP) {
	    p = (u_char *) argstart;
	    argsizep = (u_char *) acct + TAC_ACCT_REQ_FIXED_FIELDS_SIZE;
	    for (i = 0; i < (int) acct->arg_cnt; i++) {
		if (!strcmp((char *) p, "service=exec")) {
		    char *mu = alloca(acct->user_len + 1);
		    char *mp = alloca(acct->port_len + 1);
		    strncpy(mu, username, acct->user_len);
		    mu[acct->user_len] = 0;
		    strncpy(mp, portname, acct->port_len);
		    mp[acct->port_len] = 0;
		    tac_script_set_exec_context(session, mu, mp, NULL);
		    break;
		}
		p += *argsizep++;
	    }
	}
    }

    send_acct_reply(session, TAC_PLUS_ACCT_STATUS_SUCCESS, NULL, NULL);
}
Exemplo n.º 7
0
/**
 * Reports statistics.
 */
static void reportStats(void)
{
    struct timeval          now;
    double                  interval;
    double                  rate;
    char                    buf[80];
    int                     logmask;
    unsigned long           byteCount;
    unsigned long           packetCount, missedPacketCount, prodCount;
    static unsigned long    totalPacketCount;
    static unsigned long    totalMissedPacketCount;
    static unsigned long    totalProdCount;
    static unsigned long    totalByteCount;

    (void)gettimeofday(&now, NULL);
    readerGetStatistics(reader, &byteCount);
    pmGetStatistics(productMaker, &packetCount, &missedPacketCount, &prodCount);

    totalByteCount += byteCount;
    totalPacketCount += packetCount;
    totalMissedPacketCount += missedPacketCount;
    totalProdCount += prodCount;

    logmask = setulogmask(LOG_UPTO(LOG_NOTICE));

    log_start("----------------------------------------");
    log_add("Ingestion Statistics:");
    log_add("    Since Previous Report (or Start):");
    interval = duration(&now, &reportTime);
    encodeDuration(buf, sizeof(buf), interval);
    log_add("        Duration          %s", buf);
    log_add("        Raw Data:");
    log_add("            Octets        %lu", CHAR_BIT*byteCount/8);
    log_add("            Mean Rate:");
    rate = (byteCount/interval)*(CHAR_BIT/8.0);
    log_add("                Octets    %g/s", rate);
    log_add("                Bits      %g/s", 8*rate);
    log_add("        Received packets:");
    log_add("            Number        %lu", packetCount);
    log_add("            Mean Rate     %g/s", packetCount/interval);
    log_add("        Missed packets:");
    log_add("            Number        %lu", missedPacketCount);
    log_add("            %%             %g",
            100.0 * missedPacketCount / (missedPacketCount + packetCount));
    log_add("        Products:");
    log_add("            Inserted      %lu", prodCount);
    log_add("            Mean Rate     %g/s", prodCount/interval);
    log_add("    Since Start:");
    interval = duration(&now, &startTime);
    encodeDuration(buf, sizeof(buf), interval);
    log_add("        Duration          %s", buf);
    log_add("        Raw Data:");
    log_add("            Octets        %lu", CHAR_BIT*totalByteCount/8);
    log_add("            Mean Rate:");
    rate = (totalByteCount/interval)*(CHAR_BIT/8.0);
    log_add("                Octets    %g/s", rate);
    log_add("                Bits      %g/s", 8*rate);
    log_add("        Received packets:");
    log_add("            Number        %lu", totalPacketCount);
    log_add("            Mean Rate     %g/s", totalPacketCount/interval);
    log_add("        Missed packets:");
    log_add("            Number        %lu", totalMissedPacketCount);
    log_add("            %%             %g", 100.0 * totalMissedPacketCount /
            (totalMissedPacketCount + totalPacketCount));
    log_add("        Products:");
    log_add("            Inserted      %lu", totalProdCount);
    log_add("            Mean Rate     %g/s", totalProdCount/interval);

#ifdef RETRANS_SUPPORT
   if(retrans_xmit_enable == OPTION_ENABLE){
    log_add("       Retransmissions:");	
    log_add("           Requested     %lu", total_prods_retrans_rqstd);	
    log_add("           Received      %lu", total_prods_retrans_rcvd);	
    log_add("           Duplicates    %lu", total_prods_retrans_rcvd_notlost);	
    log_add("           No duplicates %lu", total_prods_retrans_rcvd_lost);	
    }
#endif 
    log_add("----------------------------------------");

    log_log(LOG_NOTICE);
    (void)setulogmask(logmask);

    reportTime = now;
}