Exemple #1
0
int main(int argc, char *argv[])
{
	hash_function_t fun;
	unsigned long databytes = 30000000;
	unsigned long len, calls;

	if (argc < 2)
		die_usage();

	fun = get_hashfunc_by_name(argv[1]);
	if (!fun)
		die_list();

	if (argc == 2) /* only output summary of several get_speed() runs are done */
		printf("# %s\n# length    calls\ttime\n", argv[1]);
	if (argc > 2)
		databytes = atoi(argv[2]);
	if (argc > 3) {
		len = atoi(argv[3]);
		if (len == 0)
			die_usage();
		calls = databytes /= len;
		get_speed(fun, len, calls);
		return 0;
	}
	calls = databytes /= 4;
	get_speed(fun,    4, calls); calls /= 10;
	get_speed(fun,   40, calls); calls /= 10;
	get_speed(fun,  400, calls); calls /= 10;
	get_speed(fun, 4000, calls); calls /= 10;
	get_speed(fun,40000, calls);

	return 0;
}
int main(int argc,char **argv)
{
  char *d;

  if (!argv[0]) die_usage();
  if (!argv[1]) die_usage();
  d = argv[1];

  umask(022);
  if (mkdir(d,0755) == -1) die_fatal("unable to create directory",d,0);
  if (chdir(d) == -1) die_fatal("unable to chdir to directory",d,0);
  if (mkdir(".expertsonly",0700) == -1) die_fatal("unable to create directory",d,".expertsonly");

  sodium_init();

  crypto_box_keypair(pk,sk);
  create(d,"publickey",pk,sizeof pk);

  randombytes(noncekey,sizeof noncekey);

  umask(077);
  create(d,".expertsonly/secretkey",sk,sizeof sk);
  create(d,".expertsonly/lock",lock,sizeof lock);
  create(d,".expertsonly/noncekey",noncekey,sizeof noncekey);
  create(d,".expertsonly/noncecounter",noncecounter,sizeof noncecounter);

  return 0;
}
Exemple #3
0
int cmd_main(int argc, const char **argv)
{
	const char **arg = argv;
	int my_argc = argc;
	int output_url = 0;
	int lookup_name = 0;

	arg++;
	my_argc--;
	while (starts_with(arg[0], "--")) {
		if (!strcmp(arg[0], "--url"))
			output_url = 1;
		if (!strcmp(arg[0], "--name"))
			lookup_name = 1;
		arg++;
		my_argc--;
	}

	if (my_argc % 2 != 0)
		die_usage(argc, argv, "Wrong number of arguments.");

	setup_git_directory();
	gitmodules_config();
	git_config(git_test_config, NULL);

	while (*arg) {
		unsigned char commit_sha1[20];
		const struct submodule *submodule;
		const char *commit;
		const char *path_or_name;

		commit = arg[0];
		path_or_name = arg[1];

		if (commit[0] == '\0')
			hashclr(commit_sha1);
		else if (get_sha1(commit, commit_sha1) < 0)
			die_usage(argc, argv, "Commit not found.");

		if (lookup_name) {
			submodule = submodule_from_name(commit_sha1, path_or_name);
		} else
			submodule = submodule_from_path(commit_sha1, path_or_name);
		if (!submodule)
			die_usage(argc, argv, "Submodule not found.");

		if (output_url)
			printf("Submodule url: '%s' for path '%s'\n",
					submodule->url, submodule->path);
		else
			printf("Submodule name: '%s' for path '%s'\n",
					submodule->name, submodule->path);

		arg += 2;
	}

	submodule_free();

	return 0;
}
Exemple #4
0
int
main(int argc, char **argv)
{
    struct xmpp xmpp = { 0 };
    int i, port = XMPP_PORT, fd, ret = 1;
    char *jid = 0, *pwdfile = 0, *srv = 0;

    for (i = 1; i < argc - 1 && argv[i][0] == '-'; i++)
        switch (argv[i][1]) {
        case 'j':
            jid = argv[++i];
            break;
        case 'k':
            pwdfile = argv[++i];
            break;
        case 's':
            srv = argv[++i];
            break;
        case 'l':
            show_log = atoi(argv[++i]);
            break;
        case 'p':
            port = atoi(argv[++i]);
            break;
        default:
            die_usage();
        }
    if (!jid)
        die_usage();

    xmpp.io_context = &fd;
    xmpp.send = io_send;
    xmpp.tls_fn = use_tls ? start_tls : 0;
    xmpp.stream_fn = stream_handler;
    xmpp.node_fn = node_handler;
    xmpp.auth_fn = auth_handler;
    xmpp.use_sasl = use_sasl;
    xmpp.jid = jid;

    read_pw(pwdfile, &xmpp);

    if (xmpp_init(&xmpp, 4096))
        return 1;

    if (!srv)
        srv = xmpp.server;

    fd = tcp_connect(srv, port);
    if (fd < 0)
        return 1;

    if (!(xmpp_start(&xmpp) || process_connection(fd, &xmpp)))
        ret = 0;

    xmpp_printf(&xmpp, "</stream:stream>");
    xmpp_clean(&xmpp);
    close(fd);
    shutdown(fd, 2);
    return ret;
}
Exemple #5
0
Fichier : ji.c Projet : placek/ji
int
main(int argc, char **argv)
{
  struct xmpp xmpp = {0};
  char path_buf[PATH_BUF];
  int i, port = XMPP_PORT, ret = 1;
  char *jid = 0, *srv = 0, *s;

  s = getenv("HOME");
  snprintf(path_buf, sizeof(path_buf), "%s/%s", (s) ? s : ".", root);
  s = getenv("USER");
  snprintf(me, sizeof(me), "%s", (s) ? s : "me");

  for (i = 1; i < argc - 1 && argv[i][0] == '-'; i++)
    switch (argv[i][1]) {
    case 'r': snprintf(path_buf, sizeof(path_buf), "%s", argv[++i]); break;
    case 'n': snprintf(me, sizeof(me), "%s", argv[++i]); break;
    case 'j': jid = argv[++i]; break;
    case 's': srv = argv[++i]; break;
    case 'p': port = atoi(argv[++i]); break;
    case 'l': log_level = atoi(argv[++i]); break;
    case 'e': snprintf(evfifo, sizeof(evfifo), "%s", argv[++i]); break;
    default: die_usage();
    }
  if (!jid)
    die_usage();

  xmpp.send = io_send;
  xmpp.tls_fn = start_tls;
  xmpp.stream_fn = stream_handler;
  xmpp.node_fn = node_handler;
  xmpp.auth_fn = auth_handler;
  xmpp.use_sasl = use_sasl;
  xmpp.jid = jid;

  if (read_line(0, sizeof(xmpp.pwd), xmpp.pwd))
    xmpp.pwd[0] = 0;

  if (xmpp_init(&xmpp, 4096))
    return 1;

  if (!srv)
    srv = xmpp.server;

  s = jid_partial(xmpp.jid, &i);
  snprintf(rootdir, sizeof(rootdir), "%s/%.*s", path_buf, i, s);

  fd = tcp_connect(srv, port);
  if (fd < 0)
    return 1;

  if (!(xmpp_start(&xmpp) != 0 || process_connection(fd, &xmpp)))
    ret = 0;

  xmpp_clean(&xmpp);
  close(fd);
  shutdown(fd, 2);
  return ret;
}
Exemple #6
0
int main(int argc, char **argv) {

    unsigned char *x;
    unsigned long long xlen;

    if (argv[0])
        if (argv[1]) {
            if (str_equal(argv[1], "-h"))
                die_usage(0);
        }

    /* get password  */
    x = (unsigned char *)env_get("PASSWORD");
    if (!x) { errno = 0; die_usage("$PASSWORD not set"); }
    xlen = str_len((char *)x);

    /* create salt */
    randombytes(s, sizeof s);

    /* derive key  */
    if (sha512hmacpbkdf2(h, sizeof h, x, xlen, s, sizeof s, ROUNDS) == -1) die_fatal("unable to derive keys", 0);
    byte_zero(x, xlen);

    /* create nonce */
    randombytes(n, sizeof n);
    uint64_pack(n, nanoseconds());
    sha512(nk, (unsigned char *)MAGIC, MAGICBYTES);
    crypto_block_aes256vulnerable(n, n, nk);

    /* initialize */
    crypto_init(&ctx, n, h, MAGIC);
    randombytes(h, sizeof h);
    sha512_init(&shactx);

    /* write header */
    if (writeall(1, MAGIC, MAGICBYTES) == -1) die_fatal("unable to write output", 0);
    if (writeall(1, s, sizeof s) == -1) die_fatal("unable to write output", 0);
    randombytes(s, sizeof s);
    if (writeall(1, n, sizeof n) == -1) die_fatal("unable to write output", 0);

    for (;;) {
        inlen = readblock(in, BLOCK);
        if (inlen != BLOCK) break;
        if (sha512_block(&shactx, in, inlen) != 0) die_fatal("unable to compute hash", 0);
        if (crypto_block(&ctx, in, inlen) != 0) die_fatal("unable to encrypt stream", 0);
        if (writeall(1, in, inlen) == -1) die_fatal("unable to write output", 0);
    }
    if (sha512_last(&shactx, h, in, inlen) != 0) die_fatal("unable to compute hash", 0);
    byte_copy(in + inlen, CHECKSUMBYTES, h);
    inlen += CHECKSUMBYTES;
    if (crypto_last(&ctx, in, inlen) != 0) die_fatal("unable to encrypt stream", 0);
    if (writeall(1, in, inlen) == -1) die_fatal("unable to write output", 0);

    if (fsyncfd(1) == -1) die_fatal("unable to write output", 0);
    cleanup();
    _exit(0);
}
Exemple #7
0
void main(int argc,char **argv)
{
  char *def;
  int opt;
  int dash;
  
  while ((opt = getopt(argc,argv,"vV")) != opteof)
    switch (opt) {
    case 'v':
    case 'V':
      strerr_die2x(0, "ezmlm-dispatch version: ",auto_version);
    default:
      die_usage();
    }

  if (argv[optind] == 0)
    die_usage();
  wrap_chdir(argv[optind]);
  if (!stralloc_copys(&basedir,argv[optind++])) die_nomem();

  sender = env_get("SENDER");
  if (!sender)
    strerr_die2x(100,FATAL,ERR_NOSENDER);
  def = env_get("DEFAULT");

  if (argv[optind] != 0) {
    wrap_chdir(argv[optind]);
    dispatch(argv[optind],def);
  }
  else if (!def || !*def)
    strerr_die2x(100,FATAL,ERR_NODEFAULT);
  else {
    if (def[str_chr(def,'/')] != 0)
      strerr_die2x(100,FATAL,"Recipient address may not contain '/'");

    if (chdir(def) == 0)
      dispatch(def,0);

    dash = str_len(def);
    for (;;) {
      while (--dash > 0)
	if (def[dash] == '-')
	  break;
      if (dash <= 0)
	break;
      def[dash] = 0;
      if (chdir(def) == 0)
	dispatch(def,def+dash+1);
      def[dash] = '-';
    }
    strerr_die3x(100,FATAL,"Could not match recipient name to any list: ",def);
  }
}
int main(int argc, char **argv, char **envp) {

    if (!argv[0]) die_usage();
    if (!argv[1]) die_usage();
    if (str_equal(argv[1], "-h")) die_usage();

    if (extremesandbox_droproot() == -1) die_fatal("unable to drop root privileges", 0);

    pathexec_run(argv[1], argv + 1, envp);
    die_fatal("unable to run", argv[1]);
    return 111;
}
Exemple #9
0
int cmd_rm(int argc, char **argv)
{
	unsigned char key[KDF_HASH_LEN];
	struct session *session = NULL;
	struct blob *blob = NULL;
	static struct option long_options[] = {
		{"sync", required_argument, NULL, 'S'},
		{"color", required_argument, NULL, 'C'},
		{0, 0, 0, 0}
	};
	int option;
	int option_index;
	char *name;
	enum blobsync sync = BLOB_SYNC_AUTO;
	struct account *found;

	while ((option = getopt_long(argc, argv, "", long_options, &option_index)) != -1) {
		switch (option) {
			case 'S':
				sync = parse_sync_string(optarg);
				break;
			case 'C':
				terminal_set_color_mode(
					parse_color_mode_string(optarg));
				break;
			case '?':
			default:
				die_usage(cmd_rm_usage);
		}
	}

	if (argc - optind != 1)
		die_usage(cmd_rm_usage);
	name = argv[optind];

	init_all(sync, key, &session, &blob);
	found = find_unique_account(blob, name);
	if (!found)
		die("Could not find specified account '%s'.", name);
	if (found->share && found->share->readonly)
		die("%s is a readonly shared entry from %s. It cannot be deleted.", found->fullname, found->share->name);

	list_del(&found->list);

	lastpass_remove_account(sync, key, session, found, blob);
	blob_save(blob, key);
	account_free(found);

	session_free(session);
	blob_free(blob);
	return 0;
}
Exemple #10
0
int main(int argc,char *argv[])
{
  const char* dir;
  int fd;
  int match;
  unsigned long msgsize = 0L;
  int opt;
  
  while ((opt = getopt(argc,argv,"vV")) != opteof) {
    switch(opt) {
    case 'v':
    case 'V':
      strerr_die2x(0, "ezmlm-import version: ",auto_version);
    default:
      die_usage();
    }
  }

  if (argc - optind != 2)
    die_usage();

  if ((fd = open_read(argv[optind+1])) == -1)
    strerr_die4sys(111,FATAL,ERR_OPEN,argv[optind+1],": ");
  substdio_fdbuf(&ssin,read,fd,inputbuf,sizeof inputbuf);

  startup(dir = argv[optind]);
  lockfile("lock");

  getconf_ulong2(&msgnum,&cumsize,"num",0,dir);
  
  fd = 0;
  while (getln(&ssin,&line,&match,'\n') == 0 && match) {
    if (line.len > 5
	&& byte_diff(line.s,5,"From ") == 0) {
      if (fd > 0) {
	if (substdio_flush(&ssarchive) == -1
	    || fchmod(fd,MODE_ARCHIVE|0700) == -1
	    || close(fd) == -1)
	  strerr_die4sys(111,FATAL,ERR_WRITE,fnaf.s,": ");
	fd = 0;
      }
      ++msgnum;
      cumsize += (msgsize + 128L) >> 8;
      msgsize = 0L;
      fd = openone(msgnum);
    }
    else if (fd > 0) {
      substdio_put(&ssarchive,line.s,line.len);
      msgsize += line.len;
    }
  }
Exemple #11
0
int main(int argc, char **argv)
{
  sig_alarmcatch(die);
  sig_pipeignore();
 
  hostname = argv[1];
  if (!hostname) die_usage();
  childargs = argv + 2;
  if (!*childargs) die_usage();
 
  pop3_greet();
  commands(&ssin,pop3commands);
  return 1;
}
Exemple #12
0
int cmd_logout(int argc, char **argv)
{
	static struct option long_options[] = {
		{"force", no_argument, NULL, 'f'},
		{0, 0, 0, 0}
	};
	int option;
	int option_index;
	bool force = false;
	struct session *session = NULL;
	unsigned char key[KDF_HASH_LEN];

	while ((option = getopt_long(argc, argv, "f", long_options, &option_index)) != -1) {
		switch (option) {
			case 'f':
				force = true;
				break;
			case '?':
			default:
				die_usage(cmd_logout_usage);
		}
	}
	if (optind < argc)
		die_usage(cmd_logout_usage);

	if (!config_exists("verify"))
		die("Not currently logged in.");

	if (!force && !ask_yes_no(true, "Are you sure you would like to log out?")) {
		terminal_printf(TERMINAL_FG_YELLOW TERMINAL_BOLD "Log out" TERMINAL_RESET ": aborted.\n");
		return 1;
	}

	init_all(0, key, &session, NULL);

	if (!config_unlink("verify") || !config_unlink("username") || !config_unlink("session_sessionid") || !config_unlink("iterations"))
		die_errno("could not log out.");
	config_unlink("blob");
	config_unlink("session_token");
	config_unlink("session_uid");
	config_unlink("session_privatekey");
	config_unlink("plaintext_key");
	agent_kill();
	upload_queue_kill();
	lastpass_logout(session);
	terminal_printf(TERMINAL_FG_YELLOW TERMINAL_BOLD "Log out" TERMINAL_RESET ": complete.\n");
	return 0;
}
Exemple #13
0
int main(int argc, char **argv) {

    long long r,w;

    if (argv[0])
        if (argv[1])
            if (str_equal(argv[1], "-h"))
                die_usage();

    for (;;) {
        r = readblock(0, buf, BLOCK);
        if (r == -1) die_fatal("unable to read input", 0);

        for (;;) {
            if (r <= 0) goto end;
            if (buf[r - 1] == '\n') { --r; continue; }
            if (buf[r - 1] == '\r') { --r; continue; }
            break;
        }
        buf[r] = 0;
        if (r % 2) { errno = 0; die_fatal("unable to decode from hex", 0); }
        w = r / 2;
        if (!hexparse(buf, w, (char *)buf)) { errno = 0; die_fatal("unable to decode from hex", 0); }
        if (writeall(1, buf, w) == -1) die_fatal("unable to write output", 0);
        if (r != BLOCK) break;
    }

end:
    if (fsyncfd(1) == -1) die_fatal("unable to write output", 0);
    _exit(0);
}
Exemple #14
0
/**
 * Função de entrada do programa.
 *
 * Sintaxe:
 *    sensor NOME
 *
 * Inicia o sensor, que utilizará o segmento de memória compartilhada
 * com o nome fornecido.
 *
 * @param argc Número de argumentos na linha de comando.
 * @param argv Vetor de argumentos da linha de comando.
 * @return Zero para execução com êxito, diferente de zero para erro.
 */
int main(int argc, char *argv[])
{
	if (argc != 2)
		die_usage();

	const char *const shmname = argv[1];
	const size_t shmsize = sizeof(my_queue_t);

	my_queue_t *q;

	/**
	 * === IMPLEMENTAR ===
	 *
	 * - Abrir o segmento de memória compartilhada cujo nome que está em
	 *      'shmname'.
	 * - Mapear a memória compartilhada no espaço virtual do processo,
	 *      obtendo um ponteiro 'q' para a memória compartilhada.
	 */
	
    	int shmdes = shm_open(shmname, O_CREAT | O_RDWR, 0600);
	if (shmdes < 0){
		perror("shm_open");
		exit(EXIT_FAILURE);
	}
	if (ftruncate(shmdes,sizeof(int)) < 0){
		perror("ftruncate");
		exit(EXIT_FAILURE);
	}

	int *p = mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED, shmdes, 0);

	if(p == MAP_FAILED){
		perror("mmap");
		exit(EXIT_FAILURE);
	}

	printf("Novo valor: ", %d\n, *p);

	for (int i = 0; i < 50; i++) {
		double v[2];
		rand_normal(25.0, 3.0, v);
		queue_send(q, v[0]); printf("Enviado valor %lf.\n", v[0]);
		queue_send(q, v[1]); printf("Enviado valor %lf.\n", v[1]);
	}

	queue_send(q, -1.0);

	/**
	 * === IMPLEMENTAR ===
	 *
	 * - Remover o mapeamento de memória em 'q'.
	 * - Fechar o segmento de memória compartilhada.
	 */

	munmap(q, shmsize);
	close(shmdes);
	return 0;
}
Exemple #15
0
int cmd_main(int argc, const char **argv)
{
	int i;

	BUG_exit_code = 99;
	if (argc < 2)
		die_usage();

	for (i = 0; i < ARRAY_SIZE(cmds); i++) {
		if (!strcmp(cmds[i].name, argv[1])) {
			argv++;
			argc--;
			return cmds[i].fn(argc, argv);
		}
	}
	error("there is no tool named '%s'", argv[1]);
	die_usage();
}
Exemple #16
0
void startup(const char *dir)
{
  if (dir == 0)
    die_usage();

  listdir = dir;
  wrap_chdir(dir);
  load_config();
}
Exemple #17
0
static int parse(int argc,char *argv[],struct option *options)
{
    int i;
    int j;
    int ch;
    struct option *o;

    for (i = 1; i < argc && argv[i][0] == '-'; ++i) {
        if (argv[i][1] == 0
                || (argv[i][1] == '-' && argv[i][2] == 0))
            break;
        for (j = 1; argv[i][j] != 0; ++j) {
            ch = argv[i][j];
            for (o = options; o->type != 0; ++o) {
                if (ch == o->ch) {
                    if (!o->type->needsarg)
                        (void)o->type->parse(o,0);
                    else {
                        /* Look for -oVALUE */
                        if (argv[i][j+1] != 0) {
                            ++j;
                            if (!o->type->parse(o,argv[i]+j))
                                die_usage();
                        }
                        /* Look for -o VALUE */
                        else if (i + 1 < argc) {
                            ++i;
                            if (!o->type->parse(o,argv[i]))
                                die_usage();
                        }
                        else
                            die_usage();
                        j = str_len(argv[i]) - 1;
                    }
                    o->isset = 1;
                    break;
                }
            }
            if (o->type == 0)
                die_usage();
        }
    }
    return i;
}
Exemple #18
0
void startup(const char *dir)
{
  if (dir == 0)
    die_usage();

  if (dir[0] != '/')
    strerr_die2x(100,FATAL,ERR_SLASH);

  wrap_chdir(dir);
}
Exemple #19
0
int main (int argc, char** argv) {
	int i = 1;
	for (; i < argc; ) {
		if (!strcmp("--", argv[i])) {
			if (i + 1 > argc)
				die_usage();
			if (execvp(argv[i + 1], argv + i + 1) < 0)
				return 1;
		} else if (!strcmp("--pipe", argv[i])) {
			if (i + 2 > argc)
				die_usage();
			create_pipe(atoi(argv[i + 1]), atoi(argv[i + 2]));
			i += 3;
		} else
			die_usage();
	}
	die_usage();
	return 0;
}
Exemple #20
0
main(int argc,char **argv)
{
  char *key;
  int r;
  uint32 pos;
  uint32 len;
  unsigned long u = 0;

  if (!*argv) die_usage();

  if (!*++argv) die_usage();
  key = *argv;

  if (*++argv) {
    scan_ulong(*argv,&u);
  }

  cdb_init(&c,0);
  cdb_findstart(&c);

  for (;;) {
    r = cdb_findnext(&c,key,str_len(key));
    if (r == -1) die_read();
    if (!r) _exit(100);
    if (!u) break;
    --u;
  }

  pos = cdb_datapos(&c);
  len = cdb_datalen(&c);

  while (len > 0) {
    r = sizeof buf;
    if (r > len) r = len;
    if (cdb_read(&c,buf,r,pos) == -1) die_read();
    if (buffer_put(buffer_1small,buf,r) == -1) die_write();
    pos += r;
    len -= r;
  }
  if (buffer_flush(buffer_1small) == -1) die_write();
  _exit(0);
}
Exemple #21
0
enum color_mode parse_color_mode_string(const char *colormode)
{
	if (!colormode || strcmp(colormode, "auto") == 0)
		return COLOR_MODE_AUTO;
	else if (strcmp(colormode, "never") == 0)
		return COLOR_MODE_NEVER;
	else if (strcmp(colormode, "always") == 0)
		return COLOR_MODE_ALWAYS;
	else
		die_usage("... --color=auto|never|always");
}
Exemple #22
0
enum blobsync parse_sync_string(const char *syncstr)
{
	if (!syncstr || !strcasecmp(syncstr, "auto"))
		return BLOB_SYNC_AUTO;
	else if (!strcasecmp(syncstr, "now"))
		return BLOB_SYNC_YES;
	else if (!strcasecmp(syncstr, "no"))
		return BLOB_SYNC_NO;
	else
		die_usage("... --sync=auto|now|no");
}
Exemple #23
0
int main(int argc, const char **argv)
{
	ProcessSerialNumber psn;
	int resultCode;
	bool printResult = TRUE;
	
	if (argc < 2) print_detailed_usage();

	if (!strcmp(argv[1], "--")) {
		argc -= 1; argv += 1;
	}
	else if (!strcmp(argv[1], "-q")) {
		argc -= 1; argv += 1;
		printResult = FALSE;
	}
	else if (!strcmp(argv[1], "-s")) {
		argc -= 1; argv += 1;
		printResult = FALSE;
		give_up_silently = TRUE;
	}
	else if (!strcmp(argv[1], "-l")) {
		list_open_applications();
		return 0;
	}
	
	if (argc > 3 || argc < 2) die_usage();
	
	if (application_is_open(
		CFStringCreateWithCString(kCFAllocatorDefault, argv[1], kCFStringEncodingUTF8),
		&psn))
	{
		if (argc == 2
		|| document_is_open(
			CFStringCreateWithCString(kCFAllocatorDefault, argv[2], kCFStringEncodingUTF8),
			&psn))
		{
			resultCode = 0;			
		}
		else resultCode = 2;
	}
	else resultCode = 1;
	
	if (printResult) {
		switch (resultCode) {
		case 1:
			printf("Application '%s' not running\n", argv[1]);
			break;
		case 2:
			printf("Document '%s' not open in application\n", argv[2]);
		}
	}
	return resultCode;
}
int cmd__submodule_nested_repo_config(int argc, const char **argv)
{
	struct repository subrepo;
	const struct submodule *sub;

	if (argc < 3)
		die_usage(argc, argv, "Wrong number of arguments.");

	setup_git_directory();

	sub = submodule_from_path(the_repository, &null_oid, argv[1]);
	if (repo_submodule_init(&subrepo, the_repository, sub)) {
		die_usage(argc, argv, "Submodule not found.");
	}

	/* Read the config of _child_ submodules. */
	print_config_from_gitmodules(&subrepo, argv[2]);

	submodule_free(the_repository);

	return 0;
}
Exemple #25
0
int
main(int argc, char *argv[], char *envp[])
{
  nextopt_t  nopt = nextopt_INIT(argc, argv, "hV");
  char       opt;
  pid_t      pid;

  progname = nextopt_progname(&nopt);
  while((opt = nextopt(&nopt))){
      char optc[2] = {nopt.opt_got, '\0'};
      switch(opt){
      case 'h': usage(); die(0); break;
      case 'V': version(); die(0); break;
      case ':':
          fatal_usage("missing argument for option -", optc);
          break;
      case '?':
          if(nopt.opt_got != '?'){
              fatal_usage("invalid option: -", optc);
          }
          /* else fallthrough: */
      default :
          die_usage(); break; 
      }
  }

  argc -= nopt.arg_ndx;
  argv += nopt.arg_ndx;

  if(argc < 1){
      fatal_usage("missing required program argument");
  }

  if((pid = fork()) == -1){
      fatal_syserr("failure to detach");
  }
  if(pid != 0){
      /* parent exits: */
      _exit(0);
  }
  setsid(); 

  /* execvx() provides path search for prog */
  execvx(argv[0], argv, envp, NULL);

  /* uh oh: */
  fatal_syserr("unable to run ", argv[0]);

  /* not reached: */
  return 0;
}
Exemple #26
0
int main(int argc, char **argv) {
	application = argv[0];
	if (argc != 3)
		die_usage();
	if (!strncmp(argv[1], "set", 4)) {
		password = malloc(MAX_PW_LEN);
		if (!password)
			die("memory error");
		if (!fgets(password, MAX_PW_LEN, stdin)) {
			gnome_keyring_free_password(password);
			die("failed reading stdin");
		}
		GnomeKeyringResult result = set(argv[2], password);
		if (result != GNOME_KEYRING_RESULT_OK) {
			gnome_keyring_free_password(password);
			die_result(result);
		}
		gnome_keyring_free_password(password);
		return EXIT_SUCCESS;
	}
	if (!strncmp(argv[1], "get", 4)) {
		GnomeKeyringResult result = get(argv[2], &password);
		if (result != GNOME_KEYRING_RESULT_OK) {
			gnome_keyring_free_password(password);
			die_result(result);
		}
		printf("%s", password);
		gnome_keyring_free_password(password);
		return EXIT_SUCCESS;
	}
	if (!strncmp(argv[1], "del", 4)) {
		GnomeKeyringResult result = del(argv[2]);
		if (result != GNOME_KEYRING_RESULT_OK)
			die_result(result);
		return EXIT_SUCCESS;
	}
	die_usage(argv[0]);
}
int main(int argc, char *argv[]) {
    char *prog;
    int flags, opt;
    int nsecs, tfnd;

    nsecs = 0;
    tfnd = 0;
    flags = 0;
    prog = basename(argv[0]);

    while ((opt = getopt(argc, argv, "hnt:")) != -1) {
        switch (opt) {
        case 'n':
            flags = 1;
            break;
        case 't':
            nsecs = atoi(optarg);
            tfnd = 1;
            break;
        case 'h':
        default: /* '?' */
            die_usage(prog, NULL);
        }
    }

    printf("flags=%d; tfnd=%d; optind=%d\n", flags, tfnd, optind);

    if (optind >= argc) {
        die_usage(prog, "Expected argument after options");
    }

    printf("name argument = %s\n", argv[optind]);
    printf("nsecs = %d\n", nsecs);

    exit(EXIT_SUCCESS);
}
Exemple #28
0
int
main(int argc, char *argv[], char *envp[])
{
  nextopt_t    nopt = nextopt_INIT(argc, argv, "hV");
  char         opt;
  const char  *prog = NULL;

  progname = nextopt_progname(&nopt);
  while((opt = nextopt(&nopt))){
      char optc[2] = {nopt.opt_got, '\0'};
      switch(opt){
      case 'h': usage(); die(0); break;
      case 'V': version(); die(0); break;
      case ':':
          fatal_usage("missing argument for option -", optc);
          break;
      case '?':
          if(nopt.opt_got != '?'){
              fatal_usage("invalid option: -", optc);
          }
          /* else fallthrough: */
      default :
          die_usage(); break; 
      }
  }

  argc -= nopt.arg_ndx;
  argv += nopt.arg_ndx;

  if(argc < 2){
      fatal_usage("missing required argument(s)");
  }

  /* our real executable: */
  prog = argv[0];

  /* ratchet alias into argv[0]: */
  ++argv;

  /* execvx() provides path search for prog */
  execvx(prog, argv, envp, NULL);

  /* uh oh: */
  fatal_syserr("unable to run ", prog);

  /* not reached: */
  return 0;
}
Exemple #29
0
enum note_type parse_note_type_string(const char *extra)
{
	enum note_type result;

