Ejemplo n.º 1
0
int main (int argc, char ** argv) {
	if (argc < 2) {
		fprintf(stderr, "%s: expected argument\n", argv[0]);
		return 1;
	}

	printf("(This should fork and the child process (but not the parent) should segfault)\n");

	size_t size = 27;
	volatile char * shm = (char *)syscall_shm_obtain(argv[1], &size);
	if (shm == NULL) {
		return 1;
	}

	int pid = getpid();
	uint32_t f = fork();
	if (getpid() != pid) {
		// Child: client
		return main_client(shm);
	} else {
		// Parent: server
		return main_server(shm);
	}

	return 0;
}
Ejemplo n.º 2
0
 int main(int argc, char const *argv[]) {
   if (atoi(argv[1]) == 1) {
     main_server();
  //    Order orders[MAX_QUEUE_SIZE];
  //    int i;
  //    elev_init();
  //    pthread_t buttons;
   //
  //    for (i = 0; i < MAX_QUEUE_SIZE; i++) {
  //    orders[i] = malloc(sizeof(Order));
   //
  //  }
   //
  //    pthread_create(&buttons, NULL, thread_monitor_button_inputs, (void *) orders);
   //
   //
   //
  //    while(1) {
   //
   //
  //      for (i = 0; i < MAX_QUEUE_SIZE; i++) {
  //        printf("Floor: %d, Direction: %d\n", orders[i].floor, orders[i].button_type);
  //      }
  //      printf("--------------------\n");
  //      sleep(5);
  //    }
     //
    //  pthread_join(buttons, NULL);



   }
   else if (atoi(argv[1]) == 2) {

     if(argc != 3) {
       printf("Not enough input arguments\n");
       exit(1);
     }
    main_client(argv[2]);
   }
   return 0;
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
	int ret = 0, c, udp = 0, ipv4 = -1, daemon = 1, log = 1;
	char *port = NULL, *stun = NULL, *dev = NULL, *home = NULL, *alias = NULL;
	enum working_mode wmode = MODE_UNKNOW;

	setfsuid(getuid());
	setfsgid(getgid());

	home = fetch_home_dir();

	while ((c = getopt_long(argc, argv, short_options, long_options,
				NULL)) != EOF) {
		switch (c) {
		case 'h':
			help();
			break;
		case 'v':
			version();
			break;
		case 'D':
			daemon = 0;
			break;
		case 'N':
			log = 0;
			break;
		case 'C':
			wmode = MODE_DUMPC;
			break;
		case 'S':
			wmode = MODE_DUMPS;
			break;
		case 'c':
			wmode = MODE_CLIENT;
			if (optarg) {
				if (*optarg == '=')
					optarg++;
				alias = xstrdup(optarg);
			}
			break;
		case 'd':
			dev = xstrdup(optarg);
			break;
		case 'k':
			wmode = MODE_KEYGEN;
			break;
		case '4':
			ipv4 = 1;
			break;
		case '6':
			ipv4 = 0;
			break;
		case 'x':
			wmode = MODE_EXPORT;
			break;
		case 's':
			wmode = MODE_SERVER;
			break;
		case 'u':
			udp = 1;
			break;
		case 't':
			stun = xstrdup(optarg);
			break;
		case 'p':
			port = xstrdup(optarg);
			break;
		case '?':
			switch (optopt) {
			case 't':
			case 'd':
			case 'u':
			case 'p':
				panic("Option -%c requires an argument!\n",
				      optopt);
			default:
				if (isprint(optopt))
					printf("Unknown option character `0x%X\'!\n", optopt);
				die();
			}
		default:
			break;
		}
	}

	if (argc < 2)
		help();

	register_signal(SIGINT, signal_handler);
	register_signal(SIGHUP, signal_handler);
	register_signal(SIGTERM, signal_handler);
	register_signal(SIGPIPE, signal_handler);

	curve25519_selftest();

	switch (wmode) {
	case MODE_KEYGEN:
		ret = main_keygen(home);
		break;
	case MODE_EXPORT:
		ret = main_export(home);
		break;
	case MODE_DUMPC:
		ret = main_dumpc(home);
		break;
	case MODE_DUMPS:
		ret = main_dumps(home);
		break;
	case MODE_CLIENT:
		ret = main_client(home, dev, alias, daemon);
		break;
	case MODE_SERVER:
		if (!port)
			panic("No port specified!\n");
		if (stun)
			print_stun_probe(stun, 3478, strtoul(port, NULL, 10));
		ret = main_server(home, dev, port, udp, ipv4, daemon, log);
		break;
	default:
		die();
	}

	free(dev);
	free(stun);
	free(port);
	free(alias);

	return ret;
}
Ejemplo n.º 4
0
int main(int argc, char **argv)
{
  qi::Application app(argc, argv);

  std::string usage = "If no mode is specified, run client and server in same process\n";

  po::options_description desc(std::string("Usage:\n ")+argv[0]+"\n" + usage);
  desc.add_options()
    ("help,h", "Print this help.")
    ("all", po::value<std::string>()->default_value("tcp://0.0.0.0:0"), "(default) Run all in the same process.")
    ("client,c", po::value<std::string>(), "Run as a client (tcp://xxx.xxx.xxx.xxx:xxxxx).")
    ("server,s", po::value<std::string>()->implicit_value("tcp://0.0.0.0:0"), "Run as a server.")
    ("gateway", po::value<std::string>(), "Run as a gateway.")
    ("local", "Run in local.")
    ("thread", po::value<int>()->default_value(1, "1"),
     "Number of thread to launch for clients")
    ("valgrind", "Set low loopcount and wait for valgrind.")
    ("gateway", "Run without gateway.")
    ("rstart", po::value<int>()->default_value(0, "0"), "rstart")
    ("rend", po::value<int>()->default_value(20, "20"), "rend")
    ("pipeline", po::value<int>()->default_value(1, "1"), "Max number of parallel calls to run")
    ("threadsafe", po::bool_switch()->default_value(false), "Declare threadsafe service")
    ("msdelay", po::value<int>()->default_value(0, "0"), "Delay in milliseconds to simulate long call")
    ;

  desc.add(qi::details::getPerfOptions());

  po::variables_map vm;
  po::store(po::command_line_parser(argc, argv)
            .options(desc).run(), vm);
  po::notify(vm);

  if (vm.count("help")) {
    std::cout << desc << std::endl;
    return EXIT_SUCCESS;
  }

  if (vm.count("gateway"))
    noGateway = false;

  if (vm.count("valgrind")) {
    gLoopCount = 500;
    valgrind = true;
  }


  if (vm.count("client") + vm.count("server") + !vm["all"].defaulted() + vm.count("gateway") + vm.count("local") > 1) {
    std::cerr << desc << std::endl << "You must put at most one option between [all|client|server|gateway|local]" << std::endl;
    return EXIT_FAILURE;
  }

  if (!vm["thread"].defaulted() && (vm.count("server") != 0 || vm.count("gateway") != 0)) {
    std::cerr << "[thread] is useless with [server] or [gateway]" << std::endl;
  }

  rstart = vm["rstart"].as<int>();
  rend   = vm["rend"].as<int>();
  pipeline = vm["pipeline"].as<int>();
  threadsafe = vm["threadsafe"].as<bool>();
  msDelay = vm["msdelay"].as<int>();

  out = new qi::DataPerfSuite("qimessaging", "transport", qi::DataPerfSuite::OutputData_Period, vm["output"].as<std::string>());

  if (vm.count("client"))
  {
    serverUrl = qi::Url(vm["client"].as<std::string>());
    int threadc = vm["thread"].as<int>();
    start_client(threadc);
  } else if (vm.count("server")) {
    serverUrl = vm["server"].as<std::string>();
    return main_server();
  } else if (vm.count("gateway")) {
    serverUrl = vm["gateway"].as<std::string>();
    return main_gateway(serverUrl);
  } else if (vm.count("local")) {
    return main_local();
  } else {
    //start the server
    int threadc = vm["thread"].as<int>();
    serverUrl = vm["all"].as<std::string>();
    allInOne = true;
    boost::thread threadServer1(boost::bind(&main_server));
    do {
      qi::os::msleep(500); // give it time to listen
    } while (!serverReady); // be nice for valgrind
    if (!noGateway)
      boost::thread threadServer2(boost::bind(&main_gateway, serverUrl));
    qi::os::sleep(1);

    start_client(threadc);
  }

  delete out;

  return EXIT_SUCCESS;
}