Re: C code for parsing rc.conf?
Ah yes, I was just being crude .. giving some lame example :-P Parsing the rc.conf would take considerably more work than that "Tha whistles go WOO!" - Bubb Rubb Brandon At 04:59 PM 4/14/2004, you wrote: --- Brandon Erhart <[EMAIL PROTECTED]> wrote: > Not that I know of, but it should be a breeze to write a simple parsing > engine. > Just ignore all lines starting with a '#', and break at the '=' sign. The > first part would be your variable name, the last part your value for it. Don't forget to deal with quotes: some_variable="Double-quoted value" - or - some_other_variable='Single-quoted value' Not to mention lines with trailing comments: some_variable="Some Value" # Set some variable to some value. And, as somebody else pointed out, some other embedded shell syntax (which might contain an equal sign, so just blindly splitting lines on equal signs won't work): if [ "$some_variable" = "NO" ]; then # do something here... fi Remember that /etc/rc.conf is just a shell script, and so it is parsed by the shell interpreter (/bin/sh). You might end up writing a shell parser if you want to cover all possibilities! (in other words, re-inventing the wheel.) Be careful. -brian > Then just display variables and their names, and maybe parse the variable > names so you can assign meaningful help information to them. > > I didn't compile this, not sure if it'll work, but it'll give you a good > idea as to what your code may look like .. > [...] __ Do you Yahoo!? Yahoo! Tax Center - File online by April 15th http://taxes.yahoo.com/filing.html ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: C code for parsing rc.conf?
Not that I know of, but it should be a breeze to write a simple parsing engine. Just ignore all lines starting with a '#', and break at the '=' sign. The first part would be your variable name, the last part your value for it. Then just display variables and their names, and maybe parse the variable names so you can assign meaningful help information to them. I didn't compile this, not sure if it'll work, but it'll give you a good idea as to what your code may look like .. int main(int argc, char **argv) { FILE *rc; char buf[512]; if ( (rc=fopen("/etc/rc.conf", "r")) == NULL) { perror("fopen()"); exit(EXIT_FAILURE); } while (fgets(buf, sizeof(buf), rc) != NULL) { char *eq_ptr, var_name[256], var_value[256]; some_function_to_strip_trailing_and_pre_whitespace(buf); /* this function will just strip pre- and trailing whitespace from the line */ if (!strlen(buf)) continue;/* blank line */ if (buf[0] == '#') continue; /* comment line */ if ( (eq_ptr = index(buf, '=')) == NULL) continue; /* no equal sign */ *eq_ptr = '\0'; memset(var_name, 0, 256); memset(var_value, 0, 256); if (!strlen(buf) || !strlen(eq_ptr+1)) continue;/* either the variable name or the value was empty */ strncpy(var_name, buf, 255); strncpy(var_value, eq_ptr+1, 255); printf("%s=%s\n", var_name, var_value); } exit(EXIT_SUCCESS); } At 03:56 PM 4/14/2004, you wrote: Hi, Is there a C library that comes with FreeBSD which can be used to parse, append to, and validate rc.conf? I'd like to customize some of the settings in /etc/rc.conf with my own GUI-based program. It's not too hard to write something on my own, but I was wondering if a reusable library existed in FreeBSD 4.x or 5.x for doing this. Thanks. -- Craig Rodrigues http://crodrigues.org [EMAIL PROTECTED] ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "[EMAIL PROTECTED]" ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Weird behavior with either reading or write()ing !?
Hello, This is a rather odd bug/weird behavior. Confidence is high that it is not logic in my code this time. Please read the following carefully! In a web-crawling program I am writing, I deal with several thousand fds at a time. I am using FreeBSD's KQueue to keep track of them all so that I may be notified when an event is pending on a given socket. The program works as it should for about 75% of the connections. The other 25% don't work so well. I have implemented read timeouts in the fashion that, whenever I am in the callback function for data being wait to be read off an fd (EVFILT_READ or whatever), I store the last time (via gettimeofday()) that data was read on that socket. Then, in my main loop, I check all sockets to see if the last time data was read isn't any greater than 10 seconds ago. However, I am receiving a lot of read timeouts. I keep track of the last response from the remote server, and the current state I'm in (E.G., sent another GET request on a keepalive connection). In several cases, I had received a response for the last page I requested, processed/parsed it, and sent down another request. However, data never got back to me. Even after 10 seconds. Hell, even after 30 seconds in some cases. What I am wondering is, is it possible for either my write() to be failing it's ability to get data to the remote site (I check the return value of write(), and its always returning the amount of bytes I am writing), or possibly for data to be being "dropped" per-se on my end by the kernel (no data waiting on the socket). I have all my sockets in O_NONBLOCK mode. To test the possibility of perhaps KQueue not notifying me of data waiting, or me not grabbing the event off the queue in time, I call a read() on the socket one last time when I catch the read timeout. Most of the time (99% of it) there is no data waiting. This all seems to be random. It's never consistent (same server) over several runs of the program. Any ideas folks? This has completely stumped me. Thanks for your support, Brandon ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: FreeBSD and Debugging?
Thank you. You are my new god. I had checked out a version of valgrind for BSD (one of the patches) and it failed to compile. Everything seems to be working, except I get this warning at the beginning of the program: "Warning: ignoring --pointercheck=yes, because i386_set_ldt failed (errno=45)" Any ideas? Brandon At 11:17 PM 4/9/2004, you wrote: Brandon Erhart wrote: For Linux, I've seen valgrind (probably one of the best) as well as several others. In the commercial arena, Rational's PURIFY and Parasoft's INSURE++ work on every OS *but* BSD. Any particular reason for this? Are there any debuggers out there for BSD that will detect the heap/stack corruption!? Valgrind is available for FreeBSD. http://eirikn.kerneled.com/valgrind/ -- Lev Walkin [EMAIL PROTECTED] ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "[EMAIL PROTECTED]" ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "[EMAIL PROTECTED]"
FreeBSD and Debugging?
Hi, I've been writing an application for some time now, and I seem to have introduced some kind of bug that is smashing the stack or the heap *somewhere*. One of my variables (or more) are being changed, and the program relies on this being set to the last time data was read from a socket. It's getting reset to 0 for some odd, odd reason. But enough of my whining. My code, my problems. What isn't my problem, though, and is probably a lot of people's problem, is the lack of a *good* debugger for BSD. I know gdb is pretty good, and it does help me often, but I can't seem to find a debugger that will detect under/over reads/writes in the heap and/or stack (bounds checking). I had downloaded the bounds checking gcc, it compiled fine, but I get an error that doesn't allow it to run on FreeBSD 4.9 (w/ gcc-2.95.2) -- something about ulimit not being found. I checked Google, and of course, found nothing. I didn't bother enough to look any deeper than that. For Linux, I've seen valgrind (probably one of the best) as well as several others. In the commercial arena, Rational's PURIFY and Parasoft's INSURE++ work on every OS *but* BSD. Any particular reason for this? Are there any debuggers out there for BSD that will detect the heap/stack corruption!? Thanks in advance for you support, Brandon ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "[EMAIL PROTECTED]"
KQueue dropping events?
Hi, I am writing a web sucker downer (mirror) for a project on indexing the web (got myself a 1TB raid, just gonna d/l text ..). I am using the KQueue API in FreeBSD 4.9-REL to take care of watching over my sockets. I seem to be running into a nasty problem, however. Here's a scenario. I set the outgoing connections to, say, 5000. The problem is, the amount of connections my program shows as being connected is roughly 1/5 to sometimes even 1/8th of what is actually connected. I see what is "actually connected" by doing a netstat. The program would say 750/5000 connections, while a netstat would show 4500 connections in the ESTABLISHED state. You may be saying, "it must be a bug in your connection tracking logic". I honestly don't think that's it. I have only TWO places in my code where I check if the connection was successful by calling getpeername(), if it wasnt, i return back to the main loops, otherwise I know it connected (and therefore increasing the global connection counter) -- in the callback function for data read() from KQueue-monitored fds (all of the sockets), and then also in my main loop (I check for read, write and connect timeouts there, right after my call to kevent()). Basically the main loop looks like, in psuedo-code of course: while (there_is_still_events) { if (kevent()) <-- i pull 16 events from the kqueue { execute_the_callback_function; } check_for_read()_write()_and_connect()_timeouts; check_for_"client_descriptors(basically just a structure that holds info on the kqueue event)"_that_need_to_be_connected_to_the_next_server_and_do_so; } It's pretty straight forward. I have no idea why my program would be reporting a smaller amount. Is it possible that my program is not getting ALL the information it needs from kevent()? Perhaps the KQueue is becoming "full"? Is this possible? Should I be pulling more than the 16 events off the kqueue at a time? I have been up ALL NIGHT trying to debug this, and cannot figure it out. Any and all help is appreciated! Thanks, Brandon ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "[EMAIL PROTECTED]"