static void
complete(CamelMimeFilter *mf, char *in, size_t len, size_t prespace, char **out, size_t *outlenptr, size_t *outprespace)
{
	run(mf, in, len, prespace, out, outlenptr, outprespace, TRUE);
}
/**
 * Main function of "gnunet-helper-dns", which opens a VPN tunnel interface,
 * redirects all outgoing DNS traffic (except from the specified port) to that
 * interface and then passes traffic from and to the interface via stdin/stdout.
 *
 * Once stdin/stdout close or have other errors, the tunnel is closed and the
 * DNS traffic redirection is stopped.
 *
 * @param argc number of arguments
 * @param argv 0: binary name (should be "gnunet-helper-vpn")
 *             1: tunnel interface name (typically "gnunet-dns")
 *             2: IPv6 address for the tunnel ("FE80::1")
 *             3: IPv6 netmask length in bits ("64")
 *             4: IPv4 address for the tunnel ("1.2.3.4")
 *             5: IPv4 netmask ("255.255.0.0")
 * @return 0 on success, otherwise code indicating type of error:
 *         1 wrong number of arguments
 *         2 invalid arguments (i.e. port number / prefix length wrong)
 *         3 iptables not executable
 *         4 ip not executable
 *         5 failed to initialize tunnel interface
 *         6 failed to initialize control pipe
 *         8 failed to change routing table, cleanup successful
 *         9-23 failed to change routing table and failed to undo some changes to routing table
 *         24 failed to drop privs
 *         25-39 failed to drop privs and then failed to undo some changes to routing table
 *         40 failed to regain privs
 *         41-55 failed to regain prisv and then failed to undo some changes to routing table
 *         254 insufficient priviledges
 *         255 failed to handle kill signal properly
 */
int
main (int argc, char *const*argv)
{
  int r;
  char dev[IFNAMSIZ];
  char mygid[32];
  int fd_tun;
  uid_t uid;

  if (6 != argc)
  {
    fprintf (stderr, "Fatal: must supply 6 arguments!\n");
    return 1;
  }

  /* assert privs so we can modify the firewall rules! */
  uid = getuid ();
#ifdef HAVE_SETRESUID
  if (0 != setresuid (uid, 0, 0))
  {
    fprintf (stderr, "Failed to setresuid to root: %s\n", strerror (errno));
    return 254;
  }
#else
  if (0 != seteuid (0))
  {
    fprintf (stderr, "Failed to seteuid back to root: %s\n", strerror (errno));
    return 254;
  }
#endif

  /* verify that the binaries were care about are executable */
  if (0 == access ("/sbin/iptables", X_OK))
    sbin_iptables = "/sbin/iptables";
  else if (0 == access ("/usr/sbin/iptables", X_OK))
    sbin_iptables = "/usr/sbin/iptables";
  else
  {
    fprintf (stderr,
	     "Fatal: executable iptables not found in approved directories: %s\n",
	     strerror (errno));
    return 3;
  }
  if (0 == access ("/sbin/ip", X_OK))
    sbin_ip = "/sbin/ip";
  else if (0 == access ("/usr/sbin/ip", X_OK))
    sbin_ip = "/usr/sbin/ip";
  else
  {
    fprintf (stderr,
	     "Fatal: executable ip not found in approved directories: %s\n",
	     strerror (errno));
    return 4;
  }
  if (0 == access ("/sbin/sysctl", X_OK))
    sbin_sysctl = "/sbin/sysctl";
  else if (0 == access ("/usr/sbin/sysctl", X_OK))
    sbin_sysctl = "/usr/sbin/sysctl";
  else
  {
    fprintf (stderr,
             "Fatal: executable sysctl not found in approved directories: %s\n",
             strerror (errno));
    return 5;
  }

  /* setup 'mygid' string */
  snprintf (mygid, sizeof (mygid), "%d", (int) getegid());

  /* do not die on SIGPIPE */
  if (SIG_ERR == signal (SIGPIPE, SIG_IGN))
  {
    fprintf (stderr, "Failed to protect against SIGPIPE: %s\n",
             strerror (errno));
    return 7;
  }

  /* setup pipe to shutdown nicely on SIGINT */
  if (0 != pipe (cpipe))
  {
    fprintf (stderr,
	     "Fatal: could not setup control pipe: %s\n",
	     strerror (errno));
    return 6;
  }
  if (cpipe[0] >= FD_SETSIZE)
  {
    fprintf (stderr, "Pipe file descriptor to large: %d", cpipe[0]);
    (void) close (cpipe[0]);
    (void) close (cpipe[1]);
    return 6;
  }
  {
    /* make pipe non-blocking, as we theoretically could otherwise block
       in the signal handler */
    int flags = fcntl (cpipe[1], F_GETFL);
    if (-1 == flags)
    {
      fprintf (stderr, "Failed to read flags for pipe: %s", strerror (errno));
      (void) close (cpipe[0]);
      (void) close (cpipe[1]);
      return 6;
    }
    flags |= O_NONBLOCK;
    if (0 != fcntl (cpipe[1], F_SETFL, flags))
    {
      fprintf (stderr, "Failed to make pipe non-blocking: %s", strerror (errno));
      (void) close (cpipe[0]);
      (void) close (cpipe[1]);
      return 6;
    }
  }
  if ( (SIG_ERR == signal (SIGTERM, &signal_handler)) ||
#if (SIGTERM != GNUNET_TERM_SIG)
       (SIG_ERR == signal (GNUNET_TERM_SIG, &signal_handler)) ||
#endif
       (SIG_ERR == signal (SIGINT, &signal_handler)) ||
       (SIG_ERR == signal (SIGHUP, &signal_handler)) )
  {
    fprintf (stderr,
	     "Fatal: could not initialize signal handler: %s\n",
	     strerror (errno));
    (void) close (cpipe[0]);
    (void) close (cpipe[1]);
    return 7;
  }


  /* get interface name */
  strncpy (dev, argv[1], IFNAMSIZ);
  dev[IFNAMSIZ - 1] = '\0';

  /* Disable rp filtering */
  {
    char *const sysctl_args[] = {"sysctl", "-w",
      "net.ipv4.conf.all.rp_filter=0", NULL};
    char *const sysctl_args2[] = {"sysctl", "-w",
      "net.ipv4.conf.default.rp_filter=0", NULL};
    if ((0 != fork_and_exec (sbin_sysctl, sysctl_args)) ||
        (0 != fork_and_exec (sbin_sysctl, sysctl_args2)))
    {
      fprintf (stderr,
               "Failed to disable rp filtering.\n");
      return 5;
    }
  }


  /* now open virtual interface (first part that requires root) */
  if (-1 == (fd_tun = init_tun (dev)))
  {
    fprintf (stderr, "Fatal: could not initialize tun-interface\n");
    (void) signal (SIGTERM, SIG_IGN);
#if (SIGTERM != GNUNET_TERM_SIG)
    (void) signal (GNUNET_TERM_SIG, SIG_IGN);
#endif
    (void) signal (SIGINT, SIG_IGN);
    (void) signal (SIGHUP, SIG_IGN);
    (void) close (cpipe[0]);
    (void) close (cpipe[1]);
    return 5;
  }

  /* now set interface addresses */
  {
    const char *address = argv[2];
    long prefix_len = atol (argv[3]);

    if ((prefix_len < 1) || (prefix_len > 127))
    {
      fprintf (stderr, "Fatal: prefix_len out of range\n");
      (void) signal (SIGTERM, SIG_IGN);
#if (SIGTERM != GNUNET_TERM_SIG)
    (void) signal (GNUNET_TERM_SIG, SIG_IGN);
#endif
      (void) signal (SIGINT, SIG_IGN);
      (void) signal (SIGHUP, SIG_IGN);
      (void) close (cpipe[0]);
      (void) close (cpipe[1]);
      return 2;
    }
    set_address6 (dev, address, prefix_len);
  }

  {
    const char *address = argv[4];
    const char *mask = argv[5];

    set_address4 (dev, address, mask);
  }


  /* update routing tables -- next part why we need SUID! */
  /* Forward everything from our EGID (which should only be held
     by the 'gnunet-service-dns') and with destination
     to port 53 on UDP, without hijacking */
  r = 8; /* failed to fully setup routing table */
  {
    char *const mangle_args[] =
      {
	"iptables", "-m", "owner", "-t", "mangle", "-I", "OUTPUT", "1", "-p",
	"udp", "--gid-owner", mygid, "--dport", DNS_PORT, "-j",
	"ACCEPT", NULL
      };
    if (0 != fork_and_exec (sbin_iptables, mangle_args))
      goto cleanup_rest;
  }
  /* Mark all of the other DNS traffic using our mark DNS_MARK */
  {
    char *const mark_args[] =
      {
	"iptables", "-t", "mangle", "-I", "OUTPUT", "2", "-p",
	"udp", "--dport", DNS_PORT, "-j", "MARK", "--set-mark", DNS_MARK,
	NULL
      };
    if (0 != fork_and_exec (sbin_iptables, mark_args))
      goto cleanup_mangle_1;
  }
  /* Forward all marked DNS traffic to our DNS_TABLE */
  {
    char *const forward_args[] =
      {
	"ip", "rule", "add", "fwmark", DNS_MARK, "table", DNS_TABLE, NULL
      };
    if (0 != fork_and_exec (sbin_ip, forward_args))
      goto cleanup_mark_2;
  }
  /* Finally, add rule in our forwarding table to pass to our virtual interface */
  {
    char *const route_args[] =
      {
	"ip", "route", "add", "default", "dev", dev,
	"table", DNS_TABLE, NULL
      };
    if (0 != fork_and_exec (sbin_ip, route_args))
      goto cleanup_forward_3;
  }

  /* drop privs *except* for the saved UID; this is not perfect, but better
     than doing nothing */
#ifdef HAVE_SETRESUID
  if (0 != setresuid (uid, uid, 0))
  {
    fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno));
    r = 24;
    goto cleanup_route_4;
  }
