コード例 #1
0
ファイル: runlevel.c プロジェクト: cigolabs/flux-core
/* Note: return value of this function is ignored by libsubprocess.
 * Also: zio_json_decode() returns -1 on error, 0 on eof, strlen(s) on
 * success; caller must free 's'.
 */
static int subprocess_io_cb (struct subprocess *p, const char *json_str)
{
    runlevel_t *r;
    json_object *o = NULL;
    const char *name;
    int len;
    bool eof;
    char *s = NULL, *argz = NULL, *line = NULL;
    size_t argz_len;

    r = subprocess_get_context (p, "runlevel_t");
    assert (r != NULL);

    if (!r->io_cb)
        goto done;
    if (!(o = Jfromstr (json_str)) || !Jget_str (o, "name", &name))
        goto done;
    len = zio_json_decode (json_str, (void **)&s, &eof);
    if (len <= 0 || !s || !*s || s[len] != '\0')
        goto done;
    if (argz_create_sep (s, '\n', &argz, &argz_len) != 0)
        goto done;
    while ((line = argz_next (argz, argz_len, line)) && *line)
        r->io_cb (r, name, line, r->io_cb_arg);
done:
    if (s)
        free (s);
    if (argz)
        free (argz);
    Jput (o);
    return 0;
}
コード例 #2
0
ファイル: c_locale_glibc.c プロジェクト: inetra/peers1
const struct locale_data*
_Category_create(const char * name, int category)
{
  /* JGS, where should this path come from? */
  char* locpath_var;
  char* locale_path = NULL;
  size_t locale_path_len = 0;

  locpath_var = __secure_getenv("LOCPATH");

  if (locpath_var != NULL && locpath_var[0] != '\0')
    if (argz_create_sep (locpath_var, ':',
       &locale_path, &locale_path_len) != 0)
      return NULL;

  if (argz_add_sep (&locale_path, &locale_path_len, __LOCALE_PATH, ':') != 0)
    return NULL;

  return _Find_locale(locale_path, locale_path_len,
                      category, (char**)&name);
}
コード例 #3
0
ファイル: usermux.c プロジェクト: GNUHurdTR/hurd
  error_t parse_opt (int key, char *arg, struct argp_state *state)
    {
      switch (key)
	{
	case OPT_USER_PAT: mux.user_pat = arg; break;
	case OPT_HOME_PAT: mux.home_pat = arg; break;
	case OPT_UID_PAT: mux.uid_pat = arg; break;
	case 'C': memset (&mux, 0, sizeof mux); break;

	case ARGP_KEY_NO_ARGS:
	  memset (&mux, 0, sizeof mux); /* Default doesn't use them;
					   be careful. */
	  return argz_create_sep (_HURD_SYMLINK, 0,
				  &mux.trans_template, &mux.trans_template_len);
	case ARGP_KEY_ARGS:
	  /* Steal the entire tail of arg vector for our own use.  */
	  return argz_create (state->argv + state->next,
			      &mux.trans_template, &mux.trans_template_len);

	default:
	  return ARGP_ERR_UNKNOWN;
	}
      return 0;
    }
