[Libsysio-commit] HEAD: libsysio/src init.c
Brought to you by:
lward
From: Lee W. <lw...@us...> - 2004-11-18 13:00:58
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26352/src Modified Files: init.c Log Message: Enabled trace logging. Added the --with-tracing option at build time. By default, it's enabled. Altered _sysio_boot to accommodate. It now takes a struct _sysio_boot_ctl record to control the various things instead of an argument list. If you want trace logging turned on, set the tracing field to a non-zero value. In the test directory, recognize the SYSIO_TRACING environment variable at startup and enable trace logging if found. Index: init.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/init.c,v retrieving revision 1.16 retrieving revision 1.17 diff -u -w -b -B -p -r1.16 -r1.17 --- init.c 24 Oct 2004 20:41:19 -0000 1.16 +++ init.c 18 Nov 2004 13:00:45 -0000 1.17 @@ -43,10 +43,19 @@ #define _BSD_SOURCE +#if SYSIO_TRACING +#include <stdio.h> +#endif #include <stdlib.h> +#if SYSIO_TRACING +#include <sys/syscall.h> +#endif #include <unistd.h> #include <string.h> #include <errno.h> +#if SYSIO_TRACING +#include <stdarg.h> +#endif #include <limits.h> #include <assert.h> #include <sys/types.h> @@ -57,6 +66,9 @@ #include "xtio.h" #include "sysio.h" +#if SYSIO_TRACING +#include "native.h" +#endif #include "inode.h" #include "fs.h" #include "mount.h" @@ -67,6 +79,10 @@ #include "stdfd.h" #endif +#if SYSIO_TRACING +int _sysio_tracing = 0; +#endif + /* * White space characters. */ @@ -81,7 +97,7 @@ _sysio_init() { int err; #ifdef WITH_SOCKETS - int _sysio_sockets_init(void); + extern int _sysio_sockets_init(void); #endif err = _sysio_ioctx_init(); @@ -137,6 +153,97 @@ _sysio_shutdown() #endif } +#if SYSIO_TRACING + +#if !(defined(_HAVE_ASPRINTF) && _HAVE_ASPRINTF) +/* + * Print a string to allocated memory. + */ +int +vasprintf(char **strp, const char *fmt, va_list ap) +{ + size_t siz; + char *s; + va_list aq; + int n; + + siz = 50; + if (!(s = malloc(siz))) + return -1; + for (;;) { + va_copy(aq, ap); + n = vsnprintf (s, siz, fmt, aq); + va_end(aq); + if (n > -1 && (size_t )n < siz) + break; + if (n > -1) /* glibc 2.1 */ + siz = n+1; /* precise */ + else /* glibc 2.0 */ + siz *= 2; /* twice the old */ + if (!(s = realloc (s, siz))) + break; + } + *strp = s; + return n; +} + +int +asprintf(char **strp, const char *fmt, ...) +{ + va_list ap; + int n; + + va_start(ap, fmt); + n = vasprintf(strp, fmt, ap); + va_end(ap); + return n; +} +#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); + errno = oerrno; +} + +void +_sysio_leave(const char *fname) +{ + int oerrno; + int len; + char *buf; + + oerrno = errno; + do { + len = asprintf(&buf, "+LEAVE+ %s\n", fname); + if (len < 0) + break; + _sysio_cwrite(buf, (size_t )len); + free(buf); + } while (0); + errno = oerrno; +} +#endif /* defined(SYSIO_TRACING) */ + /* * (kind of)Duplicates strtok function. * @@ -673,16 +780,14 @@ do_command(char *buf) * commands */ int -_sysio_boot(const char *buf -#if DEFER_INIT_CWD - , const char *path -#endif - ) +_sysio_boot(struct _sysio_boot_ctl *ctl) { + const char *buf; char c, *tok; ssize_t len; int err; + buf = ctl->buf; if (!buf) buf = ""; /* @@ -730,7 +835,10 @@ _sysio_boot(const char *buf #if DEFER_INIT_CWD if (err) return err; - _sysio_init_cwd = path; + _sysio_init_cwd = ctl->path; +#endif +#if SYSIO_TRACING + _sysio_tracing = ctl->tracing; #endif return err; } |