Exemple #1
0
int execute_script(const char *cmd)
{
	char args[4096];
	char *argv[16];
	int  argc;
	int len;

	len = strlen(cmd);

	if(len > 0)
	{
		char redir[PATH_MAX];
		int  type;
		int binlen = parse_cli(cmd, args, &argc, argv, 16, 0, NULL, &type, redir);
		if(binlen > 0)
		{
			if(open_script(argv[0], argc, argv))
			{
				if(execute_script_line() > 0)
				{
					return 1;
				}
			}
		}
	}

	return 0;
}
Exemple #2
0
int
main(int argc, char **argv)
{
  int cache_strategy, cache_metric, cache_size, help;
  Eina_List *filters = NULL,
	    *list_iter;
  Filter *f, *last, *load, *sink; 
  char *file = NULL;
  int verbose;
  
  lime_init();

  if (parse_cli(argc, argv, &filters, NULL, &cache_size, &cache_metric, &cache_strategy, &file, NULL, &verbose, &help))
    return EXIT_FAILURE;
  
  if (help) {
    print_help();
    return EXIT_SUCCESS;
  }
  
  print_init_info(NULL, cache_size, cache_metric, cache_strategy, NULL);
  
  lime_cache_set(cache_size, cache_strategy | cache_metric);
  
  if (!strcmp(((Filter*)eina_list_data_get(filters))->fc->shortname, "load")) {
    load = eina_list_data_get(filters);
    if (file)
      lime_setting_string_set(load, "filename", file);
  }
  else {
    if (!file) { 
      printf("ERROR: need file to execute filter chain!\n");
      return EXIT_FAILURE;
    }
    load = lime_filter_new("load");
    lime_setting_string_set(load, "filename", file);
    filters = eina_list_prepend(filters, load);
  }
  

  last = NULL;
  EINA_LIST_FOREACH(filters, list_iter, f) {
    if (last)
      lime_filter_connect(last, f);
    
    last = f;
  }
  
  sink = last;

  lime_render(sink);
  
  cache_stats_print();
  
  lime_shutdown();
  
  return 0;
}
Exemple #3
0
/* Process command line args, create the bound socket,
 * spawn child (worker) processes, and wait for them all to die
 * (which they shouldn't!) */
int main(int argc, char **argv) {

    parse_cli(argc, argv);

    if (OPTIONS.SYSLOG)
        openlog("stud", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_DAEMON);

    signal(SIGPIPE, SIG_IGN);

    listener_socket = create_main_socket();

    struct addrinfo hints;
    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = 0;
    const int gai_err = getaddrinfo(OPTIONS.BACK_IP, OPTIONS.BACK_PORT,
                                    &hints, &backaddr);
    if (gai_err != 0) {
        ERR("{getaddrinfo}: [%s]", gai_strerror(gai_err));
        exit(1);
    }

    /* load certificate, pass to handle_connections */
    SSL_CTX * ctx = init_openssl();

    master_pid = getpid();

    if (OPTIONS.CHROOT && OPTIONS.CHROOT[0])
        change_root();

    if (OPTIONS.UID || OPTIONS.GID)
        drop_privileges();

    for (child_num=0; child_num < OPTIONS.NCORES; child_num++) {
        int pid = fork();
        if (pid == -1) {
            ERR("{core} fork() failed! Goodbye cruel world!\n");
            exit(1);
        }
        else if (pid == 0) // child
            goto handle;
    }

    int child_status;
    int dead_child_pid = wait(&child_status);
    ERR("{core} A child (%d) died!  This should not happen! Goodbye cruel world!\n", dead_child_pid);
    kill(0, SIGTERM);
    exit(2);

handle:
    handle_connections(ctx);

    return 0;
}
Exemple #4
0
int parse_opt(int argc, char **argv, http_request *request) 
{
	if (argc == 1) {  
		help();
		exit(EXIT_SUCCESS);
	}

	parse_cli(argc, argv, request);

	char *src_url = argv[optind];
	/* In this case, the first argument is the request url, just like: ./webpress google.com -c 100 */
	if (optind == 1) {
		parse_cli(argc - 1, argv + 1, request);
	}

	if (optind == argc) {
		SCREEN(SCREEN_RED, stderr, "Please input your request url.\n");
		exit(EXIT_FAILURE);
	}

	struct http_parser_url us;
  	
	if (parse_url(src_url, &us, request) != 0) {
		exit(EXIT_FAILURE);
	}

	request->ip = sk_get_host_ipv4(request->host); 
	char ipstr[64] = {0};
	sk_ipv4_tostr(request->ip, ipstr, strlen(ipstr));
	if (request->ip == 0) {
		SCREEN(SCREEN_RED, stderr, "Could not resolve host: %s\n", request->host);
		exit(EXIT_FAILURE);
	}
	SCREEN(SCREEN_YELLOW, stdout, "Host:\t\t\t");
	SCREEN(SCREEN_DARK_GREEN, stdout, "%s\n", request->host);
	SCREEN(SCREEN_YELLOW, stdout, "Address:\t\t");
	SCREEN(SCREEN_DARK_GREEN, stdout, "%s:", ipstr);
	SCREEN(SCREEN_DARK_GREEN, stdout, "%d\n", request->port);

	return 0;
}
int main(int argv, char *argc[])
{
	int ret_val = 0;
	char test_string[STRING_SIZE];

	if(!parse_cli(test_string, argv, argc)) {
		ret_val = 1;
		goto Exit;
	}

	printf("ORIGINAL: %s\n", test_string);
	process_input(test_string);
	printf("MODIFIED: %s\n", test_string);

Exit:
	return ret_val;
}
Exemple #6
0
/* Process command line args, create the bound socket,
 * spawn child (worker) processes, and wait for them all to die
 * (which they shouldn't!) */
