Exemplo n.º 1
0
Arquivo: log.c Projeto: maczpc/csf
/*
 * check the time point and determine weather to create a new log file
 * the time point is an uint32_t, which indicates the create time stamp
 * of current used log file.
 */
static inline void
check_timepoint()
{
	struct tm *timefields;
	timefields = get_time();
	uint32_t tp_month = 0x0;
	uint32_t tp_mday = 0x0;
	uint32_t tp_hour = 0x0;
	
	switch (local_handle->csf_log_tpf) {
		case WLOG_MONTH : 
			tp_month = ((uint32_t)timefields->tm_mon) << 24;
			if ((local_handle->current_time_point & 0xFF000000) != tp_month) {
				fclose(local_handle->log_fd);
				create_logfile();
			}
			break;

		case WLOG_DAY : 
			tp_mday = ((uint32_t)timefields->tm_mday) << 16;
			if ((local_handle->current_time_point & 0x00FF0000) != tp_mday) {
				fclose(local_handle->log_fd);
				create_logfile();
			}
			break;

		case WLOG_HOUR : 
			tp_hour = ((uint32_t)timefields->tm_hour) << 8;
			if ((local_handle->current_time_point & 0x0000FF00) != tp_hour) {
				fclose(local_handle->log_fd);
				create_logfile();
			}
			break;
	}
}
Exemplo n.º 2
0
/* marks the siege.log with a user defined
   message.  checks for the existence of a
   log and creates one if not found.      */
void
mark_log_file(char *message)
{
    int  fd;
    char entry[512];

    /* if the file does NOT exist then create it.  */
    if(!file_exists(my.logfile)) {
        if(!create_logfile(my.logfile)) {
            NOTIFY(ERROR, "unable to create log file");
            return;
        }
    }

    /* create the log file entry */
    snprintf(entry, sizeof entry, "**** %s ****\n", message);

    if ((fd = open( my.logfile, O_WRONLY | O_APPEND, 0644 )) < 0) {
        NOTIFY(ERROR, "Unable to write to file" );
    }

    write(fd, entry, strlen(entry));
    close(fd);

    return;
}
Exemplo n.º 3
0
void
write_to_log(int count, float elapsed, int bytes, float ttime, int code, int failed)
{
    int     fd;
    char    entry[512];
#ifdef  HAVE_LOCALTIME_R
    struct  tm keepsake;
#endif/*HAVE_LOCALTIME_R*/
    struct  tm *tmp;
    time_t  now;
    size_t  len;
    char    date[65];

    now = time(NULL);
#ifdef HAVE_LOCALTIME_R
    tmp = (struct tm *)localtime_r(&now, &keepsake);
#else
    tmp = localtime(&now);
#endif/*HAVE_LOCALTIME_R*/

    setlocale(LC_TIME, "C");
    len = strftime(date, sizeof date, "%Y-%m-%d %H:%M:%S", tmp);

    /* if the file does NOT exist then we'll create it. */
    if(my.shlog) {
        printf( "FILE: %s\n", my.logfile );
        puts("You can disable this annoying message by editing");
        puts("the .siegerc file in your home directory; change");
        puts("the directive \'show-logfile\' to false." );
    }

    if(!file_exists(my.logfile)) {
        if(!create_logfile(my.logfile)) {
            NOTIFY(ERROR, "unable to create log file");
            return;
        }
    }

    /* create the log file entry with function params. */
    snprintf(
        entry, sizeof entry,
        "%s,%7d,%11.2f,%12u,%11.2f,%12.2f,%12.2f,%12.2f,%8d,%8d\n",
        date, count, elapsed, bytes, ttime / count, count / elapsed, bytes / elapsed,
        ttime / elapsed, code, failed
    );

    /* open the log and write to file */
    if((fd = open( my.logfile, O_WRONLY | O_APPEND, 0644 )) < 0) {
        NOTIFY(ERROR, "Unable to write to file");
        return;
    }

    write(fd, entry, strlen(entry));
    close(fd);

    return;
}
Exemplo n.º 4
0
void setup()
    {
    create_logfile();

    ops_crypto_init();

    // Create temp directory
    if (!mktmpdir())
        return;

    assert(strlen(dir));
    snprintf(gpgcmd, sizeof gpgcmd,
	     "gpg --quiet --no-tty --homedir=%s --openpgp", dir);

    setup_test_keys();
    setup_test_extra_dsa_keys();
    setup_test_keyptrs();

    }
Exemplo n.º 5
0
/* marks the siege.log with a user defined 
   message.  checks for the existence of a
   log and creates one if not found.      */
