Exemple #1
0
void
pmdaCloseHelp(int handle)
{
    help_t		*hp;

    if (handle < 0 || handle >= numhelp)
	return;
    hp = &tab[handle];

    if (hp->dir_fd != -1)
	close(hp->dir_fd);
    if (hp->pag_fd != -1)
	close(hp->pag_fd);
    if (hp->index != NULL)
	__pmMemoryUnmap((void *)hp->index, (hp->numidx+1) * sizeof(help_idx_t));
    if (hp->text != NULL)
	__pmMemoryUnmap(hp->text, hp->textlen);

    hp->textlen = 0;
    hp->dir_fd = -1;
    hp->pag_fd = -1;
    hp->numidx = 0;
    hp->index = NULL;
    hp->text = NULL;
}
Exemple #2
0
int
main(int argc, char **argv)
{
    struct stat sbuf;
    char *file, *flags = NULL;
    int c, err = 0, pid = 0;

    __pmSetProgname(argv[0]);
    while ((c = getopt(argc, argv, "f:p:")) != EOF) {
        switch (c) {
        case 'f':
            flags = optarg;
            break;
        case 'p':
            pid = atoi(optarg);
            break;
        default:
            err++;
        }
    }

    if (err || argc != optind + 1)
        usage();

    file = argv[optind];

    c = open(file, O_RDWR, 0644);
    if (c < 0) {
        fprintf(stderr, "Cannot open %s for writing: %s\n",
                file, strerror(errno));
        exit(1);
    }
    fstat(c, &sbuf);
    addr = __pmMemoryMap(c, sbuf.st_size, 1);
    close(c);

    if (flags)
        write_flags(flags);

    if (pid)
        write_pid(pid);

    __pmMemoryUnmap(addr, sbuf.st_size);
    exit(0);
}