#else
  /* Note: no 'setuid' here as we must keep our saved UID as root */
  if (0 != seteuid (uid))
  {
    fprintf (stderr, "Failed to seteuid: %s\n", strerror (errno));
    r = 24;
    goto cleanup_route_4;
  }
#endif

  r = 0; /* did fully setup routing table (if nothing else happens, we were successful!) */

  /* now forward until we hit a problem */
   run (fd_tun);

  /* now need to regain privs so we can remove the firewall rules we added! */
#ifdef HAVE_SETRESUID
  if (0 != setresuid (uid, 0, 0))
  {
    fprintf (stderr, "Failed to setresuid back to root: %s\n", strerror (errno));
    r = 40;
    goto cleanup_route_4;
  }
#else
  if (0 != seteuid (0))
  {
    fprintf (stderr, "Failed to seteuid back to root: %s\n", strerror (errno));
    r = 40;
    goto cleanup_route_4;
  }
#endif

  /* update routing tables again -- this is why we could not fully drop privs */
  /* now undo updating of routing tables; normal exit or clean-up-on-error case */
 cleanup_route_4:
  {
    char *const route_clean_args[] = 			
      {
	"ip", "route", "del", "default", "dev", dev,
	"table", DNS_TABLE, NULL
      };
    if (0 != fork_and_exec (sbin_ip, route_clean_args))
      r += 1;
  }
 cleanup_forward_3:
  {
    char *const forward_clean_args[] =
      {
	"ip", "rule", "del", "fwmark", DNS_MARK, "table", DNS_TABLE, NULL
      };
    if (0 != fork_and_exec (sbin_ip, forward_clean_args))
      r += 2;	
  }
 cleanup_mark_2:
  {
    char *const mark_clean_args[] =
      {
	"iptables", "-t", "mangle", "-D", "OUTPUT", "-p", "udp",
	"--dport", DNS_PORT, "-j", "MARK", "--set-mark", DNS_MARK, NULL
      };
    if (0 != fork_and_exec (sbin_iptables, mark_clean_args))
      r += 4;
  }	
 cleanup_mangle_1:
  {
    char *const mangle_clean_args[] =
      {
	"iptables", "-m", "owner", "-t", "mangle", "-D", "OUTPUT", "-p", "udp",
	 "--gid-owner", mygid, "--dport", DNS_PORT, "-j", "ACCEPT",
	NULL
      };
    if (0 != fork_and_exec (sbin_iptables, mangle_clean_args))
      r += 8;
  }

 cleanup_rest:
  /* close virtual interface */
  (void) close (fd_tun);
  /* remove signal handler so we can close the pipes */
  (void) signal (SIGTERM, SIG_IGN);
