Esempio n. 1
0
static void
xml_out_status(struct Output *out, FILE *fp, time_t timestamp, int status,
               unsigned ip, unsigned ip_proto, unsigned port, unsigned reason, unsigned ttl)
{
    char reason_buffer[128];
    UNUSEDPARM(out);
    fprintf(fp, "<host endtime=\"%u\">"
                    "<address addr=\"%u.%u.%u.%u\" addrtype=\"ipv4\"/>"
                    "<ports>"
                    "<port protocol=\"%s\" portid=\"%u\">"
                    "<state state=\"%s\" reason=\"%s\" reason_ttl=\"%u\"/>"
                    "</port>"
                    "</ports>"
                "</host>"
                "\r\n",
        (unsigned)timestamp,
        (ip>>24)&0xFF,
        (ip>>16)&0xFF,
        (ip>> 8)&0xFF,
        (ip>> 0)&0xFF,
        name_from_ip_proto(ip_proto),
        port,
        status_string(status),
        reason_string(reason, reason_buffer, sizeof(reason_buffer)),
        ttl
        );
}
Esempio n. 2
0
/** Draw the status line at the top of the screen. The size of the filename
 * field varies depending on the width of the screen and the length of
 * the filename. */
void
edit_status (WEdit * edit)
{
    const int w = edit->widget.owner->cols;
    const size_t status_size = w + 1;
    char *const status = g_malloc (status_size);
    int status_len;
    const char *fname = "";
    int fname_len;
    const int gap = 3;          /* between the filename and the status */
    const int right_gap = 5;    /* at the right end of the screen */
    const int preferred_fname_len = 16;

    status_string (edit, status, status_size);
    status_len = (int) str_term_width1 (status);

    if (edit->filename_vpath != NULL)
        fname = vfs_path_get_last_path_str (edit->filename_vpath);

    fname_len = str_term_width1 (fname);
    if (fname_len < preferred_fname_len)
        fname_len = preferred_fname_len;

    if (fname_len + gap + status_len + right_gap >= w)
    {
        if (preferred_fname_len + gap + status_len + right_gap >= w)
            fname_len = preferred_fname_len;
        else
            fname_len = w - (gap + status_len + right_gap);
        fname = str_trunc (fname, fname_len);
    }

    dlg_move (edit->widget.owner, 0, 0);
    tty_setcolor (STATUSBAR_COLOR);
    printwstr (fname, fname_len + gap);
    printwstr (status, w - (fname_len + gap));

    if (simple_statusbar && w > EDITOR_MINIMUM_TERMINAL_WIDTH)
    {
        size_t percent = 100;

        if (edit->total_lines + 1 != 0)
            percent = (edit->curs_line + 1) * 100 / (edit->total_lines + 1);
        dlg_move (edit->widget.owner, 0, w - 5);
        tty_printf (" %3d%%", percent);
    }

    g_free (status);
}
Esempio n. 3
0
static inline void
edit_status_fullscreen (WEdit * edit, int color)
{
    Widget *h = WIDGET (WIDGET (edit)->owner);
    const int w = h->cols;
    const size_t status_size = w + 1;
    char *const status = g_malloc (status_size);
    int status_len;
    const char *fname = "";
    int fname_len;
    const int gap = 3;          /* between the filename and the status */
    const int right_gap = 5;    /* at the right end of the screen */
    const int preferred_fname_len = 16;

    status_string (edit, status, status_size);
    status_len = (int) str_term_width1 (status);

    if (edit->filename_vpath != NULL)
        fname = vfs_path_get_last_path_str (edit->filename_vpath);

    fname_len = str_term_width1 (fname);
    if (fname_len < preferred_fname_len)
        fname_len = preferred_fname_len;

    if (fname_len + gap + status_len + right_gap >= w)
    {
        if (preferred_fname_len + gap + status_len + right_gap >= w)
            fname_len = preferred_fname_len;
        else
            fname_len = w - (gap + status_len + right_gap);
        fname = str_trunc (fname, fname_len);
    }

    widget_move (h, 0, 0);
    tty_setcolor (color);
    printwstr (fname, fname_len + gap);
    printwstr (status, w - (fname_len + gap));

    if (simple_statusbar && w > EDITOR_MINIMUM_TERMINAL_WIDTH)
    {
        int percent;

        percent = edit_buffer_calc_percent (&edit->buffer, edit->buffer.curs1);
        widget_move (h, 0, w - 6 - 6);
        tty_printf (" %3d%%", percent);
    }

    g_free (status);
}
Esempio n. 4
0
static void
text_out_status(struct Output *out, FILE *fp, time_t timestamp,
    int status, unsigned ip, unsigned port, unsigned reason, unsigned ttl)
{
    UNUSEDPARM(ttl);
    UNUSEDPARM(reason);
    UNUSEDPARM(out);


    fprintf(fp, "%s tcp %u %u.%u.%u.%u %u\n",
        status_string(status),
        port,
        (ip>>24)&0xFF,
        (ip>>16)&0xFF,
        (ip>> 8)&0xFF,
        (ip>> 0)&0xFF,
        (unsigned)timestamp
        );
}
Esempio n. 5
0
void RTMFPServer::handleShellCommand(RTMFPReceiving * received) {
	if (!received) return;
	std::string tmp;
	std::string resp = "Cumulus server, build time: " __DATE__ " " __TIME__ ", start time: ";
	resp += _startDatetimeStr;
	resp += ", cur time: " + DateTimeFormatter::format(LocalDateTime(),"%b %d %Y %H:%M:%S");
	resp += "\n";

	//std::string req(received->bufdata());
	if (std::strcmp(received->bufdata(), "status") == 0) {
#if 0
		resp += "sessions_n: " + Poco::NumberFormatter::format(_sessions.count()) 
			+ " sessions_n_peak: " + Poco::NumberFormatter::format(_sessions.peakCount) 
			+ " task_handle_peak_qsize: " + Poco::NumberFormatter::format(peak_qsize()) + "\n"
			+ "rcvp: " + Poco::NumberFormatter::format(rcvpCnt > 0 ? (rcvpTm / rcvpCnt) : 0)  
			+ " peak_rcvp: " + Poco::NumberFormatter::format(peakRcvp)
			+ " psnd: " + Poco::NumberFormatter::format(psndCnt > 0 ? (psndTm / psndCnt) : 0)
			+ " peak_psnd: " + Poco::NumberFormatter::format(peakPsnd)
			+ "\n";
#endif
		poolThreads.status_string(tmp);
		resp += tmp; 
		sockets.status_string(tmp);
		resp += tmp;
		status_string(tmp);
		resp += tmp;
	}
	else if (std::strcmp(received->bufdata(), "help") == 0) {
		resp += "Commands: help status quit\n";
	}
	else if (std::strcmp(received->bufdata(), "quit") == 0) {
		//resp += "Good bye\n";	
		resp = "";	
	}
	else {
		resp += "Please type in `help` for details.\n";
	}

	received->socket.sendTo(resp.c_str(), resp.length(), received->address, 0); 
}
Esempio n. 6
0
/* Draw the status line at the top of the widget. The size of the filename
 * field varies depending on the width of the screen and the length of
 * the filename. */
