Пример #1
0
/**
 * exp_file_print --  Print out the contents of the exports file
 *
 * @file : Exports file to print
 *
 * Not for external use.
 */
void
exp_file_print(const struct exports_file *file)
{
    GF_VALIDATE_OR_GOTO(GF_EXP, file, out);
    dict_foreach(file->exports_dict, __exp_file_print_walk, NULL);
out:
    return;
}
Пример #2
0
/**
 * __exp_file_print_walk -- Print all the keys and values in the dict
 *
 * @dict : the dict to walk
 * @key  : the key in the dict we are currently on
 * @val  : the value in the dict associated with the key
 * @tmp  : Additional parameter data (not used)
 *
 * Passed as a function pointer to dict_foreach ().
 *
 * Not for external use.
 */
static int
__exp_file_print_walk(dict_t *dict, char *key, data_t *val, void *tmp)
{
    if (val) {
        struct export_dir *dir = (struct export_dir *)val->data;

        printf("%s ", key);

        if (dir->netgroups)
            dict_foreach(dir->netgroups, __exp_item_print_walk, NULL);

        if (dir->hosts)
            dict_foreach(dir->hosts, __exp_item_print_walk, NULL);

        printf("\n");
    }
    return 0;
}
Пример #3
0
int32_t ida_dict_combine_cow(ida_local_t * local, dict_t ** dst, dict_t * src)
{
    if (src == NULL)
    {
        return 0;
    }

    return dict_foreach(src, ida_dict_combine_enum, dst);
}
Пример #4
0
/**
 * _exp_dict_destroy -- Delete all the items from this dict
 *                               through the helper function above.
 *
 * @ng_dict : Dict to free
 *
 * Not for external use.
 */
static void
_exp_dict_destroy(dict_t *ng_dict)
{
    if (!ng_dict)
        goto out;

    dict_foreach(ng_dict, __exp_dict_free_walk, NULL);
out:
    return;
}
Пример #5
0
/**
 * _exp_file_deinit -- Free memory used by an export file
 *
 * @expfile : Pointer to the exports file to free
 *
 * Externally usable.
 */