#if (SIGTERM != GNUNET_TERM_SIG)
    (void) signal (GNUNET_TERM_SIG, SIG_IGN);
#endif
  (void) signal (SIGINT, SIG_IGN);
  (void) signal (SIGHUP, SIG_IGN);
  (void) close (cpipe[0]);
  (void) close (cpipe[1]);
  return r;
}
示例#3
0
文件: dag.c 项目: bjarneh/organice
static void 
dag_link(struct dag * slf,char *output, char *match, char ** look, char ** lnk)
{
    
    int i, rv, main_count;
    char * args;
    struct pkg ** pks;
    
    if(slf->sorted){
        
        main_count = num_main_pkgs(slf);

        if( main_count > 1 ){
            pks = filter_relevant_main(slf, match);
        }else{
            pks = slf->sorted;
        }
        
        if( ! global_get_bool("-dryrun") ){
            if( dag_binary_up2date( pks , output ) ){
                if(! global_get_bool("-quiet")){
                    printf("up 2 date: %s\n", output );
                }
                return;
            }
        }

        struct strvec * v = new_strvec();
        
        v->add(v, global_get_str("-backend"));
        v->add(v, "-o");
        v->add(v, output );

        for(i = 0; pks[i]; i++){
            if(pks[i]->o_file){
                v->add(v, pks[i]->o_file);
            }
        }
        
        if(v->len(v) > 3){
            
            if(!global_get_bool("-quiet") && !global_get_bool("-dryrun") ) {
                printf("linking  : %s\n", output );
            }
            
            if( global_get_bool("-static") ){
                v->add(v, "-static");
            }
            
            if(look){
                for(i = 0; look[i]; i++){
                    v->add(v, "-L");
                    v->add(v, look[i]);
                }
            }

            if(lnk){
                for(i = 0; lnk[i]; i++){
                    v->add(v, "-l");
                    v->add(v, lnk[i]);
                }
            }

            args = v->join(v, " ");

            if(global_get_bool("-dryrun")) {
                printf("%s\n", args);
            }else{
                rv = run(args);
                if(rv == -1){ panic("failed to fork()",__FILE__,__LINE__); }
                if(rv){ exit(EXIT_FAILURE); }
            }
            
            free(args);
        }
        v->free(v);

        // we have allocated a new array if we filtered
        if( main_count > 1 ){
            free(pks);
        }
    }
};
示例#4
0
void TestFixture::run(const std::string &str)
{
    testToRun = str;
    run();
}
示例#5
0
文件: t_glob.c 项目: Lxg1582/freebsd
ATF_TC_BODY(glob_star_not, tc)
{
	run("a/**", 0, glob_star_not, __arraycount(glob_star_not));
}
示例#6
0
文件: server.cpp 项目: abners/brpc
 void run_and_delete() {
     run();
     delete this;
 }
// This test is expected to be executed either by a regular
// user or by root. If executed by a regular user it doesn't
// test all the functions that would depend on changing the
// effective user id. If executed by a super-user everything
// gets tested. Here are different ways of execing the test binary:
// 1. regular user assuming user == yarn user
//    $ test-container-executor     
// 2. regular user with a given yarn user
//    $ test-container-executor yarn_user
// 3. super user with a given user and assuming user == yarn user
//    # test-container-executor user
// 4. super user with a given user and a given yarn user
//    # test-container-executor user yarn_user
int main(int argc, char **argv) {
  LOGFILE = stdout;
  ERRORFILE = stderr;

  // clean up any junk from previous run
  if (system("chmod -R u=rwx " TEST_ROOT "; rm -fr " TEST_ROOT)) {
    exit(1);
  }
  
  if (mkdirs(TEST_ROOT "/logs/userlogs", 0755) != 0) {
    exit(1);
  }
  
  if (write_config_file(TEST_ROOT "/test.cfg", 1) != 0) {
    exit(1);
  }
  read_config(TEST_ROOT "/test.cfg");

  local_dirs = extract_values(strdup(NM_LOCAL_DIRS));
  log_dirs = extract_values(strdup(NM_LOG_DIRS));

  create_nm_roots(local_dirs);

  // See the description above of various ways this test
  // can be executed in order to understand the following logic
  char* current_username = strdup(getpwuid(getuid())->pw_name);
  if (getuid() == 0 && (argc == 2 || argc == 3)) {
    username = argv[1];
    yarn_username = (argc == 3) ? argv[2] : argv[1];
  } else {
    username = current_username;
    yarn_username = (argc == 2) ? argv[1] : current_username;
  }
  set_nm_uid(geteuid(), getegid());

  if (set_user(username)) {
    exit(1);
  }

  printf("\nStarting tests\n");

  printf("\nTesting resolve_config_path()\n");
  test_resolve_config_path();

  printf("\nTesting get_user_directory()\n");
  test_get_user_directory();

  printf("\nTesting get_app_directory()\n");
  test_get_app_directory();

  printf("\nTesting get_container_directory()\n");
  test_get_container_directory();

  printf("\nTesting get_container_launcher_file()\n");
  test_get_container_launcher_file();

  printf("\nTesting get_app_log_dir()\n");
  test_get_app_log_dir();

  test_check_configuration_permissions();

  printf("\nTesting delete_container()\n");
  test_delete_container();

  printf("\nTesting delete_app()\n");
  test_delete_app();

  test_check_user();

  // the tests that change user need to be run in a subshell, so that
  // when they change user they don't give up our privs
  run_test_in_child("test_signal_container_group", test_signal_container_group);

  // init app and run container can't be run if you aren't testing as root
  if (getuid() == 0) {
    // these tests do internal forks so that the change_owner and execs
    // don't mess up our process.
    test_init_app();
    test_run_container();
  }

  seteuid(0);
  // test_delete_user must run as root since that's how we use the delete_as_user
  test_delete_user();
  free_configurations();

  printf("\nTrying banned default user()\n");
  if (write_config_file(TEST_ROOT "/test.cfg", 0) != 0) {
    exit(1);
  }

  read_config(TEST_ROOT "/test.cfg");
  username = "******";
  test_check_user();

  run("rm -fr " TEST_ROOT);
  printf("\nFinished tests\n");

  free(current_username);
  free_configurations();
  return 0;
}
示例#8
0
void BundleRTS::apply() {
	run();
	output();
}
示例#9
0
void BundleRTS::run() {
	run(m_nPtsCon, m_nCamsCon, m_nMaxIter);
}
	typename std::shared_future<typename std::result_of<F(detail::convertible_to_async_helper)>::type> do_async(F f){
		auto ret = std::make_shared<detail::simple_async_function_holder<F>>(f);
		return ret->run();
	}