void
edit_status (WEdit *edit)
{
    const int w = edit->widget.cols;
    const size_t status_size = w + 1;
    char * const status = g_malloc (status_size);
    int status_len;
    const char *fname = "";
    int fname_len;
    const int gap = 3; /* between the filename and the status */
    const int right_gap = 2; /* at the right end of the screen */
    const int preferred_fname_len = 16;

    status_string (edit, status, status_size);
    status_len = (int) strlen (status);

    if (edit->filename)
        fname = edit->filename;
    fname_len = strlen(fname);
    if (fname_len < preferred_fname_len)
        fname_len = preferred_fname_len;

    if (fname_len + gap + status_len + right_gap >= w) {
	if (preferred_fname_len + gap + status_len + right_gap >= w)
	    fname_len = preferred_fname_len;
	else
            fname_len = w - (gap + status_len + right_gap);
	fname = name_trunc (fname, fname_len);
    }

    widget_move (edit, 0, 0);
    attrset (SELECTED_COLOR);
    printwstr (fname, fname_len + gap);
    printwstr (status, w - (fname_len + gap));
    attrset (EDITOR_NORMAL_COLOR);

    g_free (status);
}
Esempio n. 7
0
static void
text_out_status(struct Output *out, FILE *fp, time_t timestamp,
    int status, unsigned ip, unsigned ip_proto, unsigned port, unsigned reason, unsigned ttl)
{
    const char *service = port_to_service(port, ip_proto);

    UNUSEDPARM(ttl);
    UNUSEDPARM(reason);
    UNUSEDPARM(out);

    fprintf(fp, "%s %s %u %u.%u.%u.%u %u %s\n",
        status_string(status),
        name_from_ip_proto(ip_proto),
        port,
        (ip>>24)&0xFF,
        (ip>>16)&0xFF,
        (ip>> 8)&0xFF,
        (ip>> 0)&0xFF,
        (unsigned)timestamp,
        service
        );
    fflush(fp);
}
Esempio n. 8
0
std::string Path_Validation_Result::result_string() const
   {
   return status_string(result());
   }