void
mark_log_file(char *message)
{
  int    fd;
  size_t len;
  char   entry[512];

  /* if the file does NOT exist then create it.  */
  if (!file_exists(my.logfile)) {
    if (!create_logfile(my.logfile)) {
      NOTIFY(ERROR, "unable to create log file: %s", my.logfile);
      return;
    }
  }

  /* create the log file entry */
  snprintf(entry, sizeof entry, "**** %s ****\n", message);

  if ((fd = open( my.logfile, O_WRONLY | O_APPEND, 0644 )) < 0) {
    NOTIFY(ERROR, "Unable to write to file: %s", my.logfile);
  }

  len = write(fd, entry, strlen(entry));
  if (len == (unsigned int)-1) {
    switch (errno) {
      case EBADF:
        NOTIFY(ERROR, "Unable to mark log file (bad file descriptor): %s", my.logfile);
        break;
      case EINTR:
        NOTIFY(ERROR, "Unable to mark log file (system interrupt): %s", my.logfile);
        break;
      default:
        NOTIFY(ERROR, "Unable to mark log file (unknown error): %s", my.logfile);
        break;
    }
  }
  close(fd);
  return; 
}
Exemplo n.º 6
0
//-----------------------------------------------------------------------
//  FUNCTION WinMain
//  PURPOSE:  application entry point, register MainWindow class
//-----------------------------------------------------------------------
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow )
{
	MSG msg;
	hInst=hInstance;

	// conv_file();

	init_path();
	register_classes(hInstance);

    if(!(ghWndMain=CreateWindow("brainBay_Class", "BrainBay", 
     	 WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, 10, 20, 900, 520, NULL, NULL, hInstance, NULL)))
        critical_error("can't create main Window");
    else {GLOBAL.left=20;GLOBAL.top=20;GLOBAL.right=900;GLOBAL.bottom=520; }
    ShowWindow( ghWndMain, SW_SHOWNORMAL );
    UpdateWindow( ghWndMain );

	create_logfile();
	write_logfile("BrainBay start.");
	GlobalInitialize();

	ghWndStatusbox=CreateDialog(hInst, (LPCTSTR)IDD_STATUSBOX, ghWndMain, (DLGPROC)StatusDlgHandler); 

	if(!(ghWndDesign=CreateWindow("Design_Class", "Design", WS_CLIPSIBLINGS | WS_CAPTION  | WS_THICKFRAME | WS_CHILD | WS_HSCROLL | WS_VSCROLL ,GLOBAL.design_left, GLOBAL.design_top, GLOBAL.design_right-GLOBAL.design_left, GLOBAL.design_bottom-GLOBAL.design_top, ghWndMain, NULL, hInst, NULL))) 
	    report_error("can't create Design Window");
	else 
	{
		SCROLLINFO si;
        ZeroMemory(&si, sizeof(si));
	    si.cbSize = sizeof(si);
		si.fMask = SIF_TRACKPOS|SIF_RANGE|SIF_TRACKPOS;
	    GetScrollInfo(ghWndDesign, SB_HORZ, &si);
		si.nMax=5000; si.nMin=0; si.nPos=0; si.nTrackPos=0;
		SetScrollInfo(ghWndDesign, SB_HORZ, &si,TRUE);
	    GetScrollInfo(ghWndDesign, SB_VERT, &si);
		si.nMax=5000; si.nMin=0; si.nPos=0; si.nTrackPos=0;
		SetScrollInfo(ghWndDesign, SB_VERT, &si,TRUE);
		ShowWindow( ghWndDesign, TRUE ); UpdateWindow( ghWndDesign ); 
	}

	if (GLOBAL.startup) 
	{
		if (!load_configfile(GLOBAL.configfile)) report_error("Could not load Config File");
		//else sort_objects();
	}

	update_status_window();
	UINT timerid= timeSetEvent(30,5,AnimProc,1,TIME_PERIODIC | TIME_CALLBACK_FUNCTION);

	// main message loop
	while (TRUE)
	{
		check_keys();
  		if(!GetMessage(&msg, NULL, 0, 0))	break;
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

    timeKillEvent(timerid);
	return msg.wParam;
}
Exemplo n.º 7
0
Arquivo: log.c Projeto: maczpc/csf
void * 
logger_init(void *handle, const char *ident, int logopt, int facility)
{
	int res, _res;
	char *hp;
	LOG_HANDLE *lhp;
	
	if (handle == NULL) {
	
		/* parse the config file */
		res = load_conf(NULL, "server", NULL, conf_str_array);
		_res = load_conf(NULL, "server", conf_int_array, NULL);

		if (res != 0 || _res != 0) {
			PRINT("ERROR! Can not parse the logger configuration.");
			return NULL;
		}	

		if (log_fd != NULL)
			fclose(log_fd);
		
		lhp = (LOG_HANDLE *)malloc(sizeof(LOG_HANDLE));
	
		if (lhp == NULL) {
			PRINT("logger init failed. not enough memory.");
			return NULL;
		}	
		local_handle = lhp;
		
		lhp->log_path = log_path;
		lhp->log_filenameprefix = log_filenameprefix;
		lhp->log_ident = log_ident;
		lhp->host_name = host_name;

		if (strncmp("csflogger", log_method, 1) == 0) {
			csf_log_method = CSF_LOGGER;

			/* set the log ident */
			memset(log_ident, '\0', MAX_MSG_LEN + 1);
			strlcpy(log_ident, ident, MAX_MSG_LEN + 1);

			/* get the current pid */
			pid = getpid();

			/* get the current host name(not full domain name) */
			memset(host_name, '\0', HOST_NAME_MAXLEN + 1);
		
			if (gethostname(host_name, HOST_NAME_MAXLEN) == 0 &&
				host_name != NULL) {

				hp = host_name;
				while (*hp != '\0') {
					if (*hp == '.') {
						*hp = '\0';
						break;
					}
					hp++;
				}
			} else {
				memmove(host_name, "NULL", 5);
			}

			/* get time per file */
			switch (log_timeperfile[0]) {
				case 'm': csf_log_tpf = WLOG_MONTH; break;
				case 'd': csf_log_tpf = WLOG_DAY; break;
				case 'h': csf_log_tpf = WLOG_HOUR; break;
				default : csf_log_tpf = WLOG_HOUR; break;
			}

			/* get the log time zone */
			if (log_timezone[0] == 'U') {
				csf_log_timezone = WLOG_UTC;
			} else {
				csf_log_timezone = WLOG_LOCAL;
			}

			/* point to current logger function */
			is_syslog = 0;

			/* create and open the csf build-in log file */
			if (create_logfile() != LOG_CREATE_OK) {
				PRINT("ERROR! Can not create log file.");
				return NULL;
			}
		} else {
			/* point to current logger function */
			is_syslog = 1;

			/* open the syslog */
			openlog(ident, logopt, facility);
		}
	
		lhp->csf_log_method = csf_log_method;
		lhp->csf_log_timezone = csf_log_timezone;
		lhp->csf_log_tpf = csf_log_tpf;
		lhp->is_syslog = is_syslog;
		lhp->pid = pid;
	}
	else {
		local_handle = (LOG_HANDLE *)handle;
	}

	return local_handle;
}
Exemplo n.º 8
0
void
write_to_log(int count, float elapsed, int bytes, float ttime, int code, int failed)
{
  int     fd; 
  char    entry[512];
#ifdef  HAVE_LOCALTIME_R
  struct  tm keepsake;
#endif/*HAVE_LOCALTIME_R*/ 
  struct  tm *tmp;  
  time_t  now;
  size_t  len = 0;
  char    date[65];

  now = time(NULL);
#ifdef HAVE_LOCALTIME_R
  tmp = (struct tm *)localtime_r(&now, &keepsake);
#else
  tmp = localtime(&now);
#endif/*HAVE_LOCALTIME_R*/  

  setlocale(LC_TIME, "C");
  len = strftime(date, sizeof date, "%Y-%m-%d %H:%M:%S", tmp);

  /* if the file does NOT exist then we'll create it. */
  if (my.shlog) { 
    printf("LOG FILE: %s\n", my.logfile ); 
    printf("You can disable this log file notification by editing\n");
    printf("%s/.siege/siege.conf ", getenv("HOME"));
    puts("and changing \'show-logfile\' to false." );
  }

  if (!file_exists(my.logfile)) {
    if (!create_logfile(my.logfile)) {
      NOTIFY(ERROR, "unable to create log file: %s", my.logfile);
      return;
    }
  }

  /* create the log file entry with function params. */
  snprintf(
    entry, sizeof entry, 
    "%s,%7d,%11.2f,%12u,%11.2f,%12.2f,%12.2f,%12.2f,%8d,%8d\n", 
    date, count, elapsed, bytes, ttime / count, count / elapsed, bytes / elapsed, 
    ttime / elapsed, code, failed 
  );

  /* open the log and write to file */
  if ((fd = open(my.logfile, O_WRONLY | O_APPEND, 0644)) < 0) {
    NOTIFY(ERROR, "Unable to open file: %s", my.logfile);
    return;
  }

  len = write(fd, entry, strlen(entry));
  if (len == (unsigned int)-1) {
    switch (errno) {
      case EBADF:
        NOTIFY(ERROR, "Unable to write to log file (bad file descriptor): %s", my.logfile);
        break;
      case EINTR:
        NOTIFY(ERROR, "Unable to write to log file (system interrupt): %s", my.logfile);
        break;
      default:
        NOTIFY(ERROR, "Unable to write to log file (unknown error): %s", my.logfile);
        break; 
    }
  }
  close(fd);
  return;
}