Exemplo n.º 1
0
char *join_path(char *left, char *right) {
  char *trimmed_left = trim_trailing_slash(left);
  size_t size = strlen(trimmed_left) + strlen(right) + 2;
  char *result = malloc(sizeof(char) * size);
  snprintf(result, size, "%s/%s", trimmed_left, right);
  free(trimmed_left);
  return result;
}
Exemplo n.º 2
0
void rbenv_initialize_root() {
  if (hasenv("RBENV_ROOT")) {
    rbenv_root = trim_trailing_slash(getenv("RBENV_ROOT"));
  } else {
    rbenv_root = join_path(default(getenv("HOME"), "/"), ".rbenv");
  }

  setenv("RBENV_ROOT", rbenv_root, 1);
}
Exemplo n.º 3
0
static void startLog(char *path, char *logFileNam)
{
	char logFilePath[MAXPATH+1];

	if(path)
	{
		trim_trailing_slash(path);
		pgxcCtlMkdir(path);
		if(logFileNam)
		{
			if (logFileNam[0] == '/')
			{
				fprintf(stderr, "ERROR: both --logdir and --logfile are specified and logfile was abosolute path.\n");
				exit(1);
			}
			if (path[0] == '/')
				snprintf(logFilePath, MAXPATH, "%s/%s", path, logFileNam);
			else
				snprintf(logFilePath, MAXPATH, "%s/%s/%s", pgxc_ctl_home, path, logFileNam);
			initLog(NULL, logFilePath);
		}
		else
		{
			if (path[0] == '/')
				initLog(path, NULL);
			else
			{
				snprintf(logFilePath, MAXPATH, "%s/%s", pgxc_ctl_home, path);
				initLog(logFilePath, NULL);
			}
		}
	}
	else
	{
		if (logFileNam && logFileNam[0] == '/')
		{
			/* This is used as log file path */
			initLog(NULL, logFileNam);
			return;
		}
		else
		{
			snprintf(logFilePath, MAXPATH, "%s/pgxc_log", pgxc_ctl_home);
			pgxcCtlMkdir(logFilePath);
			initLog(logFilePath, NULL);
		}
	}
	return;
}
Exemplo n.º 4
0
static krb5_error_code
load_plugins(krb5_context context)
{
    struct plugin *e;
    krb5_error_code ret;
    char **dirs = NULL, **di;
    struct dirent *entry;
    char *path;
    DIR *d = NULL;

    if (!plugins_needs_scan)
	return 0;
    plugins_needs_scan = 0;

#ifdef HAVE_DLOPEN

    dirs = krb5_config_get_strings(context, NULL, "libdefaults",
				   "plugin_dir", NULL);
    if (dirs == NULL)
	dirs = rk_UNCONST(sysplugin_dirs);

    for (di = dirs; *di != NULL; di++) {
        char * dir = *di;

#ifdef KRB5_USE_PATH_TOKENS
        if (_krb5_expand_path_tokens(context, *di, &dir))
            goto next_dir;
#endif

        trim_trailing_slash(dir);

        d = opendir(dir);

	if (d == NULL)
	    goto next_dir;

	rk_cloexec_dir(d);

	while ((entry = readdir(d)) != NULL) {
	    char *n = entry->d_name;

	    /* skip . and .. */
            if (!is_valid_plugin_filename(n))
		continue;

	    path = NULL;
	    ret = 0;
#ifdef __APPLE__
	    { /* support loading bundles on MacOS */
		size_t len = strlen(n);
		if (len > 7 && strcmp(&n[len - 7],  ".bundle") == 0)
		    ret = asprintf(&path, "%s/%s/Contents/MacOS/%.*s", dir, n, (int)(len - 7), n);
	    }
#endif
	    if (ret < 0 || path == NULL)
		ret = asprintf(&path, "%s/%s", dir, n);

	    if (ret < 0 || path == NULL) {
		ret = ENOMEM;
		krb5_set_error_message(context, ret, "malloc: out of memory");
		return ret;
	    }

	    /* check if already tried */
	    for (e = registered; e != NULL; e = e->next)
		if (e->type == DSO && strcmp(e->u.dso.path, path) == 0)
		    break;
	    if (e) {
		free(path);
	    } else {
		loadlib(context, path); /* store or frees path */
	    }
	}
	closedir(d);

    next_dir:
        if (dir != *di)
            free(dir);
    }
    if (dirs != rk_UNCONST(sysplugin_dirs))
	krb5_config_free_strings(dirs);
#endif /* HAVE_DLOPEN */
    return 0;
}
Exemplo n.º 5
0
static void build_pgxc_ctl_home(char *home)
{
	char *env_pgxc_ctl_home = getenv(PGXC_CTL_HOME);
	char *env_home = getenv(HOME);		/* We assume this is always available */

	if (home)
	{
		if (home[0] == '/')
		{
			/* Absolute path */
			strncpy(pgxc_ctl_home, home, MAXPATH);
			goto set_bash;
		}
		else
		{
			/* Relative path */
			trim_trailing_slash(home);
			snprintf(pgxc_ctl_home, MAXPATH, "%s/%s", env_home, home);
			goto set_bash;
		}
	}
	if ((env_pgxc_ctl_home = getenv(PGXC_CTL_HOME)) == NULL)
	{
		snprintf(pgxc_ctl_home, MAXPATH, "%s/%s", env_home, pgxc_ctl_home_def);
		goto set_bash;
	}
	if (env_pgxc_ctl_home[0] == '/') /* Absoute path */
	{
		strncpy(pgxc_ctl_home, env_pgxc_ctl_home, MAXPATH);
		goto set_bash;
	}
	trim_trailing_slash(env_pgxc_ctl_home);
	if (env_pgxc_ctl_home[0] == '\0' || env_pgxc_ctl_home[0] == ' ' || env_pgxc_ctl_home[0] == '\t')
	{
		/* Null environment */
		snprintf(pgxc_ctl_home, MAXPATH, "%s/%s", env_home, pgxc_ctl_home_def);
		goto set_bash;
	}
	snprintf(pgxc_ctl_home, MAXPATH, "%s/%s", env_home, home);
	goto set_bash;

set_bash:
	snprintf(pgxc_ctl_bash_path, MAXPATH, "%s/%s", pgxc_ctl_home, PGXC_CTL_BASH);
	/*
	 * Create home dir if necessary and change current directory to it.
	 */
	{
		struct stat buf;
		char	cmd[MAXLINE+1];
		
		if (stat(pgxc_ctl_home, &buf) ==0)
		{
			if (S_ISDIR(buf.st_mode))
			{
				Chdir(pgxc_ctl_home, TRUE);
				return;
			}
			else
			{
				fprintf(stderr, "%s is not directory.  Check your configurfation\n", pgxc_ctl_home);
				exit(1);
			}
		}
		snprintf(cmd, MAXLINE, "mkdir -p %s", pgxc_ctl_home);
		system(cmd);
		if (stat(pgxc_ctl_home, &buf) ==0)
		{
			if (S_ISDIR(buf.st_mode))
			{
				Chdir(pgxc_ctl_home, TRUE);
				return;
			}
			else
			{
				fprintf(stderr, "Creating %s directory failed. Check your configuration\n", pgxc_ctl_home);
				exit(1);
			}
		}
		fprintf(stderr, "Creating directory %s failed. %s\n", pgxc_ctl_home, strerror(errno));
		exit(1);
	}
	return;
}