Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 84231
Collapse All | Expand All

(-)module-init-tools-3.2-pre1/modprobe.c.original (-51 / +80 lines)
Lines 950-955 Link Here
950
	return strsep(string, delim);
950
	return strsep(string, delim);
951
}
951
}
952
952
953
struct alias_module {
954
	struct alias_module *next;
955
	char * name;
956
};
957
958
static int add_alias_module(char *name, struct alias_module **alias_module)
959
{
960
	struct alias_module *new = NOFAIL(malloc(sizeof(struct alias_module)));
961
	new->next = *alias_module;
962
	new->name = NOFAIL(strdup(name));
963
	*alias_module = new;
964
965
	return 0;
966
}
967
953
/* Recursion */
968
/* Recursion */
954
static int read_config(const char *filename,
969
static int read_config(const char *filename,
955
		       const char *name,
970
		       const char *name,
Lines 957-963 Link Here
957
		       int removing,
972
		       int removing,
958
		       struct module_options **options,
973
		       struct module_options **options,
959
		       struct module_command **commands,
974
		       struct module_command **commands,
960
		       char **alias);
975
		       struct alias_module **alias);
976
961
977
962
/* FIXME: Maybe should be extended to "alias a b [and|or c]...". --RR */
978
/* FIXME: Maybe should be extended to "alias a b [and|or c]...". --RR */
963
static int read_config_file(const char *filename,
979
static int read_config_file(const char *filename,
Lines 966-972 Link Here
966
			    int removing,
982
			    int removing,
967
			    struct module_options **options,
983
			    struct module_options **options,
968
			    struct module_command **commands,
984
			    struct module_command **commands,
969
			    char **alias)
985
			    struct alias_module **alias)
970
{
986
{
971
	char *line;
987
	char *line;
972
	unsigned int linenum = 0;
988
	unsigned int linenum = 0;
Lines 996-1004 Link Here
996
			if (!wildcard || !realname)
1012
			if (!wildcard || !realname)
997
				grammar(cmd, filename, linenum);
1013
				grammar(cmd, filename, linenum);
998
			else if (fnmatch(wildcard,name,0) == 0)
1014
			else if (fnmatch(wildcard,name,0) == 0)
999
				*alias = NOFAIL(strdup(realname));
1015
				add_alias_module(realname, alias);
1000
		} else if (strcmp(cmd, "include") == 0) {
1016
		} else if (strcmp(cmd, "include") == 0) {
1001
			char *newalias = NULL, *newfilename;
1017
			char *newfilename;
1002
1018
1003
			newfilename = strsep_skipspace(&ptr, "\t ");
1019
			newfilename = strsep_skipspace(&ptr, "\t ");
1004
			if (!newfilename)
1020
			if (!newfilename)
Lines 1006-1020 Link Here
1006
			else {
1022
			else {
1007
				if (!read_config(newfilename, name,
1023
				if (!read_config(newfilename, name,
1008
						 dump_only, removing,
1024
						 dump_only, removing,
1009
						 options, commands, &newalias))
1025
						 options, commands, alias))
1010
					warn("Failed to open included"
1026
					warn("Failed to open included"
1011
					      " config file %s: %s\n",
1027
					      " config file %s: %s\n",
1012
					      newfilename, strerror(errno));
1028
					      newfilename, strerror(errno));
1013
1014
				/* Files included override aliases,
1015
				   etc that was already set ... */
1016
				if (newalias)
1017
					*alias = newalias;
1018
			}
1029
			}
1019
		} else if (strcmp(cmd, "options") == 0) {
1030
		} else if (strcmp(cmd, "options") == 0) {
1020
			modname = strsep_skipspace(&ptr, "\t ");
1031
			modname = strsep_skipspace(&ptr, "\t ");
Lines 1060-1066 Link Here
1060
		       int removing,
1071
		       int removing,
1061
		       struct module_options **options,
1072
		       struct module_options **options,
1062
		       struct module_command **commands,
1073
		       struct module_command **commands,
1063
		       char **alias)
1074
		       struct alias_module **alias)
1064
{
1075
{
1065
	DIR *dir;
1076
	DIR *dir;
1066
1077
Lines 1103-1109 Link Here
1103
				 int removing,
1114
				 int removing,
1104
				 struct module_options **options,
1115
				 struct module_options **options,
1105
				 struct module_command **commands,
1116
				 struct module_command **commands,
1106
				 char **alias)
1117
				 struct alias_module **alias)
1107
{
1118
{
1108
	unsigned int i;
1119
	unsigned int i;
1109
1120
Lines 1226-1231 Link Here
1226
	return 0;
1237
	return 0;
1227
}
1238
}
1228
1239
1240
#define HANDLE_ONE_MODULE()						\
1241
	if (list_empty(&list)) {					\
1242
		/* The dependencies have to be real modules, but	\
1243
		   handle case where the first is completely bogus. */	\
1244
		command = find_command(modname, commands);		\
1245
		if (command && !ignore_commands) {			\
1246
			do_command(modname, command, verbose, dry_run,	\
1247
				   fatal, remove ? "remove":"install");	\
1248
			continue;					\
1249
		}							\
1250
		if (unknown_silent)					\
1251
			exit(1);					\
1252
		error("Module %s not found.\n", modname);		\
1253
		continue;						\
1254
	}								\
1255
									\
1256
	if (remove)							\
1257
		rmmod(&list, newname, first_time, error, dry_run,	\
1258
		      verbose, commands, ignore_commands, 0);		\
1259
	else								\