示例#11
0
void BundleRTS::apply(int nPtsCon, int nCamsCon, int maxIter) {
	run(nPtsCon, nCamsCon, maxIter);
	output();
}
示例#12
0
GUIEngine::GUIEngine(	irr::IrrlichtDevice* dev,
						gui::IGUIElement* parent,
						IMenuManager *menumgr,
						scene::ISceneManager* smgr,
						MainMenuData* data,
						bool& kill) :
	m_device(dev),
	m_parent(parent),
	m_menumanager(menumgr),
	m_smgr(smgr),
	m_data(data),
	m_texture_source(NULL),
	m_sound_manager(NULL),
	m_formspecgui(0),
	m_buttonhandler(0),
	m_menu(0),
	m_kill(kill),
	m_startgame(false),
	m_script(0),
	m_scriptdir(""),
	m_irr_toplefttext(0),
	m_clouds_enabled(true),
	m_cloud()
{
	//initialize texture pointers
	for (unsigned int i = 0; i < TEX_LAYER_MAX; i++) {
		m_textures[i].texture = NULL;
	}
	// is deleted by guiformspec!
	m_buttonhandler = new TextDestGuiEngine(this);

	//create texture source
	m_texture_source = new MenuTextureSource(m_device->getVideoDriver());

	//create soundmanager
	MenuMusicFetcher soundfetcher;
#if USE_SOUND
	m_sound_manager = createOpenALSoundManager(&soundfetcher);
#endif
	if(!m_sound_manager)
		m_sound_manager = &dummySoundManager;

	//create topleft header
	std::wstring t = narrow_to_wide(std::string("")); // = narrow_to_wide(std::string("MultiCraft ") + g_version_hash);

	core::rect<s32> rect(0, 0, g_fontengine->getTextWidth(t), g_fontengine->getTextHeight());
	rect += v2s32(4, 0);

	m_irr_toplefttext =
		m_device->getGUIEnvironment()->addStaticText(t.c_str(),
		rect,false,true,0,-1);

	//create formspecsource
	m_formspecgui = new FormspecFormSource("");

	/* Create menu */
	m_menu = new GUIFormSpecMenu(m_device,
			m_parent,
			-1,
			m_menumanager,
			NULL /* &client */,
			NULL /* gamedef */,
			m_texture_source,
			m_formspecgui,
			m_buttonhandler,
			NULL,
			false);

	m_menu->allowClose(false);
	m_menu->lockSize(true,v2u32(800,600));

	// Initialize scripting

	infostream << "GUIEngine: Initializing Lua" << std::endl;

	m_script = new MainMenuScripting(this);

	try {
		if (m_data->errormessage != "") {
			m_script->setMainMenuErrorMessage(m_data->errormessage);
			m_data->errormessage = "";
		}

		if (!loadMainMenuScript()) {
			errorstream << "No future without mainmenu" << std::endl;
			abort();
		}

		run();
	}
	catch(LuaError &e) {
		errorstream << "MAINMENU ERROR: " << e.what() << std::endl;
		m_data->errormessage = e.what();
	}

	m_menu->quitMenu();
	m_menu->drop();
	m_menu = NULL;
}
示例#13
0
 MatrixXd MCDAQ_t::run_get_data() {
      run();
      return get_data();
 }
static void
filter(CamelMimeFilter *mf, char *in, size_t len, size_t prespace, char **out, size_t *outlenptr, size_t *outprespace)
{
	run(mf, in, len, prespace, out, outlenptr, outprespace, FALSE);
}
示例#15
0
文件: cli.cpp 项目: FollowMyVote/fc
void cli::start()
{
   cli_commands() = get_method_names(0);
   _run_complete = fc::async( [&](){ run(); } );
}
示例#16
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    auto keys = QStyleFactory::keys();
    for (auto s : keys)
    {
        qDebug(s.toStdString().c_str());
    }

    QString ss = load_stylesheet(":/Stylesheets/common.qss");

#ifdef _6IT_UI_MOBILE
    ss.append(load_stylesheet(":/Stylesheets/common_mobile.qss"));
#else
    ss.append(load_stylesheet(":/Stylesheets/common_desktop.qss"));
#endif

#ifdef _6IT_QT_WINRT_DESKTOP
    ss.append(load_stylesheet(":/Stylesheets/winrt_desktop.qss"));
#elif defined(_6IT_QT_WINRT_PHONE)
    a.setStyle(QStyleFactory::create("Fusion"));
    ss.append(load_stylesheet(":/Stylesheets/winrt_phone.qss"));
