Thread: [Libsysio-commit] HEAD: libsysio/src init.c
Brought to you by:
lward
From: Lee W. <lw...@us...> - 2004-06-24 19:58:37
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32257/src Modified Files: init.c Log Message: Mods to namespace boot. Added the "open" command in order to pre-open a file on a given file descriptor. Usage: open, nm=<path>,fd=<#>,m=<#> Where: nm is the path to the file -- it should already exist fd is the desired fildes m mode flags to open -- only one of O_RDONLY, O_WRONLY, O_RDWR supported Index: init.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/init.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -w -b -B -p -r1.9 -r1.10 --- init.c 28 May 2004 12:48:26 -0000 1.9 +++ init.c 24 Jun 2004 19:58:28 -0000 1.10 @@ -549,6 +549,69 @@ do_chmd(char *args) return err; } +static int +do_open(char *args) +{ + size_t len; + struct named_argument v[] = { + { "nm", NULL }, /* path */ + { "fd", NULL }, /* fildes */ + { "m", NULL }, /* mode */ + { NULL, NULL } + }; + char *cp; + int fd; + mode_t m; + struct pnode *dir, *pno; + struct intent intent; + int err; + struct file *fil; + + len = strlen(args); + if (get_args(args, v) - args != (ssize_t )len || + !(v[0].value && v[1].value && v[2].value)) + return -EINVAL; + fd = strtol(v[1].value, (char **)&cp, 0); + if (*cp || + (((fd == LONG_MIN || fd == LONG_MAX) && errno == ERANGE)) || + fd < 0) + return -EINVAL; + m = strtoul(v[1].value, (char **)&cp, 0); + if (*cp || + (m == LONG_MAX && errno == ERANGE)) + return -EINVAL; + m &= O_RDONLY|O_WRONLY|O_RDWR; + + if (!(dir = _sysio_cwd) && !(dir = _sysio_root)) + return -ENOENT; + INTENT_INIT(&intent, INT_OPEN, &m, NULL); + pno = NULL; + err = _sysio_namei(dir, v[0].value, 0, &intent, &pno); + if (err) + return err; + fil = NULL; + do { + err = _sysio_open(pno, m, 0); + if (err) + break; + fil = _sysio_fnew(pno->p_base->pb_ino, m); + if (!fil) { + err = -ENOMEM; + break; + } + err = _sysio_fd_set(fil, fd); + if (err < 0) + break; + P_RELE(pno); + return 0; + } while (0); + if (fil) + F_RELE(fil); + if (pno) + P_RELE(pno); + return err; +} + /* * Execute the given cmd. * @@ -571,6 +634,8 @@ do_command(char *buf) return do_cd(args); if (strcmp("chmd", cmd) == 0) return do_chmd(args); + if (strcmp("open", cmd) == 0) + return do_open(args); } return -EINVAL; } |
From: Lee W. <lw...@us...> - 2004-08-30 19:06:44
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1143 Modified Files: init.c Log Message: Kevin Pedretti says x86-64 build complained about int/long assignments and compares. This should fix it. Index: init.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/init.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -w -b -B -p -r1.13 -r1.14 --- init.c 27 Jul 2004 15:00:43 -0000 1.13 +++ init.c 30 Aug 2004 19:06:34 -0000 1.14 @@ -557,27 +557,39 @@ do_open(char *args) { NULL, NULL } }; char *cp; + long l; int fd; + unsigned long ul; mode_t m; struct pnode *dir, *pno; struct intent intent; int err; struct file *fil; +/* + * Check if long overflows integer range. + */ +#if LONG_MAX <= INT_MAX +#define _irecheck(_l, _e) \ + ((_l) == LONG_MAX && (_e) == ERANGE) +#else +#define _irecheck(_l, _e) \ + ((_l) > INT_MAX) +#endif + len = strlen(args); if (get_args(args, v) - args != (ssize_t )len || !(v[0].value && v[1].value && v[2].value)) return -EINVAL; - fd = strtol(v[1].value, (char **)&cp, 0); - if (*cp || - (((fd == LONG_MIN || fd == LONG_MAX) && errno == ERANGE)) || - fd < 0) + l = strtol(v[1].value, (char **)&cp, 0); + if (*cp || l < 0 || _irecheck(l, errno)) return -EINVAL; - m = strtoul(v[1].value, (char **)&cp, 0); + fd = (int )l; + ul = strtoul(v[1].value, (char **)&cp, 0); if (*cp || - (m == LONG_MAX && errno == ERANGE)) + (ul == ULONG_MAX && errno == ERANGE)) return -EINVAL; - m &= O_RDONLY|O_WRONLY|O_RDWR; + m = (mode_t )ul & (O_RDONLY|O_WRONLY|O_RDWR); if (!(dir = _sysio_cwd) && !(dir = _sysio_root)) return -ENOENT; @@ -607,6 +619,8 @@ do_open(char *args) if (pno) P_RELE(pno); return err; + +#undef _irecheck } /* |
From: Lee W. <lw...@us...> - 2004-10-24 20:41:29
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13722 Modified Files: init.c Log Message: Changes from Kevin Pedretti to internalize the initialization of the sockets driver when --with-sockets is supplied. Index: init.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/init.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -w -b -B -p -r1.15 -r1.16 --- init.c 14 Oct 2004 14:59:29 -0000 1.15 +++ init.c 24 Oct 2004 20:41:19 -0000 1.16 @@ -80,6 +80,9 @@ int _sysio_init() { int err; +#ifdef WITH_SOCKETS + int _sysio_sockets_init(void); +#endif err = _sysio_ioctx_init(); if (err) @@ -99,6 +102,11 @@ _sysio_init() if (err) goto error; #endif +#ifdef WITH_SOCKETS + err = _sysio_sockets_init(); + if (err) + goto error; +#endif goto out; error: |
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; } |
From: Lee W. <lw...@us...> - 2004-11-18 13:21:40
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31684 Modified Files: init.c Log Message: Let's go ahead and make asprintf and vasprintf static. They aren't used anywhere else. Index: init.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/init.c,v retrieving revision 1.17 retrieving revision 1.18 diff -u -w -b -B -p -r1.17 -r1.18 --- init.c 18 Nov 2004 13:00:45 -0000 1.17 +++ init.c 18 Nov 2004 13:21:21 -0000 1.18 @@ -159,7 +159,7 @@ _sysio_shutdown() /* * Print a string to allocated memory. */ -int +static int vasprintf(char **strp, const char *fmt, va_list ap) { size_t siz; @@ -187,7 +187,7 @@ vasprintf(char **strp, const char *fmt, return n; } -int +static int asprintf(char **strp, const char *fmt, ...) { va_list ap; |
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; } |
From: Lee W. <lw...@us...> - 2004-11-29 23:55:16
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1404/src Modified Files: init.c Log Message: Ok, round 3 with the _sysio_boot function. Every time I add a new little option, I'm going to break the Cray crt0 build. New deal, then. Now, _sysio_boot takes a name and value pair. We call it repeatedly for different pairs, then. To support legacy, the name/value pairs are: "namespace" and the buffer is the argument "cwd" and the deferred, initial path is the argument Since it's now 2 calls, I suggest "namespace" first, then "cwd" to preserve the older behavior. As previously, _sysio_boot still returns 0 on success or a, negated, error number. Now, though, you know which failed :-) You decide if it's fatal. I've also added a new pair identified by "tracing" that enables tracing if configured for it. The value is a readable string, expected to parse as a number by strtol. Then, it should turn into a 0 or positive. Zero, being off and positive being on. Index: init.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/init.c,v retrieving revision 1.19 retrieving revision 1.20 diff -u -w -b -B -p -r1.19 -r1.20 --- init.c 19 Nov 2004 17:49:54 -0000 1.19 +++ init.c 29 Nov 2004 23:55:01 -0000 1.20 @@ -89,6 +89,17 @@ int _sysio_tracing = 0; #define IGNORE_WHITE " \t\r\n" /* + * Check if long overflows integer range. + */ +#if LONG_MAX <= INT_MAX +#define _irecheck(_l, _e) \ + ((_l) == LONG_MAX && (_e) == ERANGE) +#else +#define _irecheck(_l, _e) \ + ((_l) > INT_MAX) +#endif + +/* * Sysio library initialization. Must be called before anything else in the * library. */ @@ -682,17 +693,6 @@ do_open(char *args) int err; struct file *fil; -/* - * Check if long overflows integer range. - */ -#if LONG_MAX <= INT_MAX -#define _irecheck(_l, _e) \ - ((_l) == LONG_MAX && (_e) == ERANGE) -#else -#define _irecheck(_l, _e) \ - ((_l) > INT_MAX) -#endif - len = strlen(args); if (_sysio_get_args(args, v) - args != (ssize_t )len || !(v[0].ovi_value && v[1].ovi_value && v[2].ovi_value)) @@ -735,8 +735,6 @@ do_open(char *args) if (pno) P_RELE(pno); return err; - -#undef _irecheck } /* @@ -769,30 +767,41 @@ do_command(char *buf) return -EINVAL; } +#if SYSIO_TRACING /* - * Given a command sequence buffer, parse it and run the given - * commands + * Set/Unset tracing. */ -int -_sysio_boot(struct _sysio_boot_ctl *ctl) +static int +_sysio_boot_tracing(const char *arg) +{ + long l; + char *cp; + + l = 0; + if (arg) { + l = strtol(arg, (char **)&cp, 0); + if (*cp || !(l == 0 || l == 1)) + return -EINVAL; + } + _sysio_tracing = (int )l; + return 0; +} +#endif + +/* + * Initialize the namespace. + */ +static int +_sysio_boot_namespace(const char *arg) { - const char *buf; char c, *tok; ssize_t len; int err; unsigned count; - -#if SYSIO_TRACING - _sysio_tracing = ctl->tracing; -#endif - - buf = ctl->buf; - if (!buf) - buf = ""; /* * Allocate token buffer. */ - len = strlen(buf); + len = strlen(arg); tok = malloc(len ? len : 1); if (!tok) return -ENOMEM; @@ -802,9 +811,9 @@ _sysio_boot(struct _sysio_boot_ctl *ctl) /* * Discard leading white space. */ - while ((c = *buf) != '\0' && + while ((c = *arg) != '\0' && !(c == '{' || strchr(IGNORE_WHITE, c) == NULL)) - buf++; + arg++; if (c == '\0') break; if (c != '{') { @@ -815,13 +824,13 @@ _sysio_boot(struct _sysio_boot_ctl *ctl) * Get the command. */ *tok = '\0'; - buf = - (char *)_sysio_get_token(buf + 1, + arg = + (char *)_sysio_get_token(arg + 1, 0, "}", IGNORE_WHITE, tok); - if (!buf) { + if (!arg) { err = -EINVAL; break; } @@ -841,10 +850,55 @@ _sysio_boot(struct _sysio_boot_ctl *ctl) strerror(-err)); #endif free(tok); -#if DEFER_INIT_CWD - if (err) return err; - _sysio_init_cwd = ctl->path; +} + +#if DEFER_INIT_CWD +/* + * Set deferred initial working directory. + */ +static int +_sysio_boot_cwd(const char *arg) +{ + + _sysio_init_cwd = arg; + return 0; +} #endif - return err; + +/* + * Given an identifier and it's arguments, perform optional initializations. + */ +int +_sysio_boot(const char *opt, const char *arg) +{ + struct option_value_info vec[] = { +#if SYSIO_TRACING + { "trace", NULL }, /* tracing? */ +#endif + { "namespace", NULL }, /* init namespace? */ +#if DEFER_INIT_CWD + { "cwd", NULL }, /* init working dir */ +#endif + { NULL, NULL } + }; + struct option_value_info *v; + unsigned u; + static int (*f[])(const char *) = { +#if SYSIO_TRACING + _sysio_boot_tracing, +#endif + _sysio_boot_namespace, +#if DEFER_INIT_CWD + _sysio_boot_cwd, +#endif + NULL /* can't happen */ + }; + + for (v = vec, u = 0; v->ovi_name; v++, u++) + if (strcmp(v->ovi_name, opt) == 0) + break; + if (!v->ovi_name) + return -EINVAL; + return (*f[u])(arg); } |
From: Lee W. <lw...@us...> - 2005-09-15 21:31:46
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19135/src Modified Files: init.c Log Message: Support user-defined entry/exit callbacks and switch existing trace-print support to the new mechanism. Introduces: _sysio_entry_trace_q and _sysio_exit_trace_q; pointers to the 2 callback queues. _sysio_register_trace; To register a callback _sysio_remove_trace; To remove a previously registered callback _sysio_run_trace_q; To execute the callbacks in a trace queue. Index: init.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/init.c,v retrieving revision 1.21 retrieving revision 1.22 diff -u -w -b -B -p -r1.21 -r1.22 --- init.c 25 Jan 2005 00:37:11 -0000 1.21 +++ init.c 15 Sep 2005 21:31:38 -0000 1.22 @@ -80,7 +80,23 @@ #endif #if SYSIO_TRACING -int _sysio_tracing = 0; + +struct trace_callback { + TAILQ_ENTRY(trace_callback) links; + void (*f)(const char *file, const char *func, int line); +}; + +#define TCB_INIT(__tcb, __f) \ + do { \ + (__tcb)->f = (__f); \ + } while (0); + +TAILQ_HEAD(trace_q, trace_callback); + +static struct trace_q _sysio_entry_trace_head; +void *_sysio_entry_trace_q = &_sysio_entry_trace_head; +static struct trace_q _sysio_exit_trace_head; +void *_sysio_exit_trace_q = &_sysio_exit_trace_head; #endif /* @@ -111,6 +127,12 @@ _sysio_init() extern int _sysio_sockets_init(void); #endif + /* + * Initialize tracing callback queues. + */ + TAILQ_INIT(&_sysio_entry_trace_head); + TAILQ_INIT(&_sysio_exit_trace_head); + err = _sysio_ioctx_init(); if (err) goto error; @@ -161,6 +183,20 @@ _sysio_shutdown() _sysio_fd_shutdown(); _sysio_i_shutdown(); _sysio_fssw_shutdown(); +#if SYSIO_TRACING + { + struct trace_callback *tcb; + + while ((tcb = _sysio_entry_trace_head.tqh_first) != NULL) { + TAILQ_REMOVE(&_sysio_entry_trace_head, tcb, links); + free(tcb); + } + while ((tcb = _sysio_exit_trace_head.tqh_first) != NULL) { + TAILQ_REMOVE(&_sysio_exit_trace_head, tcb, links); + free(tcb); + } + } +#endif #endif } @@ -247,6 +283,68 @@ _sysio_cprintf(const char *fmt, ...) _sysio_cwrite(buf, len); free(buf); } + +/* + * Register a trace callback. + * + * The pointer to the tracde record is returned. + */ +void * +_sysio_register_trace(void *q, + void (*f)(const char *file, + const char *func, + int line)) +{ + struct trace_callback *tcb; + + tcb = malloc(sizeof(struct trace_callback)); + if (!tcb) + return NULL; + TCB_INIT(tcb, f); + TAILQ_INSERT_TAIL((struct trace_q *)q, tcb, links); + return tcb; +} + +void +_sysio_remove_trace(void *q, void *p) +{ + + TAILQ_REMOVE((struct trace_q *)q, (struct trace_callback *)p, links); + free(p); +} + +void +_sysio_run_trace_q(void *q, + const char *file, + const char *func, + int line) +{ + struct trace_callback *tcb; + + tcb = ((struct trace_q *)q)->tqh_first; + while (tcb) { + (*tcb->f)(file, func, line); + tcb = tcb->links.tqe_next; + } +} + +static void +_sysio_trace_entry(const char *file __IS_UNUSED, + const char *func, + int line __IS_UNUSED) +{ + + _sysio_cprintf("+ENTER+ %s\n", func); +} + +static void +_sysio_trace_exit(const char *file __IS_UNUSED, + const char *func, + int line __IS_UNUSED) +{ + + _sysio_cprintf("+EXIT+ %s\n", func); +} #endif /* defined(SYSIO_TRACING) */ /* @@ -776,6 +874,9 @@ _sysio_boot_tracing(const char *arg) { long l; char *cp; + static struct trace_callback + *entcb = NULL, + *exitcb = NULL; l = 0; if (arg) { @@ -783,7 +884,27 @@ _sysio_boot_tracing(const char *arg) if (*cp || !(l == 0 || l == 1)) return -EINVAL; } - _sysio_tracing = (int )l; + if (l) { + if (entcb == NULL) + entcb = + _sysio_register_trace(_sysio_entry_trace_q, + _sysio_trace_entry); + if (entcb == NULL) + return -errno; + if (exitcb == NULL) + exitcb = + _sysio_register_trace(_sysio_exit_trace_q, + _sysio_trace_exit); + if (exitcb == NULL) + return -errno; + } else { + if (entcb != NULL) + _sysio_remove_trace(_sysio_entry_trace_q, entcb); + entcb = NULL; + if (exitcb != NULL) + _sysio_remove_trace(_sysio_exit_trace_q, exitcb); + exitcb = NULL; + } return 0; } #endif |
From: Lee W. <lw...@us...> - 2005-09-15 21:46:31
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23070/src Modified Files: init.c Log Message: Oops. forgot to remove the old _sysio_tracing global declaration. Fixed. Added a bunch of comments. Index: init.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/init.c,v retrieving revision 1.22 retrieving revision 1.23 diff -u -w -b -B -p -r1.22 -r1.23 --- init.c 15 Sep 2005 21:31:38 -0000 1.22 +++ init.c 15 Sep 2005 21:46:23 -0000 1.23 @@ -81,18 +81,30 @@ #if SYSIO_TRACING +/* + * Tracing callback record. + */ struct trace_callback { TAILQ_ENTRY(trace_callback) links; void (*f)(const char *file, const char *func, int line); }; +/* + * Initialize a tracing callback record. + */ #define TCB_INIT(__tcb, __f) \ do { \ (__tcb)->f = (__f); \ } while (0); +/* + * Trace queue head record. + */ TAILQ_HEAD(trace_q, trace_callback); +/* + * The entry and exit queue heads, and queue pointers. + */ static struct trace_q _sysio_entry_trace_head; void *_sysio_entry_trace_q = &_sysio_entry_trace_head; static struct trace_q _sysio_exit_trace_head; @@ -187,6 +199,9 @@ _sysio_shutdown() { struct trace_callback *tcb; + /* + * Empty the trace queues and free the entries. + */ while ((tcb = _sysio_entry_trace_head.tqh_first) != NULL) { TAILQ_REMOVE(&_sysio_entry_trace_head, tcb, links); free(tcb); @@ -287,7 +302,7 @@ _sysio_cprintf(const char *fmt, ...) /* * Register a trace callback. * - * The pointer to the tracde record is returned. + * The pointer to the trace record is returned. */ void * _sysio_register_trace(void *q, @@ -305,6 +320,9 @@ _sysio_register_trace(void *q, return tcb; } +/* + * Remove a registered trace callback. + */ void _sysio_remove_trace(void *q, void *p) { @@ -314,6 +332,9 @@ _sysio_remove_trace(void *q, void *p) } void +/* + * Run a trace queue, making all the callbacks. + */ _sysio_run_trace_q(void *q, const char *file, const char *func, |
From: Lee W. <lw...@us...> - 2005-09-18 17:44:55
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28137/src Modified Files: init.c Log Message: Oops. Forgot to surround one addition with SYSIO_TRACING define. Fixed. It now build when ==with-tracing set to "no". Changed the copyright date. Index: init.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/init.c,v retrieving revision 1.23 retrieving revision 1.24 diff -u -w -b -B -p -r1.23 -r1.24 --- init.c 15 Sep 2005 21:46:23 -0000 1.23 +++ init.c 18 Sep 2005 17:44:45 -0000 1.24 @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2004 Sandia Corporation. + * Cplant(TM) Copyright 1998-2005 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States @@ -139,11 +139,13 @@ _sysio_init() extern int _sysio_sockets_init(void); #endif +#if SYSIO_TRACING /* * Initialize tracing callback queues. */ TAILQ_INIT(&_sysio_entry_trace_head); TAILQ_INIT(&_sysio_exit_trace_head); +#endif err = _sysio_ioctx_init(); if (err) |
From: Lee W. <lw...@us...> - 2006-01-18 00:48:01
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11788 Modified Files: init.c Log Message: Add comments to init files; From Cray. A hash, '#', symbol begins a comment that reads to the end of the line. Since the init configuration language is not line-based, though, this is dangerous. Just be *real* careful to terminate with a newline. Also, this only works *outside* a specification -- The '{' to '}' groupings. Used inside, it's a parsed character and would almost certainly err. Unfortunately, the precedent is set and it's too difficult to back out now. Beware! Index: init.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/init.c,v retrieving revision 1.24 retrieving revision 1.25 diff -u -w -b -B -p -r1.24 -r1.25 --- init.c 18 Sep 2005 17:44:45 -0000 1.24 +++ init.c 18 Jan 2006 00:47:41 -0000 1.25 @@ -128,6 +128,12 @@ void *_sysio_exit_trace_q = &_sysio_exit #endif /* + * In sysio_init we'll allow simple comments, strings outside {} + * delimited by COMMENT_INTRO, and '\n' or '\0' + */ +#define COMMENT_INTRO '#' + +/* * Sysio library initialization. Must be called before anything else in the * library. */ @@ -958,6 +964,16 @@ _sysio_boot_namespace(const char *arg) while ((c = *arg) != '\0' && !(c == '{' || strchr(IGNORE_WHITE, c) == NULL)) arg++; + if (COMMENT_INTRO == c) { + /* + * Discard comment. + */ + while (*arg && (*arg != '\n')) { + ++arg; + } + continue; + } + if (c == '\0') break; if (c != '{') { |
From: Lee W. <lw...@us...> - 2006-02-27 17:26:58
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21374/src Modified Files: init.c Log Message: Tracing now can reference user-supplied data. The callbacks are supplied the data pointer originally given at registration. A destructor, given at registration, is called with a copy of the user-supplied data pointer when the the trace remove function is invoked if it wasn't NULL. Index: init.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/init.c,v retrieving revision 1.25 retrieving revision 1.26 diff -u -w -b -B -p -r1.25 -r1.26 --- init.c 18 Jan 2006 00:47:41 -0000 1.25 +++ init.c 27 Feb 2006 17:26:55 -0000 1.26 @@ -85,16 +85,23 @@ * Tracing callback record. */ struct trace_callback { - TAILQ_ENTRY(trace_callback) links; - void (*f)(const char *file, const char *func, int line); + TAILQ_ENTRY(trace_callback) links; /* trace list links */ + void (*f)(const char *file, /* callback function */ + const char *func, + int line, + void *data); + void *data; /* callback data */ + void (*destructor)(void *data); /* data destructor */ }; /* * Initialize a tracing callback record. */ -#define TCB_INIT(__tcb, __f) \ +#define TCB_INIT(__tcb, __f, __d, __destroy) \ do { \ (__tcb)->f = (__f); \ + (__tcb)->data = (__d); \ + (__tcb)->destructor = (__destroy); \ } while (0); /* @@ -210,14 +217,10 @@ _sysio_shutdown() /* * Empty the trace queues and free the entries. */ - while ((tcb = _sysio_entry_trace_head.tqh_first) != NULL) { - TAILQ_REMOVE(&_sysio_entry_trace_head, tcb, links); - free(tcb); - } - while ((tcb = _sysio_exit_trace_head.tqh_first) != NULL) { - TAILQ_REMOVE(&_sysio_exit_trace_head, tcb, links); - free(tcb); - } + while ((tcb = _sysio_entry_trace_head.tqh_first) != NULL) + _sysio_remove_trace(&_sysio_entry_trace_head, tcb); + while ((tcb = _sysio_exit_trace_head.tqh_first) != NULL) + _sysio_remove_trace(&_sysio_exit_trace_head, tcb); } #endif #endif @@ -316,14 +319,17 @@ void * _sysio_register_trace(void *q, void (*f)(const char *file, const char *func, - int line)) + int line, + void *data), + void *data, + void (*destructor)(void *data)) { struct trace_callback *tcb; tcb = malloc(sizeof(struct trace_callback)); if (!tcb) return NULL; - TCB_INIT(tcb, f); + TCB_INIT(tcb, f, data, destructor); TAILQ_INSERT_TAIL((struct trace_q *)q, tcb, links); return tcb; } @@ -334,9 +340,14 @@ _sysio_register_trace(void *q, void _sysio_remove_trace(void *q, void *p) { + struct trace_callback *tcb; - TAILQ_REMOVE((struct trace_q *)q, (struct trace_callback *)p, links); - free(p); + tcb = (struct trace_callback *)p; + + if (tcb->destructor) + (*tcb->destructor)(tcb->data); + TAILQ_REMOVE((struct trace_q *)q, tcb, links); + free(tcb); } void @@ -352,7 +363,7 @@ _sysio_run_trace_q(void *q, tcb = ((struct trace_q *)q)->tqh_first; while (tcb) { - (*tcb->f)(file, func, line); + (*tcb->f)(file, func, line, tcb->data); tcb = tcb->links.tqe_next; } } @@ -360,7 +371,8 @@ _sysio_run_trace_q(void *q, static void _sysio_trace_entry(const char *file __IS_UNUSED, const char *func, - int line __IS_UNUSED) + int line __IS_UNUSED, + void *data __IS_UNUSED) { _sysio_cprintf("+ENTER+ %s\n", func); @@ -369,7 +381,8 @@ _sysio_trace_entry(const char *file __IS static void _sysio_trace_exit(const char *file __IS_UNUSED, const char *func, - int line __IS_UNUSED) + int line __IS_UNUSED, + void *data __IS_UNUSED) { _sysio_cprintf("+EXIT+ %s\n", func); @@ -917,13 +930,17 @@ _sysio_boot_tracing(const char *arg) if (entcb == NULL) entcb = _sysio_register_trace(_sysio_entry_trace_q, - _sysio_trace_entry); + _sysio_trace_entry, + NULL, + NULL); if (entcb == NULL) return -errno; if (exitcb == NULL) exitcb = _sysio_register_trace(_sysio_exit_trace_q, - _sysio_trace_exit); + _sysio_trace_exit, + NULL, + NULL); if (exitcb == NULL) return -errno; } else { |
From: Lee W. <lw...@us...> - 2006-05-04 02:31:10
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21220 Modified Files: init.c Log Message: Oops. Mknod case in do_command fell through to open case. Fixed. Index: init.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/init.c,v retrieving revision 1.29 retrieving revision 1.30 diff -u -w -b -B -p -r1.29 -r1.30 --- init.c 3 May 2006 22:34:46 -0000 1.29 +++ init.c 4 May 2006 02:31:05 -0000 1.30 @@ -634,6 +634,7 @@ do_creat(char *args) case CREATE_CHR: case CREATE_BLK: err = _sysio_mknod(pno, mode, dev); + break; case CREATE_FILE: err = _sysio_open(pno, O_CREAT|O_EXCL, mode); if (err) |
From: Lee W. <lw...@us...> - 2007-04-12 20:06:16
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv13923 Modified Files: init.c Log Message: Define _BSD_SOURCE conditionally on whether we are compiling under linux or not. Index: init.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/init.c,v retrieving revision 1.30 retrieving revision 1.31 diff -u -w -b -B -p -r1.30 -r1.31 --- init.c 4 May 2006 02:31:05 -0000 1.30 +++ init.c 12 Apr 2007 20:05:52 -0000 1.31 @@ -41,13 +41,15 @@ * le...@sa... */ +#ifdef __linux__ #define _BSD_SOURCE +#endif #if SYSIO_TRACING #include <stdio.h> #endif #include <stdlib.h> -#if SYSIO_TRACING +#ifdef _BSD_SOURCE #include <sys/syscall.h> #endif #include <unistd.h> |
From: Ruth K. <rk...@us...> - 2007-05-09 23:40:24
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv15081/src Modified Files: init.c Log Message: missed endif Index: init.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/init.c,v retrieving revision 1.34 retrieving revision 1.35 diff -u -w -b -B -p -r1.34 -r1.35 --- init.c 9 May 2007 23:16:20 -0000 1.34 +++ init.c 9 May 2007 23:40:20 -0000 1.35 @@ -227,6 +227,7 @@ _sysio_shutdown() _sysio_remove_trace(&_sysio_exit_trace_head, tcb); } #endif +#endif } #ifdef SYSIO_TRACING |
From: Lee W. <lw...@us...> - 2007-09-26 19:46:29
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv16384 Modified Files: init.c Log Message: >From Bob Glossman (bo...@cr...): Simplified and removed a constant check in the namespace boot parser. Index: init.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/init.c,v retrieving revision 1.38 retrieving revision 1.39 diff -u -w -b -B -p -r1.38 -r1.39 --- init.c 20 Aug 2007 19:12:08 -0000 1.38 +++ init.c 26 Sep 2007 19:46:25 -0000 1.39 @@ -830,8 +830,7 @@ _sysio_boot_namespace(const char *arg) /* * Discard leading white space. */ - while ((c = *arg) != '\0' && - !(c == '{' || strchr(IGNORE_WHITE, c) == NULL)) + while ((c = *arg) != '\0' && strchr(IGNORE_WHITE, c)) arg++; if (COMMENT_INTRO == c) { /* |
From: Lee W. <lw...@us...> - 2008-06-17 15:11:44
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30094 Modified Files: init.c Log Message: Fixed a bug in parse_mm. It was building the dev_t by hand, incorrectly. It should have been using SYSIO_MKDEV. It does now. Index: init.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/init.c,v retrieving revision 1.39 retrieving revision 1.40 diff -u -w -b -B -p -r1.39 -r1.40 --- init.c 26 Sep 2007 19:46:25 -0000 1.39 +++ init.c 17 Jun 2008 15:11:40 -0000 1.40 @@ -62,6 +62,9 @@ #ifdef STDFD_DEV #include "stdfd.h" #endif +#ifdef STDDEV_DEV +#include "stddev.h" +#endif /* * White space characters. @@ -222,6 +225,11 @@ _sysio_init() if (err) goto error; #endif +#ifdef STDDEV_DEV + err = _sysio_stddev_init(); + if (err) + goto error; +#endif #ifdef WITH_SOCKETS err = _sysio_sockets_init(); if (err) @@ -368,18 +376,22 @@ parse_mm(const char *s, dev_t *devp) { unsigned long ul; char *cp; - dev_t dev; + dev_t major, minor; ul = strtoul(s, &cp, 0); if (*cp != '+' || ul > USHRT_MAX) return -EINVAL; - dev = ul << 16; + major = ul; + if (major != ul) + return -ERANGE; s = (const char *)++cp; ul = strtoul(s, &cp, 0); if (*cp != '\0' || ul > USHRT_MAX) return -EINVAL; - dev |= ul & 0xffff; - *devp = dev; + minor = ul; + if (minor != ul) + return -ERANGE; + *devp = SYSIO_MKDEV(major, minor); return 0; } |
From: Lee W. <lw...@us...> - 2008-12-06 18:30:56
|
Update of /cvsroot/libsysio/libsysio/src In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv10149 Modified Files: init.c Log Message: Ficxed a bug in do_open(). It could do an improper release under many circumstances. Index: init.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/init.c,v retrieving revision 1.42 retrieving revision 1.43 diff -u -w -b -B -p -r1.42 -r1.43 --- init.c 15 Oct 2008 22:01:01 -0000 1.42 +++ init.c 6 Dec 2008 18:30:49 -0000 1.43 @@ -748,11 +748,11 @@ do_open(char *args) err = -ENOMEM; break; } + pno = NULL; err = _sysio_fd_set(fil, fd, 1); if (err < 0) break; - P_RELE(pno); - return 0; + err = 0; } while (0); if (fil) FIL_PUT(fil); |