Esempio n. 9
0
extern int opnorm(const double *M, majority_t maj,
		  size_t m, size_t n,
		  double p, double q,
		  opnorm_opt_t opt,
		  double *norm,
		  double *vmax,
		  opnorm_stats_t *pstats)
{
  if ( (p <= 1.0) || (isinf(p) == 1) )
    {
      errno = EDOM;
      return OPNORM_EDOM_P;
    }

  if ( q < 1.0 )
    {
      errno = EDOM;
      return OPNORM_EDOM_Q;
    }

  if ( opt.eps <= 0.0 )
    {
      errno = EDOM;
      return OPNORM_EDOM_EPS;
    }

  if ( opt.eps <= DBL_EPSILON )
    {
      return OPNORM_INACC;
    }

  /* prepare shared thread data */

  tdat_shared_t ts =
    {
      .n = n,
      .m = m,
      .p = p,
      .q = q,
      .M = M,
      .eps = opt.eps,
      .tmax = 0,
      .vmax = vmax
    };

  /*
    mutexes - we maintain seperate mutexes for the
    fifo (queue and dequeue) and for the tmax variable,
    since the latter has a much higher access cadence
  */

  if (pthread_mutex_init(&(ts.fifolock), NULL) < 0)
    return OPNORM_FIFO;

  if (pthread_mutex_init(&(ts.maxlock), NULL) < 0)
    return OPNORM_FIFO;

  /*
    choose matrix-vector multiply function depending
    on the specified matrix majority (matvec.c)
  */

  switch (maj)
    {
    case row_major:
      ts.matvec = matvec_row_major;
      break;
    case column_major:
      ts.matvec = matvec_column_major;
      break;
    default:
      return OPNORM_BUG;
    }

  /* initialise the cube queue */

  if ( !(ts.fifo = init_fifo(n, opt.fifomax)) )
    return OPNORM_FIFO;

  /* Lipschitz constant for the radial projection */

  if (lcrp(p, &(ts.LCRP)) != 0)
    return OPNORM_BUG;

  /*
    surface cube diameter - the diameter of a (n-1)-cube
    of side one measured with the lp norm
  */

  ts.SCD = pow(n-1, 1/p);

  /* get number of threads */

  int nt = 1;

#if (defined HAVE_SYSCONF) && (defined _SC_NPROCESSORS_ONLN)

  nt = sysconf(_SC_NPROCESSORS_ONLN);

#endif

  char *ntenv = getenv("OPNORM_NTHREAD");

  if (ntenv)
    nt = atoi(ntenv);

  if (nt < 1)
    return OPNORM_THREAD;

  if (nt > MAX_THREADS)
    nt = MAX_THREADS;

  /*
    set up per-thread data - the status is set to
    OPNORM_USER since this field is assigned (to
    something else) before the worker threads exit
    normally. Having this as the default value means
    that those threads don't need to assign this
    field in response to a pthread_cancel() (which
    would require adding cleanup functions)
  */

  tdat_t td[nt];

  for (int i = 0 ; i < nt ; i++)
    {
      td[i].nfifo  = 0;
      td[i].neval  = 0;
      td[i].status = OPNORM_USER;
      td[i].shared = &ts;
    }

#ifdef HAVE_SIGNAL_H

  /* setup the signal handling thread */

  sigset_t sigset;

  sigemptyset(&sigset);
  sigaddset(&sigset, SIGQUIT);
  sigaddset(&sigset, SIGINT);
  sigaddset(&sigset, SIGUSR1);

  if (pthread_sigmask(SIG_BLOCK, &sigset, NULL) < 0)
    return OPNORM_THREAD;

#endif

  /* run worker threads */

  pthread_t thread[nt];

  for (int i = 0 ; i < nt ; i++)
    {
      if (pthread_create(thread + i,
			 NULL,
			 (void* (*)(void*))worker,
			 td + i) < 0)
	return OPNORM_THREAD;
    }

#ifdef HAVE_SIGNAL_H

  /* run signal handling thread */

  stdat_t stdat =
    {
      .n = nt,
      .thread = thread,
      .sigset = &sigset
    };

  pthread_t sigth;

  if (pthread_create(&sigth,
		     NULL,
		     (void* (*)(void*)) sigthread,
		     (void*) &stdat) < 0)
    return OPNORM_THREAD;

#endif

  /* join worker threads */

  for (int i = 0 ; i < nt ; i++)
    {
      if (pthread_join(thread[i], NULL) < 0)
	return OPNORM_THREAD;
    }

#ifdef HAVE_SIGNAL_H

  /* cancel and join the signal thread */

  if (pthread_cancel(sigth) < 0)
    return OPNORM_THREAD;

  if (pthread_join(sigth, NULL) < 0)
    return OPNORM_THREAD;

#endif

  /* harvest statistics */

  opnorm_stats_t stats =
    {
      .neval   = 0,
      .nfifo   = 0,
      .fifomax = 0,
      .nthread = nt
    };

  for (int i = 0 ; i < nt ; i++)
    {
      stats.nfifo += td[i].nfifo;
      stats.neval += td[i].neval;
    }

  stats.fifomax = fifo_peak(ts.fifo);

  /* clean up fifo */

  if (empty_fifo(ts.fifo) != 0)
    return OPNORM_FIFO;

  fifo_destroy(ts.fifo);

  /* clean up mutexes */

  if (pthread_mutex_destroy(&(ts.fifolock)) < 0)
    return OPNORM_THREAD;

  if (pthread_mutex_destroy(&(ts.maxlock)) < 0)
    return OPNORM_THREAD;

  /*
    harvest return values - the first that we find that
    is not OPNORM_OK we return
  */

  for (int i = 0 ; i < nt ; i++)
    {
      if ( td[i].status != OPNORM_OK )
	return td[i].status;
    }

  /* assign results */

  if (norm) *norm = ts.tmax;
  if (pstats) *pstats = stats;

  return OPNORM_OK;
}