	result = notes_get_type_by_shortname(extra);
	if (result == NOTE_TYPE_NONE) {
		_cleanup_free_ char *params = NULL;
		_cleanup_free_ char *usage = NULL;

		params = note_type_usage();
		xasprintf(&usage, "... %s", params);
		die_usage(usage);
	}

	return result;
}
Exemple #30
0
int
main(int argc, char *argv[])
{
  nextopt_t  nopt = nextopt_INIT(argc, argv, "hV");
  char       opt;
  int        i;

  progname = nextopt_progname(&nopt);
  while((opt = nextopt(&nopt))){
      char optc[2] = {nopt.opt_got, '\0'};
      switch(opt){
      case 'V': version(); die(0); break;
      case 'h': usage(); die(0); break;
      case '?':
          if(nopt.opt_got != '?'){
              eputs(progname, ": usage error: invalid option: -", optc);
          }
          /* fallthrough: */
      default :
          die_usage(); break; 
      }
  }

  argc -= nopt.arg_ndx;
  argv += nopt.arg_ndx;

  for(i = 0; resources[i] != NULL; ++i){
      const char  *resource = resources[i];
      int  r = rlimit_lookup(resource);
      char  nfmt[NFMT_SIZE];
      struct rlimit  rlim;
      if(r == -1){
          ioq_vputs(ioq1, resource, "\t[not provided on this platform]\n");
          continue;
      }
      getrlimit(r, &rlim);
      ioq_vputs(ioq1, resource, "\t", rlimit_mesg(r), ": "); 
      if(rlim.rlim_cur == RLIM_INFINITY){
          ioq_vputs(ioq1, "unlimited\n");
      } else {
          ioq_vputs(ioq1, nfmt_uint32(nfmt, rlim.rlim_cur), "\n");
      }
  }
  ioq_flush(ioq1);

  return 0;
}