void
exp_file_deinit(struct exports_file *expfile)
{
    if (!expfile)
        goto out;

    if (expfile->exports_dict) {
        dict_foreach(expfile->exports_dict, _exp_file_dict_destroy, NULL);
        dict_unref(expfile->exports_dict);
    }

    if (expfile->exports_map) {
        dict_foreach(expfile->exports_map, _exp_file_dict_destroy, NULL);
        dict_unref(expfile->exports_map);
    }

    GF_FREE(expfile->filename);
    GF_FREE(expfile);
out:
    return;
}
Пример #6
0
bool ida_dict_compare(dict_t * dst, dict_t * src)
{
    if ((dst == NULL) || (src == NULL))
    {
        return dst == src;
    }
    if (dst->count != src->count)
    {
        logW("dict-compare: mismatching number of items");
        return false;
    }
    return dict_foreach(src, ida_dict_compare_enum, dst) == 0;
}
Пример #7
0
int check_record(const char *key, void *data, UNUSED_ARG(void *extra))
{
    struct record_data *rd = data;
    switch (rd->type) {
    case RECDB_INVALID:
	fprintf(stdout, "Invalid database record type for key %s\n", key);
	return 1;
    case RECDB_QSTRING:
    case RECDB_STRING_LIST:
	return 0;
    case RECDB_OBJECT:
	return dict_foreach(rd->d.object, check_record, NULL) ? 1 : 0;
    }
    return 0;
}
Пример #8
0
int main(int argc, char *argv[])
{
    dict_t db;
    char *infile;

    if (argc < 2 || argc > 3) {
        fprintf(stderr, "%s usage: %s <dbfile> [outputfile]\n\n", argv[0], argv[0]);
        fprintf(stderr, "If [outputfile] is specified, dbfile is rewritten into outputfile after being\nparsed.\n\n");
        fprintf(stderr, "<dbfile> and/or [outputfile] may be given as '-' to use stdin and stdout,\nrespectively.\n");
        return 1;
    }

    tools_init();
    if (!strcmp(argv[1], "-")) {
        infile = "/dev/stdin";
    } else {
        infile = argv[1];
    }
    if (!(db = parse_database(infile))) return 2;
    fprintf(stdout, "Database read okay.\n");
    fflush(stdout);
    if (dict_foreach(db, check_record, 0)) return 3;
    if (!bad) {
        fprintf(stdout, "Database checked okay.\n");
        fflush(stdout);
    }

    if (argc == 3) {
        FILE *f;

        if (!strcmp(argv[2], "-")) {
            f = stdout;
        } else {
            if (!(f = fopen(argv[2], "w+"))) {
                fprintf(stderr, "fopen: %s\n", strerror(errno));
                return 4;
            }
        }

        write_database(f, db);
        fclose(f);
        fprintf(stdout, "Database written okay.\n");
        fflush(stdout);
    }

    return 0;
}
Пример #9
0
static int
glusterfs_graph_print (struct gf_printer *gp, glusterfs_graph_t *graph)
{
        xlator_t      *trav = NULL;
        xlator_list_t *xch = NULL;
        int            ret = 0;
        ssize_t        len = 0;

        if (!graph->first)
                return 0;

        for (trav = graph->first; trav->next; trav = trav->next);
        for (; trav; trav = trav->prev) {
                GPPRINTF (gp, "volume %s\n    type %s\n", trav->name,
                          trav->type);

                ret = dict_foreach (trav->options, _print_volume_options, gp);
                if (ret)
                        goto out;

                if (trav->children) {
                        GPPRINTF (gp, "    subvolumes");

                        for (xch = trav->children; xch; xch = xch->next)
                                GPPRINTF (gp, " %s", xch->xlator->name);

                        GPPRINTF (gp, "\n");
                }

                GPPRINTF (gp, "end-volume\n");
                if (trav != graph->first)
                        GPPRINTF (gp, "\n");
        }

out:
        len = gp->len;
        if (ret == -1) {
                gf_msg ("graph-print", GF_LOG_ERROR, 0, LG_MSG_PRINT_FAILED,
                        "printing failed");

                return -1;
        }

        return len;

#undef GPPRINTF
}
Пример #10
0
void
log_rewrite(const char *filename, struct server *s) {
	
	struct client c;
	struct cmd *cm;
	int fd = open(filename, O_RDONLY), tmp_fd, ret;
	char tmp_filename[] = "/tmp/keystack-rewrite-file-XXXXXX";

	c.s = s;

	s->log = NULL;

	printf("Importing existing data..."); fflush(stdout);
	/* first, import log */
	while(1) {
		int ret;
		uint32_t sz;
		char *buffer;

		/* read size */
		ret = read(fd, &sz, sizeof(uint32_t));
		if(ret != sizeof(uint32_t)) {
			break;
		}
		sz = ntohl(sz);
		
		/* read message */
		buffer = malloc(sz);
		ret = read(fd, buffer, sz);
		if(ret != (int)sz) {
			break;
		}

		/* process message */
		cm = cmd_parse(buffer, sz);
		cmd_run(s, cm);
		cmd_free(cm);
	}
	close(fd);	
	printf("done.\nRewriting log file... "); fflush(stdout);

	/* second, write to tmp file. */
	tmp_fd = mkstemp(tmp_filename);
	if(tmp_fd == -1) {
		fprintf(stderr, "Failed to create tmp log file.\n");
		return;
	}

	dict_foreach(s->d, log_add_cb, &tmp_fd);
	printf("done (%ld keys).\nSyncing... ", dict_count(s->d)); fflush(stdout);
	fdatasync(tmp_fd);
	close(tmp_fd);

	printf("done.\nReplacing log file... "); fflush(stdout);
	ret = rename(tmp_filename, filename);
	if(ret != 0) {
		fprintf(stderr, "Failed to replace log file.\n");
		return;
	}

	/* third, replace log file with tmp file */
	printf("done.\nStarting to serve clients.\n");
}
Пример #11
0
const char*
conf_enum_root(dict_iterator_f it, void *extra)
{
    return dict_foreach(conf_db, it, extra);
}