示例#1
0
void cleanup()
{
	sock_close();
	while(commandq.tqh_first != NULL)
	{
		commandq_pop();
	}
	queue_clear();
	if(get_logfile() != NULL)
	{
		fclose(get_logfile());
	}
	search_clear();
}
示例#2
0
void vdiag(const char *component,int severity,const char *fmt,va_list ap)
{
    COMPONENT *walk;
    FILE *to;
    char buffer[MAX_DIAG_MSG+1];
    int i;

    for (walk = components; walk; walk = walk->next)
	if (!strcmp(walk->name,component)) break;
    if (severity > (walk ? walk->verbosity : default_verbosity)) return;
    fflush(stdout);
    to = get_logfile();
    if (!to) {
	for (i = 0; sev2prio[i] == severity || sev2prio[i] == -1; i += 2);
	vsprintf(buffer,fmt,ap);
	syslog(sev2prio[i+1],"%s: %s",component,buffer);
    }
    else {
	if (app_name) fprintf(to,"%s:%s: ",app_name,component);
	else fprintf(to,"%s: ",component);
	vfprintf(to,fmt,ap);
	fputc('\n',to);
	fflush(to);
    }
    if (severity == DIAG_FATAL) {
	diag_fatal_debug_hook();
	fprintf(stderr,"Fatal error - Terminating\n");
	exit(1);
    }
}
示例#3
0
void shadow_satisfy(shadow_mgr mgr, ref_t r) {
    if (!mgr->do_cudd)
	return;
    DdNode *n = get_ddnode(mgr, r);
    bool zdd = is_zdd(mgr, r);
    FILE *logfile = get_logfile();
    if (zdd) {
	Cudd_zddPrintMinterm(mgr->bdd_manager, n);
	if (logfile) {
	    FILE *savefile = Cudd_ReadStdout(mgr->bdd_manager);
	    Cudd_SetStdout(mgr->bdd_manager, logfile);
	    Cudd_zddPrintMinterm(mgr->bdd_manager, n);
	    Cudd_SetStdout(mgr->bdd_manager, savefile);
	}
    }
    else {
	Cudd_PrintMinterm(mgr->bdd_manager, n);
	if (logfile) {
	    FILE *savefile = Cudd_ReadStdout(mgr->bdd_manager);
	    Cudd_SetStdout(mgr->bdd_manager, logfile);
	    Cudd_PrintMinterm(mgr->bdd_manager, n);
	    Cudd_SetStdout(mgr->bdd_manager, savefile);
	}
    }
}
// sqlci run with input coming in from an infile specified at command line
void SqlciEnv::run(char * in_filename, char * input_string)
{
  if ((! in_filename) && (input_string))
    {
      runWithInputString(input_string);
      return;
    }
  interactive_session = 0;		// overwrite value from ctor!
  // This function is called during the initialization phase of MXCI
  // (SqlciEnv_prologue_to_run). Use specialERROR_ as a flag indicating that
  // the querry being executed is invoke during MXCI's initialization phase and
  // that any errors will be fatal. Should an error occur,  exit MXCI.
  SqlciEnv_prologue_to_run(this);

   SqlCmd::executeQuery("SET SESSION DEFAULT SQL_SESSION 'BEGIN';", this);
  Int32 retval = 0;
  SqlciNode * sqlci_node = 0;

  // input is from a file given at command line (SQLCI -i<filename>).
  // Create an "OBEY filename" command and process it.
  char * command = new char[10 + strlen(in_filename)];
  strcpy(command, "OBEY ");
  strcat(command, in_filename);
  strcat(command, ";");
  sqlci_parser(command, command, &sqlci_node,this);
  delete [] command;
  void (*intHandler_addr) (Int32);
  intHandler_addr = interruptHandler;
      if (sqlci_node)
      {
        retval = sqlci_node->process(this);
        delete sqlci_node;
        sqlci_node = NULL;
        displayDiagnostics();
        sqlci_DA.clear(); // Clear the DiagnosticsArea for the next command...
      }

      if (!retval) // EXIT not seen in the obey file
      {
        // create an EXIT command
        char command[10];
        strcpy(command, "exit;");
        get_logfile()->WriteAll(">>exit;");
        sqlci_parser(command, command, &sqlci_node,this);
        if (sqlci_node)
	{
	  retval = sqlci_node->process(this);
	  delete sqlci_node;
          sqlci_node = NULL;
	  displayDiagnostics();
	  sqlci_DA.clear();
	}
      }
   DeleteCriticalSection(&g_CriticalSection);
   DeleteCriticalSection(&g_InterruptCriticalSection);

  cleanupSockets();
}  // run (in_filename)
示例#5
0
/*
 * Initialize logging.
 */
