Пример #1
0
bool flux_is_installed (void)
{
    char *selfdir = dir_self ();
    bool ret = false;

    if (!strcmp (selfdir, X_BINDIR))
        ret = true;
    free (selfdir);
    return ret;
}
Пример #2
0
/*
 * If flux command was run with relative or absolute path, then
 *  prepend the directory for the flux executable to PATH. This
 *  ensures that in "flux [OPTIONS] [COMMAND] flux" the second
 *  flux executable is the same as the first. This is important
 *  for example with "flux start".
 */
void setup_path (struct environment *env, const char *argv0)
{
    char *selfdir;
    assert (argv0);

    /*  If argv[0] was explicitly "flux" then assume PATH is already set */
    if (strcmp (argv0, "flux") == 0)
        return;
    environment_from_env (env, "PATH", "/bin:/usr/bin", ':');
    selfdir = dir_self ();
    environment_push (env, "PATH", selfdir);
    free (selfdir);
}
Пример #3
0
int main (int argc, char *argv[])
{
    int ch;
    bool hopt = false;
    char *config_filename = NULL;
    opt_t opt;

    memset (&opt, 0, sizeof (opt));
    opt.device = xstrdup ("USB1");

    prog = basename (argv[0]);

    while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) {
        switch (ch) {
            case 'c': /* --config FILE */
                config_filename = xstrdup (optarg);
                break;
            default:
                break;
        }
    }
    if (!config_filename) {
        struct passwd *pw = getpwuid (getuid ());
        if (!pw)
            msg_exit ("Who are you?");
        if (asprintf (&config_filename, "%s/.sbig/config.ini", pw->pw_dir) < 0)
            oom ();
    }
    if (setenv ("SBIG_CONFIG_FILE", config_filename, 1) < 0)
        err_exit ("setenv");
    (void)ini_parse (config_filename, config_cb, &opt);

    optind = 0;
    while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) {
        switch (ch) {
            case 'c': /* --config FILE */
                break;
            case 'X': /* --xpa-nsinet */
                if (opt.xpa_nsinet)
                    free (opt.xpa_nsinet);
                opt.xpa_nsinet = xstrdup (optarg);
                break;
            case 'x': /* --exec-dir */
                if (setenv ("SBIG_EXEC_DIR", optarg, 1) < 0)
                    err_exit ("setenv");
                break;
            case 'S': /* --sbig-udrv FILE */
                if (opt.sbigudrv)
                    free (opt.sbigudrv);
                opt.sbigudrv = xstrdup (optarg);                
                break;
            case 'd': /* --device DEV */
                if (opt.device)
                    free (opt.device);
                opt.device = xstrdup (optarg);
                break;
            case 'h': /* --help  */
                hopt = true;
                break;
            default:
                usage ();
                exit (1);
        }
    }
    argc -= optind;
    argv += optind;

    if (opt.sbigudrv) {
        if (setenv ("SBIG_UDRV", opt.sbigudrv, 1) < 0)
            err_exit ("setenv");
    }
    if (opt.xpa_nsinet) {
        if (setenv ("XPA_NSINET", opt.xpa_nsinet, 1) < 0)
            err_exit ("setenv");
    }
    if (setenv ("SBIG_DEVICE", opt.device, 1) < 0)
        err_exit ("setenv");

    if (!strcmp (dir_self (), X_BINDIR)) {
        if (setenv ("SBIG_EXEC_DIR", EXEC_DIR, 0) < 0)
            err_exit ("setenv");
        if (setenv ("SBIG_UDRV", PATH_SBIGUDRV, 0) < 0)
            err_exit ("setenv");
    } else {
        if (setenv ("SBIG_EXEC_DIR", ".", 0) < 0)
            err_exit ("setenv");
        if (setenv ("SBIG_UDRV", PATH_SBIGUDRV_BUILD, 0) < 0)
            err_exit ("setenv");
    }

    if (hopt) {
        if (argc > 0) {
            char *av[] = { argv[0], "--help", NULL };
            exec_subcommand (av);
        } else
            help ();
        exit (0);
    }
    if (argc == 0) {
        usage ();
        exit (1);
    }

    exec_subcommand (argv);
    fprintf (stderr, "`%s' is not an sbig command.  See 'sbig --help\n'",
             argv[0]);

    return 0;
}