/* error messages for opnorm() return values */

extern const char* opnorm_strerror(int err)
{
  return status_string(err);
}
Esempio n. 10
0
/* Program body */
int main(int argc, char *argv[]) {
	static int N; // Number of nodes
	static int token;
	static int event;
	static int r;
	static int i;
	static char fa_name[5];
	
	if (argc != 2) {
		puts("Uso correto: tempo [num-nodos]");
		exit(1);
	}
	
	N = atoi(argv[1]);
	smpl(0, "programa tempo");
	reset();
	stream(1); // 1 execution thread
	
	// Node intialization
	nodes = (Node*) malloc(N*sizeof(Node));
	for (i=0; i<N; i++) {
		memset (fa_name, '\0', 5);
		sprintf(fa_name, "%d", i);
		nodes[i].id = facility(fa_name, 1);
	}
	
	for (i=0; i<N; i++) {
		schedule (TEST, 30.0, i);
	}
	schedule (FAULT, 31.0, 2);
	schedule (REPAIR, 61.0, 2);
	
	while (time() < 100.0) {
		cause(&event, &token);
		switch(event) {
			case TEST:
				if(status(nodes[token].id) != FAULT_FREE) {
					printf("Deu zica");
					break;
				}
				printf("Sou o nodo %d, vou testar no tempo %5.1f\n", token, time());

				int j = token;
				do {
					j = (j+1) % N;

					printf("Estou testando o nodo %d, cujo status é: %s\n", j, status_string(status(nodes[j].id)));
					if (status(nodes[j].id) == FAULT_FREE) {
						// Get J's state array
					}

				} while (status(nodes[j].id) != FAULT_FREE);

				printf("\n");
				schedule(TEST, 30.0, token);
				break;
			case FAULT:
				r = request(nodes[token].id, token, 0);
				if (r != 0) {
					puts("Não consegui falhar o nodo!");
					exit(1);
				}
				printf("Sou o nodo %d, falhei no tempo %5.1f\n", token, time());

				break;
			case REPAIR:
				release(nodes[token].id, token);
				printf("Sou o nodo %d, recuperei no tempo %5.1f\n", token, time());

				schedule(TEST, 30.0, token);
				break;
		}
	}
}