Esempio n. 1
0
int resetlog_cgi(HttpState *state)
{
   count = 0;
   clear_log();
   cgi_redirectto(state, REDIRECTTO);
   return 0;
}
Esempio n. 2
0
void ServerWidget::init_console()
{

    connect(action_clear_log, &QAction::triggered, this, &ServerWidget::clear_log);

    complete_cvar.setModel(&model_cvar);
    complete_cvar.setCaseSensitivity(Qt::CaseSensitive);
    complete_cvar.setModelSorting(QCompleter::CaseSensitivelySortedModel);
    complete_cvar.setCompletionColumn(CvarModel::Name);
    complete_cvar.setCompletionRole(Qt::DisplayRole);
    input_console->setWordCompleterPrefix("$");
    input_console->setHistory(settings().get_history(connection.details().name));
    clear_log();
}
Esempio n. 3
0
void LogDialog::on_pushButton_2_clicked()
{
    if (this->text.isEmpty() == false) {
        QMessageBox mbox;
        int ret;

        mbox.setText(QObject::tr("Are you sure you want to clear the log?"));
        mbox.setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
        mbox.setDefaultButton(QMessageBox::Cancel);
        mbox.setButtonText(QMessageBox::Ok, tr("Clear"));

        ret = mbox.exec();
        if (ret == QMessageBox::Ok) {
            emit clear_log();
            this->text.clear();
            ui->listWidget->clear();
        }
    }
}
Esempio n. 4
0
int main(int argc, char **argv)
{
    int err;
    int has_set_log_format = 0;
    int is_clear_log = 0;
    int getLogSize = 0;
    int mode = O_RDONLY;
	int i;
//    const char *forceFilters = NULL;
	struct log_device_t* devices = NULL;
	struct log_device_t* dev;

    g_logformat = (log_format *)log_format_new();

    if (argc == 2 && 0 == strcmp(argv[1], "--test")) {
        logprint_run_tests();
        exit(0);
    }

    if (argc == 2 && 0 == strcmp(argv[1], "--help")) {
        show_help(argv[0]);
        exit(0);
    }

    for (;;) {
        int ret;

        ret = getopt(argc, argv, "cdt:gsf:r:n:v:b:D");

        if (ret < 0) {
            break;
        }

        switch(ret) {
            case 's':
                // default to all silent
                log_add_filter_rule(g_logformat, "*:s");
            break;

            case 'c':
                is_clear_log = 1;
                mode = O_WRONLY;
            break;

            case 'd':
                g_nonblock = true;
            break;

            case 't':
                g_nonblock = true;
                g_tail_lines = atoi(optarg);
            break;


            case 'g':
                getLogSize = 1;
            break;

			case 'b': {
						  char* buf = (char*) malloc(strlen(LOG_FILE_DIR) + strlen(optarg) + 1);
						  if (buf == NULL) {
							  fprintf(stderr,"Can't malloc LOG_FILE_DIR\n");
							  exit(-1);
						  }
						  strcpy(buf, LOG_FILE_DIR);
						  strcat(buf, optarg);
						  //		snprintf(buf, strlen(LOG_FILE_DIR) + strlen(optarg) + 1, "%s%s", LOG_FILE_DIR, optarg);

                if (devices) {
					dev = devices;
                    while (dev->next) {
						dev = dev->next;
					}
					dev->next = (struct log_device_t *)malloc( sizeof(struct log_device_t));
					if (dev->next == NULL) {
						fprintf(stderr,"Can't malloc log_device\n");
						exit(-1);
					}
					dev->next->device = buf;
					dev->next->fd = -1;
					dev->next->printed = false;
					dev->next->queue = NULL;
					dev->next->next = NULL;

                } else {
					devices = (struct log_device_t *)malloc( sizeof(struct log_device_t));
					if (devices == NULL) {
						fprintf(stderr,"Can't malloc log_device\n");
						exit(-1);
					}
					devices->device = buf;
					devices->fd = -1;
					devices->printed = false;
					devices->queue = NULL;
					devices->next = NULL;
                }
                g_dev_count++;
            }
            break;

            case 'f':
                // redirect output to a file

                g_output_filename = optarg;

            break;

            case 'r':
//                if (optarg == NULL) {
//					fprintf(stderr,"optarg == null\n");
 //                  g_log_rotate_size_kbytes = DEFAULT_LOG_ROTATE_SIZE_KBYTES;
 //              } else {
                    //long logRotateSize;
                    //char *lastDigit;

                    if (!isdigit(optarg[0])) {
                        fprintf(stderr,"Invalid parameter to -r\n");
                        show_help(argv[0]);
                        exit(-1);
                    }
                    g_log_rotate_size_kbytes = atoi(optarg);
   //             }
            break;

            case 'n':
                if (!isdigit(optarg[0])) {
                    fprintf(stderr,"Invalid parameter to -r\n");
                    show_help(argv[0]);
                    exit(-1);
                }

                g_max_rotated_logs = atoi(optarg);
            break;

            case 'v':
                err = set_log_format (optarg);
                if (err < 0) {
                    fprintf(stderr,"Invalid parameter to -v\n");
                    show_help(argv[0]);
                    exit(-1);
                }

                has_set_log_format = 1;
            break;

			default:
				fprintf(stderr,"Unrecognized Option\n");
				show_help(argv[0]);
				exit(-1);
			break;
		}
	}

	if (!devices) {
        devices = (struct log_device_t *)malloc( sizeof(struct log_device_t));
		if (devices == NULL) {
			fprintf(stderr,"Can't malloc log_device\n");
			exit(-1);
		}
		devices->device = strdup("/dev/"LOGGER_LOG_MAIN);
		devices->fd = -1;
		devices->printed = false;
		devices->queue = NULL;
		devices->next = NULL;
        g_dev_count = 1;


        int accessmode =
                  (mode & O_RDONLY) ? R_OK : 0
                | (mode & O_WRONLY) ? W_OK : 0;

        // only add this if it's available
	if (0 == access("/dev/"LOGGER_LOG_SYSTEM, accessmode)) {
		devices->next = (struct log_device_t *)malloc( sizeof(struct log_device_t));
		if (devices->next == NULL) {
			fprintf(stderr,"Can't malloc log_device\n");
			exit(-1);
		}
		devices->next->device = strdup("/dev/"LOGGER_LOG_SYSTEM);
		devices->next->fd = -1;
		devices->next->printed = false;
		devices->next->queue = NULL;
		devices->next->next = NULL;
		g_dev_count ++;
	}
	if (0 == access("/dev/"LOGGER_LOG_APPS, accessmode)) {
		devices->next = (struct log_device_t *)malloc( sizeof(struct log_device_t));
		if (devices->next == NULL) {
			fprintf(stderr,"Can't malloc log_device\n");
			exit(-1);
		}
		devices->next->device = strdup("/dev/"LOGGER_LOG_APPS);
		devices->next->fd = -1;
		devices->next->printed = false;
		devices->next->queue = NULL;
		devices->next->next = NULL;
		g_dev_count ++;
	}
/*
        // only add this if it's available
	int fd;
	if ((fd = open("/dev/"LOGGER_LOG_SYSTEM, mode)) != -1) {
		devices->next = (struct log_device_t *)malloc( sizeof(struct log_device_t));
		devices->next->device = strdup("/dev/"LOGGER_LOG_SYSTEM);
		devices->next->fd = -1;
		devices->next->printed = false;
		devices->next->queue = NULL;
		devices->next->next = NULL;
		g_dev_count ++;

		close(fd);
        }
*/
    }

    if (g_log_rotate_size_kbytes != 0 && g_output_filename == NULL)
	{
		fprintf(stderr,"-r requires -f as well\n");
		show_help(argv[0]);
		exit(-1);
	}

    setup_output();


	if (has_set_log_format == 0) {
		err = set_log_format("brief");
	}
/*
		const char* logFormat = getenv("DLOG_PRINTF_LOG");

	        if (logFormat != NULL) {
			err = set_log_format("brief");

			if (err < 0) {
				fprintf(stderr, "invalid format in DLOG_PRINTF_LOG '%s'\n", logFormat);
			}
		}
	}
	if (forceFilters) {
		err = log_add_filter_string(g_logformat, forceFilters);
		if (err < 0) {
			fprintf (stderr, "Invalid filter expression in -logcat option\n");
			exit(0);
		}
	} else if (argc == optind) {
        // Add from environment variable
		char *env_tags_orig = getenv("DLOG_LOG_TAGS");

		if (env_tags_orig != NULL) {
			err = log_add_filter_string(g_logformat, env_tags_orig);

			if (err < 0) {
				fprintf(stderr, "Invalid filter expression in DLOG_LOG_TAGS\n");
				show_help(argv[0]);
				exit(-1);
			}
		}
	} else {
        // Add from commandline
*/
	fprintf(stderr,"arc = %d, optind = %d ,Kb %d, rotate %d\n", argc, optind,g_log_rotate_size_kbytes,g_max_rotated_logs);

	if(argc == optind )
	{
		// Add from environment variable
        //char *env_tags_orig = getenv("DLOG_TAGS");
		log_add_filter_string(g_logformat, "*:d");
	}
	else
	{

		for (i = optind ; i < argc ; i++) {
			err = log_add_filter_string(g_logformat, argv[i]);

			if (err < 0) {
				fprintf (stderr, "Invalid filter expression '%s'\n", argv[i]);
				show_help(argv[0]);
				exit(-1);
			}
		}
	}
/*
    }
*/
    dev = devices;
    while (dev) {
        dev->fd = open(dev->device, mode);
        if (dev->fd < 0) {
            fprintf(stderr, "Unable to open log device '%s': %s\n",
                dev->device, strerror(errno));
            exit(EXIT_FAILURE);
        }

        if (is_clear_log) {
            int ret;
            ret = clear_log(dev->fd);
            if (ret) {
                perror("ioctl");
                exit(EXIT_FAILURE);
            }
        }

        if (getLogSize) {
            int size, readable;

            size = get_log_size(dev->fd);
            if (size < 0) {
                perror("ioctl");
                exit(EXIT_FAILURE);
            }

            readable = get_log_readable_size(dev->fd);
            if (readable < 0) {
                perror("ioctl");
                exit(EXIT_FAILURE);
            }

            printf("%s: ring buffer is %dKb (%dKb consumed), "
                   "max entry is %db, max payload is %db\n", dev->device,
                   size / 1024, readable / 1024,
                   (int) LOGGER_ENTRY_MAX_LEN, (int) LOGGER_ENTRY_MAX_PAYLOAD);
        }

        dev = dev->next;
    }

    if (getLogSize) {
        return 0;
    }

    if (is_clear_log) {
        return 0;
    }

    read_log_lines(devices);

    return 0;
}
Esempio n. 5
0
int main() {

  // Initial blocks
  uint8_t blocks[5][2] = { {2,1}, {3,5}, {4,5}, {4,6}, {9,8}};

  // Initial start position
  uint8_t startx = WIDTH / 2;
  uint8_t starty = HEIGHT / 2;
	
  int readc = 0, quit = 0, playerid = PLAYER1;
  int textpos = 0;
	
  // Game area
  gamearea* game = new_gamearea(WIDTH,HEIGHT,5,blocks);
	
  // Player
  player* pl1 = new_player(playerid,startx,starty,HEALTH);

  initscr(); // Start ncurses
  noecho(); // Disable echoing of terminal input
  cbreak(); // Individual keystrokes
  intrflush(stdscr, FALSE); // Prevent interrupt flush
  keypad(stdscr,TRUE); // Allow keypad usage 

  start_color(); // Initialize colors

  // Color pairs init_pair(colorpair id,foreground color, background color)
  init_pair(PLAYER1,PLAYER1,COLOR_BLACK); // Player1 = COLOR_RED (1)
  init_pair(PLAYER2,PLAYER2,COLOR_BLACK); // Player2 = COLOR_GREEN (2)
  init_pair(PLAYER3,PLAYER3,COLOR_BLACK); // Player3 = COLOR_YELLOW (3)
  init_pair(PLAYER4,PLAYER4,COLOR_BLACK); // Player4 = COLOR_BLUE (4)
  init_pair(PLAYER_HIT_COLOR,COLOR_RED,COLOR_YELLOW);
  init_pair(WALL_COLOR,COLOR_WHITE,COLOR_WHITE);

  // Prepare everything
  clear_log();
  prepare_horizontal_line(WIDTH);
  ui_draw_grid(game, pl1);

  fd_set readfs;
  int rval = 0;

  while(1) {
    FD_ZERO(&readfs);
    FD_SET(fileno(stdin),&readfs);
 
    // Block until we have something
    if((rval = select(fileno(stdin)+1,&readfs,NULL,NULL,NULL)) > 0) {

      // From user
      if(FD_ISSET(fileno(stdin),&readfs)) {
        readc = getch(); // Get each keypress
        pl1->hitwall = 0;

        switch(readc) {
          case KEY_LEFT:
            if(is_position_a_wall(game,pl1->posx-1,pl1->posy)) pl1->hitwall = 1;
            else pl1->posx--;
            break;
          case KEY_RIGHT:
            if(is_position_a_wall(game,pl1->posx+1,pl1->posy)) pl1->hitwall = 1;
            else pl1->posx++;
            break;
          case KEY_UP:
            if(is_position_a_wall(game,pl1->posx,pl1->posy-1)) pl1->hitwall = 1;
            else pl1->posy--;
            break;
          case KEY_DOWN:
            if(is_position_a_wall(game,pl1->posx,pl1->posy+1)) pl1->hitwall = 1;
            else pl1->posy++;
            break;
          // Function keys, here F1 is reacted to
          case KEY_F(1):
            status = status ^ 1;
            break;
          case 27: // Escape key
            quit = 1;
            break;
          case '/':
            // User wants to write something
            memset(&textbuffer,0,BUFFER);
            textinput = 1;
            textpos = 0;
            break;
          // Erase text
          case KEY_BACKSPACE:
          case KEY_DC:
            textpos--;
            textbuffer[textpos] = '\0';
            break;
          // Push the line to log with enter
          case KEY_ENTER:
          case '\n':
            textinput = 0;
            if(strlen(textbuffer) > 0) add_log(textbuffer,textpos);
            textpos = 0;
            memset(&textbuffer,0,BUFFER);
            break;
          // Add the character to textbuffer if we were inputting text
          default:
            if(textinput == 1) {
              textbuffer[textpos] = readc;
              textpos++;
              if(textpos == BUFFER-1) {
                textpos = 0;
                textinput = 0;
              }
            }
            break;
          }
        }
      }

    // Hit a wall, change player
    if(pl1->hitwall) {
      pl1->health--;
      if(pl1->id == PLAYER4) pl1->id = PLAYER1;
      else pl1->id++;
    }

    // Update screen
    ui_draw_grid(game, pl1);

    // Suicide
    if(pl1->health == 0) {
      ui_draw_end(1);
      break;
    }
		
    // Surrended
    if(quit) {
      ui_draw_end(0);
      break;
    }
  }
  free_gamearea(game);
  free_player(pl1);
  free_horizontal_line();
  sleep(1);
  endwin(); // End ncurses
  return 0;
}
Esempio n. 6
0
int main (int argc, char *argv[]) {
  int i;
  progname = argv[0];
  while ((i = getopt (argc, argv, "fhvu:m:s:t:M:F")) != -1) {
    switch (i) {
    case 'F':
      filter_member_fan = 1;
      break;
    case 'v':
      verbosity += 1;
      break;
    case 'f':
      // vkprintf(2, "setting skip_rotate\n");
      skip_rotate = 1;
      break;
    case 'h':
      usage ();
      return 2;
    case 'u':
      username = optarg;
      break;
    case 'm':
      if (sscanf (optarg, "%d,%d", &copy_rem, &copy_mod) != 2 || copy_rem < 0 || copy_rem >= copy_mod) {
	usage();
	return 2;
      }
      break;
    case 's':
      jump_log_pos = atoll (optarg);
      break;
    case 't':
      keep_log_limit_pos = log_limit_pos = atoll (optarg);
      break;
    case 'M':
      if (!strncmp(optarg, "firstint", 9)) {
        split_mode = SPLIT_FIRSTINT;
      } else if (!strncmp(optarg, "liked", 6)) {
        split_mode = SPLIT_LIKED;
      } else {
        usage();
        return 2;
      }
      break;
    default:
      assert (0);
      return 2;
    }
  }

  if (optind >= argc || optind + 2 < argc) {
    usage();
    return 2;
  }

  if (filter_member_fan) {
    vkprintf (1, "fix member_fans, fan_members mode\n");
    char *p = strrchr (argv[optind], '/');
    p = (p == NULL) ? argv[optind] : (p + 1);
    if (!strncmp (p, "member_fans", 11)) {
      want_write = member_fans_want_write;
    } else if (!strncmp (p, "fan_members", 11)) {
      want_write = fan_members_want_write;
    } else {
      kprintf ("binlogname should starts from member_fans of fan_members when command line switch -F used.\n");
      exit (1);
    }
  }

  if (log_limit_pos >= 0) {
    if (jump_log_pos > log_limit_pos) {
      fprintf (stderr, "fatal: log start position %lld after stop position %lld\n", jump_log_pos, log_limit_pos);
      return 2;
    }
  }

  if (username && change_user (username) < 0) {
    fprintf (stderr, "fatal: cannot change user to %s\n", username ? username : "******");
    return 1;
  }

  if (engine_preload_filelist (argv[optind], binlogname) < 0) {
    fprintf (stderr, "cannot open binlog files for %s\n", binlogname ? binlogname : argv[optind]);
    exit (1);
  }

  Binlog = open_binlog (engine_replica, 0);
  if (!Binlog) {
    fprintf (stderr, "fatal: cannot find binlog for %s, log position %lld\n", engine_replica->replica_prefix, 0LL);
    exit (1);
  }

  binlogname = Binlog->info->filename;

  if (verbosity) {
    fprintf (stderr, "replaying binlog file %s (size %lld)\n", binlogname, Binlog->info->file_size);
  }

  clear_log();

  init_log_data (0, 0, 0);

  if (optind + 1 < argc) {
    targ_fname = argv[optind+1];
    targ_fd = open (targ_fname, O_WRONLY | O_APPEND | O_CREAT, 0644);
    if (targ_fd < 0) {
      fprintf (stderr, "cannot create %s: %m\n", targ_fname);
      return 1;
    }
    targ_orig_size = lseek (targ_fd, 0, SEEK_END);
    targ_existed = (targ_orig_size > 0);
  } else {
    targ_fname = "stdout";
    targ_fd = 1;
  }

  if (jump_log_pos > 0) {

    log_limit_pos = 256;
    immediate_exit = 1;

    i = replay_log (0, 1);

    if (!list_id_ints) {
      fprintf (stderr, "fatal: cannot parse first LEV_START entry");
      exit (1);
    }

    log_limit_pos = keep_log_limit_pos;
    immediate_exit = 0;

    clear_log ();

    close_binlog (Binlog, 1);
    Binlog = 0;

    Binlog = open_binlog (engine_replica, jump_log_pos);
    if (!Binlog) {
      fprintf (stderr, "fatal: cannot find binlog for %s, log position %lld\n", engine_replica->replica_prefix, jump_log_pos);
      exit (1);
    }

    binlogname = Binlog->info->filename;

    if (verbosity) {
      fprintf (stderr, "replaying binlog file %s (size %lld) from log position %lld\n", binlogname, Binlog->info->file_size, jump_log_pos);
    }

    init_log_data (jump_log_pos, 0, 0);
  }

  i = replay_log (0, 1);

  if (i < 0) {
    fprintf (stderr, "fatal: error reading binlog\n");
    exit (1);
  }

  if (log_limit_pos >= 0 && log_readto_pos != log_limit_pos) {
    fprintf (stderr, "fatal: binlog read up to position %lld instead of %lld\n", log_readto_pos, log_limit_pos);
    exit (1);
  }

  if (!targ_orig_size && !jump_log_pos) {
    vkprintf (1, "Writing CRC32 to the end of target binlog.\n");
    struct lev_crc32 *C = write_alloc (20);
    C->type = LEV_CRC32;
    C->timestamp = last_timestamp;
    C->pos = wr_bytes;
    C->crc32 = ~wr_crc32_complement;
    wr_bytes += 20;
    wr_rec++;
  }

  flush_out ();

  if (targ_fd != 1) {
    if (fdatasync (targ_fd) < 0) {
      fprintf (stderr, "error syncing %s: %m", targ_fname);
      exit (1);
    }
    close (targ_fd);
  }

  if (verbosity > 0) {
    output_stats ();
  }

  return 0;
}
Esempio n. 7
0
int main (int argc, char *argv[]) {
  int i;
  progname = argv[0];
  while ((i = getopt (argc, argv, "hvu:m:s:t:p")) != -1) {
    switch (i) {
    case 'p':
      fits = positive_counter_fits;
      break;
    case 'v':
      verbosity = 1;
      break;
    case 'h':
      usage();
      return 2;
    case 'u':
      username = optarg;
      break;
    case 'm':
      if (sscanf (optarg, "%d,%d", &copy_rem, &copy_mod) != 2 || copy_rem < 0 || copy_rem >= copy_mod) {
	usage();
	return 2;
      }
      break;
    case 's':
      jump_log_pos = atoll (optarg);
      break;
    case 't':
      log_limit_pos = atoll (optarg);
      break;
    }
  }

  if (copy_mod < 0) {
    usage ();
    return 2;
  }

  if (optind >= argc || optind + 2 < argc) {
    usage();
    return 2;
  }

  if (log_limit_pos >= 0) {
    if (jump_log_pos > log_limit_pos) {
      fprintf (stderr, "fatal: log start position %lld after stop position %lld\n", jump_log_pos, log_limit_pos);
      return 2;
    }
  }

  if (username && change_user (username) < 0) {
    fprintf (stderr, "fatal: cannot change user to %s\n", username ? username : "******");
    return 1;
  }

  if (engine_preload_filelist (argv[optind], binlogname) < 0) {
    fprintf (stderr, "cannot open binlog files for %s\n", binlogname ? binlogname : argv[optind]);
    exit (1);
  }

  Binlog = open_binlog (engine_replica, jump_log_pos);
  if (!Binlog) {
    fprintf (stderr, "fatal: cannot find binlog for %s, log position %lld\n", engine_replica->replica_prefix, 0LL);
    exit (1);
  }

  binlogname = Binlog->info->filename;

  if (verbosity) {
    fprintf (stderr, "replaying binlog file %s (size %lld)\n", binlogname, Binlog->info->file_size);
  }

  clear_log();

  init_log_data (jump_log_pos, 0, 0);

  if (jump_log_pos > 0) {
    init_stats_data (0);
  }

  if (optind + 1 < argc) {
    targ_fname = argv[optind+1];
    targ_fd = open (targ_fname, O_WRONLY | O_APPEND | O_CREAT, 0644);
    if (targ_fd < 0) {
      fprintf (stderr, "cannot create %s: %m\n", targ_fname);
      return 1;
    }
    targ_orig_size = lseek (targ_fd, 0, SEEK_END);
    targ_existed = (targ_orig_size > 0);
  } else {
    targ_fname = "stdout";
    targ_fd = 1;
  }

  i = replay_log (0, 1);

  if (i < 0) {
    fprintf (stderr, "fatal: error reading binlog\n");
    exit (1);
  }

  if (log_limit_pos >= 0 && log_readto_pos != log_limit_pos) {
    fprintf (stderr, "fatal: binlog read up to position %lld instead of %lld\n", log_readto_pos, log_limit_pos);
    exit (1);
  }

  flush_out ();

  if (targ_fd != 1) {
    if (fdatasync (targ_fd) < 0) {
      fprintf (stderr, "error syncing %s: %m", targ_fname);
      exit (1);
    }
    close (targ_fd);
  }

  if (verbosity > 0) {
    output_stats ();
  }

  return 0;
}
int main (int argc, char *argv[]) {
  int i;
  char new_binlog = 0;
  set_debug_handlers ();

  progname = argv[0];
  while ((i = getopt (argc, argv, "a:b:c:l:p:dhu:vEM:")) != -1) {
    switch (i) {
    case 'E':
      new_binlog = 1;
      break;
    case 'M':
      if (sscanf (optarg, "%d", &i) != 1 || i < 1) {
        kprintf ("invalid -M arg: %s", optarg);
        usage ();
      }
      max_lru_size = i;
      break;
    case 'a':
      binlogname = optarg;
      break;
    case 'b':
      backlog = atoi (optarg);
      if (backlog <= 0) backlog = BACKLOG;
      break;
    case 'c':
      maxconn = atoi (optarg);
      if (maxconn <= 0 || maxconn > MAX_CONNECTIONS) {
	maxconn = MAX_CONNECTIONS;
      }
      break;
    case 'd':
      daemonize ^= 1;
      break;
    case 'h':
      usage ();
      break;
    case 'l':
      logname = optarg;
      break;
    case 'p':
      port = atoi(optarg);
      break;
    case 'u':
      username = optarg;
      break;
    case 'v':
      verbosity++;
      break;
    }
  }

  if (argc != optind + 1) {
    usage ();
  }

  if (raise_file_rlimit (maxconn + 16) < 0) {
    kprintf ("fatal: cannot raise open file limit to %d\n", maxconn+16);
    exit (1);
  }

  aes_load_pwd_file (0);

  if (change_user (username) < 0) {
    kprintf ("fatal: cannot change user to %s\n", username ? username : "******");
    exit (1);
  }

  if (new_binlog) {
    copyexec_results_make_empty_binlog (argv[optind]);
    exit (0);
  }

  init_dyn_data ();

  if (engine_preload_filelist (argv[optind], binlogname) < 0) {
    kprintf ("cannot open binlog files for %s\n", binlogname ? binlogname : argv[optind]);
    exit (1);
  }

  vkprintf (3, "engine_preload_filelist done\n");

  //Binlog reading
  Binlog = open_binlog (engine_replica, jump_log_pos);
  if (!Binlog) {
    kprintf ("fatal: cannot find binlog for %s, log position %lld\n", engine_replica->replica_prefix, jump_log_pos);
    exit (1);
  }
  binlogname = Binlog->info->filename;
  vkprintf (1, "replaying binlog file %s (size %lld) from position %lld\n", binlogname, Binlog->info->file_size, jump_log_pos);
  binlog_load_time = -mytime();
  clear_log ();
  init_log_data (jump_log_pos, jump_log_ts, jump_log_crc32);
  vkprintf (1, "replay log events started\n");
  i = replay_log (0, 1);
  vkprintf (1, "replay log events finished\n");
  if (i < 0) {
    kprintf ("fatal: error reading binlog\n");
    exit (1);
  }
  binlog_load_time += mytime();
  binlog_loaded_size = log_readto_pos - jump_log_pos;
  if (!binlog_disabled) {
    clear_read_log();
  }
  clear_write_log ();
  start_time = time (0);

  start_server ();

  return 0;
}
Esempio n. 9
0
void CMainFrame::OnEditClearLog() {
  clear_log();
}
Esempio n. 10
0
int main(int argc, char *argv[])
{
	signal (SIGINT, signal_handler);
	//printf("\033[?1049h\033[H");

	clear_log();
	my_log("Software switch starting...");
	my_log(pcap_lib_version());

	int option = 0, ret;
	char c;
	pthread_t config_thread;
	char errbuf[PCAP_ERRBUF_SIZE];
	p1 = create_port_struct(1);
	p2 = create_port_struct(2);

	while ((option = getopt(argc, argv,"h l 1:2: m")) != -1) {
		switch (option) {
			case '1' :
				strcpy(p1->name, optarg);
				break;
			case '2' :
				strcpy(p2->name, optarg);
				break;
			case 'l':
				list_interfaces();
				exit(0);
			case 'm':
				mock_rule();
				break;
			case 'h':
			default: print_usage();
				exit(EXIT_FAILURE);
		}
	}

	p1->handle = pcap_create(p1->name, errbuf);
	if ( (ret = pcap_setdirection(p1->handle, PCAP_D_IN)) != 0){
		printf("pcap_setdirection returned %i\n", ret);
		my_log("pcap_setdirection failed");
		pcap_perror(p1->handle, 0);
		//exit(-1);
	}
	if ( pcap_set_promisc(p1->handle, 1) != 0){
		printf("pcap_set_promisc returned \n%s\n", pcap_geterr(p1->handle));

		my_log("pcap_set_promisc failed");
		pcap_perror(p1->handle, 0);
		exit(-1);
	}
	if ( pcap_set_immediate_mode(p1->handle, 1) != 0){
		printf("pcap_set_immediate_mode returned \n%s\n", pcap_geterr(p1->handle));
		my_log("pcap_set_immediate_mode failed");
		pcap_perror(p1->handle, 0);
		exit(-1);
	}
	if ( pcap_activate(p1->handle)){
		printf("Failed to open interface %s\n", pcap_geterr(p1->handle));
		exit(-1);
	} else {
		sprintf(log_b, "Handle activated for %s", p1->name);
		my_log(log_b);
	}




	p2->handle = pcap_create(p2->name, errbuf);
	if ( pcap_setdirection(p2->handle, PCAP_D_OUT) != 0){
		my_log("pcap_setdirection failed");
		pcap_perror(p2->handle, 0);
		//exit(-1);
	}
	if ( pcap_set_promisc(p2->handle, 1) != 0){
		my_log("pcap_set_promisc failed");
		pcap_perror(p2->handle, 0);
		exit(-1);
	}
	if ( pcap_set_immediate_mode(p2->handle, 1) != 0){
		my_log("pcap_set_immediate_mode failed");
		pcap_perror(p2->handle, 0);
		exit(-1);
	}
	if ( pcap_activate(p2->handle)){
		printf("Failed to open interface %s\n", pcap_geterr(p2->handle));
		exit(-1);
	} else {
		sprintf(log_b, "Handle activated for %s", p2->name);
		my_log(log_b);
	}

	//exit(0);

	my_log("Deleting mac table..");
	clear_mac();
	sprintf(log_b, "Default action is %s", (DEFAULT_ACTION == R_ALLOW)? "R_ALLOW" : "R_DENY");
	my_log(log_b);

	my_log("Creating threads...");
	pthread_mutex_init(&mutex, NULL);
	if ( pthread_create(&(p1->thread), 0, port_listener, (void *)p1) ){
		my_log("Error creating p1 thread");
		exit(-1);
	}
	if ( pthread_create(&(p2->thread), 0, port_listener, (void *)p2) ){
		my_log("Error creating p2 thread");
		exit(-1);
	}

	pthread_create(&config_thread, 0, config, 0);

	while (1) {
		mac_delete_old_entries(5);
		if(pause_rendering == 1)
			continue;

		// render here
		system("clear");
		print_mac();
		print_rules();
		print_stats_header();
		print_stats(p1->in, "1 IN");
		print_stats(p1->out, "1 OUT");
		print_stats(p2->in, "2 IN");
		print_stats(p2->out, "2 OUT");
		printf("p1in: %i\tp1out: %i\tp2in: %i\tp2out: %i\n", p1in, p1out, p2in, p2out);
		sleep(1);

	}

	pthread_join(config_thread, 0);
	pthread_join(p1->thread, 0);
	pthread_join(p2->thread, 0);

	//printf("\033[?1049l"); // go back

	return 0;
}