[Libsysio-commit] HEAD: libsysio/src init.c
Brought to you by:
lward
From: Lee W. <lw...@us...> - 2004-11-19 17:50:05
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19149/src Modified Files: init.c Log Message: Implemented _sysio_cprintf, a console printf function. Changed ENTER and LEAVE macros to call this new function directly, instead of _sysio_enter and _sysio_leave. Got rid of the aforementioned functions. Enhanced _sysio_boot to report failures, via _sysio_cprintf, when processing the namespace initialization buffer. Debugging the silent failures was taking way too much time. Index: init.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/init.c,v retrieving revision 1.18 retrieving revision 1.19 diff -u -w -b -B -p -r1.18 -r1.19 --- init.c 18 Nov 2004 13:21:21 -0000 1.18 +++ init.c 19 Nov 2004 17:49:54 -0000 1.19 @@ -163,13 +163,17 @@ static int vasprintf(char **strp, const char *fmt, va_list ap) { size_t siz; + int oerrno; char *s; va_list aq; int n; siz = 50; - if (!(s = malloc(siz))) + oerrno = errno; + if (!(s = malloc(siz))) { + errno = oerrno; return -1; + } for (;;) { va_copy(aq, ap); n = vsnprintf (s, siz, fmt, aq); @@ -184,9 +188,11 @@ vasprintf(char **strp, const char *fmt, break; } *strp = s; + errno = oerrno; return n; } +#if 0 static int asprintf(char **strp, const char *fmt, ...) { @@ -198,49 +204,37 @@ asprintf(char **strp, const char *fmt, . va_end(ap); return n; } +#endif #endif /* !(defined(_HAVE_ASPRINTF) && _HAVE_ASPRINTF) */ static void _sysio_cwrite(const char *buf, size_t len) { - - (void )syscall(SYSIO_SYS_write, STDERR_FILENO, buf, len); -} - -void -_sysio_enter(const char *fname) -{ int oerrno; - int len; - char *buf; oerrno = errno; - do { - len = asprintf(&buf, "+ENTER+ %s\n", fname); - if (len < 0) - break; - _sysio_cwrite(buf, (size_t )len); - free(buf); - } while (0); + (void )syscall(SYSIO_SYS_write, STDERR_FILENO, buf, len); errno = oerrno; } +/* + * Console printf. + */ void -_sysio_leave(const char *fname) +_sysio_cprintf(const char *fmt, ...) { - int oerrno; + va_list ap; int len; char *buf; - oerrno = errno; - do { - len = asprintf(&buf, "+LEAVE+ %s\n", fname); + va_start(ap, fmt); + buf = NULL; + len = vasprintf(&buf, fmt, ap); + va_end(ap); if (len < 0) - break; - _sysio_cwrite(buf, (size_t )len); + return; + _sysio_cwrite(buf, len); free(buf); - } while (0); - errno = oerrno; } #endif /* defined(SYSIO_TRACING) */ @@ -786,6 +780,11 @@ _sysio_boot(struct _sysio_boot_ctl *ctl) char c, *tok; ssize_t len; int err; + unsigned count; + +#if SYSIO_TRACING + _sysio_tracing = ctl->tracing; +#endif buf = ctl->buf; if (!buf) @@ -798,6 +797,7 @@ _sysio_boot(struct _sysio_boot_ctl *ctl) if (!tok) return -ENOMEM; err = 0; + count = 0; while (1) { /* * Discard leading white space. @@ -814,6 +814,7 @@ _sysio_boot(struct _sysio_boot_ctl *ctl) /* * Get the command. */ + *tok = '\0'; buf = (char *)_sysio_get_token(buf + 1, 0, @@ -824,6 +825,7 @@ _sysio_boot(struct _sysio_boot_ctl *ctl) err = -EINVAL; break; } + count++; /* * Perform. */ @@ -831,14 +833,18 @@ _sysio_boot(struct _sysio_boot_ctl *ctl) if (err) break; } +#if SYSIO_TRACING + if (err) + _sysio_cprintf("+NS init+ failed at expr %u (last = %s): %s\n", + count, + tok && *tok ? tok : "NULL", + strerror(-err)); +#endif free(tok); #if DEFER_INIT_CWD if (err) return err; _sysio_init_cwd = ctl->path; #endif -#if SYSIO_TRACING - _sysio_tracing = ctl->tracing; -#endif return err; } |