#elif defined(_6IT_QT_WINRT_DESKTOP)
    ss.append(load_stylesheet(":/Stylesheets/windows_desktop.qss"));
#elif defined(_6IT_QT_IOS)
    ss.append(load_stylesheet(":/Stylesheets/ios.qss"));
#elif defined(_6IT_QT_ANDROID)
    a.setStyle(QStyleFactory::create("Fusion"));
    ss.append(load_stylesheet(":/Stylesheets/android.qss"));
#elif defined(_6IT_QT_LINUX_DESKTOP)
    ss.append(load_stylesheet(":/Stylesheets/linux_desktop.qss"));
#endif

    a.setStyleSheet(ss);

    QThread thread;
    auto pworker = new RZQtSubCWorker();
    auto &worker = *pworker;
    worker.moveToThread(&thread);
    thread.start();

    FileListWindow fileListWindow;
    ViewSourceWindow editorWindow;
    RunWindow runWindow;
    CompileWindow compileWindow(worker);
    fileListWindow.show();

    QObject::connect(&fileListWindow, SIGNAL(sourceSelected(QString)), &editorWindow, SLOT(show()));
    QObject::connect(&fileListWindow, SIGNAL(sourceSelected(QString)), &editorWindow, SLOT(loadFile(QString)));
    QObject::connect(&fileListWindow, SIGNAL(sourceSelected(QString)), &fileListWindow, SLOT(hide()));

    QObject::connect(&editorWindow, SIGNAL(navigatedBack()), &fileListWindow, SLOT(show()));
    QObject::connect(&editorWindow, SIGNAL(navigatedBack()), &editorWindow, SLOT(hide()));

    QObject::connect(&editorWindow, SIGNAL(runCode(QString const &)), &editorWindow, SLOT(hide()));
    QObject::connect(&editorWindow, SIGNAL(runCode(QString const &)), &compileWindow, SLOT(show()));
    QObject::connect(&editorWindow, SIGNAL(runCode(QString const &)), &compileWindow, SLOT(clear()));
    QObject::connect(&editorWindow, SIGNAL(runCode(QString const &)), &worker, SLOT(setSource(QString const &)));

    QObject::connect(&compileWindow, SIGNAL(navigatedBack()), &editorWindow, SLOT(show()));
    QObject::connect(&compileWindow, SIGNAL(navigatedBack()), &compileWindow, SLOT(hide()));
    QObject::connect(&worker, SIGNAL(compilationWillStart()), &compileWindow, SLOT(compileStarted()));
    QObject::connect(&worker, SIGNAL(compilationDidFinish()), &compileWindow, SLOT(compileFinished()));

    QObject::connect(&compileWindow, SIGNAL(runClicked()), &compileWindow, SLOT(hide()));
    QObject::connect(&compileWindow, SIGNAL(runClicked()), &runWindow, SLOT(show()));
    QObject::connect(&compileWindow, SIGNAL(runClicked()), &worker, SLOT(run()));

    QObject::connect(&runWindow, SIGNAL(navigatedBack()), &compileWindow, SLOT(show()));
    QObject::connect(&runWindow, SIGNAL(navigatedBack()), &runWindow, SLOT(hide()));
    QObject::connect(&worker, SIGNAL(runWillStart()), &runWindow, SLOT(runStarted()));
    QObject::connect(&worker, SIGNAL(runDidFinish()), &runWindow, SLOT(runFinished()));

    QObject::connect(&worker, SIGNAL(sourceChanged()), &worker, SLOT(compile()));
    QObject::connect(&worker, SIGNAL(compilerConsoleOutput(QString const &, int)), &compileWindow, SLOT(printString(QString const &, int)));
    QObject::connect(&worker, SIGNAL(runConsoleOutput(QString const &, int)), &runWindow, SLOT(printString(QString const &, int)));

    return a.exec();
}
示例#17
0
bool RenderHub::init()
{
    //std::cout<<"----------------------------\n"
    //		<<"SPACE LION - Early Prototype\n"
    //		<<"----------------------------\n";
    //	Initialize GLFW
    if(!glfwInit())
    {
        std::cout<<"-----\n"
                 <<"The time is out of joint - O cursed spite,\n"
                 <<"That ever I was born to set it right!\n"
                 <<"-----\n"
                 <<"Error: Couldn't initialize glfw.";

        return false;
    }
    //std::cout<<"Initializing GLFW\n";

    //glfwWindowHint(GLFW_VERSION_MAJOR,3);
    //glfwWindowHint(GLFW_VERSION_MINOR,3);
    glfwWindowHint(GLFW_SAMPLES, 4);

    activeWindow = glfwCreateWindow(800,450,"Sea-Crossing",NULL,NULL);

    if(!activeWindow)
    {
        std::cout<<"-----\n"
                 <<"The time is out of joint - O cursed spite,\n"
                 <<"That ever I was born to set it right!\n"
                 <<"-----\n"
                 <<"Error: Couldn't open glfw window";

        glfwTerminate();
        return false;
    }

    glfwMakeContextCurrent(activeWindow);

    /*
    /	The callback function needs a reference to this object,
    /	so just hand it over and quietly weep in the corner.
    */
    setActiveInstance(this);
    glfwSetWindowSizeCallback(activeWindow,windowSizeCallback);
    glfwSetWindowCloseCallback(activeWindow,windowCloseCallback);
    Controls::setControlCallbacks(activeWindow);

    /*	Initialize glew */
    //glewExperimental = GL_TRUE;
    GLenum error = glewInit();
    if( GLEW_OK != error)
    {
        std::cout<<"-----\n"
                 <<"The time is out of joint - O cursed spite,\n"
                 <<"That ever I was born to set it right!\n"
                 <<"-----\n"
                 <<"Error: "<<glewGetErrorString(error);
        return false;
    }
    /*
    /	Apparently glweInit() causes a GL ERROR 1280, so let's just catch that...
    */
    glGetError();

    /*
    /	This is actually not supposed to be done like this!
    */
    addScene();
    setActiveScene(0);
    run();

    return true;
}
int main(int argc, char *argv[]) {
	check_usage(argc);
	init(argv);
	run();
	return 0;
}
void test_delete_container() {
  if (initialize_user(yarn_username, local_dirs)) {
    printf("FAIL: failed to initialize user %s\n", yarn_username);
    exit(1);
  }
  char* app_dir = get_app_directory(TEST_ROOT "/local-2", yarn_username, "app_1");
  char* dont_touch = get_app_directory(TEST_ROOT "/local-2", yarn_username, 
                                       DONT_TOUCH_FILE);
  char* container_dir = get_container_work_directory(TEST_ROOT "/local-2", 
					      yarn_username, "app_1", "container_1");
  char buffer[100000];
  sprintf(buffer, "mkdir -p %s/who/let/the/dogs/out/who/who", container_dir);
  run(buffer);
  sprintf(buffer, "touch %s", dont_touch);
  run(buffer);

  // soft link to the canary file from the container directory
  sprintf(buffer, "ln -s %s %s/who/softlink", dont_touch, container_dir);
  run(buffer);
  // hard link to the canary file from the container directory
  sprintf(buffer, "ln %s %s/who/hardlink", dont_touch, container_dir);
  run(buffer);
  // create a dot file in the container directory
  sprintf(buffer, "touch %s/who/let/.dotfile", container_dir);
  run(buffer);
  // create a no permission file
  sprintf(buffer, "touch %s/who/let/protect", container_dir);
  run(buffer);
  sprintf(buffer, "chmod 000 %s/who/let/protect", container_dir);
  run(buffer);
  // create a no permission directory
  sprintf(buffer, "chmod 000 %s/who/let", container_dir);
  run(buffer);

  // delete container directory
  char * dirs[] = {app_dir, 0};
  int ret = delete_as_user(yarn_username, "container_1" , dirs);
  if (ret != 0) {
    printf("FAIL: return code from delete_as_user is %d\n", ret);
    exit(1);
  }

  // check to make sure the container directory is gone
  if (access(container_dir, R_OK) == 0) {
    printf("FAIL: failed to delete the directory - %s\n", container_dir);
    exit(1);
  }
  // check to make sure the app directory is not gone
  if (access(app_dir, R_OK) != 0) {
    printf("FAIL: accidently deleted the directory - %s\n", app_dir);
    exit(1);
  }
  // but that the canary is not gone
  if (access(dont_touch, R_OK) != 0) {
    printf("FAIL: accidently deleted file %s\n", dont_touch);
    exit(1);
  }
  sprintf(buffer, "chmod -R 700 %s", app_dir);
  run(buffer);
  sprintf(buffer, "rm -fr %s", app_dir);
  run(buffer);
  free(app_dir);
  free(container_dir);
  free(dont_touch);
}
示例#20
0
int main(int argc, char *argv[]){
	run();
	return 0;
}
示例#21
0
void UfrawWorker::developImpl(bool preview, WorkerBase *predecessor)
{
    qDebug() << "UfrawWorker::developImpl()" << this << predecessor;

    double progressPhaseA = 0.1;
    double progressPhaseB = 0.5;

    int nof = config()->settings()->getSetting(UfrawSettings::Fuse)->value().toInt();
    Magick::Image normalImg;
    std::vector<UfrawProcess>  ufraw(nof);
    int firstIdx = -(nof-1)/2;
    for( int i=0; i<nof; i++ )
    {
        setProgress( double(i) / nof * progressPhaseA );
        qDebug() << "UfrawWorker::developImpl() running" << i << "...";
        run( ufraw[i], preview, firstIdx+i, nof );
    }
    for( int i=0; i<nof; i++ )
    {
        setProgress( progressPhaseA + double(i) / nof * progressPhaseB );
        ufraw[i].waitForFinished(-1);
        qDebug() << "UfrawWorker::developImpl()" << i << "finished with exitcode" << ufraw[i].exitCode() << ":" << ufraw[i].console();
        if( ufraw[i].exitCode() == 0 )
        {
            bool isNormalExposed = (firstIdx+i)==0;
            bool isOverExposed   = (firstIdx+i)>0;
            qDebug() << "UfrawWorker::developImpl()" << i << "loading" << ufraw[i].output();
            Magick::Image img, mask;
            img.read( ufraw[i].output().toStdString().c_str() );
            if( isNormalExposed )
            {
                normalImg = img;
                normalImg.write( QString("/Users/manuel/tmp/test_normal.tif").toStdString().c_str() );
            }
            else
            {
                mask = masked( isOverExposed, 0.98, img );
                mask.write( ufraw[i].output().toStdString().c_str() );
                mask.write( QString("/Users/manuel/tmp/test_masked%1.tif").arg(i).toStdString().c_str() );
            }
        }
    }

    QStringList rawImages;
    for( int i=0; i<nof; i++ )
    {
        rawImages << ufraw[i].output();
    }

    if( nof > 1 )
    {
        double sigma = config()->settings()->getSetting(UfrawSettings::ExposureSigma)->value().toDouble();
        EnfuseProcess enfuse;
        enfuse.setProgram( m_enfusePath );
        enfuse.setInputs( rawImages );
        enfuse.setExposureSigma( sigma );
        connect( &enfuse, &EnfuseProcess::progress, [&](double progress) {
            setProgress( progressPhaseA + progressPhaseB + (1-progressPhaseA-progressPhaseB)*progress );
        });
        enfuse.run();
        enfuse.waitForFinished(-1);
        qDebug() << "UfrawWorker::developImpl() enfuse finished with exitcode" << enfuse.exitCode() << ":" << enfuse.console();
        if( enfuse.exitCode() == 0 )
        {
            qDebug() << "UfrawWorker::developImpl()" << "loading" << enfuse.output();
            m_img.read( enfuse.output().toStdString().c_str() );
            m_img.matte(false);
            qDebug() << "UfrawWorker::developImpl() fused" << m_img.format().c_str();
        }
    }
    else
    {
        m_img = normalImg;
    }
}
示例#22
0
文件: dmenu.c 项目: stilvoid/dmenu
int
main(int argc, char *argv[]) {
    int i;

    progname = "dmenu";
    for(i = 1; i < argc; i++)
        /* single flags */
        if(!strcmp(argv[i], "-v") || !strcmp(argv[1], "--version")) {
            fputs("dmenu-"VERSION", © 2006-2011 dmenu engineers, see LICENSE for details\n", stdout);
            exit(EXIT_SUCCESS);
        }
        else if(!strcmp(argv[i], "-b") || !strcmp(argv[i], "--bottom"))
            topbar = False;
        else if(!strcmp(argv[i], "-e") || !strcmp(argv[i], "--echo"))
            message = True;
        else if(!strcmp(argv[i], "-ec") || !strcmp(argv[i], "--echo-centre"))
            message = True, messageposition = CENTRE;
        else if(!strcmp(argv[i], "-er") || !strcmp(argv[i], "--echo-right"))
            message = True, messageposition = RIGHT;
        else if(!strcmp(argv[i], "-i") || !strcmp(argv[i], "--insensitive"))
            fstrncmp = strncasecmp;
        else if(!strcmp(argv[i], "-r") || !strcmp(argv[i], "--return-early"))
            returnearly = True;
        else if(i==argc-1)
            usage();
    /* opts that need 1 arg */
        else if(!strcmp(argv[i], "-et") || !strcmp(argv[i], "--echo-timeout"))
            timeout = atoi(argv[++i]);
        else if(!strcmp(argv[i], "-h") || !strcmp(argv[i], "--height"))
            height = atoi(argv[++i]);
        else if(!strcmp(argv[i], "-l") || !strcmp(argv[i], "--lines"))
            lines = atoi(argv[++i]);
        else if(!strcmp(argv[i], "-m") || !strcmp(argv[i], "--monitor"))
            monitor = atoi(argv[++i]);
        else if(!strcmp(argv[i], "-p") || !strcmp(argv[i], "--prompt"))
            prompt = argv[++i];
        else if(!strcmp(argv[i], "-po") || !strcmp(argv[i], "--prompt-only"))
            prompt = argv[++i], nostdin = True;
        else if(!strcmp(argv[i], "-fn") || !strcmp(argv[i], "--font-name"))
            font = argv[++i];
        else if(!strcmp(argv[i], "-nb") || !strcmp(argv[i], "--normal-background"))
            normbgcolor = argv[++i];
        else if(!strcmp(argv[i], "-nf") || !strcmp(argv[i], "--normal-foreground"))
            normfgcolor = argv[++i];
        else if(!strcmp(argv[i], "-sb") || !strcmp(argv[i], "--selected-background"))
            selbgcolor = argv[++i];
        else if(!strcmp(argv[i], "-sf") || !strcmp(argv[i], "--selected-foreground"))
            selfgcolor = argv[++i];
        else
            usage();

    if(message) {
        signal(SIGALRM, alarmhandler);
        alarm(timeout);
    }

    dc = initdc();
    initfont(dc, font);
    if(!nostdin) {
        readstdin();
    }
    setup();
    run();

    return EXIT_FAILURE;  /* should not reach */
}
示例#23
0
文件: t_glob.c 项目: Lxg1582/freebsd
ATF_TC_BODY(glob_star, tc)
{
	run("a/**", GLOB_STAR, glob_star, __arraycount(glob_star));
}
示例#24
0
int
main (int argc, char *const *argv)
{	
	  
  int getopt_ret;
  int option_index;
  struct option long_options[] = {
    {"port",  required_argument, 0, 'p'},
    {"certificate",  required_argument, 0, 'c'},
    {"certificate-key",  required_argument, 0, 'k'},
    {"backend-server",  required_argument, 0, 'b'},
    {"no-tls",  no_argument, 0, 'r'},
    {"verbose",  no_argument, 0, 'v'},
    {"curl-verbose",  no_argument, 0, 'h'},
    {"http10",  no_argument, 0, '0'},
    {"no-delay",  no_argument, 0, 'D'},
    {"transparent",  no_argument, 0, 't'},
    {"curl-ipv4",  no_argument, 0, '4'},
    {"curl-ipv6",  no_argument, 0, '6'},
    {0, 0, 0, 0}
  };
  
  while (1)
  {
    getopt_ret = getopt_long( argc, argv, "p:l:c:k:b:rv0Dth46", long_options, &option_index);
    if (getopt_ret == -1)
      break;

    switch(getopt_ret)
    {
      case 'p':
        glob_opt.listen_port = atoi(optarg);
        break;
        
      case 'l':
        glob_opt.listen_host= strdup(optarg);
        if(NULL == glob_opt.listen_host)
          return 1;
        break;
        
      case 'c':
        glob_opt.cert = strdup(optarg);
        break;
        
      case 'k':
        glob_opt.cert_key = strdup(optarg);
        break;
        
      case 'b':
        glob_opt.http_backend = strdup(optarg);
        if(NULL == glob_opt.http_backend)
          return 1;
        break;
        
      case 'r':
        glob_opt.notls = true;
        break;
        
      case 'v':
        glob_opt.verbose = true;
        break;
        
      case 'h':
        glob_opt.curl_verbose = true;
        break;
        
      case '0':
        glob_opt.http10 = true;
        break;
        
      case 'D':
        glob_opt.nodelay = true;
        break;
        
      case 't':
        glob_opt.transparent = true;
        break;
        
      case '4':
        glob_opt.ipv4 = true;
        break;
        
      case '6':
        glob_opt.ipv6 = true;
        break;
        
      case 0:
        PRINT_INFO("0 from getopt");
        break;
        
      case '?':
        display_usage();
        return 1;
        
      default:
        DIE("default from getopt");
    }
  }
  
  if(
    0 == glob_opt.listen_port
    || (!glob_opt.notls && (NULL == glob_opt.cert || NULL == glob_opt.cert_key))
    //|| !glob_opt.transparent && NULL != glob_opt.http_backend
    )
  {
    display_usage();
    return 1;
  }
    
  return run();
}
示例#25
0
文件: tuvm.c 项目: kprintf/edu
int main(int argc, char **argv)
{
	int i;
	int in_offset=0;
	char *in_fill=NULL;
	FILE *pfile;
	char ltrs[] = "urls";
	int synt = 5;
	pfile = stdin;
	for(i=1;i<argc;i++)
	{
		if(argv[i][0]=='-')
		{
			if(argv[i][1]=='p')
				pfile = fopen(argv[++i],"r");
			else if(argv[i][1]=='i' && argv[i][2]=='o')
				sscanf(argv[++i], "%i", &in_offset);
			else if(argv[i][1]=='i' && argv[i][2]==0)
				in_fill=argv[++i];
			else if(argv[i][1]=='d')
				debug = 1;
			else if(argv[i][1]=='s')
			{
				if(argv[i][2]=='4' || argv[i][2]=='5')
					synt = argv[i][2]-'0';
				else
				{
					printf("Wrong syntax type!\n");
					return 0;
				};
			}
			else if(argv[i][1]=='h')
			{
				printf(USAGE_MSG);
				return 0;
			}
		}
	}
	if(in_fill)
	{
		data.pos = in_offset;
		while(*in_fill)
		{
			data_write(*in_fill);
			in_fill++;
			data.pos++;
		}
	}
	if(!pfile)
	{
		printf("Cant open program file.\n");
		return 0;
	}
	if(synt==5)
		feed_program(pfile);
	else	feed_program4(pfile);
	run();
	print_line();
	if(debug)
		for(i=0;i<prog_len;i++)
			printf("%2u,%c,%c,%c,%2u\n",	cmd_qF(prog[i]),
							cmd_cF(prog[i]),
							cmd_cT(prog[i]),
							ltrs[cmd_act(prog[i])>>16],
							cmd_qT(prog[i])
							);
	return 0;
}
示例#26
0
void DelayedAction::run()
{
    if (next)
        QTimer::singleShot(next->delay, next, SLOT(run()));
};
示例#27
0
int main(int argc, char *argv[])
{
	const char *fs = NULL;

	setlocale(LC_CTYPE, "");
	setlocale(LC_NUMERIC, "C"); /* for parsing cmdline & prog */
	cmdname = argv[0];
	if (argc == 1) {
		fprintf(stderr, "Usage: %s [-f programfile | 'program'] [-Ffieldsep] [-v var=value] [files]\n", cmdname);
		exit(1);
	}
	signal(SIGFPE, fpecatch);
	yyin = NULL;
	symtab = makesymtab(NSYMTAB);
	while (argc > 1 && argv[1][0] == '-' && argv[1][1] != '\0') {
		if (strcmp(argv[1], "--") == 0) {	/* explicit end of args */
			argc--;
			argv++;
			break;
		}
		switch (argv[1][1]) {
		case 's':
			if (strcmp(argv[1], "-safe") == 0)
				safe = 1;
			break;
		case 'f':	/* next argument is program filename */
			argc--;
			argv++;
			if (argc <= 1)
				FATAL("no program filename");
			pfile[npfile++] = argv[1];
			break;
		case 'F':	/* set field separator */
			if (argv[1][2] != 0) {	/* arg is -Fsomething */
				if (argv[1][2] == 't' && argv[1][3] == 0)	/* wart: t=>\t */
					fs = "\t";
				else if (argv[1][2] != 0)
					fs = &argv[1][2];
			} else {		/* arg is -F something */
				argc--; argv++;
				if (argc > 1 && argv[1][0] == 't' && argv[1][1] == 0)	/* wart: t=>\t */
					fs = "\t";
				else if (argc > 1 && argv[1][0] != 0)
					fs = &argv[1][0];
			}
			if (fs == NULL || *fs == '\0')
				WARNING("field separator FS is empty");
			break;
		case 'v':	/* -v a=1 to be done NOW.  one -v for each */
			if (argv[1][2] == '\0' && --argc > 1 && isclvar((++argv)[1]))
				setclvar(argv[1]);
			break;
		case 'm':	/* more memory: -mr=record, -mf=fields */
				/* no longer supported */
			WARNING("obsolete option %s ignored", argv[1]);
			break;
		case 'd':
			dbg = atoi(&argv[1][2]);
			if (dbg == 0)
				dbg = 1;
			printf("awk %s\n", version);
			break;
		case 'V':	/* added for exptools "standard" */
			printf("awk %s\n", version);
			exit(0);
			break;
		default:
			WARNING("unknown option %s ignored", argv[1]);
			break;
		}
		argc--;
		argv++;
	}
	/* argv[1] is now the first argument */
	if (npfile == 0) {	/* no -f; first argument is program */
		if (argc <= 1) {
			if (dbg)
				exit(0);
			FATAL("no program given");
		}
		   dprintf( ("program = |%s|\n", argv[1]) );
		lexprog = argv[1];
		argc--;
		argv++;
	}
	recinit(recsize);
	syminit();
	compile_time = 1;
	argv[0] = cmdname;	/* put prog name at front of arglist */
	   dprintf( ("argc=%d, argv[0]=%s\n", argc, argv[0]) );
	arginit(argc, argv);
	if (!safe)
		envinit(environ);
	yyparse();
	setlocale(LC_NUMERIC, ""); /* back to whatever it is locally */
	if (fs)
		*FS = qstring(fs, '\0');
	   dprintf( ("errorflag=%d\n", errorflag) );
	if (errorflag == 0) {
		compile_time = 0;
		run(winner);
	} else
		bracecheck();
	return(errorflag);
}
示例#28
0
void GuiTester::runSequence()
{
    QTimer::singleShot(0, startAction, SLOT(run()));
}
示例#29
0
//Calculate the speed wrt shift, will run.
float speed()
{
	if (shift)
		return walk();
	return run();
}
示例#30
0
文件: main.cpp 项目: CCJY/coliru
int main() {
    for( int i = 0; i<20; ++i)
        run( i );
}