int main(int argc, char **argv) {
    parse_cli(argc, argv);

    int s = create_main_socket();
    int x;

    struct addrinfo hints;
    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = 0;
    const int gai_err = getaddrinfo(OPTIONS.BACK_IP, OPTIONS.BACK_PORT,
                                    &hints, &backaddr);
    if (gai_err != 0) {
        fprintf(stderr, "{getaddrinfo}: [%s]", gai_strerror(gai_err));
        exit(1);
    }

    /* load certificate, pass to handle_connections */
    SSL_CTX * ctx = init_openssl();

    for (x=0; x < OPTIONS.NCORES; x++) {
        int pid = fork();
        if (pid == -1) {
            fprintf(stderr, "{core} fork() failed! Goodbye cruel world!\n");
            exit(1);
        }
        else if (pid == 0) // child
            goto handle;
    }

    int child_status;
    for (x=0; x < OPTIONS.NCORES; x++) {
        wait(&child_status);
        fprintf(stderr, "{core} A child died!  This should not happen! Goodbye cruel world!\n");
        exit(2);
    }

handle:
    handle_connections(x, s, ctx);

    return 0;
}
/** Entry point of application.
  @param argc Number of arguments on command line
  @param argv Array of strings with arguments from command line
  @return 0 on success, otherwise >0.
*/
int main(int argc,char *argv[]) {
  int mode,operation;
  char *hostname, *port;
  char *pname;
  int port_n;
  PRFileDesc *fd_socket;
  int res;

  pname=basename(argv[0]);

  atexit(atexit_handler);

  if (!parse_cli(argc,argv,&operation,&mode,&hostname,&port) || operation==OPERATION_HELP) {
    show_usage(pname);

    if (operation!=OPERATION_HELP) return 1;

    return 0;
  }

  if ((port_n=return_port(port))==-1) {
    fprintf(stderr,"Error. Unknown port number/name %s!\n",port);

    return 1;
  }

  if (!(mode&MODE_NO_SSL)) {
    if (!init_nss()) return 1;
  }

  if (!(fd_socket=create_connected_socket(hostname,port_n,mode)))
    return 1;

  res=poll_cycle(fd_socket,mode);

  if (PR_Close(fd_socket)!=PR_SUCCESS) {
    print_nspr_error();

    return 1;
  }

  return (res?0:1);
}
Exemple #8
0
int main(void)
{
	char str[1024];
	char out[1024];

	while(fgets(str, sizeof(str), stdin))
	{
		char *argv[16];
		char redir[1025];
		int  type = 0;
		int  argc;
		int binlen;

		binlen = parse_cli("test me\n", out, &argc, argv, 16, 0, NULL, &type, redir);
		if(binlen > 0)
		{
			int i;
			for(i = 0; i < argc; i++)
			{
				printf("Arg %d: '%s'\n", i, argv[i]);
			}

			for(i = 0; i < binlen; i++)
			{
				if(out[i] < 32)
				{
					printf("\\x%02X", out[i]);
				}
				else
				{
					printf("%c", out[i]);
				}
			}
			printf("\n");
			if(type > 0)
			{
				printf("Redir type %d, '%s'\n", type, redir);
			}
		}
	}
}
Exemple #9
0
Fichier : fqd.c Projet : Sphonic/fq
int main(int argc, char **argv) {
  nodeid = get_my_ip();
  parse_cli(argc,argv);
  if(nodeid == 0) {
    fprintf(stderr, "Could not determine host address, use -n <ip>\n");
    exit(-1);
  }
  signal(SIGPIPE, SIG_IGN);
  if(foreground) {
    fqd_config_init(nodeid, config_path, queue_path);
    listener_thread(NULL);
    exit(0);
  }
  else {
    int pid, fd;

    /* Handle stdin/stdout/stderr */
    fd = open("/dev/null", O_RDONLY);
    if(fd < 0 || dup2(fd, STDIN_FILENO) < 0) die("Failed to setup stdin");
    close(fd);
    fd = open("/dev/null", O_WRONLY);
    if(fd < 0 || dup2(fd, STDOUT_FILENO) < 0 || dup2(fd, STDERR_FILENO) < 0)
      die("Failed to setup std{out,err}");
    close(fd);

    /* daemonize */
    pid = fork();
    if(pid < 0) die("Failed to fork");
    if(pid > 0) exit(0);
    setsid();
    pid = fork();
    if(pid < 0) die("Failed to fork");
    if(pid > 0) exit(0);

    /* run */
    fqd_config_init(nodeid, config_path, queue_path);
    listener_thread(NULL);
  }
  return 0;
}
Exemple #10
0
int execute_line(const char *buf)
{
	char args[4096];
	char *argv[16];
	int  argc;
	int len;
	int ret = 0;

	len = strlen(buf);

	if(len > 0)
	{
		char redir[PATH_MAX];
		int  type;
		int binlen = parse_cli(buf, args, &argc, argv, 16, g_context.sargc, g_context.sargv, &type, redir);
		if((binlen > 0) && (args[0] != '#'))
		{
			if(strchr(argv[0], '.') || strchr(argv[0], '/'))
			{
				int ldlen = strlen("ld")+1;
				/* If this looks to be a path then prefix ld and send */
				memmove(args+ldlen, args, binlen);
				memcpy(args, "ld", ldlen);
				binlen += ldlen;
			}
			else
			{
				const struct sh_command *cmd = find_command(argv[0]);
				if((cmd) && (cmd->func))
				{
					if(cmd->min_args > (argc-1))
					{
						help_cmd(argc, argv);
						return 0;
					}
					else
					{
						if(!cmd->func(argc-1, argv+1))
						{
							/* If it returns 0 then dont continue with the output */
							return 0;
						}
					}
				}
			}

			if(!g_context.args.script)
			{
				/* Remove the handler and prompt */
				rl_callback_handler_remove();
				rl_callback_handler_install("", cli_handler);
			}

			if(type != REDIR_TYPE_NONE)
			{
				if(type == REDIR_TYPE_NEW)
				{
					g_context.fredir = fopen(redir, "w");
				}
				else
				{
					g_context.fredir = fopen(redir, "a");
				}

				if(g_context.fredir == NULL)
				{
					fprintf(stderr, "Warning: Could not open file %s\n", redir);
				}
			}

			len = fixed_write(g_context.sock, args, binlen);
			if(len < 0)
			{
				close(g_context.sock);
				g_context.sock = -1;
				return -1;
			}
			strcpy(g_context.currcmd, args);
			ret = 1;
		}
	}

	return ret;
}
Exemple #11
0
int cmd_config(git_repository *repo, int argc, char **argv)
{
	int rc = EXIT_FAILURE;
	int err = 0;

	git_config *config = NULL;

	struct cli cli = {0};

	if (!parse_cli(argc, argv, &cli, POF_VALIDATE))
	{
		return GIT_ERROR;
	}

	if (usage_cli(argv[0], &cli))
	{
		return GIT_OK;
	}

	if (repo && !cli.global)
	{
		if (!cli.value)
		{
			if ((err = git_repository_config_snapshot(&config,repo)) != GIT_OK)
				goto out;
		} else
		{
			if ((err = git_repository_config(&config,repo)) != GIT_OK)
				goto out;
		}
	} else
	{
#ifdef __amigaos4__
		FILE *f = fopen("ENVARC:gitconfig", "rb");
		if (!f)
		{
			if ((f = fopen("ENVARC:gitconfig", "wb")))
			{
				fprintf(stderr, "Created global config in ENVARC:gitconfig\n");
			} else
			{
				fprintf(stderr, "Unable to create ENVARC:gitconfig\n");
			}
		}
		if (f)
		{
			fclose(f);
		}
#endif
		if ((err = git_config_open_default(&config)))
			goto out;

		if (!cli.value)
		{
			git_config *snapshot;

			if ((err = git_config_snapshot(&snapshot, config)))
				goto out;

			git_config_free(config);
			config = snapshot;
		}
	}

	if (!cli.name)
	{
		fprintf(stderr,"Invalid or not supported command line format!\n");
		goto out;
	}

	if (cli.value)
	{
		if ((err = git_config_set_string(config, cli.name, cli.value)))
			goto out;
	} else
	{
		const char *val;

		if ((err = git_config_get_string(&val, config, cli.name)) != GIT_OK)
			goto out;
		printf("%s\n",val);
	}

	rc = EXIT_SUCCESS;
out:
	if (err) libgit_error();
	if (config) git_config_free(config);

	return rc;
}