diff options
author | nate <nate@FreeBSD.org> | 1997-01-06 08:35:06 +0000 |
---|---|---|
committer | nate <nate@FreeBSD.org> | 1997-01-06 08:35:06 +0000 |
commit | f9fe9c12ffcbbda26f384c4be1b8631c30a305c5 (patch) | |
tree | dec8b10a63b5485ef5a4e45cc59c0d3d0aaccb40 /usr.sbin | |
parent | 52af5bcc3c861288762768e8dccc79bc049763b2 (diff) | |
download | FreeBSD-src-f9fe9c12ffcbbda26f384c4be1b8631c30a305c5.zip FreeBSD-src-f9fe9c12ffcbbda26f384c4be1b8631c30a305c5.tar.gz |
- A pass at staticizing things.
- Try to have all output go through the routines in util.c [logerr(),
log_1s(), die()]
- Add *some* code in util.c to allow pccardd to run out of sysinstall.
Submitted by: Mostly me, but some by Tatsumi Hosokawa <hosokawa@jp.FreeBSD.org>
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/pccard/pccardd/cardd.c | 116 | ||||
-rw-r--r-- | usr.sbin/pccard/pccardd/cardd.h | 40 | ||||
-rw-r--r-- | usr.sbin/pccard/pccardd/file.c | 13 | ||||
-rw-r--r-- | usr.sbin/pccard/pccardd/readcis.c | 5 | ||||
-rw-r--r-- | usr.sbin/pccard/pccardd/util.c | 64 |
5 files changed, 131 insertions, 107 deletions
diff --git a/usr.sbin/pccard/pccardd/cardd.c b/usr.sbin/pccard/pccardd/cardd.c index 065ba7f..7b0fd2d 100644 --- a/usr.sbin/pccard/pccardd/cardd.c +++ b/usr.sbin/pccard/pccardd/cardd.c @@ -23,7 +23,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: cardd.c,v 1.12 1996/06/19 17:27:55 nate Exp $ + * $Id: cardd.c,v 1.13 1996/06/20 21:06:51 nate Exp $ */ #include <stdio.h> @@ -34,21 +34,21 @@ #include <sys/ioctl.h> #include <sys/types.h> #include <sys/time.h> -#include <syslog.h> +#define EXTERN #include "cardd.h" char *config_file = "/etc/pccard.conf"; -struct card_config *assign_driver(struct card *); -int setup_slot(struct slot *); -void read_ether(struct slot *); -void dump_config_file(void); -void pr_cmd(struct cmd *); -void readslots(void); -void slot_change(struct slot *); -void card_removed(struct slot *); -void card_inserted(struct slot *); -int assign_io(struct slot *); +static struct card_config *assign_driver(struct card *); +static int assign_io(struct slot *); +static int setup_slot(struct slot *); +static void card_inserted(struct slot *); +static void card_removed(struct slot *); +static void dump_config_file(void); +static void pr_cmd(struct cmd *); +static void read_ether(struct slot *); +static void readslots(void); +static void slot_change(struct slot *); /* * mainline code for cardd @@ -93,35 +93,22 @@ main(int argc, char *argv[]) readfile(config_file); if (verbose) dump_config_file(); - if (!debug) { + log_setup(); + if (!debug) if (daemon(0, 0)) die("fork failed"); - openlog("cardd", LOG_PID, LOG_DAEMON); - do_log = 1; - } -#ifdef DEBUG - printf("Before readslots\n"); -#endif readslots(); -#ifdef DEBUG - printf("After readslots\n"); -#endif if (slots == 0) die("No PC-CARD slots"); + log_1s("pccardd started", NULL); for (;;) { fd_set mask; FD_ZERO(&mask); for (sp = slots; sp; sp = sp->next) FD_SET(sp->fd, &mask); -#ifdef DEBUG - printf("Doing select\n"); -#endif count = select(32, 0, 0, &mask, 0); -#ifdef DEBUG - printf("select=%d\n", count); -#endif if (count == -1) { - perror("Select"); + logerr("Select"); continue; } if (count) @@ -157,8 +144,8 @@ dump_config_file(void) } } -void -pr_cmd(struct cmd * cp) +static void +pr_cmd(struct cmd *cp) { while (cp) { printf("\t%s\n", cp->line); @@ -182,9 +169,6 @@ readslots(void) fd = open(name, 2); if (fd < 0) continue; -#ifdef DEBUG - printf("opened %s\n", name); -#endif sp = xmalloc(sizeof(*sp)); sp->fd = fd; sp->name = newstr(name); @@ -196,16 +180,16 @@ readslots(void) unsigned long mem = 0; if (ioctl(fd, PIOCRWMEM, &mem)) - perror("ioctl (PIOCRWMEM)"); + logerr("ioctl (PIOCRWMEM)"); #ifdef DEBUG - printf("mem=%x\n", mem); + log_1s("mem=0x%x\n", mem); #endif if (mem == 0) { mem = alloc_memory(4 * 1024); if (mem == 0) die("Can't allocate memory for controller access"); if (ioctl(fd, PIOCRWMEM, &mem)) - perror("ioctl (PIOCRWMEM)"); + logerr("ioctl (PIOCRWMEM)"); } } #ifdef DEBUG @@ -228,12 +212,9 @@ slot_change(struct slot *sp) current_slot = sp; if (ioctl(sp->fd, PIOCGSTATE, &state)) { - perror("ioctl (PIOCGSTATE)"); + logerr("ioctl (PIOCGSTATE)"); return; } -#ifdef DEBUG - printf("%p %p %d %d\n", sp, &sp->state, state.state, sp->state); -#endif if (state.state == sp->state) return; sp->state = state.state; @@ -309,8 +290,8 @@ card_inserted(struct slot *sp) reset_slot(sp); #endif if (cp == 0) { - log_1s("No card in database for \"%s\"", sp->cis->manuf); - log_1s("vers: \"%s\"", sp->cis->vers); + log_1s("No card in database for \"%s\"(\"%s\")", + sp->cis->manuf, sp->cis->vers); return; } if (cp->ether) @@ -326,8 +307,9 @@ card_inserted(struct slot *sp) } /* - * Once assigned, then set up the I/O & mem contexts, and - * set up the windows, and then attach the driver. + * + * Once assigned, set up the I/O & mem contexts, set up the + * windows, and then attach the driver. */ if (setup_slot(sp)) execute(cp->insert); @@ -341,7 +323,7 @@ card_inserted(struct slot *sp) * read_ether - read ethernet address from card. Offset is * the offset into the attribute memory of the card. */ -void +static void read_ether(struct slot *sp) { unsigned char net_addr[12]; @@ -357,7 +339,7 @@ read_ether(struct slot *sp) sp->eaddr[3] = net_addr[6]; sp->eaddr[4] = net_addr[8]; sp->eaddr[5] = net_addr[10]; - printf("Ether=%02x:%02x:%02x:%02x:%02x:%02x\n", + log_1s("Ether=%02x:%02x:%02x:%02x:%02x:%02x\n", sp->eaddr[0], sp->eaddr[1], sp->eaddr[2], sp->eaddr[3], sp->eaddr[4], sp->eaddr[5]); } @@ -366,7 +348,7 @@ read_ether(struct slot *sp) * assign_driver - Assign driver to card. * First, see if an existing driver is already setup. */ -struct card_config * +static struct card_config * assign_driver(struct card *cp) { struct driver *drvp; @@ -376,7 +358,7 @@ assign_driver(struct card *cp) if (conf->inuse == 0 && conf->driver->card == cp && conf->driver->config == conf) { #ifdef DEBUG - fprintf(stderr, "Found existing driver (%s) for %s\n", + log_1s(stderr, "Found existing driver (%s) for %s\n", conf->driver->name, cp->manuf); #endif return (conf); @@ -455,7 +437,7 @@ assign_driver(struct card *cp) * assign_io - Allocate resources to slot matching the * configuration index selected. */ -int +static int assign_io(struct slot *sp) { struct cis *cis; @@ -492,14 +474,13 @@ assign_io(struct slot *sp) if (sp->mem.size && sp->mem.addr == 0) { sp->mem.addr = alloc_memory(mp->length); if (sp->mem.addr == 0) - return (-1); + return (-2); sp->config->driver->mem = sp->mem.addr; } sp->mem.cardaddr = 0x4000; #ifdef DEBUG - fprintf(stderr, - "Using mem addr 0x%x, size %d, card addr 0x%x\n", - sp->mem.addr, sp->mem.cardaddr, sp->mem.size); + log_1s("Using mem addr 0x%x, size %d, card addr 0x%x\n", + sp->mem.addr, sp->mem.size, sp->mem.cardaddr); #endif } @@ -554,18 +535,19 @@ assign_io(struct slot *sp) break; } #ifdef DEBUG - fprintf(stderr, "Using I/O addr 0x%x, size %d\n", + log_1s("Using I/O addr 0x%x, size %d\n", sp->io.addr, sp->io.size); #endif } sp->irq = sp->config->irq; return (0); } + /* * setup_slot - Allocate the I/O and memory contexts * return true if completed OK. */ -int +static int setup_slot(struct slot *sp) { struct mem_desc mem; @@ -594,9 +576,8 @@ setup_slot(struct slot *sp) c |= 0x40; write(sp->fd, &c, sizeof(c)); #ifdef DEBUG - printf("Setting config reg at offs 0x%x", offs); - printf(" to 0x%x\n", c); - printf("Reset time = %d ms\n", sp->card->reset_time); + log_1s("Setting config reg at offs 0x%lx to 0x%x, Reset time = %d ms\n", + (unsigned long)offs, c, sp->card->reset_time); #endif sleep(5); usleep(sp->card->reset_time * 1000); @@ -612,14 +593,8 @@ setup_slot(struct slot *sp) c |= 0x20; lseek(sp->fd, offs + 2, SEEK_SET); write(sp->fd, &c, sizeof(c)); -#ifdef DEBUG - printf("Setting CCSR reg to 0x%x\n", c); -#endif } mem.window = 0; -#ifdef DEBUG - printf("Mem@ %x %d %x\n", sp->mem.addr, sp->mem.size, sp->mem.cardaddr); -#endif if (sp->mem.addr) { mem.window = 0; mem.flags = sp->mem.flags | MDF_ACTIVE | MDF_16BITS; @@ -645,8 +620,8 @@ setup_slot(struct slot *sp) } #endif #ifdef DEBUG - printf("Assigning I/O window 0, start 0x%x, size 0x%x flags 0x%x\n", - io.start, io.size, io.flags); + log_1s("Assigning I/O window %d, start 0x%x, size 0x%x flags 0x%x\n", + io.window, io.start, io.size, io.flags); #endif io.flags |= IODF_ACTIVE; if (ioctl(sp->fd, PIOCSIO, &io)) { @@ -670,9 +645,9 @@ setup_slot(struct slot *sp) else drv.iobase = 0; #ifdef DEBUG - fprintf(stderr, "Assign %s%d, io 0x%x, mem 0x%x, %d bytes, irq %x, flags %x\n", + log_1s("Assign %s%d, io 0x%x, mem 0x%lx, %d bytes, irq %d, flags %x\n", drv.name, drv.unit, drv.iobase, drv.mem, drv.memsize, sp->irq, drv.flags); -#endif /* DEBUG */ +#endif /* * If the driver fails to be connected to the device, @@ -680,9 +655,6 @@ setup_slot(struct slot *sp) */ memcpy(drv.misc, sp->eaddr, 6); if (ioctl(sp->fd, PIOCSDRV, &drv)) { -#ifdef DEBUG - perror(sp->card->manuf); -#endif log_1s("driver allocation failed for %s", sp->card->manuf); return (0); } diff --git a/usr.sbin/pccard/pccardd/cardd.h b/usr.sbin/pccard/pccardd/cardd.h index aad1e7e..22bd136 100644 --- a/usr.sbin/pccard/pccardd/cardd.h +++ b/usr.sbin/pccard/pccardd/cardd.h @@ -23,7 +23,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: cardd.h,v 1.4 1996/04/18 04:25:12 nate Exp $ + * $Id: cardd.h,v 1.5 1996/06/18 19:52:29 nate Exp $ * * Common include file for PCMCIA daemon */ @@ -34,6 +34,10 @@ #include "readcis.h" +#ifndef EXTERN +#define EXTERN extern +#endif + struct cmd { struct cmd *next; char *line; /* Command line */ @@ -107,28 +111,32 @@ struct slot { int irq; /* Irq value */ }; -struct slot *slots, *current_slot; +EXTERN struct slot *slots, *current_slot; -struct allocblk *pool_ioblks; /* I/O blocks in the pool */ -struct allocblk *pool_mem; /* Memory in the pool */ -int pool_irq[16]; /* IRQ allocations */ -struct driver *drivers; /* List of drivers */ -struct card *cards; -bitstr_t *mem_avail; -bitstr_t *io_avail; +EXTERN struct allocblk *pool_ioblks; /* I/O blocks in the pool */ +EXTERN struct allocblk *pool_mem; /* Memory in the pool */ +EXTERN int pool_irq[16]; /* IRQ allocations */ +EXTERN struct driver *drivers; /* List of drivers */ +EXTERN struct card *cards; +EXTERN bitstr_t *mem_avail; +EXTERN bitstr_t *io_avail; -int verbose, do_log; +EXTERN int verbose; -char *newstr(); +/* util.c functions */ +unsigned long alloc_memory(int); +int bit_fns(bitstr_t *, int, int); void die(char *); -void *xmalloc(int); -void log_1s(char *, char *); +void execute(struct cmd *); +void log_1s(const char *, ...); +void log_setup(void); void logerr(char *); +char *newstr(); void reset_slot(struct slot *); -void execute(struct cmd *); +void *xmalloc(int); + +/* file.c */ void readfile(char *); -int bit_fns(bitstr_t *, int, int); -unsigned long alloc_memory(int); #define IOPORTS 0x400 #define MEMUNIT 0x1000 diff --git a/usr.sbin/pccard/pccardd/file.c b/usr.sbin/pccard/pccardd/file.c index b8dc30b..1313ed6 100644 --- a/usr.sbin/pccard/pccardd/file.c +++ b/usr.sbin/pccard/pccardd/file.c @@ -23,7 +23,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: file.c,v 1.7 1996/06/19 01:08:58 nate Exp $ + * $Id: file.c,v 1.8 1996/07/11 15:04:43 nate Exp $ */ #include <stdio.h> #include <stdlib.h> @@ -69,7 +69,7 @@ static struct allocblk *ioblk_tok(int); static struct allocblk *memblk_tok(int); static struct driver *new_driver(char *); -static void addcmd(struct cmd **cp); +static void addcmd(struct cmd **); static void parse_card(void); /* @@ -83,14 +83,13 @@ readfile(char *name) in = fopen(name, "r"); if (in == 0) { - perror(name); - exit(1); + logerr(name); + die("readfile"); } parsefile(); for (cp = cards; cp; cp = cp->next) { if (cp->config == 0) - fprintf(stderr, - "warning: card %s(%s) has no valid configuration\n", + log_1s("warning: card %s(%s) has no valid configuration\n", cp->manuf, cp->version); } } @@ -398,7 +397,7 @@ static void error(char *msg) { pusht = 1; - fprintf(stderr, "%s: %s at line %d, near %s\n", + log_1s("%s: %s at line %d, near %s\n", filename, msg, lineno, next_tok()); pusht = 1; } diff --git a/usr.sbin/pccard/pccardd/readcis.c b/usr.sbin/pccard/pccardd/readcis.c index ddded99..8704ec9 100644 --- a/usr.sbin/pccard/pccardd/readcis.c +++ b/usr.sbin/pccard/pccardd/readcis.c @@ -23,7 +23,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: readcis.c,v 1.5 1996/06/17 22:30:29 nate Exp $ + * $Id: readcis.c,v 1.6 1996/06/18 21:58:51 nate Exp $ */ #include <stdio.h> #include <unistd.h> @@ -493,8 +493,7 @@ read_one_tuplelist(int fd, int flags, off_t offs) total++; tp->length = length; #ifdef DEBUG - fprintf(stderr, "Tuple code = 0x%x, len = %d\n", - code, length); + printf("Tuple code = 0x%x, len = %d\n", code, length); #endif if (length == 0xFF) { length = tp->length = 0; diff --git a/usr.sbin/pccard/pccardd/util.c b/usr.sbin/pccard/pccardd/util.c index b7f0de3..282ea99 100644 --- a/usr.sbin/pccard/pccardd/util.c +++ b/usr.sbin/pccard/pccardd/util.c @@ -23,28 +23,59 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: util.c,v 1.5 1996/04/18 04:25:17 nate Exp $ + * $Id: util.c,v 1.6 1996/06/20 21:06:53 nate Exp $ */ + +/* + * Code cleanup, bug-fix and extension + * by: + * Tatsumi Hosokawa <hosokawa@jp.FreeBSD.org> + * Nate Williams <nate@FreeBSD.org> + */ + #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <fcntl.h> +#include <stdarg.h> #include <sys/types.h> #include <sys/ioctl.h> #include <syslog.h> +#ifdef SYSINSTALL +#include <dialog.h> +#endif #include "cardd.h" +static int do_log = 0; + +void +log_setup(void) +{ +#ifndef SYSINSTALL + do_log = 1; + openlog("pccardd", LOG_PID, LOG_DAEMON); +#endif +} void -log_1s(char *msg, char *arg) +log_1s(const char *fmt, ...) { + va_list ap; + char s[256]; + + va_start(ap, fmt); + vsprintf(s, fmt, ap); + if (do_log) - syslog(LOG_ERR, msg, arg); + syslog(LOG_ERR, s); else { - fprintf(stderr, "cardd: "); - fprintf(stderr, msg, arg); - fprintf(stderr, "\n"); +#ifdef SYSINSTALL + dialog_clear(); + msgConfirm(s); +#else + fprintf(stderr, "cardd: %s\n", s); +#endif } } @@ -53,8 +84,14 @@ logerr(char *msg) { if (do_log) syslog(LOG_ERR, "%s: %m", msg); - else + else { +#ifdef SYSINSTALL + dialog_clear(); + msgConfirm(msg); +#else perror(msg); +#endif + } } /* @@ -65,8 +102,17 @@ die(char *msg) { if (do_log) syslog(LOG_CRIT, "fatal error: %s", msg); - else + else { +#ifdef SYSINSTALL + char s[256]; + + sprintf(s, "cardd fatal error: %s\n", msg); + dialog_clear(); + msgConfirm(s); +#else fprintf(stderr, "cardd fatal error: %s\n", msg); +#endif + } closelog(); exit(1); } @@ -216,7 +262,7 @@ execute(struct cmd *cmdp) continue; #ifdef DEBUG fprintf(stderr, "Executing [%s]\n", cmd); -#endif /* DEBUG */ +#endif system(cmd); } } |