Exemple #1
0
/*
 * Parse a socket path.
 * Accept anything up to, but not including the first ':', '?' or the end of the spec.
 */
static int      /* 0 -> ok, PM_ERR_GENERIC -> error message is set */
parseSocketPath(
    const char *spec,
    char **position,            /* parse this string, return end char */
    pmHostSpec **rslt)          /* result allocated and returned here */
{
    pmHostSpec *hsp = NULL;
    const char *s, *start, *path;
    char absolute_path[MAXPATHLEN];
    size_t len;
    int nhosts = 0, delimited = 0;

    /* Scan to the end of the string or to the first delimiter. */
    for (s = start = *position; s != NULL; s++) {
	if (*s == '\0')
	    break;
	if (*s == ':' || *s == '?') {
	    delimited = 1;
	    break;
	}
    }

    /* If the path is empty, then provide the default. */
    if (s == start || (delimited && s == start + 1)) {
	path = __pmPMCDLocalSocketDefault();
	len = strlen(path);
    }
    else {
	path = start;
	len = s - start;
	if (len >= MAXPATHLEN)
	    len = MAXPATHLEN - 1;
    }

    /*
     * Make sure that the path is absolute. parseProtocolSpec() removes the
     * (optional) "//" from "local://some/path".
     */
    if (*path != pmPathSeparator()) {
	absolute_path[0] = pmPathSeparator();
	strncpy(absolute_path + 1, path, len);
	if (len < sizeof(absolute_path)-1)
	    absolute_path[++len] = '\0';
	absolute_path[sizeof(absolute_path)-1] = '\0';
	path = absolute_path;
    }

    /* Add the path as the only member of the host list. */
    hsp = hostAdd(hsp, &nhosts, path, len);
    if (hsp == NULL) {
	__pmFreeHostSpec(hsp, nhosts);
	*rslt = NULL;
	return -ENOMEM;
    }

    *position = (char *)s;
    *rslt = hsp;
    return 0;
}
Exemple #2
0
void
__pmServerSetLocalSocket(const char *path)
{
    if (path != NULL && *path != '\0')
	localSocketPath = strdup(path);
    else
	localSocketPath = __pmPMCDLocalSocketDefault();
}