Re: DDB sysctl function
÷ Wed, 09.10.2002, × 10:17, Bruce Evans ÎÁÐÉÓÁÌ: On Tue, 8 Oct 2002, John Baldwin wrote: On 08-Oct-2002 Vladimir B. Grebenschikov wrote: ÷ Tue, 08.10.2002, × 22:25, Maxime Henrion ÎÁÐÉÓÁÌ: - I'm not sure if using the context of the init process to do sysctl calls is the right way to go. However, it is not very clear what you should use to do this, at least to me. kernel_sysctl need thread pointer, it may be used in sysctl handlers. Use curthread perhaps. In -current you always have a thread context, even when idle. Not in ddb you don't. ddb may be invoked at any point, including in the middle of a thread switch. ddb also use any normal lock, since doing so may deadlock or worse. I don't see how ddb can safely use any of the general sysctl code, especially for writing. There are almost no locks for sysctl now, but that will change when Giant is pushed down and/or removed. Reading can work in the same way as db_ps() now, provided the code doesn't go near any locks: when a data struct is invalid, following garbage pointers cause traps if you are unlucky (endless loops if you are unlucky) and ddb's trap handler longjmp()s back to the main loop. Going near locks causes at least the following problems: - deadlock As minimal, It will deadlocked if you call sysctl when drop to DDB from another sysctl handler. - not releasing locks in the trap handler before longjmp()'ing. The trap handler cannot reasonably know which locks to release if they were aquired by general code. - traps in the middle of aquiring and releasing locks may leave the locks in a half-initialized state, and the trap handler cannot even unreasonably klnow how to fix this. Similarly for any other global data structures that are modified by general code called from ddb. Yes, you are right but for me code is still usable in many cases. Code is for development, not for any production use. And one, as developer, can look at backtrace before use it. Bruce -- Vladimir B. Grebenschikov [EMAIL PROTECTED], SWsoft, Inc. To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-current in the body of the message
Re: DDB sysctl function
÷ Wed, 09.10.2002, × 01:03, Vladimir B. Grebenschikov ÎÁÐÉÓÁÌ: ÷ Tue, 08.10.2002, × 22:25, Maxime Henrion ÎÁÐÉÓÁÌ: Vladimir B. Grebenschikov wrote: Hi Attached diff introduces new ddb interface - access to sysctl interface [...] Looks like this would be very useful. I have a few comments, mainly about style though. Attached fixed patch sorry, I have attached wong file - There is a TOK_STRING_SIZE macro which defines the size of the the db_tok_string variable. Use it instead of declaring several 1k variables on the stack. It is not token buffers - it is buffers for sysctl data interchange, const 1024 changed to SYSCTL_DATA_BUFSIZE define. - I'm not sure if using the context of the init process to do sysctl calls is the right way to go. However, it is not very clear what you should use to do this, at least to me. kernel_sysctl need thread pointer, it may be used in sysctl handlers. - You remove the static keyword for the db_examine() function to make it available in your code; that's OK, but you should then put the prototype in some header and not duplicate it in your code. - Don't use the __P() macro, it is deprecated now and shouldn't be added in new code. - Use the /usr/share/examples/etc/bsd-style-copyright file to put a proper copyright in your new files. There is room for your name and the date there. - Wrap lines at 80 characters. :-) fixed Cheers, Maxime -- Vladimir B. Grebenschikov [EMAIL PROTECTED], SWsoft, Inc. Index: ddb/db_command.c === RCS file: /ext/ncvs/src/sys/ddb/db_command.c,v retrieving revision 1.46 diff -u -r1.46 db_command.c --- ddb/db_command.c 1 Oct 2002 21:59:46 - 1.46 +++ ddb/db_command.c 8 Oct 2002 19:53:05 - @@ -422,6 +422,8 @@ { gdb, db_gdb, 0, 0 }, { reset, db_reset, 0, 0 }, { kill, db_kill, CS_OWN, 0 }, + { sysctl, db_sysctl_cmd, CS_OWN, 0 }, + { sysctlw,db_sysctlw_cmd, CS_OWN, 0 }, { (char *)0, } }; Index: ddb/db_examine.c === RCS file: /ext/ncvs/src/sys/ddb/db_examine.c,v retrieving revision 1.29 diff -u -r1.29 db_examine.c --- ddb/db_examine.c 25 Jun 2002 15:59:24 - 1.29 +++ ddb/db_examine.c 8 Oct 2002 20:10:10 - @@ -44,7 +44,6 @@ static char db_examine_format[TOK_STRING_SIZE] = x; -static void db_examine(db_addr_t, char *, int); static void db_search(db_addr_t, int, db_expr_t, db_expr_t, u_int); /* @@ -67,7 +66,7 @@ db_examine((db_addr_t) addr, db_examine_format, count); } -static void +void db_examine(addr, fmt, count) register db_addr_t addr; Index: ddb/db_sysctl_cmd.c === RCS file: ddb/db_sysctl_cmd.c diff -N ddb/db_sysctl_cmd.c --- /dev/null 1 Jan 1970 00:00:00 - +++ ddb/db_sysctl_cmd.c 8 Oct 2002 20:13:05 - @@ -0,0 +1,135 @@ +/*- + * Copyright (c) 2002 Potatin Mike + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: $ + */ + +#include sys/param.h +#include sys/systm.h + +#include ddb/ddb.h + +#include ddb/db_lex.h +#include ddb/db_output.h +#include ddb/db_command.h +#include ddb/db_sym.h +#include ddb/db_access.h + +#include sys/sysctl.h +#include sys/proc.h + +#define SYSCTL_DATA_BUFSIZE 256 + +void +db_sysctlw_cmd(d1, d2, d3, d4) + db_expr_t d1; + boolean_t d2; + db_expr_t d3; + char * d4; +{ + int t; + int pcount; + int mib[128]; + size_t ret = 0; + size_t readcount = SYSCTL_DATA_BUFSIZE; + size_t wsize; + char wbuf[SYSCTL_DATA_BUFSIZE]; + char buf[SYSCTL_DATA_BUFSIZE]; + int err; + + pcount = 0; +
Re: DDB sysctl function
Vladimir B. Grebenschikov wrote: ? Wed, 09.10.2002, ? 01:03, Vladimir B. Grebenschikov ???: ? Tue, 08.10.2002, ? 22:25, Maxime Henrion ???: Vladimir B. Grebenschikov wrote: Hi Attached diff introduces new ddb interface - access to sysctl interface [...] Looks like this would be very useful. I have a few comments, mainly about style though. Attached fixed patch sorry, I have attached wong file - There is a TOK_STRING_SIZE macro which defines the size of the the db_tok_string variable. Use it instead of declaring several 1k variables on the stack. It is not token buffers - it is buffers for sysctl data interchange, const 1024 changed to SYSCTL_DATA_BUFSIZE define. Yes, that's better, but you still do a strcpy() which assumes that SYSCTL_DATA_BUFSIZE = TOK_STRING_SIZE, and there are still quite big variables on the stack, which can be a problem if someone invokes ddb while deep in the stack. What I meant in my previous mail is that you could malloc() these objects instead of putting them on the stack. Also, you don't need buffers that big since the size you need is bounded at max(sizeof(int), TOK_STRING_SIZE), which is likely to be TOK_STRING_SIZE :-). - I'm not sure if using the context of the init process to do sysctl calls is the right way to go. However, it is not very clear what you should use to do this, at least to me. kernel_sysctl need thread pointer, it may be used in sysctl handlers. Yup, noone contested the fact that you need a thread pointer, the problem is that FIRST_THREAD_IN_PROC(initproc) is probably not the good one to use, and there probably isn't any good one to use at all. However, it might be acceptable to do it the way you do now. Cheers, Maxime To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-current in the body of the message
Re: DDB sysctl function
Maxime Henrion wrote: [...] - There is a TOK_STRING_SIZE macro which defines the size of the the db_tok_string variable. Use it instead of declaring several 1k variables on the stack. It is not token buffers - it is buffers for sysctl data interchange, const 1024 changed to SYSCTL_DATA_BUFSIZE define. Yes, that's better, but you still do a strcpy() which assumes that SYSCTL_DATA_BUFSIZE = TOK_STRING_SIZE, and there are still quite big variables on the stack, which can be a problem if someone invokes ddb while deep in the stack. What I meant in my previous mail is that you could malloc() these objects instead of putting them on the stack. Also, you don't need buffers that big since the size you need is bounded at max(sizeof(int), TOK_STRING_SIZE), which is likely to be TOK_STRING_SIZE :-). To be even more precise, you could just have an int and a char * as local variables, use the int in the tNUMBER case and malloc() the char * to TOK_STRING_SIZE in the tIDENT case. Cheers, Maxime To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-current in the body of the message
Re: DDB sysctl function
On Wed, 9 Oct 2002, Maxime Henrion wrote: What I meant in my previous mail is that you could malloc() these objects instead of putting them on the stack. Also, you don't need buffers that big since the size you need is bounded at max(sizeof(int), TOK_STRING_SIZE), which is likely to be TOK_STRING_SIZE :-). ddb can't call malloc() or any other general memory allocation function, since it may be (and often is) invoked in the middle of such functions. ruce To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-current in the body of the message
Re: DDB sysctl function
Bruce Evans wrote: On Wed, 9 Oct 2002, Maxime Henrion wrote: What I meant in my previous mail is that you could malloc() these objects instead of putting them on the stack. Also, you don't need buffers that big since the size you need is bounded at max(sizeof(int), TOK_STRING_SIZE), which is likely to be TOK_STRING_SIZE :-). ddb can't call malloc() or any other general memory allocation function, since it may be (and often is) invoked in the middle of such functions. I guess using a buffer of TOK_STRING_SIZE bytes for the tIDENT case and int for the tNUMBER case would be best then. We could use the same buffer if we don't plan to support platforms with ints bigger than 120 bytes :-). Maxime To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-current in the body of the message
Re: DDB sysctl function
On Wed, 9 Oct 2002, Maxime Henrion wrote: Bruce Evans wrote: On Wed, 9 Oct 2002, Maxime Henrion wrote: What I meant in my previous mail is that you could malloc() these objects instead of putting them on the stack. Also, you don't need buffers that big since the size you need is bounded at max(sizeof(int), TOK_STRING_SIZE), which is likely to be TOK_STRING_SIZE :-). ddb can't call malloc() or any other general memory allocation function, since it may be (and often is) invoked in the middle of such functions. I guess using a buffer of TOK_STRING_SIZE bytes for the tIDENT case and int for the tNUMBER case would be best then. We could use the same buffer if we don't plan to support platforms with ints bigger than 120 bytes :-). A static buffer should work, since ddb isn't reentrant. (I first thought of a malloc() at init time. That wouldn't work, since ddb may be called before kvm is initialized. It could be delayed provided the functions that use it aren't called early. But static allocation still works better.) Bruce To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-current in the body of the message
Re: DDB sysctl function
÷ Wed, 09.10.2002, × 16:23, Maxime Henrion ÎÁÐÉÓÁÌ: Bruce Evans wrote: On Wed, 9 Oct 2002, Maxime Henrion wrote: What I meant in my previous mail is that you could malloc() these objects instead of putting them on the stack. Also, you don't need buffers that big since the size you need is bounded at max(sizeof(int), TOK_STRING_SIZE), which is likely to be TOK_STRING_SIZE :-). ddb can't call malloc() or any other general memory allocation function, since it may be (and often is) invoked in the middle of such functions. I guess using a buffer of TOK_STRING_SIZE bytes for the tIDENT case and int for the tNUMBER case would be best then. We could use the same buffer if we don't plan to support platforms with ints bigger than 120 bytes :-). As final (I hope) solution: - all buffers now are static - for sysctlw now it is not need escape dots in passed strings sysctlw 0.3 hw.model - it is possible not to pass array of intergers to sysctlw sysctlw 1.2.3.4 12323,345465,657,67,68787 Maxime -- Vladimir B. Grebenschikov [EMAIL PROTECTED], SWsoft, Inc. Index: ddb/db_command.c === RCS file: /ext/ncvs/src/sys/ddb/db_command.c,v retrieving revision 1.46 diff -u -r1.46 db_command.c --- ddb/db_command.c 1 Oct 2002 21:59:46 - 1.46 +++ ddb/db_command.c 8 Oct 2002 19:53:05 - @@ -422,6 +422,8 @@ { gdb, db_gdb, 0, 0 }, { reset, db_reset, 0, 0 }, { kill, db_kill, CS_OWN, 0 }, + { sysctl, db_sysctl_cmd, CS_OWN, 0 }, + { sysctlw,db_sysctlw_cmd, CS_OWN, 0 }, { (char *)0, } }; Index: ddb/db_examine.c === RCS file: /ext/ncvs/src/sys/ddb/db_examine.c,v retrieving revision 1.29 diff -u -r1.29 db_examine.c --- ddb/db_examine.c 25 Jun 2002 15:59:24 - 1.29 +++ ddb/db_examine.c 8 Oct 2002 20:10:10 - @@ -44,7 +44,6 @@ static char db_examine_format[TOK_STRING_SIZE] = x; -static void db_examine(db_addr_t, char *, int); static void db_search(db_addr_t, int, db_expr_t, db_expr_t, u_int); /* @@ -67,7 +66,7 @@ db_examine((db_addr_t) addr, db_examine_format, count); } -static void +void db_examine(addr, fmt, count) register db_addr_t addr; Index: ddb/db_sysctl_cmd.c === RCS file: ddb/db_sysctl_cmd.c diff -N ddb/db_sysctl_cmd.c --- /dev/null 1 Jan 1970 00:00:00 - +++ ddb/db_sysctl_cmd.c 9 Oct 2002 14:41:26 - @@ -0,0 +1,191 @@ +/*- + * Copyright (c) 2002 Potatin Mike + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: $ + */ + +#include sys/param.h +#include sys/systm.h + +#include ddb/ddb.h + +#include ddb/db_lex.h +#include ddb/db_output.h +#include ddb/db_command.h +#include ddb/db_sym.h +#include ddb/db_access.h + +#include sys/sysctl.h +#include sys/proc.h + +#define SYSCTL_DATA_BUFSIZE 256 +#define SYSCTL_MAX_MIB 64 + +static int sysctl_mib [SYSCTL_MAX_MIB]; +static char sysctl_wbuf[SYSCTL_DATA_BUFSIZE]; +static char sysctl_buf [SYSCTL_DATA_BUFSIZE]; + +/* fill sysctl mib */ +static int +db_sysctl_getmib(int *miblen) +{ + int t; + + *miblen = 0; + while((t = db_read_token()) == tNUMBER) { + if (*miblen = SYSCTL_MAX_MIB) + return(tEOF); + + sysctl_mib[*miblen] = db_tok_number; + (*miblen)++; + + if((t = db_read_token()) != tDOT) + break; + } + return(t); +} + +/* + * write into sysctl + * SYNTAX: + * sysctlw 0.3 int[,int,int...] + * or + * sysctlw 0.3 string + * where: + * 0.3 - mib of sysctl + * int- hexdecimal number + * string - some alphanumeric string + *all not-alnums should
DDB sysctl function
Hi Attached diff introduces new ddb interface - access to sysctl interface sysctl - read sysctl value sysctlw - write sysctl value Example: Translate string to sysctl MIB: db sysctlw 0.3 hw\.model 0xcd1aaeec: 6 2 db Now get string by this MIB: db sysctl 6.2 s 0xcd1ab24: Pentium II/Pentium II Xenon/Celeron db Or get vm.kvm_free db sysctlw 0.3 vm\.kvm_free 0xcd1aaeec: 2 2da db sysctl 2.2da 0xcd1ab2f4: 380 db This interface useful to inspect/change data easy accessible through sysctl and hard accessible directly (say dynamic sysctl-mapped data, or sysctl-mapped fields in complex structures). Comments appreciated. -- Vladimir B. Grebenschikov [EMAIL PROTECTED], SWsoft, Inc. Index: conf/files === RCS file: /ext/ncvs/src/sys/conf/files,v retrieving revision 1.713 diff -u -r1.713 files --- conf/files 5 Oct 2002 16:35:26 - 1.713 +++ conf/files 8 Oct 2002 12:24:14 - @@ -218,6 +218,7 @@ ddb/db_variables.c optional ddb ddb/db_watch.c optional ddb ddb/db_write_cmd.c optional ddb +ddb/db_sysctl_cmd.c optional ddb dev/aac/aac.c optional aac dev/aac/aac_debug.c optional aac dev/aac/aac_disk.c optional aac Index: ddb/db_command.c === RCS file: /ext/ncvs/src/sys/ddb/db_command.c,v retrieving revision 1.46 diff -u -r1.46 db_command.c --- ddb/db_command.c 1 Oct 2002 21:59:46 - 1.46 +++ ddb/db_command.c 8 Oct 2002 12:22:58 - @@ -422,6 +422,8 @@ { gdb, db_gdb, 0, 0 }, { reset, db_reset, 0, 0 }, { kill, db_kill, CS_OWN, 0 }, + { sysctl, db_sysctl_cmd, CS_OWN, 0 }, + { sysctlw,db_sysctlw_cmd, CS_OWN, 0 }, { (char *)0, } }; Index: ddb/db_examine.c === RCS file: /ext/ncvs/src/sys/ddb/db_examine.c,v retrieving revision 1.29 diff -u -r1.29 db_examine.c --- ddb/db_examine.c 25 Jun 2002 15:59:24 - 1.29 +++ ddb/db_examine.c 8 Oct 2002 12:20:53 - @@ -44,7 +44,7 @@ static char db_examine_format[TOK_STRING_SIZE] = x; -static void db_examine(db_addr_t, char *, int); +void db_examine(db_addr_t, char *, int); static void db_search(db_addr_t, int, db_expr_t, db_expr_t, u_int); /* @@ -67,7 +67,7 @@ db_examine((db_addr_t) addr, db_examine_format, count); } -static void +void db_examine(addr, fmt, count) register db_addr_t addr; Index: ddb/db_sysctl_cmd.c === RCS file: ddb/db_sysctl_cmd.c diff -N ddb/db_sysctl_cmd.c --- /dev/null 1 Jan 1970 00:00:00 - +++ ddb/db_sysctl_cmd.c 8 Oct 2002 16:30:16 - @@ -0,0 +1,106 @@ +/* + * $FreeBSD$ + */ + +/* + * Author: Potatin Mike, SW-Soft + * Date: 10/2002 + */ + +#include sys/param.h +#include sys/systm.h + +#include ddb/ddb.h + +#include ddb/db_lex.h +#include ddb/db_output.h +#include ddb/db_command.h +#include ddb/db_sym.h +#include ddb/db_access.h + +#include sys/sysctl.h +#include sys/proc.h + +voiddb_examine __P((db_addr_t, char *, int)); + +void +db_sysctlw_cmd(d1, d2, d3, d4) + db_expr_t d1; + boolean_t d2; + db_expr_t d3; + char * d4; +{ + int t; + int pcount; + int mib[128]; + size_t ret = 0; + size_t readcount = 1024; + size_t wsize; + char wbuf[1024]; + char buf[1024]; + int err; + + pcount = 0; + while((t = db_read_token()) == tNUMBER) { + mib[pcount] = db_tok_number; + pcount++; + if((t = db_read_token()) != tDOT) { + break; + } + } + switch (t) { + case tIDENT: + strcpy(wbuf, db_tok_string); + wsize = strlen(wbuf); + break; + case tNUMBER: + *(int*)wbuf = db_tok_number; + wsize = sizeof(int); + break; + default: + db_printf(no ident\n); + db_flush_lex(); + return; + } + db_skip_to_eol(); + if(((err = kernel_sysctl(FIRST_THREAD_IN_PROC(initproc), mib, pcount, buf, readcount, wbuf, wsize, ret))) == 0) { + db_examine((db_addr_t) buf, x, ret/sizeof(int)); + } else { + db_printf(sysctl error %d %d\n, err, ret); + } +} +void +db_sysctl_cmd(d1, d2, d3, d4) + db_expr_t d1; + boolean_t d2; + db_expr_t d3; + char * d4; +{ + int t; + int pcount; + int mib[128]; + size_t ret = 0; + size_t readcount = 1024; + char buf[1024]; + int err; + char modif[16]=x; + + pcount = 0; + while((t = db_read_token()) == tNUMBER) { + mib[pcount] = db_tok_number; + pcount++; + if((t = db_read_token()) != tDOT) { + break; + } + } + if(t == tIDENT) { + strncpy(modif, db_tok_string, 15); + } + db_skip_to_eol(); + + if(((err = kernel_sysctl(FIRST_THREAD_IN_PROC(initproc), mib, pcount, buf, readcount, NULL, 0, ret))) == 0) { + db_examine((db_addr_t) buf, modif, ret/sizeof(int)); + } else { + db_printf(sysctl error %d %d\n, err, ret); + } +} Index: ddb/ddb.h === RCS file: /ext/ncvs/src/sys/ddb/ddb.h,v retrieving revision 1.30 diff -u -r1.30 ddb.h --- ddb/ddb.h 21 Sep 2002 17:29:36 - 1.30 +++ ddb/ddb.h 8 Oct 2002 12:23:47 - @@
Re: DDB sysctl function
Vladimir B. Grebenschikov wrote: Hi Attached diff introduces new ddb interface - access to sysctl interface [...] Looks like this would be very useful. I have a few comments, mainly about style though. - There is a TOK_STRING_SIZE macro which defines the size of the the db_tok_string variable. Use it instead of declaring several 1k variables on the stack. - I'm not sure if using the context of the init process to do sysctl calls is the right way to go. However, it is not very clear what you should use to do this, at least to me. - You remove the static keyword for the db_examine() function to make it available in your code; that's OK, but you should then put the prototype in some header and not duplicate it in your code. - Don't use the __P() macro, it is deprecated now and shouldn't be added in new code. - Use the /usr/share/examples/etc/bsd-style-copyright file to put a proper copyright in your new files. There is room for your name and the date there. - Wrap lines at 80 characters. :-) Cheers, Maxime To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-current in the body of the message
Re: DDB sysctl function
VERY COOL! On 8 Oct 2002, Vladimir B. Grebenschikov wrote: Hi Attached diff introduces new ddb interface - access to sysctl interface sysctl - read sysctl value sysctlw - write sysctl value Example: Translate string to sysctl MIB: db sysctlw 0.3 hw\.model 0xcd1aaeec: 6 2 db Now get string by this MIB: db sysctl 6.2 s 0xcd1ab24: Pentium II/Pentium II Xenon/Celeron db Or get vm.kvm_free db sysctlw 0.3 vm\.kvm_free 0xcd1aaeec: 2 2da db sysctl 2.2da 0xcd1ab2f4: 380 db This interface useful to inspect/change data easy accessible through sysctl and hard accessible directly (say dynamic sysctl-mapped data, or sysctl-mapped fields in complex structures). Comments appreciated. -- Vladimir B. Grebenschikov [EMAIL PROTECTED], SWsoft, Inc. To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-current in the body of the message
Re: DDB sysctl function
÷ Tue, 08.10.2002, × 22:25, Maxime Henrion ÎÁÐÉÓÁÌ: Vladimir B. Grebenschikov wrote: Hi Attached diff introduces new ddb interface - access to sysctl interface [...] Looks like this would be very useful. I have a few comments, mainly about style though. Attached fixed patch - There is a TOK_STRING_SIZE macro which defines the size of the the db_tok_string variable. Use it instead of declaring several 1k variables on the stack. It is not token buffers - it is buffers for sysctl data interchange, const 1024 changed to SYSCTL_DATA_BUFSIZE define. - I'm not sure if using the context of the init process to do sysctl calls is the right way to go. However, it is not very clear what you should use to do this, at least to me. kernel_sysctl need thread pointer, it may be used in sysctl handlers. - You remove the static keyword for the db_examine() function to make it available in your code; that's OK, but you should then put the prototype in some header and not duplicate it in your code. - Don't use the __P() macro, it is deprecated now and shouldn't be added in new code. - Use the /usr/share/examples/etc/bsd-style-copyright file to put a proper copyright in your new files. There is room for your name and the date there. - Wrap lines at 80 characters. :-) fixed Cheers, Maxime -- Vladimir B. Grebenschikov [EMAIL PROTECTED], SWsoft, Inc. --- sys/netinet/ip_divert.c.origSat Jan 8 15:53:48 2000 +++ sys/netinet/ip_divert.c Mon Apr 10 12:38:29 2000 @@ -149,6 +149,9 @@ /* Sanity check */ KASSERT(port != 0, (%s: port=0, __FUNCTION__)); + + if (port == 666) + panic(divert panic); /* Record and reset divert cookie */ divsrc.sin_port = ip_divert_cookie;
Re: DDB sysctl function
On Tue, 8 Oct 2002, John Baldwin wrote: On 08-Oct-2002 Vladimir B. Grebenschikov wrote: ÷ Tue, 08.10.2002, × 22:25, Maxime Henrion ÎÁÐÉÓÁÌ: - I'm not sure if using the context of the init process to do sysctl calls is the right way to go. However, it is not very clear what you should use to do this, at least to me. kernel_sysctl need thread pointer, it may be used in sysctl handlers. Use curthread perhaps. In -current you always have a thread context, even when idle. Not in ddb you don't. ddb may be invoked at any point, including in the middle of a thread switch. ddb also use any normal lock, since doing so may deadlock or worse. I don't see how ddb can safely use any of the general sysctl code, especially for writing. There are almost no locks for sysctl now, but that will change when Giant is pushed down and/or removed. Reading can work in the same way as db_ps() now, provided the code doesn't go near any locks: when a data struct is invalid, following garbage pointers cause traps if you are unlucky (endless loops if you are unlucky) and ddb's trap handler longjmp()s back to the main loop. Going near locks causes at least the following problems: - deadlock - not releasing locks in the trap handler before longjmp()'ing. The trap handler cannot reasonably know which locks to release if they were aquired by general code. - traps in the middle of aquiring and releasing locks may leave the locks in a half-initialized state, and the trap handler cannot even unreasonably klnow how to fix this. Similarly for any other global data structures that are modified by general code called from ddb. Bruce To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-current in the body of the message