Hi there! This question is for Unix domain sockets savvy guys. When a server that listens on a UDS has started and its socket's filename is removed from the filesystem. Is it notified somehow, maybe with a SIGPIPE signal or something? or not? I ask because when dillo-0.7.2 is out, the old bm_srv12 MUST be removed (but it may remain sleeping in memory when the binary is updated). It'd be good to be able to remove it indirectly by making it react to an 'unlink' call on its socket (well, from this release and on). For the 0.7.1.2 bm_srv12, I'm considering `fuser -k bm_srv12` and a hackish: <dpi cmd='bye' (without the closing ">" an exit(1) is forced!) Anyone? :-) Cheers Jorge.-
Tried to enable font tag size/face support and discovered that this made loading sites slow since same fonts were queried, dropped and requeried many times from X server. So here is a patch which makes Dw_style not drop any fonts from fonts_table hashmap until Dw_style_cleanup_fonts is called (from Html_close, when page rendering is finished) and enables support for font tags size and face attributes. diff -pru -x CVS -x configure -x 'aclocal*' -x 'Makefile*' -x config.h.in cvs/dillo/src/dw_style.c dillo/src/dw_style.c --- cvs/dillo/src/dw_style.c 2003-01-05 17:04:56.000000000 +0200 +++ dillo/src/dw_style.c 2003-04-13 14:26:12.000000000 +0300 @@ -24,8 +24,7 @@ #define EQUIV(a, b) (((a) && (b)) || (!(a) && !(b))) #define Dw_style_font_ref(font) ((font)->ref_count++) -#define Dw_style_font_unref(font) if (--((font)->ref_count) == 0) \ - Dw_style_font_remove (font) +#define Dw_style_font_unref(font) (--(font)->ref_count) #define Dw_style_color_ref(color) ((color)->ref_count++) #define Dw_style_color_unref(color) if (--((color)->ref_count) == 0) \ @@ -82,6 +81,8 @@ static void Dw_style_count_fonts (gpoint count[1] += font->ref_count; } + + /* * Called by a_Dw_style_freeall. */ @@ -142,6 +143,25 @@ void a_Dw_style_freeall (void) g_hash_table_destroy (colors_table); } +static gboolean Dw_style_cleanup_fonts (gpointer key, + gpointer value, + gpointer user_data) +{ + DwStyleFont *font = (DwStyleFont*) key; + + if (font->ref_count <= 0) { + Dw_style_font_remove (font); + return TRUE; + } + return FALSE; +} + +/* Collects garbage from fonts cache... */ +void a_Dw_style_fonts_cleanup (void) +{ +// fprintf(stderr, "a_Dw_style_fonts_cleanup called\n"); + g_hash_table_foreach_remove (fonts_table, Dw_style_cleanup_fonts, NULL); +} /* ---------------------------------------------------------------------- * @@ -340,6 +360,9 @@ static DwStyleFont* Dw_style_font_new_in if ((font = g_hash_table_lookup (fonts_table, font_attrs))) { return font; } else { +/*fprintf(stderr, "*** load new font... %d b%d i%d '%s'\n", + (int) font_attrs->size, (int) font_attrs->bold, + (int) font_attrs->italic, font_attrs->name);*/ font = g_new (DwStyleFont, 1); font->size = font_attrs->size; font->bold = font_attrs->bold; @@ -349,6 +372,9 @@ static DwStyleFont* Dw_style_font_new_in Dw_style_font_realize (font, try_all); if (font->font) { +/*fprintf(stderr, "*** new font: %d b%d i%d '%s'\n", + (int) font->size, (int) font->bold, + (int) font->italic, font->name);*/ g_hash_table_insert (fonts_table, font, font); return font; } else { @@ -424,7 +450,10 @@ DwStyleFont* a_Dw_style_font_new_from_li */ static void Dw_style_font_remove (DwStyleFont *font) { - g_hash_table_remove (fonts_table, font); +/*fprintf(stderr, "*** remove font... %d b%d i%d '%s'\n", + (int) font->size, (int) font->bold, + (int) font->italic, font->name);*/ +// g_hash_table_remove (fonts_table, font); g_free (font->name); gdk_font_unref (font->font); g_free (font); diff -pru -x CVS -x configure -x 'aclocal*' -x 'Makefile*' -x config.h.in cvs/di llo/src/dw_style.h dillo/src/dw_style.h --- cvs/dillo/src/dw_style.h 2002-12-29 18:09:52.000000000 +0200 +++ dillo/src/dw_style.h 2003-04-13 14:26:12.000000000 +0300 @@ -122,6 +122,7 @@ DwStyle* a_Dw_style_new GdkWindow *window); DwStyleFont* a_Dw_style_font_new (DwStyleFont *font_attrs); DwStyleFont* a_Dw_style_font_new_from_list (DwStyleFont *font_attrs); +void a_Dw_style_fonts_cleanup (void); DwStyleColor* a_Dw_style_color_new (gint color_val, GdkWindow *window); DwStyleShadedColor* a_Dw_style_shaded_color_new (gint color_val, +#define SUPPORT_FONTS 1 + +#if SUPPORT_FONTS +static const char *strcasestr(const char *haystack, const char *needle) +{ + int needle_len; + + for (needle_len = strlen(needle); *haystack; ++haystack) + if ((*haystack|' ') == (*needle|' ') && + !g_strncasecmp(haystack, needle, needle_len)) return haystack; + return NULL; +} +#endif static void Html_tag_open_font(DilloHtml *html, char *tag, gint tagsize) { #if 1 DwStyle style_attrs, *old_style; - /*DwStyleFont font;*/ +#if SUPPORT_FONTS + DwStyleFont font; + gint level, setsize = 0; +#endif const char *attrbuf; gint32 color; @@ -1792,10 +1817,26 @@ static void Html_tag_open_font(DilloHtml } } -#if 0 - if ((attrbuf = Html_get_attr(html, tag, tagsize, "face"))) { +#if SUPPORT_FONTS + if ((attrbuf = Html_get_attr(html, tag, tagsize, "size"))) { + level = strtol(attrbuf, NULL, 10); + if (level < 0 || *attrbuf == '+') + level += Html_fontsize_to_level(style_attrs.font->size); + setsize = Html_level_to_fontsize(level); + } + + if ((attrbuf = Html_get_attr(html, tag, tagsize, "face")) && + strcasestr(attrbuf, style_attrs.font->name)) + attrbuf = NULL; + + if (attrbuf || (setsize > 0 && setsize != style_attrs.font->size)) { font = *( style_attrs.font ); - font.name = attrbuf; +/* fprintf(stderr, "font '%s'->'%s', %d->%d\n", + font.name, attrbuf, font.size, setsize);*/ + if (attrbuf) + font.name = (char*) attrbuf; + if (setsize > 0) + font.size = setsize; style_attrs.font = a_Dw_style_font_new_from_list (&font); } #endif @@ -4183,6 +4289,9 @@ static void Html_close(DilloHtml *html, a_Progressbar_update(html->bw->progress, NULL, 0); g_free(html); + + /* free unused entries from font cache */ + a_Dw_style_fonts_cleanup(); }
madis writes:
Tried to enable font tag size/face support and discovered that this made loading sites slow since same fonts were queried, dropped and requeried many times from X server. So here is a patch which makes Dw_style not drop any fonts from fonts_table hashmap until Dw_style_cleanup_fonts is called (from Html_close, when page rendering is finished) and enables support for font tags size and face attributes.
Your patch was broken. It has some changes to html.c, but the diff is not marked that way, so patch died on it. Also, many of the added lines are commented out. Attached is a diff which should apply cleanly, and result in a compile-able source tree. -- Chris music is what numbers feel like San Francisco, CA http://www.nodewarrior.org/chris
Thanks for noting! I attached cleaned up patch (without commented printf-s and with ability to apply... hopefully, worked for me). On Wed, 16 Apr 2003, Chris Palmer wrote:
madis writes:
Tried to enable font tag size/face support and discovered that this made loading sites slow since same fonts were queried, dropped and requeried many times from X server. So here is a patch which makes Dw_style not drop any fonts from fonts_table hashmap until Dw_style_cleanup_fonts is called (from Html_close, when page rendering is finished) and enables support for font tags size and face attributes.
Your patch was broken. It has some changes to html.c, but the diff is not marked that way, so patch died on it.
Also, many of the added lines are commented out.
Attached is a diff which should apply cleanly, and result in a compile-able source tree.
It was too broken to fix, you had ended up with some code belonging to html.c in dw_style.h...
Madis,
Tried to enable font tag size/face support and discovered that this made loading sites slow since same fonts were queried, dropped and requeried many times from X server. So here is a patch which makes Dw_style not drop any fonts from fonts_table hashmap until Dw_style_cleanup_fonts is called (from Html_close, when page rendering is finished) and enables support for font tags size and face attributes.
Please read the FONT related articles from our [links] section. They explain why we don't include support for the FONT element. As for the expires patch, I'll get back to it after 0.7.2 is out. Cheers Jorge.-
On 2003-04-15 at 15:45 -0400, Jorge Arellano Cid wrote:
When a server that listens on a UDS has started and its socket's filename is removed from the filesystem. Is it notified somehow, maybe with a SIGPIPE signal or something? or not?
Not to the best of my knowledge. And I wrote a short C program to test it, and it's not on FreeBSD. Code available on request (I might well have messed up -- I caught myself writing Perl far too often). I've tested straight accept() and non-blocking accept socket with poll(); no poll POLL(HUP|ERR|NVAL) either. :^(
For the 0.7.1.2 bm_srv12, I'm considering `fuser -k bm_srv12` and a hackish:
fuser is platform-specific. You'd need to code logic for multiple commands. lsof(8) is fairly portable, but not as widespread as it should be. Certainly various *BSD systems have it as an optional package, and we make sure it's on our Solaris systems too. You can't invoke lsof(8) on a filename and get output if the filename represents a unix-domain socket. :^( Either "lsof -U" for a list of all unix-domain sockets, or "lsof -c /commandnameregexp/" which would give: COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME [...] unixsocke 367 me 3u unix 0xcf251c00 0t0 /home/me/SocketTest "lsof -U" gives output in identical format, except that every row will have TYPE == "unix". sockstat(8) on FreeBSD (but not OpenBSD), but again you'd need to grep the filename. "sockstat -u" gives: USER COMMAND PID FD PROTO ADDRESS [...] me unixsock 367 3 stream /home/me/SocketTest [...]
<dpi cmd='bye'
(without the closing ">" an exit(1) is forced!)
For the new version, why not just have a proper "bye" command? Any distributed system needs a way to shut down cleanly. I've worked cleaning up the mess after an application system which didn't have one and the original programmer had tried to use signals, but had ended up using SIGKILL. This thing took several minutes to start up each time, losing money when it happened. Diagnosed, added shutdown stuff to the all the IDL definitions for the various components, and put together a quick tool to remove all the old state files from the working directory which had made the tool so slow. Hey presto, decent coordinated shutdown which actually worked, reliably, and startup time of a few seconds maximum (despite being written for DCE -- don't ask). I've seen a few other situations, none as severe, but my perhaps limited experience is that provided your control protocol can be trusted (nothing untrusted can send messages, eg HTTP) then every independently running part of a system needs a start-up, a reinitialise, and a shutdown command. Preferably also "dump state" and "dump statistics" commands but that's because I'm nosy (okay, I like debugging). A _really_ sick way would be to create a token, fork a child to connect to your own unix socket and write a ping command with the token as data to its connection. If you get that coming back in, it's still your socket. If you don't get it but something else replies to the child then you've lost the socket and should exit. :^) -Phil
Hi there! Thanks Phil (Pennock) for your answer on Unix domain sockets. I kept cosidering the alternatives, and apart from the UDS idea (not feasible), the incomplete "bye" command, there's also another option! kill `ps -U <USER> | grep bm_srv12 | sed 's/^ *//g' | cut -d' ' -f1` That is, issued from dillo to force the shut down of a running bookmark server. For instance: if the user is "jcid" then a: kill `ps -U jcid | grep bm_srv12 | sed 's/^ *//g' | cut -d' ' -f1` solves the problem. Obviously, the definitive solutions need a well defined design (which I'm currently studying, BTW is a bit like JINI). The point is: Does this command work well on *BSDs, and Solaris? If that command can bring a running server down, we're done! Andreas: please give it a try. If, let's say, tomorrow I have some feedback, I'd commit a version that includes the command and 0.7.2 would be scheduled for release on Friday, so Phil B. can pack a .deb that's ready at announce time. Cheers Jorge.-
Hi,
I kept cosidering the alternatives, and apart from the UDS idea (not feasible), the incomplete "bye" command, there's also another option!
kill `ps -U <USER> | grep bm_srv12 | sed 's/^ *//g' | cut -d' ' -f1`
On OpenBSD and FreeBSD, this construct does return the PID indeed. I'm just not sure how portable that is in general. Quite less portable is killall (which does not even exist on OpenBSD), but on FreeBSD it has an -u for user option. I.e. "killall -u andy bm_srv12" will do it, but only on FreeBSD :-( Cheers, Andreas -- **************************** NEW ADDRESS ****************************** Hamburger Sternwarte Universitaet Hamburg Gojenbergsweg 112 Tel. ++49 40 42891 4016 D-21029 Hamburg, Germany Fax. ++49 40 42891 4198
On Tue, 22 Apr 2003, Andreas Schweitzer wrote:
Hi,
I kept cosidering the alternatives, and apart from the UDS idea (not feasible), the incomplete "bye" command, there's also another option!
kill `ps -U <USER> | grep bm_srv12 | sed 's/^ *//g' | cut -d' ' -f1`
On OpenBSD and FreeBSD, this construct does return the PID indeed. I'm just not sure how portable that is in general.
Quite less portable is killall (which does not even exist on OpenBSD), but on FreeBSD it has an -u for user option. I.e. "killall -u andy bm_srv12" will do it, but only on FreeBSD :-(
Don't ever, *ever* consider killall portable. Under at least HPUX, killall silently ignores its arguments and kills all the processes it can get its murderous little hands on. A bad day to be root... -Lars -- Lars Clausen (http://shasta.cs.uiuc.edu/~lrclause)| Hårdgrim of Numenor "I do not agree with a word that you say, but I |---------------------------- will defend to the death your right to say it." | Where are we going, and --Evelyn Beatrice Hall paraphrasing Voltaire | what's with the handbasket?
This is actually a newbie error on solaris :-) ... killall does kill ALL ! same as HPUX, think AIX is the same. / lars Segerlund Lars Clausen wrote:
On Tue, 22 Apr 2003, Andreas Schweitzer wrote:
Hi,
I kept cosidering the alternatives, and apart from the UDS idea (not feasible), the incomplete "bye" command, there's also another option!
kill `ps -U <USER> | grep bm_srv12 | sed 's/^ *//g' | cut -d' ' -f1`
On OpenBSD and FreeBSD, this construct does return the PID indeed. I'm just not sure how portable that is in general.
Quite less portable is killall (which does not even exist on OpenBSD), but on FreeBSD it has an -u for user option. I.e. "killall -u andy bm_srv12" will do it, but only on FreeBSD :-(
Don't ever, *ever* consider killall portable. Under at least HPUX, killall silently ignores its arguments and kills all the processes it can get its murderous little hands on. A bad day to be root...
-Lars
On Wed, Apr 23, 2003 at 11:35:16AM +0200, Lars Segerlund wrote:
This is actually a newbie error on solaris :-) ... killall does kill ALL ! same as HPUX, think AIX is the same.
Yep, AIX is just as "destructive" :-)
kill `ps -U <USER> | grep bm_srv12 | sed 's/^ *//g' | cut -d' ' -f1`
Oh, and while being with AIX, this will NOT work on AIX. The first field on AIX is the UID ... But dillo doesn't compile easily on AIX anyways :-). Back when I was working on an AIX machine I did have an executable, but there were always some gotchas. Cheers, Andreas -- **************************** NEW ADDRESS ****************************** Hamburger Sternwarte Universitaet Hamburg Gojenbergsweg 112 Tel. ++49 40 42891 4016 D-21029 Hamburg, Germany Fax. ++49 40 42891 4198
* Jorge Arellano Cid <jcid@softhome.net> [04-22-03 15:47]:
I kept cosidering the alternatives, and apart from the UDS idea (not feasible), the incomplete "bye" command, there's also another option!
kill `ps -U <USER> | grep bm_srv12 | sed 's/^ *//g' | cut -d' ' -f1`
That is, issued from dillo to force the shut down of a running bookmark server.
This works correctly on SuSE 8.1 uname -a: Linux wahoo 2.4.19-4GB #1 Wed Nov 27 00:56:40 UTC 2002 i686 unknown -- Patrick Shanahan Please avoid TOFU and trim >quotes< http://wahoo.no-ip.org Registered Linux User #207535 icq#173753138 @ http://counter.li.org Linux, a continuous *learning* experience
* Jorge Arellano Cid <jcid@softhome.net> [04-22-03 15:47]:
I kept cosidering the alternatives, and apart from the UDS idea (not feasible), the incomplete "bye" command, there's also another option!
kill `ps -U <USER> | grep bm_srv12 | sed 's/^ *//g' | cut -d' ' -f1`
That is, issued from dillo to force the shut down of a running bookmark server.
This works correctly on SuSE 8.1 uname -a: Linux wahoo 2.4.19-4GB #1 Wed Nov 27 00:56:40 UTC 2002 i686 unknown BUT, also and cleaner, kill `pidof bm_srv12` also works, but I do not know about other ?nix versions. sorry bout the repost -- Patrick Shanahan Please avoid TOFU and trim >quotes< http://wahoo.no-ip.org Registered Linux User #207535 icq#173753138 @ http://counter.li.org Linux, a continuous *learning* experience
Hey Patrick Patrick Shanahan writes:
* Jorge Arellano Cid <jcid@softhome.net> [04-22-03 15:47]:
I kept cosidering the alternatives, and apart from the UDS idea (not feasible), the incomplete "bye" command, there's also another option!
kill `ps -U <USER> | grep bm_srv12 | sed 's/^ *//g' | cut -d' ' -f1`
This works fine on the Solaris I have access to...
BUT, also and cleaner, kill `pidof bm_srv12` also works, but I do not know about other ?nix versions.
... but this does not. Sorry. best regards, -- Livio B. Soares
On Tue, 22 Apr 2003 18:55:18 -0300, Livio Baldini Soares <livio@ime.usp.br> wrote:
kill `ps -U <USER> | grep bm_srv12 | sed 's/^ *//g' | cut -d' ' -f1` This works fine on the Solaris I have access to...
it also works in irix 6.5 (although i still didnt try to compile dilo there, but i want to 8) higuita -- Naturally the common people don't want war... but after all it is the leaders of a country who determine the policy, and it is always a simple matter to drag the people along, whether it is a democracy, or a fascist dictatorship, or a parliament, or a communist dictatorship. Voice or no voice, the people can always be brought to the bidding of the leaders. That is easy. All you have to do is tell them they are being attacked, and denounce the pacifists for lack of patriotism and exposing the country to danger. It works the same in every country. -- Hermann Goering, Nazi and war criminal, 1883-1946
On 2003-04-22 at 16:20 -0400, Jorge Arellano Cid wrote:
kill `ps -U <USER> | grep bm_srv12 | sed 's/^ *//g' | cut -d' ' -f1`
Depending upon line buffering and how your PIDs are ordered (wrapped around recently?) that can end up killing the "grep" process before its given the PID for the bookmark server. A neat little Unix shell idiom for that is: grep '[b]m_srv12' The pattern there will no longer match the grep command-line, since the ']' adds an extra character. I think that I first learnt this from Aeleen Frisch's Essential System Adminstration book -- an excellent resource now in its third edition (was 1st ed when I learnt that one -- it's an old idiom). ps -U <USER> | grep '[b]m_srv' | awk '{print $1}' | xargs kill
That is, issued from dillo to force the shut down of a running bookmark server.
Suggestion: put it into a two-line shell-script which Dillo invokes; then portability simply becomes a package-maintainer issue of changing a very short shell script.
The point is: Does this command work well on *BSDs, and Solaris?
The basic stuff tested successfully on FreeBSD 4.7 ia32, OpenBSD 3.2 sparc and Solaris 2.5.1 sparc. Both the sed/cut version and the awk version. ;^) That's using the default /usr/bin/ps on Solaris; if someone has put the *BSD commands in their path first, then they'll have the really ancient syntax of /usr/ucb/ps and -U isn't supported. Such people are probably best just deemed "on their own".
participants (11)
-
Andreas Schweitzer
-
Chris Palmer
-
higuita
-
Jorge Arellano Cid
-
Lars Clausen
-
Lars Segerlund
-
Livio Baldini Soares
-
madis
-
Madis Janson
-
Patrick Shanahan
-
Phil Pennock