1260
		insmod(&list, NOFAIL(strdup(optstring)), newname,	\
1261
		       first_time, error, dry_run, verbose, modoptions,	\
1262
		       commands, ignore_commands, ignore_proc,		\
1263
		       strip_vermagic, strip_modversion);		\
1264
	free(modname);
1265
1266
#define HANDLE_ALL_ALIASES()						\
1267
	while (alias_module) {						\
1268
		struct alias_module *next = alias_module->next;		\
1269
		char *modname = alias_module->name;			\
1270
									\
1271
		optstring = add_extra_options(modulearg, optstring,	\
1272
					      modoptions);		\
1273
		read_depends(dirname, modname, &list);			\
1274
									\
1275
		HANDLE_ONE_MODULE();					\
1276
									\
1277
		free(alias_module);					\
1278
		alias_module = next;					\
1279
	}
1280
1281
1229
int main(int argc, char *argv[])
1282
int main(int argc, char *argv[])
1230
{
1283
{
1231
	struct utsname buf;
1284
	struct utsname buf;
Lines 1391-1397 Link Here
1391
	if (dump_only) {
1444
	if (dump_only) {
1392
		struct module_command *commands = NULL;
1445
		struct module_command *commands = NULL;
1393
		struct module_options *modoptions = NULL;
1446
		struct module_options *modoptions = NULL;
1394
		char *a = NULL;
1447
		struct alias_module *a = NULL;
1395
1448
1396
		read_toplevel_config(config, "", 1, 0,
1449
		read_toplevel_config(config, "", 1, 0,
1397
				     &modoptions, &commands, &a);
1450
				     &modoptions, &commands, &a);
Lines 1415-1441 Link Here
1415
		LIST_HEAD(list);
1468
		LIST_HEAD(list);
1416
		char *modulearg = argv[optind + i];
1469
		char *modulearg = argv[optind + i];
1417
		char *modname = NULL;
1470
		char *modname = NULL;
1471
		struct alias_module *alias_module = NULL;
1418
1472
1419
		/* Convert name we are looking for */
1473
		/* Convert name we are looking for */
1420
		underscores(modulearg);
1474
		underscores(modulearg);
1421
1475
1422
		/* Returns the resolved alias, options */
1476
		/* Returns the resolved alias, options */
1423
		read_toplevel_config(config, modulearg, 0,
1477
		read_toplevel_config(config, modulearg, 0,
1424
				     remove, &modoptions, &commands, &modname);
1478
				     remove, &modoptions, &commands, &alias_module);
1425
1479
1426
		/* No luck?  Try symbol names, if starts with symbol:. */
1480
		/* No luck?  Try symbol names, if starts with symbol:. */
1427
		if (!modname
1481
		if (!alias_module
1428
		    && strncmp(modulearg, "symbol:", strlen("symbol:")) == 0)
1482
		    && strncmp(modulearg, "symbol:", strlen("symbol:")) == 0)
1429
			read_config(symfilename, modulearg, 0,
1483
			read_config(symfilename, modulearg, 0,
1430
				    remove, &modoptions, &commands, &modname);
1484
				    remove, &modoptions, &commands, &alias_module);
1431
1485
1432
		/* If we have an alias, gather any options associated with it
1486
1487
		/* If we have aliases, gather any options associated with it
1433
		   (needs to happen after parsing complete). */
1488
		   (needs to happen after parsing complete). */
1434
		if (modname) {
1489
		if (alias_module) {
1435
		got_modname:
1490
			HANDLE_ALL_ALIASES();
1436
			optstring = add_extra_options(modulearg, optstring,
1437
						      modoptions);
1438
			read_depends(dirname, modname, &list);
1439
		} else {
1491
		} else {
1440
			read_depends(dirname, modulearg, &list);
1492
			read_depends(dirname, modulearg, &list);
1441
			/* We don't allow canned aliases to override
1493
			/* We don't allow canned aliases to override
Lines 1446-1482 Link Here
1446
			    && read_config(aliasfilename,
1498
			    && read_config(aliasfilename,
1447
					   modulearg, 0,
1499
					   modulearg, 0,
1448
					   remove, &modoptions,
1500
					   remove, &modoptions,
1449
					   &commands, &modname)
1501
					   &commands, &alias_module)
1450
			    && modname)
1502
			    && alias_module) {
1451
				goto got_modname;
1503
				HANDLE_ALL_ALIASES();
1452
1504
			} else {
1453
			modname = strdup(modulearg);
1505
				modname = strdup(modulearg);
1454
		}
1506
				HANDLE_ONE_MODULE();
1455
1456
		if (list_empty(&list)) {
1457
			/* The dependencies have to be real modules, but
1458
			   handle case where the first is completely bogus. */
1459
			command = find_command(modname, commands);
1460
			if (command && !ignore_commands) {
1461
				do_command(modname, command, verbose, dry_run,
1462
					   fatal, remove ? "remove":"install");
1463
				continue;
1464
			}
1507
			}
1465
			if (unknown_silent)
1466
				exit(1);
1467
			error("Module %s not found.\n", modname);
1468
			continue;
1469
		}
1508
		}
1470
1471
		if (remove)
1472
			rmmod(&list, newname, first_time, error, dry_run,
1473
			      verbose, commands, ignore_commands, 0);
1474
		else
1475
			insmod(&list, NOFAIL(strdup(optstring)), newname,
1476
			       first_time, error, dry_run, verbose, modoptions,
1477
			       commands, ignore_commands, ignore_proc,
1478
			       strip_vermagic, strip_modversion);
1479
		free(modname);
1480
	}
1509
	}
1481
1510
1482
	free(dirname);
1511
	free(dirname);

Return to bug 84231