示例#1
0
void load_conffile(void)
{
	FILE *f;
	char *confdir = NULL;
	char *head;

	if (loaded)
		return;
	if (conffile == NULL) {
		conffile = DefaultConfFile;
		confdir = DefaultConfDir;
	}

	if (strcmp(conffile, "partitions")==0) {
		char *list = dl_strdup("DEV");
		dl_init(list);
		dl_add(list, dl_strdup("partitions"));
		devline(list);
		free_line(list);
	} else if (strcmp(conffile, "none") != 0) {
		f = fopen(conffile, "r");
		/* Debian chose to relocate mdadm.conf into /etc/mdadm/.
		 * To allow Debian users to compile from clean source and still
		 * have a working mdadm, we read /etc/mdadm/mdadm.conf
		 * if /etc/mdadm.conf doesn't exist
		 */
		if (f == NULL &&
		    conffile == DefaultConfFile) {
			f = fopen(DefaultAltConfFile, "r");
			if (f) {
				conffile = DefaultAltConfFile;
				confdir = DefaultAltConfDir;
			}
		}
		if (f) {
			conf_file_or_dir(f);
			fclose(f);
		}
		if (confdir) {
			f = fopen(confdir, "r");
			if (f) {
				conf_file_or_dir(f);
				fclose(f);
			}
		}
	}
	/* If there was no AUTO line, process an empty line
	 * now so that the MDADM_CONF_AUTO env var gets processed.
	 */
	head = dl_strdup("AUTO");
	dl_init(head);
	autoline(head);
	free_line(head);

	loaded = 1;
}
示例#2
0
文件: csngen.c 项目: Firstyear/ds
/* registers callbacks to be called when csn is created or aborted */
void* csngen_register_callbacks(CSNGen *gen, GenCSNFn genFn, void *genArg, 
						        AbortCSNFn abortFn, void *abortArg)
{
    callback_node *node;
    if (gen == NULL || (genFn == NULL && abortFn == NULL))
        return NULL;

    node = (callback_node *)slapi_ch_malloc (sizeof (callback_node));
    node->gen_fn = genFn;
    node->gen_arg = genArg;
    node->abort_fn = abortFn;
    node->abort_arg = abortArg;

    slapi_rwlock_wrlock (gen->callbacks.lock);
    dl_add (gen->callbacks.list, node);
    slapi_rwlock_unlock (gen->callbacks.lock);

    return node;
}
示例#3
0
char *conf_line(FILE *file)
{
	char *w;
	char *list;

	w = conf_word(file, 1);
	if (w == NULL) return NULL;

	list = dl_strdup(w);
	free(w);
	dl_init(list);

	while ((w = conf_word(file,0))){
		char *w2 = dl_strdup(w);
		free(w);
		dl_add(list, w2);
	}
/*    printf("got a line\n");*/
	return list;
}
示例#4
0
文件: policy.c 项目: brain0/mdadm
static void pol_merge_part(struct dev_policy **pol, struct rule *rule, char *part)
{
	/* copy any name assignments from rule into pol, appending
	 * -part to any domain.  The string with -part appended is
	 * stored with the rule so it has a lifetime to match
	 * the rule.
	 */
	struct rule *r;
	char *metadata = NULL;
	for (r = rule; r ; r = r->next)
		if (r->name == pol_metadata)
			metadata = r->value;

	for (r = rule; r ; r = r->next) {
		if (r->name == pol_act)
			pol_new(pol, r->name, r->value, metadata);
		else if (r->name == pol_domain) {
			char *dom;
			int len;
			if (r->dups == NULL)
				r->dups = dl_head();
			len = strlen(r->value);
			for (dom = dl_next(r->dups); dom != r->dups;
			     dom = dl_next(dom))
				if (strcmp(dom+len+1, part)== 0)
					break;
			if (dom == r->dups) {
				char *newdom = dl_strndup(
					r->value, len + 1 + strlen(part));
				strcat(strcat(newdom, "-"), part);
				dl_add(r->dups, newdom);
				dom = newdom;
			}
			pol_new(pol, r->name, dom, metadata);
		}
	}
}
示例#5
0
int main(){
	DblList* dlist;
	dlist = (DblList *) malloc(sizeof(DblList));
	dlist->head = (NodeType *) malloc(sizeof(NodeType*));
	dlist->tail = (NodeType *) malloc(sizeof(NodeType*));
	dl_init(dlist);

	int x = 0;//just made a random variable to have an infinite while loop
	while (x == 0){
		int y;//this represents the user choice, used effectively like a switch case

		printf("888       888        888                                      \n");
		printf("888   o   888        888                                      \n");
		printf("888  d8b  888        888                                      \n");
		printf("888 d888b 888 .d88b. 888 .d8888b .d88b. 88888b.d88b.  .d88b.  \n");
		printf("888d88888b888d8P  Y8b888d88P    d88  88b888  888  88bd8P  Y8b \n");
		printf("88888P Y8888888888888888888     888  888888  888  88888888888 \n");
		printf("8888P   Y8888Y8b.    888Y88b    Y88..88P888  888  888Y8b.     \n");
		printf("888P     Y888  Y8888 888  Y8888P  Y88P  888  888  888  Y8888  \n");
		printf("\n");
		printf("1. Add a movie\n");
		printf("2. Remove a movie\n");
		printf("3. Print movies\n");
		printf("4. Exit the program\n");
		scanf("%d", &y);
		/************************************************************************
		*GOES INTO ADD MENU
		************************************************************************/
		while(y == 1){//WHILE ADDING
			Movie* movie = (Movie *) malloc(sizeof(Movie));
			movie->year = 0;
			int g;
			int yy;
			char *title;
			
			printf("Enter title to add\n");
			scanf("%15s", title); //15s so i dont get a buffer overflow
			strcpy(movie->title, title);

			printf("Choose a genre\n");
			printf("1. COMEDY\n");
			printf("2. DRAMA\n");
			printf("3. THRILLER\n");
			printf("4. ACTION\n");
			scanf("%d", &g);

			if (g == 1){movie->genre = COMEDY;}
				else if (g == 2){movie->genre = DRAMA;}
				else if (g == 3){movie->genre = THRILLER;}
				else if (g == 4){movie->genre = ACTION;}
				else{
					printf("Invalid choice\n");
					free(movie);
					continue;
				}
			dl_add(dlist, movie);
			printf("Enter 0 to add more or 1 to get out\n");
			scanf("%d", &yy);
			if(yy == 1){
				y = 0;
			}

		}
		/************************************************************************
		*GOES INTO DELETE MENU
		************************************************************************/
		while(y == 2){//WHILE DELETING
			int yy;
			char title[16];
			Movie* movie = (Movie *) malloc(sizeof(Movie));

			printf("Enter title to remove\n");
			scanf("%15s", &title); 
			strcpy(movie->title, title);

			dl_del(dlist, movie);
			free(movie);

			printf("Enter 0 to remove more or 1 to get out\n");
			scanf("%d", &yy);
			if(yy == 1){
				y = 0;
			}
		}
		/************************************************************************
		*GOES INTO PRINT MENU
		************************************************************************/
		while(y == 3){//WHILE PRINTING
			int yy;
			int g;

			printf("1. Print Forward\n");
			printf("2. Print backward\n");
			printf("3. Print by genre\n");
			printf("4. EXIT\n");
			scanf("%d", &yy);

			if( yy == 1){dl_printFwd(dlist);

			}else if (yy == 2){dl_printBack(dlist);

			}else if (yy == 3){
				printf("Please choose a GENRE to print\n");
				printf("1. COMEDY\n");
				printf("2. DRAMA\n");
				printf("3. THRILLER\n");
				printf("4. ACTION\n");
				scanf("%d", &g);
				if (g == 1){dl_printByGenre(dlist, COMEDY);}
				else if (g == 2){dl_printByGenre(dlist, DRAMA);}
				else if (g == 3){dl_printByGenre(dlist, THRILLER);}
				else if (g == 4){dl_printByGenre(dlist, ACTION);}
				else{printf("Incorrect choice");}

			}else{
				y = 0;
				printf("Exiting...");
			}
		}
		while(y == 4){//USER SELECTED EXIT
			dl_cleanup(dlist);
			printf("Goodbye! \n");
			x = 1; //exit the outermost while loop thereby returning and exiting the main
			break;

		}

	}
	return 0;
}
示例#6
0
int Examine(mddev_dev_t devlist, int brief, int scan, int SparcAdjust, struct supertype *forcest)
{

	/* Read the raid superblock from a device and
	 * display important content.
	 *
	 * If cannot be found, print reason: too small, bad magic
	 *
	 * Print:
	 *   version, ctime, level, size, raid+spare+
	 *   prefered minor
	 *   uuid
	 *
	 *   utime, state etc
	 *
	 * If (brief) gather devices for same array and just print a mdadm.conf line including devices=
	 * if devlist==NULL, use conf_get_devs()
	 */
	int fd; 
	void *super = NULL;
	int rv = 0;
	int err = 0;

	struct array {
		void *super;
		struct supertype *st;
		struct mdinfo info;
		struct mddev_ident_s ident;
		void *devs;
		struct array *next;
		int spares;
	} *arrays = NULL;

	for (; devlist ; devlist=devlist->next) {
		struct supertype *st = forcest;

		fd = dev_open(devlist->devname, O_RDONLY);
		if (fd < 0) {
			if (!scan)
				fprintf(stderr,Name ": cannot open %s: %s\n",
					devlist->devname, strerror(errno));
			err = 1;
		}
		else {
			if (!st)
				st = guess_super(fd);
			if (st)
				err = st->ss->load_super(st, fd, &super, (brief||scan)?NULL:devlist->devname);
			else {
				if (!brief)
					fprintf(stderr, Name ": No md superblock detected on %s.\n", devlist->devname);
				err = 1;
			}
			close(fd);
		}
		if (err) {
			rv = 1;
			continue;
		}

		if (SparcAdjust)
			st->ss->update_super(NULL, super, "sparc2.2", devlist->devname,  0);
		/* Ok, its good enough to try, though the checksum could be wrong */
		if (brief) {
			struct array *ap;
			char *d;
			for (ap=arrays; ap; ap=ap->next) {
				if (st->ss == ap->st->ss && st->ss->compare_super(&ap->super, super)==0)
					break;
			}
			if (!ap) {
				ap = malloc(sizeof(*ap));
				ap->super = super;
				ap->devs = dl_head();
				ap->next = arrays;
				ap->spares = 0;
				ap->st = st;
				arrays = ap;
				st->ss->getinfo_super(&ap->info, &ap->ident, super);
			} else {
				st->ss->getinfo_super(&ap->info, &ap->ident, super);
				free(super);
			}
			if (!(ap->info.disk.state & MD_DISK_SYNC))
				ap->spares++;
			d = dl_strdup(devlist->devname);
			dl_add(ap->devs, d);
		} else {
			printf("%s:\n",devlist->devname);
			st->ss->examine_super(super);
			free(super);
		}
	}
	if (brief) {
		struct array *ap;
		for (ap=arrays; ap; ap=ap->next) {
			char sep='=';
			char *d;
			ap->st->ss->brief_examine_super(ap->super);
			if (ap->spares) printf("   spares=%d", ap->spares);
			if (brief > 1) {
				printf("   devices");
				for (d=dl_next(ap->devs); d!= ap->devs; d=dl_next(d)) {
					printf("%c%s", sep, d);
					sep=',';
				}
			}
			free(ap->super);
			/* FIXME free ap */
			if (ap->spares || brief > 1)
				printf("\n");
		}
	}
	return rv;
}
示例#7
0
void load_conffile(char *conffile)
{
	FILE *f;
	char *line;

	if (loaded) return;
	if (conffile == NULL)
		conffile = DefaultConfFile;

	if (strcmp(conffile, "none") == 0) {
		loaded = 1;
		return;
	}
	if (strcmp(conffile, "partitions")==0) {
		char *list = dl_strdup("DEV");
		dl_init(list);
		dl_add(list, dl_strdup("partitions"));
		devline(list);
		free_line(list);
		loaded = 1;
		return;
	}
	f = fopen(conffile, "r");
	/* Debian chose to relocate mdadm.conf into /etc/mdadm/.
	 * To allow Debian users to compile from clean source and still
	 * have a working mdadm, we read /etc/mdadm/mdadm.conf
	 * if /etc/mdadm.conf doesn't exist
	 */
	if (f == NULL &&
	    conffile == DefaultConfFile) {
		f = fopen(DefaultAltConfFile, "r");
		if (f)
			conffile = DefaultAltConfFile;
	}
	if (f == NULL)
		return;

	loaded = 1;
	while ((line=conf_line(f))) {
		switch(match_keyword(line)) {
		case 0: /* DEVICE */
			devline(line);
			break;
		case 1: /* ARRAY */
			arrayline(line);
			break;
		case 2: /* MAIL */
			mailline(line);
			break;
		case 3: /* PROGRAM */
			programline(line);
			break;
		default:
			fprintf(stderr, Name ": Unknown keyword %s\n", line);
		}
		free_line(line);
	}
    
	fclose(f);

/*    printf("got file\n"); */
}
示例#8
0
文件: config.c 项目: AllardJ/Tomato
void load_conffile(void)
{
	FILE *f;
	char *line;

	if (loaded) return;
	if (conffile == NULL)
		conffile = DefaultConfFile;

	if (strcmp(conffile, "none") == 0) {
		loaded = 1;
		return;
	}
	if (strcmp(conffile, "partitions")==0) {
		char *list = dl_strdup("DEV");
		dl_init(list);
		dl_add(list, dl_strdup("partitions"));
		devline(list);
		free_line(list);
		loaded = 1;
		return;
	}
	f = fopen(conffile, "r");
	/* Debian chose to relocate mdadm.conf into /etc/mdadm/.
	 * To allow Debian users to compile from clean source and still
	 * have a working mdadm, we read /etc/mdadm/mdadm.conf
	 * if /etc/mdadm.conf doesn't exist
	 */
	if (f == NULL &&
	    conffile == DefaultConfFile) {
		f = fopen(DefaultAltConfFile, "r");
		if (f)
			conffile = DefaultAltConfFile;
	}
	if (f == NULL)
		return;

	loaded = 1;
	while ((line=conf_line(f))) {
		switch(match_keyword(line)) {
		case Devices:
			devline(line);
			break;
		case Array:
			arrayline(line);
			break;
		case Mailaddr:
			mailline(line);
			break;
		case Mailfrom:
			mailfromline(line);
			break;
		case Program:
			programline(line);
			break;
		case CreateDev:
			createline(line);
			break;
		case Homehost:
			homehostline(line);
			break;
		default:
			fprintf(stderr, Name ": Unknown keyword %s\n", line);
		}
		free_line(line);
	}
    
	fclose(f);

/*    printf("got file\n"); */
}