コード例 #4
0
ファイル: umount.c プロジェクト: GNUHurdTR/hurd
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
  struct fstab_argp_params *params = state->input;
  error_t err;
  switch (key)
    {
    case ARGP_KEY_INIT:
      state->child_inputs[0] = params; /* pass down to fstab_argp parser */
      break;

    case 'd':
      source_goaway = 1;
      break;

    case FAKE_KEY:
      fake = 1;
      break;

    case 'f':
      goaway_flags |= FSYS_GOAWAY_FORCE;
      break;

    case 'n':
      /* do nothing */
      break;

    case 'r':
      readonly = 1;
      break;

    case 'S':
      goaway_flags |= FSYS_GOAWAY_NOSYNC;
      break;

    case 'O':
      err = argz_create_sep (arg, ',', &test_opts, &test_opts_len);
      if (err)
	argp_failure (state, 100, ENOMEM, "%s", arg);
      break;

    case 'v':
      verbose += 1;
      break;

    case ARGP_KEY_ARG:
      err = argz_add (&targets, &targets_len, arg);
      if (err)
	argp_failure (state, 100, ENOMEM, "%s", arg);
      break;

    case ARGP_KEY_NO_ARGS:
      if (! params->do_all)
	{
	  argp_error (state,
		      "filesystem argument required if --all is not given");
	  return EINVAL;
	}
      break;

    case ARGP_KEY_END:
      if (params->do_all && targets)
	{
	  argp_error (state, "filesystem argument not allowed with --all");
	  return EINVAL;
	}
      break;

    default:
      return ARGP_ERR_UNKNOWN;
    }

  return 0;
}
コード例 #5
0
ファイル: mount.c プロジェクト: alecrosic/hurd
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
    struct fstab_argp_params *params = state->input;
    error_t err;
    switch (key)
    {
    case ARGP_KEY_INIT:
        state->child_inputs[0] = params; /* pass down to fstab_argp parser */
        break;

#define ARGZ(call)							      \
      err = argz_##call; 						      \
      if (err)								      \
	argp_failure (state, 100, ENOMEM, "%s", arg);			      \
      break
    case 'r':
        ARGZ (add (&options, &options_len, "ro"));
    case 'w':
        ARGZ (add (&options, &options_len, "rw"));
    case 'u':
        ARGZ (add (&options, &options_len, "update"));
    case 'B':
        ARGZ (add (&options, &options_len, "bind"));
    case 'o':
        ARGZ (add_sep (&options, &options_len, arg, ','));
    case 'v':
        ++verbose;
        break;
#undef ARGZ

    case 'T':
    {
        char *end;
        unsigned long int ms = strtoul (arg, &end, 10);
        if (end && *end == '\0')
            timeout = ms;
        else
        {
            argp_error (state,
                        "--timeout needs a numeric argument (milliseconds)");
            return EINVAL;
        }
    }
    break;

    case 'p':
        if (arg == 0 || !strcasecmp (arg, "fstab"))
            query_format = qf_fstab;
        else if (!strcasecmp (arg, "mount"))
            query_format = qf_standard;
        else if (!strcasecmp (arg, "translator")
                 || !strcasecmp (arg, "showtrans"))
            query_format = qf_translator;
        else
        {
            argp_error (state, "invalid argument to --format");
            return EINVAL;
        }
        break;

    case 'n':
        /* do nothing */
        break;

    case 'f':
        fake = 1;
        break;

    case 'O':
        err = argz_create_sep (arg, ',', &test_opts, &test_opts_len);
        if (err)
            argp_failure (state, 100, ENOMEM, "%s", arg);
        break;

    case ARGP_KEY_ARG:
        if (mountpoint == 0)	/* One arg: mountpoint */
            mountpoint = arg;
        else if (device == 0)	/* Two args: device, mountpoint */
        {
            device = mountpoint;
            mountpoint = arg;
        }
        else			/* More than two args.  */
        {
            argp_error (state, "too many arguments");
            return EINVAL;
        }
        break;

    case ARGP_KEY_NO_ARGS:
        if (! params->do_all)
        {
            params->do_all = 1;
            mode = query;
        }
        break;

    case ARGP_KEY_END:
        if (params->do_all && mountpoint)
        {
            argp_error (state, "filesystem argument not allowed with --all");
            return EINVAL;
        }
        if (mode == query && options_len != 0)
        {
            argp_error (state,
                        "mount options not allowed without filesystem argument");
            return EINVAL;
        }
        if (mountpoint)
            switch (argz_count (params->types, params->types_len))
            {
            default:
                argp_error (state,
                            "multiple types not allowed with filesystem argument");
                return EINVAL;
            case 1:
                fstype = params->types;
                params->types = 0;
                params->types_len = 0;
                break;
            case 0:
                break;
            }
        break;

    default:
        return ARGP_ERR_UNKNOWN;
    }
    return 0;
}