void
log_init()
{
	char *logfile = get_logfile();
	if ((log_fd = open(logfile, O_WRONLY|O_CREAT|O_APPEND)) == -1) {
		syslog(LOG_ERR, "error logging init");
		log_inited = 0;
	} else {
		syslog(LOG_INFO, "logging initialized");
		log_inited = 1;
	}
	free(logfile);
}
示例#6
0
文件: log.c 项目: knoopx/wepattack
void open_log(char *word, char *in) {

	FILE *fp;

	get_logfile(logfile);

	fp = fopen(logfile,"w");

	start_time = time(&start_time);
	fprintf(fp, "Logfile of WepAttack by Dominik Blunk and Alain Girardet\n\n");
	fprintf(fp, "Cracking started: %s", ctime(&start_time));
	fprintf(fp, "%s\t%s\n", word, in);

	fprintf(fp, "\nBssid\tKeyNo\tWepKey\tASCII\tEncryption\tElapsed Time");
	fclose(fp);
}
示例#7
0
bool		init_db0chrono(t_db0chrono * c)
{
  int		fd;
  int		r;

  c_global = c;
  if (!get_logfile(&(c->logfile)))
    return (false);
  if (!access(c->logfile, F_OK))
    {
      if ((fd = open(c->logfile, O_RDONLY)) == ERR_OPEN)
	return (print_perror(false, "open"));
      if ((r = read(fd, c->time.buf, sizeof(int))) == ERR_READ)
	return (print_perror(false, "read"));
      close(fd);
    }
  if ((signal(SIGINT, update_signal) == SIG_ERR)
      || (signal(SIGQUIT, update_signal) == SIG_ERR))
    return (print_perror(false, "signal"));
  return (true);
}
示例#8
0
文件: diag.c 项目: ebichu/dd-wrt
void vdiag(const char *component,int severity,const char *fmt,va_list ap)
{
    COMPONENT *walk;
    FILE *to;
    char buffer[MAX_DIAG_MSG+1];
    struct timeval tv;
    int i;
#define DATESTR_LEN 32
    char datestr[DATESTR_LEN];
    struct tm tm;

    for (walk = components; walk; walk = walk->next)
	if (!strcmp(walk->name,component)) break;
    if (severity > (walk ? walk->verbosity : default_verbosity)) return;
    fflush(stdout);
    to = get_logfile();
    if (!to) {
	for (i = 0; sev2prio[i] == severity || sev2prio[i] == -1; i += 2);
	vsnprintf(buffer,MAX_DIAG_MSG+1,fmt,ap);
	syslog(sev2prio[i+1],"%s: %s",component,buffer);
    }
    else {
	gettimeofday(&tv,NULL);
	localtime_r((time_t *) &tv.tv_sec, &tm);
	strftime(datestr, DATESTR_LEN, "%b %d %T", &tm);
	if (app_name)
	    fprintf(to, "%s.%06lu %s:%s: ",
		    datestr, (unsigned long) tv.tv_usec, app_name, component);
	else
	    fprintf(to,"%s.%06lu %s: ", datestr, (unsigned long) tv.tv_usec, component);
	vfprintf(to,fmt,ap);
	fputc('\n',to);
	fflush(to);
    }
    if (severity == DIAG_FATAL) {
	diag_fatal_debug_hook();
	fprintf(stderr,"Fatal error - Terminating\n");
	exit(1);
    }
}
示例#9
0
void
view_init(int refresh)
{
  int Timeouts = 0, SumRTT, CountRTT, MinRTT = 0, PktsRetrans = 0, FastRetran, DataPktsOut;
  int AckPktsOut, CurrentMSS, DupAcksIn, AckPktsIn, MaxRwinRcvd = 0, Sndbuf = 0;
  int CurrentCwnd = 0, SndLimTimeRwin, SndLimTimeCwnd, SndLimTimeSender, DataBytesOut;
  int SndLimTransRwin, SndLimTransCwnd, SndLimTransSender, MaxSsthresh;
  int CurrentRTO, CurrentRwinRcvd, CongestionSignals, PktsOut = 0;
  FILE *fp;
  int c2sspd = 0, s2cspd = 0;
  char ip_addr2[64], buff[512], *str, tmpstr[32];
  int link=0, mismatch=0, bad_cable=0, half_duplex=0, congestion=0;
  int c2sdata = 0, c2sack, s2cdata, s2cack = 0;
  int totalcnt=0, view_flag=0;

  if ((fp = fopen(get_logfile(), "r")) == NULL)
    return;

  while ((fgets(buff, 512, fp)) != NULL) {
    if ((str = strchr(buff, ',')) != NULL) {
      sscanf(buff, "%[^,]s", date);
      str++;
      sscanf(str, "%[^,]s", ip_addr2);
      if ((str = strchr(str, ',')) == NULL)
        continue;
      /* skip over s2c cwnd-limited speed value */
      str++;
      sscanf(str, "%[^,]s", tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      c2sspd = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      s2cspd = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      Timeouts = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      SumRTT = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      CountRTT = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      PktsRetrans = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      FastRetran = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      DataPktsOut = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      AckPktsOut = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      CurrentMSS = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      DupAcksIn = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      AckPktsIn = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      MaxRwinRcvd = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      Sndbuf = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      CurrentCwnd = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      SndLimTimeRwin = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      SndLimTimeCwnd = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      SndLimTimeSender = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      DataBytesOut = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      SndLimTransRwin = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      SndLimTransCwnd = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      SndLimTransSender = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      MaxSsthresh = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      CurrentRTO = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      CurrentRwinRcvd = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      link = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      mismatch = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      bad_cable = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      half_duplex = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      congestion = atoi(tmpstr);

      str = strchr(str, ',');
      if (str == NULL) {
        CongestionSignals = -1;
        goto display;
      }
      str += 1;
      sscanf(str, "%[^,]s", tmpstr);
      c2sdata = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      c2sack = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      s2cdata = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      s2cack = atoi(tmpstr);

      str = strchr(str, ',');
      if (str == NULL) {
        CongestionSignals = -1;
        goto display;
      }
      str += 1;
      sscanf(str, "%[^,]s", tmpstr);
      CongestionSignals = atoi(tmpstr);

      str = strchr(str, ',') +1;
      sscanf(str, "%[^,]s", tmpstr);
      PktsOut = atoi(tmpstr);

      str = strchr(str, ',');
      if (str == NULL)
        MinRTT = -1;
      else {
        str += 1;
        sscanf(str, "%[^,]s", tmpstr);
        MinRTT = atoi(tmpstr);
      }

display:
      log_println(4, "Web100 variables line received\n");
      totalcnt = calculate(date, SumRTT, CountRTT, CongestionSignals, PktsOut, DupAcksIn, AckPktsIn,
          CurrentMSS, SndLimTimeRwin, SndLimTimeCwnd, SndLimTimeSender,
          MaxRwinRcvd, CurrentCwnd, Sndbuf, DataBytesOut, mismatch, bad_cable,
          c2sspd, s2cspd, c2sdata, s2cack, view_flag);
    }

  }
  fclose(fp);
  view_flag = 1;
  gen_html(c2sspd, s2cspd, MinRTT, PktsRetrans, Timeouts, Sndbuf, MaxRwinRcvd,
      CurrentCwnd, mismatch, bad_cable, totalcnt, refresh);
}
示例#10
0
void
gen_html(int c2sspd, int s2cspd, int MinRTT, int PktsRetrans, int Timeouts, int Sndbuf,
  int MaxRwinRcvd, int CurrentCwnd, int mismatch, int bad_cable, int totalcnt, int refresh)
{
  FILE *fp;
  char view_string[256], tmpstr[256];
  int i;
  struct flock lock;

  fp = fopen(AdminFileName, "w");
  if (fp == NULL) {
    log_println(1, "Cannot open file for the admin web page...");
    return;
  }
  /* generate an HTML page for display.  */
  fprintf(fp, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
  fprintf(fp, "<html> <head> <title>NDT server Admin Page</title>\n");
  fprintf(fp, "<meta http-equiv=\"refresh\" content=\"%d; url="ADMINFILE"\">\n", refresh);
  fprintf(fp, "<meta http-equiv=\"Content-Language\" content=\"en\">\n");
  fprintf(fp, "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n");
  fprintf(fp, "</head>\n");

  /* First build current results table */
  fprintf(fp, "<table border>\n  <tr>\n ");
  fprintf(fp, "    <th colspan=8><font size=\"+1\">NDT Usage Statistics -- Current Test Results\n");
  fprintf(fp, "    </font></tr>\n");
  fprintf(fp, "  <tr>\n    <th>Date/Time\n    <th>Total Tests\n    <th rowspan=6>\n");
  fprintf(fp, "    <th>Bottleneck Link\n    <th>Theoritical Limit\n    <th rowspan=6>\n");
  fprintf(fp, "    <th>C2S Speed\n    <th>S2C Speed\n  </tr>\n");
  fprintf(fp, "  <tr>\n    <td align=right>%s\n    <td align=right>%d\n    <td align=right>%s\n",
      date, totalcnt, btlneck);
  if (bw2 > 1)
    fprintf(fp, "    <td align=right>%0.2f Mbps\n",  bw2);
  else
    fprintf(fp, "    <td align=right>%0.2f kbps\n",  bw2*1000);
  if (c2sspd > 1000)
    fprintf(fp, "    <td align=right>%0.2f Mbps\n    <td align=right>%0.2f Mbps\n",
        (float) c2sspd/1000, (float)s2cspd/1000);
  else
    fprintf(fp, "    <td align=right>%d kbps\n    <td align=right>%d kbps, ", c2sspd, s2cspd);
  fprintf(fp, "  </tr>\n  <tr>\n    <th>Packet Loss\n    <th>Average RTT\n");
  fprintf(fp, "    <th>Mininum RTT\n    <th>Retrans/sec\n    <th>Timeouts/sec\n");
  fprintf(fp, "    <th>%% Out-of-Order\n  </tr>\n  <tr>\n");
  if (loss2 == .000001) 
    fprintf(fp, "    <td align=right>None\n    <td align=right>%0.2f msec\n    <td align=right>%d msec\n",
        avgrtt, MinRTT);
  else
    fprintf(fp, "    <td align=right>%0.4f%%\n    <td align=right>%0.2f msec\n    <td align=right>%d msec\n",
        loss2*100, avgrtt, MinRTT);
  fprintf(fp, "    <td align=right>%0.2f\n    <td align=right>%0.2f\n    <td align=right>%0.2f\n  </tr>\n", 
      (float) PktsRetrans/timesec, (float) Timeouts/timesec, oo_order*100);
  fprintf(fp, "  <tr>\n    <th>Send Buffer\n    <th>BW*Delay\n");
  fprintf(fp, "    <th>Receive Buffer\n    <th>BW*Delay\n");
  fprintf(fp, "    <th>Congestion Window\n    <th>BW*Delay\n  </tr>\n");
  fprintf(fp, "  <tr>\n    <td align=right>%d Bytes\n    <td align=right>%0.2f Mbps\n", Sndbuf, sendbwd);
  fprintf(fp, "    <td align=right>%d Bytes\n    <td align=right>%0.2f Mbps\n", MaxRwinRcvd, recvbwd);
  fprintf(fp, "    <td align=right>%d Bytes\n    <td align=right>%0.2f Mbps\n", CurrentCwnd, cwndbwd);
  fprintf(fp, "  </tr>\n</table>\n\n");

  fprintf(fp, "<applet code=Admin.class\n  width=600 height=400>\n");
  fprintf(fp, "  <PARAM NAME=\"Fault\" VALUE=\"%d\">\n", count[0]);
  fprintf(fp, "  <PARAM NAME=\"RTT\" VALUE=\"%d\">\n", count[1]);
  fprintf(fp, "  <PARAM NAME=\"Dial-up\" VALUE=\"%d\">\n", count[2]);
  fprintf(fp, "  <PARAM NAME=\"T1\" VALUE=\"%d\">\n", count[3]);
  fprintf(fp, "  <PARAM NAME=\"Enet\" VALUE=\"%d\">\n", count[4]);
  fprintf(fp, "  <PARAM NAME=\"T3\" VALUE=\"%d\">\n", count[5]);
  fprintf(fp, "  <PARAM NAME=\"FastE\" VALUE=\"%d\">\n", count[6]);
  fprintf(fp, "  <PARAM NAME=\"OC-12\" VALUE=\"%d\">\n", count[7]);
  fprintf(fp, "  <PARAM NAME=\"GigE\" VALUE=\"%d\">\n", count[8]);
  fprintf(fp, "  <PARAM NAME=\"OC-48\" VALUE=\"%d\">\n", count[9]);
  fprintf(fp, "  <PARAM NAME=\"tenGE\" VALUE=\"%d\">\n", count[10]);
  fprintf(fp, "  <PARAM NAME=\"Total\" VALUE=\"%d\">\n", totalcnt);
  fprintf(fp, "</applet>\n<br>\n");

  /* Next generate summary table */
  fprintf(fp, "<table border>\n  <tr>\n");
  fprintf(fp, "    <th>\n    <th>Date/Time\n    <th rowspan=5>\n");
  fprintf(fp, "    <th colspan=2>Throughput Summary\n    <th rowspan=5>\n");
  fprintf(fp, "    <th colspan=2>Configuration Fault Summary\n  </tr>\n  <tr>\n");
  fprintf(fp, "    <td><b>Log Starts</b>\n    <td align=right>%s\n    <th>Client-to-Server\n", startdate);
  fprintf(fp, "    <th>Server-to-Client\n    <th>Duplex Mismatch\n");
  fprintf(fp, "    <th>Excessive Errors\n  </tr>\n");
  fprintf(fp, "  <tr>\n    <td><b>Current</b>\n    <td align=right>%s\n", date);
  if (c2sspd > 1000)
    fprintf(fp, "    <td align=right>%0.2f Mbps\n    <td align=right>%0.2f Mbps\n",
        (float) c2sspd/1000, (float)s2cspd/1000);
  else
    fprintf(fp, "    <td align=right>%d kbps\n    <td align=right>%d kbps, ", c2sspd, s2cspd);

  fprintf(fp, "    <td align=right>%s\n    <td align=right>%s\n  </tr>\n  <tr>\n",
      mismatch==1?"Yes":"No", bad_cable==1?"Yes":"No");  
  fprintf(fp, "    <td><b>Maximum</b>\n    <td align=right>%s\n", maxdate);
  if (maxc2sspd > 1000)
    fprintf(fp, "    <td align=right>%0.2f Mbps\n    <td align=right>%0.2f Mbps\n",
        (float) maxc2sspd/1000, (float)maxs2cspd/1000);
  else
    fprintf(fp, "    <td align=right>%d kbps\n    <td align=right>%d kbps, ", maxc2sspd, maxs2cspd);
  fprintf(fp, "    <td align=right>%d found\n    <td align=right>%d found\n  </tr>\n",
      totmismatch, totbad_cable);
  fprintf(fp, "  <tr>\n    <td><b>Minimum</b>\n    <td align=right>%s\n", mindate);
  if (minc2sspd > 1000)
    fprintf(fp, "    <td align=right>%0.2f Mbps\n    <td align=right>%0.2f Mbps\n",
        (float) minc2sspd/1000, (float)mins2cspd/1000);
  else
    fprintf(fp, "    <td align=right>%d kbps\n    <td align=right>%d kbps\n", minc2sspd, mins2cspd);
  fprintf(fp, "    <td>\n    <td>\n  </tr>\n</table>\n");

  fprintf(fp, "<br>\n<hr width=\"100%%\" noShade size=4>\n");
  fprintf(fp, "<table border>\n  <tr>\n");
  fprintf(fp, "    <th>\n    <th>Filename\n    <th>Size\n  </tr>\n  <tr>\n");
  fprintf(fp, "    <td><b>Log</b>\n    <td> %s    <td>\n", get_logfile());
  {
    struct stat fstats;
    
    if (stat(get_logfile(), &fstats) == 0) {
      char* names[] = {"B", "KB", "MB", "GB"};
      int idname;
      double size = fstats.st_size;
      for (idname = 0; idname < 3; ++idname) {
        if (size < 1024) {
          break;
        }
        size /= 1024.0;
      }
      fprintf(fp, "%.2f %s\n", size, names[idname]);
    }
    else {
      fprintf(fp, "???\n");
    }
  }
  fprintf(fp, "  </tr>\n</table>\n");

  /* now pick up the rest of the descriptive text that goes along with this page.
   * instead of burying all the text in this program, just include it from an external
   * file.  For now, use the system command to append the text to the just created file.
   */
  fclose(fp);
  sprintf(tmpstr, "/bin/cat %s/admin_description.html >> %s", BASEDIR,  AdminFileName);
  system(tmpstr);

  /* Save the current variables into a file for later use.  These
   * variables are updated by each child process at the end of every
   * test.  This data must be shared between multiple children.  If
   * not, then the admin view page doesn't get update after every 
   * test.
   */
  fp = fopen("/tmp/view.string", "w");
  if (fp == NULL) {
    return;
  }
  lock.l_type = F_WRLCK;
  i = fcntl((int)fp, F_SETLKW, lock);
  log_println(1, "successfully locked '/tmp/view.string' for updating");
  sprintf(view_string, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%s,%s",
      maxc2sspd, minc2sspd, maxs2cspd, mins2cspd, totalcnt,
      totmismatch, totbad_cable, count[0], count[1], count[2], count[3], count[4],
      count[5], count[6], count[7], count[8], count[9], count[10], count[11],
      count[12], count[13], count[14], count[15], maxdate, mindate);
  log_println(1, "sending '%s' to tmp file", view_string);
  fprintf(fp, "%s\n", view_string);
  lock.l_type = F_UNLCK;
  fcntl((int)fp, F_SETLK, lock);
  fclose(fp);
}
示例#11
0
/** Method to start snap worker thread that collects snap logs
 * @param snaparg object
 * @param tcp_stat_agent Agent
 * @param snaplogenabled Is snap logging enabled?
 * @param workerlooparg integer used to syncronize writing/reading from snaplog/tcp_stat snapshot
 * @param wrkrthreadidarg Thread Id of workera
 * @param metafilename	value of metafile name
 * @param tcp_stat_connection connection pointer
 * @param tcp_stat_group group web100_group pointer
 */
void start_snap_worker(SnapArgs *snaparg, tcp_stat_agent* agentarg,
                       CwndPeaks* peaks, char snaplogenabled,
                       pthread_t *wrkrthreadidarg, char *metafilename,
                       tcp_stat_connection conn, tcp_stat_group* group) {
    FILE *fplocal;

    WorkerArgs workerArgs;
    workerArgs.snapArgs = snaparg;
    workerArgs.agent = agentarg;
    workerArgs.peaks = peaks;
    workerArgs.writeSnap = snaplogenabled;

#if USE_WEB100
    group = web100_group_find(agentarg, "read");
    snaparg->snap = web100_snapshot_alloc(group, conn);
#elif USE_WEB10G
    snaparg->conn = conn;
    estats_val_data_new(&snaparg->snap);
#endif

    if (snaplogenabled) {
        // memcpy(metafilevariablename, metafilename, strlen(metafilename));
        // The above could have been here, except for a caveat: metafile stores
        // just the file name, but full filename is needed to open the log file

        fplocal = fopen(get_logfile(), "a");

#if USE_WEB100
        snaparg->log = web100_log_open_write(metafilename, conn, group);
#elif USE_WEB10G
        estats_record_open(&snaparg->log, metafilename, "w");
#endif
        if (fplocal == NULL) {
            log_println(
                0,
                "Unable to open log file '%s', continuing on without logging",
                get_logfile());
        } else {
            log_println(1, "Snaplog file: %s\n", metafilename);
            fprintf(fplocal, "Snaplog file: %s\n", metafilename);
            fclose(fplocal);
        }
    }

    if (pthread_create(wrkrthreadidarg, NULL, snapWorker,
                       (void*) &workerArgs)) {
        log_println(1, "Cannot create worker thread for writing snap log!");
        *wrkrthreadidarg = 0;
    }

    pthread_mutex_lock(&mainmutex);
    workerLoop= 1;
    // obtain web100 snap into "snaparg.snap"
#if USE_WEB100
    web100_snap(snaparg->snap);
    if (snaplogenabled) {
        web100_log_write(snaparg->log, snaparg->snap);
    }
#elif USE_WEB10G
    estats_read_vars(snaparg->snap, conn, agentarg);
    if (snaplogenabled) {
        estats_record_write_data(snaparg->log, snaparg->snap);
    }
#endif
    pthread_cond_wait(&maincond, &mainmutex);
    pthread_mutex_unlock(&mainmutex);
}
示例#12
0
void SqlciEnv::displayDiagnostics()
{
  NADumpDiags(cout, &sqlci_DA,
	      TRUE/*newline*/, FALSE/*comment-style*/,
	      get_logfile()->GetLogfile());
}
示例#13
0
Int32 SqlciEnv::executeCommands(InputStmt *& input_stmt)
{
   Int32 retval = 0;
   Int32 ignore_toggle = 0;
   SqlciNode * sqlci_node = 0;

   NABoolean inputPassedIn = (input_stmt ? TRUE : FALSE);

   try
   {

     while (!retval)
      {
	 total_opens = 0;
	 total_closes = 0;

	 // This is new'd here, deleted when history buffer fills up,
	 // in SqlciStmts::add/StmtEntry::set
	 if (NOT inputPassedIn)
	   input_stmt = new InputStmt(this);



	 Int32 read_error = 0;
	 if (NOT inputPassedIn)
	   read_error = input_stmt->readStmt(NULL/*i.e. input is stdin*/);

         prev_err_flush_input = 0;

	 if (cin.eof() || read_error == -99)
	   {
	       // allow the other thread to process
	       Sleep(50);				// milliseconds
	     if (!input_stmt->isEmpty())
	       {
		 // Unterminated statement in input file (redirected stdin).
		 // Make the parser emit an error message.
		 if (!isInteractiveSession())
		   input_stmt->display((UInt16)0);
		 input_stmt->logStmt();
		 input_stmt->syntaxErrorOnEof();
		 displayDiagnostics();
		 sqlci_DA.clear();
	       }
	     char command[10];
	     strcpy(command, ">>exit;");
	     if (!isInteractiveSession())
	       get_logfile()->WriteAll(command);
	     else if (get_logfile()->IsOpen())
#pragma nowarn(1506)   // warning elimination 
	       get_logfile()->Write(command, strlen(command));
#pragma warn(1506)  // warning elimination 
	     sqlci_parser(&command[2], &command[2], &sqlci_node,this);

	     if (sqlci_node)
	       {
		 retval = sqlci_node->process(this);
		 delete sqlci_node;
                 sqlci_node = NULL;
	       }
	   }
	 else
	   {
	     if (!isInteractiveSession())
	       input_stmt->display((UInt16)0);

	     if (logCommands())
	       get_logfile()->setNoLog(FALSE);
	     input_stmt->logStmt();
	     if (logCommands())
	       get_logfile()->setNoLog(TRUE);

	     if (!input_stmt->sectionMatches())
	       {
		 Int32 ignore_stmt = input_stmt->isIgnoreStmt();
		 if (ignore_stmt)
		   ignore_toggle = ~ignore_toggle;
		 if (ignore_stmt || ignore_toggle || input_stmt->ignoreJustThis())
		   {
		     // ignore until stmt following the untoggling ?ignore
		     sqlci_DA.clear();
		   }
		 else
		 {
		     getSqlciStmts()->add(input_stmt);
		     if (!read_error)
		     {
			retval = sqlci_parser(input_stmt->getPackedString(),
				   input_stmt->getPackedString(),
				   &sqlci_node, this);
			if (sqlci_node)
                        {
			  retval = sqlci_node->process(this);
			  delete sqlci_node;
                          sqlci_node = NULL;

			  if (retval == SQL_Canceled)
                            retval = 0;
			} else {
                          // pure MXCI synatax error. Reset retval
                            retval = 0;
                        }
		    }
                    if (retval > 0)
                    {
			if (!eol_seen_on_input)
			{
				prev_err_flush_input = -1;
			}
			retval = 0;
                    }

                 } // else
	    }// if
         } // else
	 if ( read_error == -20)
	 {
	    sqlci_DA << DgSqlCode(SQLCI_BREAK_RECEIVED, DgSqlCode::WARNING_);
	 }
         
         if (read_error == SqlciEnv::MAX_FRAGMENT_LEN_OVERFLOW && !eolSeenOnInput() )
           setPrevErrFlushInput();


        displayDiagnostics();
        sqlci_DA.clear(); // Clear the DiagnosticsArea for the next command...

	if (total_opens != total_closes)
	{
	    char buf[100];

	    sprintf(buf, "total opens = %d, total closes = %d", total_opens, total_closes);

#pragma nowarn(1506)   // warning elimination 
	    get_logfile()->WriteAll(buf, strlen(buf));
#pragma warn(1506)  // warning elimination 
	}

	// Delete the stmt if not one of those we saved on the history list
	if (!input_stmt->isInHistoryList())
	    delete input_stmt;
   
	if (inputPassedIn)
	  retval = 1;
    } // while
    if (retval == SQL_Canceled)
      return SQL_Canceled;
    else
      return 0;
   }
   catch(EHBreakException&)
   {
     sqlci_DA << DgSqlCode(SQLCI_BREAK_RECEIVED, DgSqlCode::WARNING_);
     displayDiagnostics();
     sqlci_DA.clear(); // Clear the DiagnosticsArea for the next command...

     if (sqlci_node)
       delete sqlci_node;
     sqlci_node = NULL;
     cin.clear();
     // NOTE: EnterCriticalSection has been done in ThrowBreakException()
     LeaveCriticalSection(&g_CriticalSection);
     return -1;
   }
   catch(...)
   {
      return 1;
   }

} // executeCommands