Exemple #1
0
void
DeleteClient(ClientInfo *cp)
{
    int i;

    for (i = 0; i < nClients; i++)
        if (cp == &client[i])
            break;

    if (i == nClients) {
#ifdef PCP_DEBUG
        if (pmDebug & DBG_TRACE_APPL0) {
            __pmNotifyErr(LOG_ERR, "DeleteClient: tried to delete non-existent client\n");
            Shutdown();
            exit(1);
        }
#endif
        return;
    }
    if (cp->fd != -1) {
        __pmFD_CLR(cp->fd, &clientFds);
        __pmCloseSocket(cp->fd);
    }
    if (i == nClients-1) {
        i--;
        while (i >= 0 && !client[i].status.connected)
            i--;
        nClients = (i >= 0) ? i + 1 : 0;
    }
    if (cp->fd == maxClientFd) {
        maxClientFd = -1;
        for (i = 0; i < nClients; i++) {
            if (client[i].fd > maxClientFd)
                maxClientFd = client[i].fd;
        }
    }
    for (i = 0; i < cp->szProfile; i++) {
        if (cp->profile[i] != NULL) {
            __pmFreeProfile(cp->profile[i]);
            cp->profile[i] = NULL;
        }
    }
    __pmFreeAttrsSpec(&cp->attrs);
    __pmHashClear(&cp->attrs);
    __pmSockAddrFree(cp->addr);
    cp->addr = NULL;
    cp->status.connected = 0;
    cp->fd = -1;

    NotifyEndContext(cp-client);
}
Exemple #2
0
int
main(int argc, char **argv)
{
    char		*msg;
    char		buffer[512];
    __pmHashCtl		attrs;
    pmHostSpec		*hosts;
    int			count, sts, i, j;

    if (argc != 2) {
	fprintf(stderr, "Usage: parsehostattrs spec\n");
	exit(1);
    }

    __pmHashInit(&attrs);
    printf("pmParseHostAttrsSpec(\"%s\", ...)\n", argv[1]);
    sts = __pmParseHostAttrsSpec(argv[1], &hosts, &count, &attrs, &msg);
    if (sts < 0) {
	if (sts == PM_ERR_GENERIC)
	    printf("pmParseHostAttrsSpec error:\n%s\n", msg);
	else
	    printf("Error: %s\n", pmErrStr(sts));
	exit(1);
    }
    for (i = 0; i < count; i++) {
	printf("host[%d]: \"%s\"", i, hosts[i].name);
	if (hosts[i].nports == 1)
	    printf(" port:");
	else if (hosts[i].nports > 1)
	    printf(" ports:");
	for (j = 0; j < hosts[i].nports; j++)
	    printf(" %d", hosts[i].ports[j]);
	putchar('\n');
    }
    __pmHashWalkCB(print_attribute, NULL, &attrs);

    sts = __pmUnparseHostAttrsSpec(hosts, count, &attrs, buffer, sizeof(buffer));
    if (sts < 0) {
	printf("pmUnparseHostAttrsSpec: %s\n", pmErrStr(sts));
	exit(1);
    }
    printf("pmUnparseHostAttrsSpec(\"%s\") -> \"%s\"\n", argv[1], buffer);

    __pmFreeHostAttrsSpec(hosts, count, &attrs);
    __pmHashClear(&attrs);
    exit(0);
}