Ejemplo n.º 1
0
int
main (int argc, char *argv[])
{
    const char *pid_file;
    int limit_nofile;

    if (2 != argc) {
        show_help (argv[0]);
        return -1;
    }

    if (0 > hev_config_init (argv[1]))
        return -2;

    if (0 > hev_socks5_tproxy_init ())
        return -3;

    limit_nofile = hev_config_get_misc_limit_nofile ();
    if (0 > set_limit_nofile (limit_nofile)) {
        fprintf (stderr, "Set limit nofile failed!\n");
        return -4;
    }

    pid_file = hev_config_get_misc_pid_file ();
    if (pid_file)
        run_as_daemon (pid_file);

    hev_socks5_tproxy_run ();

    hev_socks5_tproxy_fini ();

    hev_config_fini ();

    return 0;
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
#if ! defined(_WIN32)
     __log_error = (void (*)(void *, const char *,...)) log_server;     /*set c-icap library log  function */
#else
     __vlog_error = vlog_server;        /*set c-icap library  log function */
#endif

     mem_init();
     init_internal_lookup_tables();
     ci_acl_init();
     init_http_auth();
     if (init_body_system() != CI_OK) {
         ci_debug_printf(1, "Can not initialize body system\n");
         exit(-1);
     }
     ci_txt_template_init();
     ci_txt_template_set_dir(DATADIR"templates");
     commands_init();

     if (!(CI_CONF.MAGIC_DB = ci_magic_db_load(CI_CONF.magics_file))) {
          ci_debug_printf(1, "Can not load magic file %s!!!\n",
                          CI_CONF.magics_file);
     }
     init_conf_tables();
     request_stats_init();
     init_modules();
     init_services();
     config(argc, argv);
     compute_my_hostname();
     ci_debug_printf(2, "My hostname is:%s\n", MY_HOSTNAME);

     if (!log_open()) {
          ci_debug_printf(1, "Can not init loggers. Exiting.....\n");
          exit(-1);
     }

#if ! defined(_WIN32)
     if (is_icap_running(CI_CONF.PIDFILE)) {
          ci_debug_printf(1, "c-icap server already running!\n");
          exit(-1);
     }
     if (DAEMON_MODE)
          run_as_daemon();
     if (!set_running_permissions(CI_CONF.RUN_USER, CI_CONF.RUN_GROUP))
          exit(-1);
     store_pid(CI_CONF.PIDFILE);
#endif

     if (!init_server(CI_CONF.ADDRESS, CI_CONF.PORT, &(CI_CONF.PROTOCOL_FAMILY)))
          return -1;
     post_init_modules();
     post_init_services();
     start_server();
     clear_pid(CI_CONF.PIDFILE);
     return 0;
}
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
	char *app;
	int use_ssl = 1;  // 0 = disable SSL, 2 = allow insecure SSL

	if (options_parse(&argc, argv) != 0) {
		exit(1);
	}

	if (opt_daemon) {
		run_as_daemon();
	}

	/* Init exec environment */
	env_init(argc, argv);

	/* Init log management */
	log_init("hakit");
	log_str(options_summary);
	log_str("Using libwebsockets version " LWS_LIBRARY_VERSION " build " LWS_BUILD_HASH);

	/* Init system runtime */
	sys_init();

	/* Init communication engine */
	if (opt_no_ssl) {
		use_ssl = 0;
	}
	else if (opt_insecure_ssl) {
		use_ssl = 2;
	}
	if (comm_init(use_ssl, opt_no_hkcp ? 0:1, opt_hosts)) {
		return 2;
	}

	if (opt_monitor) {
		comm_monitor((comm_sink_func_t) monitor_sink_event, NULL);
	}

	/* Init module management */
	if (hk_mod_init(opt_class_path)) {
		return 2;
	}

	app = env_app();
	if (app != NULL) {
		if (hk_mod_load(app)) {
			return 3;
		}
		hk_obj_start_all();
	}

	sys_run();

	return 0;
}
Ejemplo n.º 4
0
int main(int argc, char *argv[]) {

	if (argc > 1) {
		if (strcmp(argv[1], "--daemon") == 0)
			run_as_daemon();
		else {
			fprintf(stderr, "%s (with no options)\n\tRun magiskhide and output to stdout\n", argv[0]);
			fprintf(stderr, "%s --daemon\n\tRun magiskhide as daemon, output to magisk.log\n", argv[0]);
			return 1;
		}
	} else 
		logfile = stdout;


	// Handle all killing signals
	signal(SIGINT, terminate);
	signal(SIGTERM, terminate);

	// Fork a child to handle namespace switches and unmounts
	pipe(pipefd);
	switch(fork()) {
		case -1:
			exit(-1);
		case 0:
			return hideMagisk();
		default:
			break; 
	}
	close(pipefd[0]);

	// Start a thread to constantly check the hide list
	pthread_mutex_init(&mutex, NULL);
	pthread_create(&list_monitor, NULL, monitor_list, HIDELIST);

	// Set main process to the top priority
	setpriority(PRIO_PROCESS, 0, -20);

	monitor_proc();

	terminate(0);

	fprintf(logfile, "MagiskHide: Cannot monitor am_proc_start, abort...\n");
	fclose(logfile);

	return 1;
}
Ejemplo n.º 5
0
int main(int argc, char  **argv)
{	
	out_bgorlit();
	test_hex2pro();
	test_pro2hex();
	
	cmd_parser(argc,argv,&glb_cfg);
	if(glb_cfg.daemon)
		run_as_daemon();
	
	/*
	 * Make sure only one copy of the daemon is running.
	 */
	if (already_running()) {
		debug(LOG_ERR, "daemon already running\n");
		exit(1);
	}
	
	pthread_mutex_init(&(glb_cfg.lock), NULL);
	pthread_cond_init(&(glb_cfg.cond), NULL);
//	init_log(argv[0]);
	
	init_signals();
	alarm(WT_SDCARD_PRIOD);

	pthread_t sorpid;
	pthread_create(&sorpid,NULL,handle_uart,NULL);
	
	pthread_t cmdpid;
	pthread_create(&cmdpid,NULL,handle_socket_machine,NULL);

	
	pthread_join(sorpid,NULL);
	pthread_join(cmdpid,NULL);
	
	debug(LOG_NOTICE,"<==========Process exit!\n");
//	close_log();
	return 0;
}
Ejemplo n.º 6
0
int main(int argc, char *argv[])
{
  int new_fd;
  struct sockaddr_in server_addr, conn_addr;
  int sin_size;
  int c;
  char isdaemon = 0;

  /* check parameters */
  while (( c = getopt(argc, argv, "Dv")) != -1)
    switch(c) {
    case 'D':
      isdaemon = 1;
      break;
    case 'v':
      showversion();
      exit(0);
      break;
    case '?':
      return 1;
    default:
      abort();
    }

  if (isdaemon)
    run_as_daemon();

  /* initialize the error logging */
  error_init("nettrafd", isdaemon);

  /* initialize the nettraf library - used to fetch information from the system */
  if (!nettraf_init())
    error_exit("Cannot initialize nettraf library");

  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    error_sys_exit("socket");
  }

  memset(&server_addr, 0, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(NETTRAFD_PORT);
  server_addr.sin_addr.s_addr = INADDR_ANY;

  if (bind(sockfd, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1) {
    error_sys_exit("bind");
  }

  if (listen(sockfd, 10) == -1) {
    error_sys_exit("listen");
  }

  signal(SIGINT, (void *)&sighandler);

  while (1) {
    sin_size = sizeof(struct sockaddr_in);
    if ((new_fd = accept(sockfd, (struct sockaddr *)&conn_addr, &sin_size)) == -1) {
      error_sys_report("accept");
      continue;
    }
#ifdef DEBUG
    printf("server: got connection from %s\n", inet_ntoa(conn_addr.sin_addr));
#endif

#ifdef USE_LIBWRAP
    request_init(&request, RQ_DAEMON, "nettraf", RQ_FILE, 0, 0);
    fromhost(&request);
    if (! hosts_access(&request)) {
      char text[256];

      sprintf(text, "Connection from %s:%d REFUSED by LIBWRAP", inet_ntoa(conn_addr.sin_addr), ntohs(conn_addr.sin_port));
      error_report(text);
      close(new_fd);
    } else
#endif
    ntd_newconnection(new_fd, conn_addr);
  }

  /* should never reach this... */
  do_cleanup();
  exit(0);
}
Ejemplo n.º 7
0
Archivo: main.c Proyecto: qbbian/dptf
int main (int argc, char **argv)
{
	int c = 0;
	FILE *fp = stdin;
	char command[MAX_LINE + 1] = {0};
	int quit_after_command = ESIF_FALSE;
#if defined(ESIF_ATTR_DAEMON)
        int start_as_server = ESIF_FALSE;
        int start_with_pipe = ESIF_FALSE;
        int start_with_log = ESIF_FALSE;
#else
        int start_as_server = ESIF_TRUE;
#endif

	// Init ESIF
	int rc = chdir("..");

	optind = 1;	// Rest To 1 Restart Vector Scan

	while ((c = getopt(argc, argv, "d:f:c:b:nxhq?spl")) != -1) {
		switch (c) {
		case 'd':
			g_dst = (u8)esif_atoi(optarg);
			break;

		case 'n':
			g_autocpc = ESIF_FALSE;
			break;

		case 'x':
			g_format = FORMAT_XML;
			break;

		case 'b':
			g_binary_buf_size = (int)esif_atoi(optarg);
			break;

		case 'f':
			fp = fopen(optarg, "r");
			break;

		case 'c':
			sprintf(command, "%s", optarg);
			break;

		case 'q':
			quit_after_command = ESIF_TRUE;
			break;

#if defined (ESIF_ATTR_DAEMON)

		case 's':
			start_as_server = ESIF_TRUE;
			break;

		case 'p':
			start_with_pipe = ESIF_TRUE;
			break;

		case 'l':
			start_with_log = ESIF_TRUE;
			break;
#endif

		case 'h':
		case '?':
			printf(
			"EsiF Eco-System Independent Framework Shell\n"
			"(c) 2013 Intel Corp\n\n"
			"-d [*id]            Set Destination\n"
			"-f [*filename]      Load Filename\n"
			"-n                  No Auto CPC Assignment\n"
			"-x                  XML Output Data Format\n"
			"-c [*command]       Issue Shell Command\n"
			"-q                  Quit After Command\n"
			"-b [*size]          Set Binary Buffer Size\n"
#if defined (ESIF_ATTR_DAEMON)
			"-s                  Run As Server\n"
			"-p                  Use Pipe For Input\n"
			"-l                  Use Log For Output\n"
#endif
			"-h or -?            This Help\n\n");
			exit(0);
			break;

		default:
			break;
		}
	}

#if defined (ESIF_ATTR_DAEMON)
        if (start_as_server) {
		run_as_server(fp, command, quit_after_command);
	} else {
		run_as_daemon(start_with_pipe, start_with_log);
	}
#else
	run_as_server(fp, command, quit_after_command);
#endif

 	if (fp && fp != stdin) {
                fclose(fp);
        }

	/* NICE Wait For Worker Thread To Exit */
	printf("Waiting For EVENT Thread To Exit...\n");
	while (!g_quit2) {
		esif_ccb_sleep(1);
	}
	printf("Errorlevel Returned: %d\n", g_errorlevel);

	/* Exit ESIF */
	esif_uf_exit();
	exit(g_errorlevel);
}
Ejemplo n.º 8
0
Archivo: main.cpp Proyecto: xlin/pbs
int main(int argc, char **argv){
    if (getuid()!=0){
	std::cout << "run only root" << std::endl;
	return 1;
    }
    MYSQL_RES *result;
    MYSQL_ROW row;
    MYSQL *connection, mysql;    
    
    // Защита от двойного запуска
    int fd = -1;
    if ((fd = open(PATHLOCK, O_RDWR| O_CREAT, S_IRUSR| S_IWUSR)) == -1) {
        int myerr = errno;
        printf("ERROR: open errno(%d): %s\n", errno,strerror(myerr));
        return EXIT_FAILURE;
    }
    if (LockFile(fd)==EXIT_FAILURE){
	std::cout << "ERROR: is already running" << std::endl;
	return 1;
    }
    
    
    // Читаем в map параметры командной строки
    map<string,string> cmdParam = loadArgv(argc,argv);
    
    if (cmdParam["--daemon"]=="true") run_as_daemon();
    

    map<string,string> conf = loadConfig();
    //string pathAum=conf["paths/pathAum"];
    string pathUserHome=conf["paths/pathUserHome"];
    //string pathPbs=conf["paths/pathPbs"];
    string pathTemp=conf["paths/pathTemp"];

    string cmdLine="";
    string sqlQuery="";
    int buildError=0;		// Состояние ошибки
    
    mysql_init(&mysql);
    connection = mysql_real_connect(&mysql,conf["mysql/hostname"].c_str(), conf["mysql/username"].c_str(), conf["mysql/password"].c_str(), conf["mysql/database"].c_str(), 0, NULL,0);
    if( connection == NULL ) {
	printf("%s\n",mysql_error(&mysql));
        return 1;
    }
    
    srand (time(NULL));

    // Тут будет основной цикл
    while(1){
	
	int state = mysql_query(connection, 
	    "SELECT t1.id,t1.file_id, t2.filename, t3.user, t4.os, t4.arch "
	    "FROM jobs as t1, tsrc t2, users as t3, platforms as t4 "
	    "WHERE t1.status=0 and t2.id=t1.file_id and t3.id=t2.user_id and t4.id=t1.platform_id ");
	    
	if( state != 0 ) {
	    printf("%s\n",mysql_error(connection));
	    break;
	}

        result = mysql_store_result(connection);    
	while( ( row = mysql_fetch_row(result)) != NULL ) {
    	    printf("%s, %s\n",  row[0],row[1]);
    	
    	    // 
    	    sqlQuery="UPDATE jobs SET status='1' WHERE id='"+string(row[0])+"'";
    	    mysql_query(connection,sqlQuery.c_str());
    	
    	    string dbNSrcFile=string(row[1]);
    	    string dbOsName=string(row[4]);
    	    string dbOsArch=string(row[5]);
	    string username=string(row[3]);
	    string jobFilename=string(row[2]);
	    
	    string aumOsKey=dbOsName+"_"+dbOsArch;
	    string aumLogFile=pathUserHome+"/"+username+"/logs/"+dbNSrcFile+"/"+aumOsKey+".txt";
	    string aumUploadDir=pathTemp+"/files/"+dbNSrcFile;
	    string aumFileName=pathUserHome+"/"+username+"/srpms/"+dbNSrcFile+"/"+jobFilename;

	    std::cout << " " << dbNSrcFile << " " << dbOsName << " " << dbOsArch << " " << username << " " << jobFilename << " " << aumOsKey << std::endl;
	    
	    string aumChroot=conf[aumOsKey+"/chroot"];
	    string aumDistrib=conf[aumOsKey+"/distrib"];
	    
	    string aumPathTemp=pathTemp+"/pbs-chroot-"+dbNSrcFile+"-"+aumOsKey;
	    
	    //Создание временной папки
	    pbsMkdir(aumUploadDir);
	    pbsMkdir(aumPathTemp);

	    map<string,string> options;
	
	    // Формирование строки
	    //cmdLine=pathAum+" ";
	    options["chroot"]=aumChroot;
	    options["distrib"]=aumDistrib;
	    options["log-file"]=aumLogFile;
	    options["upload-dir"]=aumUploadDir;
	    options["tmp-dir"]=aumPathTemp;
	    
	    if (boost::filesystem::exists(pathUserHome+"/"+username+"/.rpmmacros")==true){
		options["rpmmacros"]=pathUserHome+"/"+username+"/.rpmmacros";
	    }
	    options["srpm"]=aumFileName;

	    

	    // Запуск сборки
	    //buildError=system(cmdLine.c_str());
	    cBuild bb;
	    buildError=bb.build(options);
	    if (buildError!=0){
    	        string sqlQuery="UPDATE jobs SET status='11' WHERE id='"+string(row[0])+"'";
    		mysql_query(connection,sqlQuery.c_str());
		continue;
	    }
	    

	    string targetOs = pathUserHome+"/"+username+"/repo/"+dbOsName;
	    int countFile=copyRpmToRepo(aumUploadDir,targetOs);
	    if (countFile==0){
    	        string sqlQuery="UPDATE jobs SET status='11' WHERE id='"+string(row[0])+"'";
    		mysql_query(connection,sqlQuery.c_str());
		continue;
	    }
	    
	    // Удаление временной папки
	    boost::filesystem::remove_all(aumUploadDir);

	    
	    // Пересоздание репозитория
	    exec_cmd("pbs-hdlistgen "+username+ " "+dbOsName);
	    
	    
    	    sqlQuery="UPDATE jobs SET status='10' WHERE id='"+string(row[0])+"'";
	    mysql_query(connection,sqlQuery.c_str());
	    
	    std::cout << "Build end" << std::endl;
	    
	}
	mysql_free_result(result);

	sleep(1);
    }
    
    
    mysql_close(connection);

    return 0;
}