diff -ur pcmcia-cs-3.1.31/cardmgr/Makefile pcmcia-cs-3.1.31.new/cardmgr/Makefile --- pcmcia-cs-3.1.31/cardmgr/Makefile Wed Feb 7 01:41:40 2001 +++ pcmcia-cs-3.1.31.new/cardmgr/Makefile Fri Apr 12 18:12:40 2002 @@ -6,7 +6,7 @@ include ../config.mk CFLAGS = -O -Wall -Wstrict-prototypes -pipe -CPPFLAGS += -I../modules +CPPFLAGS += -I../modules -I../../../sinalib/_/include CC = $(UCC) $(UFLAGS) SRCS = cardmgr.c cardctl.c yacc_config.c lex_config.c probe.c @@ -47,7 +47,7 @@ rm -f core core.* *.o *.s *.a *~ .depend .depfiles/*.d rm -f $(TOOLS) $(EXTRA) probe -cardmgr: cardmgr.o yacc_config.o lex_config.o +cardmgr: cardmgr.o yacc_config.o lex_config.o ../../../sinalib/_/lib/libsina.a yacc_config.o lex_config.o: %.o: %.c $(CC) -c -MD -O -pipe $(CPPFLAGS) $< diff -ur pcmcia-cs-3.1.31/cardmgr/cardmgr.c pcmcia-cs-3.1.31.new/cardmgr/cardmgr.c --- pcmcia-cs-3.1.31/cardmgr/cardmgr.c Sat Dec 1 02:19:22 2001 +++ pcmcia-cs-3.1.31.new/cardmgr/cardmgr.c Fri Apr 12 18:41:58 2002 @@ -56,6 +56,7 @@ #include #include "cardmgr.h" +#include /*====================================================================*/ @@ -123,6 +124,15 @@ /* Extra message logging? */ static int verbose = 0; +/* name of card to load */ +static char *force_card = NULL; + +/* Default path for insmod binaries */ +static char *insmod_cmd = "/initrd/sbin/insmod "; +static char *modprobe_cmd = "/initrd/sbin/modprobe "; +static char *rmmod_cmd = "/initrd/sbin/rmmod"; + + /*====================================================================*/ static int major = 0; @@ -518,8 +528,7 @@ return card; } - if (!blank_card || (status.CardState & CS_EVENT_CB_DETECT) || - manfid.manf || manfid.card || pci_id.vendor || vers) { + if (!blank_card) { syslog(LOG_INFO, "unsupported card in socket %d", ns); if (one_pass) return NULL; beep(BEEP_TIME, BEEP_ERR); @@ -537,6 +546,8 @@ static void load_config(void) { + card_info_t *card = NULL; + if (chdir(configpath) != 0) { syslog(LOG_ERR, "chdir to %s failed: %m", configpath); exit(EXIT_FAILURE); @@ -547,6 +558,20 @@ syslog(LOG_WARNING, "no device drivers defined"); if ((root_card == NULL) && (root_func == NULL)) syslog(LOG_WARNING, "no cards defined"); + + if (force_card != NULL) { + for (card = root_card; card; card = card->next) { + if (strcmp(card->name, force_card) == 0) { + blank_card = card; + break; + } + } + + if (blank_card == NULL) { + syslog(LOG_WARNING, "forced card not found"); + exit(EXIT_FAILURE); + } + } } /*====================================================================*/ @@ -618,7 +643,6 @@ root_func = root_func->next; free_card(card); } - blank_card = NULL; while (root_mtd != NULL) { mtd_ident_t *mtd = root_mtd; @@ -633,26 +657,13 @@ static int execute(char *msg, char *cmd) { int ret; - FILE *f; - char line[256]; syslog(LOG_INFO, "executing: '%s'", cmd); - strcat(cmd, " 2>&1"); - f = popen(cmd, "r"); - while (fgets(line, 255, f)) { - line[strlen(line)-1] = '\0'; - syslog(LOG_INFO, "+ %s", line); - } - ret = pclose(f); - if (WIFEXITED(ret)) { - if (WEXITSTATUS(ret)) - syslog(LOG_INFO, "%s exited with status %d", - msg, WEXITSTATUS(ret)); - return WEXITSTATUS(ret); - } else - syslog(LOG_INFO, "%s exited on signal %d", - msg, WTERMSIG(ret)); - return -1; + + ret = exec_cmd(0, 0, 1, cmd); + + syslog(LOG_INFO, "%s exited with status %d", msg, ret); + return(ret); } /*====================================================================*/ @@ -669,13 +680,15 @@ static int execute_on_all(char *cmd, char *class, int sn, int fn) { - socket_info_t *s = &socket[sn]; +/* socket_info_t *s = &socket[sn]; bind_info_t *bind; int ret = 0; for (bind = s->bind[fn]; bind != NULL; bind = bind->next) if (bind->name[0] && (bind->name[2] != '#')) ret |= execute_on_dev(cmd, class, bind->name); return ret; +*/ + return 0; } /*====================================================================*/ @@ -691,16 +704,14 @@ static int try_insmod(char *mod, char *opts) { char *cmd = malloc(strlen(mod) + strlen(modpath) + - (opts ? strlen(opts) : 0) + 30); + (opts ? strlen(opts) : 0) + strlen(insmod_cmd) + 20); int ret; - strcpy(cmd, "insmod "); - if (strchr(mod, '/') != NULL) - sprintf(cmd+7, "%s/%s.o", modpath, mod); - else - sprintf(cmd+7, "%s/pcmcia/%s.o", modpath, mod); - if (access(cmd+7, R_OK) != 0) { - syslog(LOG_INFO, "module %s not available", cmd+7); + strcpy(cmd, insmod_cmd); + sprintf(cmd+strlen(insmod_cmd), "%s/%s.o", modpath, mod); + + if (access(cmd+strlen(insmod_cmd), R_OK) != 0) { + syslog(LOG_INFO, "module %s not available", cmd+strlen(insmod_cmd)); free(cmd); return -1; } @@ -715,18 +726,7 @@ static int try_modprobe(char *mod, char *opts) { - char *cmd = malloc(strlen(mod) + (opts ? strlen(opts) : 0) + 20); - char *s = strrchr(mod, '/'); - int ret; - - sprintf(cmd, "modprobe %s", (s) ? s+1 : mod); - if (opts) { - strcat(cmd, " "); - strcat(cmd, opts); - } - ret = execute("modprobe", cmd); - free(cmd); - return ret; + return (-1); } static void install_module(char *mod, char *opts) @@ -785,7 +785,11 @@ /* Strip off leading path names */ s = strrchr(mod, '/'); s = (s) ? s+1 : mod; - sprintf(cmd, do_modprobe ? "modprobe -r %s" : "rmmod %s", s); + if (do_modprobe) { + sprintf(cmd, "%s -r %s", modprobe_cmd, s); + } else { + sprintf(cmd, "%s %s", rmmod_cmd, s); + } execute(do_modprobe ? "modprobe" : "rmmod", cmd); } } @@ -1318,7 +1322,7 @@ } errflg = 0; - while ((optch = getopt(argc, argv, "Vqdvofc:m:p:s:")) != -1) { + while ((optch = getopt(argc, argv, "Vqdvofc:m:p:s:l:")) != -1) { switch (optch) { case 'V': fprintf(stderr, "cardmgr version " CS_PKG_RELEASE "\n"); @@ -1334,6 +1338,8 @@ delay_fork = 1; break; case 'c': configpath = strdup(optarg); break; + case 'l': + force_card = strdup(optarg); break; case 'd': do_modprobe = 1; break; case 'm': @@ -1383,8 +1389,6 @@ } if (access(modpath, X_OK) != 0) syslog(LOG_INFO, "cannot access %s: %m", modpath); - /* We default to using modprobe if it is available */ - do_modprobe |= (access("/sbin/modprobe", X_OK) == 0); load_config();