[25346] in Perl-Users-Digest
Perl-Users Digest, Issue: 7591 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 29 09:06:05 2004
Date: Wed, 29 Dec 2004 06:05:22 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 29 Dec 2004 Volume: 10 Number: 7591
Today's topics:
A VoIP usergroup erika_angella@yahoo.com
charting data <zebee@zip.com.au>
Re: charting data <shawn.corey@sympatico.ca>
Re: handle multiple submit button. <joe@inwap.com>
Re: how Encode::Hanextra work? <ke.kewen@gmail.com>
Re: how to delete files that create date <=20041210 <vilain@spamcop.net>
Re: Is zero even or odd? mmeron@cars3.uchicago.edu
Re: Is zero even or odd? mmeron@cars3.uchicago.edu
Re: Is zero even or odd? <bik.mido@tiscalinet.it>
Re: Is zero even or odd? <invalid@msgid.michael.mendelsohn.de>
Re: Is zero even or odd? <invalid@msgid.michael.mendelsohn.de>
Re: Leak in Win32::ChangeNotify? [solved] <ThomasKratz@REMOVEwebCAPS.de>
Re: Leak in Win32::ChangeNotify? <ThomasKratz@REMOVEwebCAPS.de>
Re: need help in programming linux with perl <lie_huo@hotmail.com>
Re: need help in programming linux with perl <lawshouse.public@btconnect.com>
Re: save & restore cursor position in perl <joe@inwap.com>
Simple question - setting up services <justin.harper@gmail.com>
Re: Simple question - setting up services <abigail@abigail.nl>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 29 Dec 2004 02:24:35 -0800
From: erika_angella@yahoo.com
Subject: A VoIP usergroup
Message-Id: <1104315875.210569.143190@z14g2000cwz.googlegroups.com>
Hi Guys,
I found a new VOIP forum, where there is a good syndication of VOIP
technical white papers. It is really worth checking out -
http://www.techieindex.com/ug/voip/index.jsp
------------------------------
Date: Wed, 29 Dec 2004 09:54:55 GMT
From: Zebee Johnstone <zebee@zip.com.au>
Subject: charting data
Message-Id: <slrnct4vgv.9dl.zebee@zeus.zipworld.com.au>
I have several - 3 to 20 - sets of data. Each has the same x-axis and
y-axis bounds. Each consists of the x axis - time - and a y axis between
80 and 180 with 2 sets of data, a max and an average, to be plotted.
I would like to create a chart which has each data set in a separate
space, one under the other - somethig I am not going to try and do in
ascii art!
png format is fine.
THe idea is to be able to see how the datasets change in relation to
each other, how the data changes from day to day, each dataset being a
day's worth of data.
Chart::Strip looks to be suitable, except that it's not really set up
to have the separate datasets plotted next to each other but separated
in the way I want as far as I can see.
Can any one suggest a way to attack this problem?
Should I just say bugger it, produce each day separately, put them one
under the other on a webpage and print that?
Zebee
--
Zebee Johnstone (zebee@zip.com.au), proud holder of
aus.motorcycles Poser Permit #1.
"Motorcycles are like peanuts... who can stop at just one?"
------------------------------
Date: Wed, 29 Dec 2004 08:03:18 -0500
From: Shawn Corey <shawn.corey@sympatico.ca>
Subject: Re: charting data
Message-Id: <bVxAd.23931$nV.751719@news20.bellglobal.com>
Zebee Johnstone wrote:
> Can any one suggest a way to attack this problem?
>
> Should I just say bugger it, produce each day separately, put them one
> under the other on a webpage and print that?
>
> Zebee
>
>
You could try GD and GD::Graph. I haven't tried anything like this
myself but you could create a separate GD object for each chart and then
use GD to combine them into one big PNG file.
You will have to download and compile some binary libraries. These are
documented in the README files for GD and GD::Graph.
--- Shawn
------------------------------
Date: Wed, 29 Dec 2004 01:13:36 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: handle multiple submit button.
Message-Id: <lfSdnSHr7Z_f6E_cRVn-qw@comcast.com>
sam wrote:
> My current perl script only is written full of print statements
That's not recommended practice. Do you know about 'here' documents?
print <<"END_OF_MESSAGE";
<form action=main.cgi>
...
<input type=submit value="callself.pl">
</form>
END_OF_MESSAGE
> Do I need to change all print statements with CGI?
To fully utilize the methods defined in CGI.pm, yes.
-Joe
------------------------------
Date: 29 Dec 2004 04:25:08 -0800
From: "auriga" <ke.kewen@gmail.com>
Subject: Re: how Encode::Hanextra work?
Message-Id: <1104323108.742883.298840@z14g2000cwz.googlegroups.com>
no,
"use Encode::HanExtra;" doesn't work also.
thanks for you replay
------------------------------
Date: Wed, 29 Dec 2004 03:46:31 -0800
From: Michael Vilain <vilain@spamcop.net>
Subject: Re: how to delete files that create date <=20041210
Message-Id: <vilain-BB38E4.03463129122004@news.giganews.com>
In article <blgl-4245BA.04361129122004@news.bahnhof.se>,
Bo Lindbergh <blgl@hagernas.com> wrote:
> In article <vilain-FC3815.14475127122004@news.giganews.com>,
> Michael Vilain <vilain@spamcop.net> wrote:
>
> > Unix does not store the file's creation time.
>
> So Mac OS X doesn't count as Unix? :-P
>
> More accurately, traditional Unix filesystems don't store it, and thus
> the stat system call doesn't return it.
Yes, I don't count the MacOS HFS+ filesystem the same as the UNIX
filesystem. HFS+ uses a different method to track the Finder attributes
like "locked", "creation date", "alias" (different from a soft link),
invisible, file creator and type, etc. Read the man pages for
GetFileInfo for more information.
If you want to quibble, MacOS X runs Darwin which isn't UNIX. If you
want argue what is and what isn't UNIX, have fun. I'll be in the bar...
--
DeeDee, don't press that button! DeeDee! NO! Dee...
------------------------------
Date: Wed, 29 Dec 2004 08:11:36 GMT
From: mmeron@cars3.uchicago.edu
Subject: Re: Is zero even or odd?
Message-Id: <YEtAd.27$25.16048@news.uchicago.edu>
In article <r984t09csj6s1ksek81lcij9g5695uv6pd@4ax.com>, John Fields <jfields@austininstruments.com> writes:
>
>OK, look at it this way:
>
>These two number lines are behind a screen, so the numbers can't be
>seen, but arranged in such a way that when a number is picked from
>one, the same number will be picked from the other and those two
>numbers will be divided and the quotient presented for viewing.
>
>-1 0 1
>-|-------------------------|-------------------------|-
>
>
>-1 0 1
>-|-------------------------|-------------------------|-
>
>I fail to see why, at one infinitesimal spot on the line(s), the
>division becomes intractable and the machine refuses to output a 1.
>
Sigh. Forget machines. Is the definition of division clear to you?
the result of the division a/b is such a number c that c*b = a.
That's *all* there is to it. So, the result of 0/0 is a number c such
that c*0 = 0. Can you tell me what c is?
OK, here is a little exercise for you. At x = 0, sin(x) is also zero.
And, so is any positive power of either x or sin(x). So, using the
Taylor expansion for sin(x), evaluate the following limits:
1) lim_x->0 sin(x)/x
2) lim_x->0 sin(x)/x^2
3) lim_x->0 (sin(x))^2/x
Mati Meron | "When you argue with a fool,
meron@cars.uchicago.edu | chances are he is doing just the same"
------------------------------
Date: Wed, 29 Dec 2004 08:13:13 GMT
From: mmeron@cars3.uchicago.edu
Subject: Re: Is zero even or odd?
Message-Id: <tGtAd.28$25.15843@news.uchicago.edu>
In article <rgb4t0h1qp1kntcsgab7qdonfdekddla05@4ax.com>, John Fields <jfields@austininstruments.com> writes:
>On Wed, 29 Dec 2004 03:03:12 +0000 (UTC), George Cox
><george_coxanti@spambtinternet.com.invalid> wrote:
>
>>John Fields wrote:
>>>
>>> If my point is that 0/0 = 1, and if k*(0/0)=k then 0/0 _must_ be
>>> equal to 1, otherwise k would not be equal to k. That, I believe,
>>> proves my point, my point being:
>>>
>>> x
>>> y = lim x->0 --- = 1
>>> x
>>
>>This is true, but it is true because
>>
>> x
>> y = lim x->0 --- = lim x->0 1 = 1.
>> x
>>
>>The "1" on the left of the equals sign is there because the two x's
>>cancelled.
>
>---
>And if those x's were zeroes when they were cancelled, that still
>results in a quotient of 1, so 0/0 = 1
>---
>
>>
>>It is not always the case that
>>
>> lim x -> A f(x) = f(A).
>>
>>So the true statement
>>
>> x
>> y = lim x->0 --- = 1
>> x
>>
>>does not allow you to conclude that 0/0 = 1.
>
>---
>It does if the case where X = 0 can result in a cancellation because
>the numerator and denominator were equal and a quotient of 1 resulted
>because of that cancellation.
>
In such case you may conclude that the specific limit evaluated is 1.
Not that 0/0 = 1.
Mati Meron | "When you argue with a fool,
meron@cars.uchicago.edu | chances are he is doing just the same"
------------------------------
Date: Wed, 29 Dec 2004 13:33:35 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Is zero even or odd?
Message-Id: <6je3t0h8uvl1rgkch8r42h8cb4ems0ma31@4ax.com>
On Tue, 28 Dec 2004 18:21:18 +0000 (UTC), Dave Seaman
<dseaman@no.such.host> wrote:
>using about half a dozen or so different C compilers on various platforms, and
>every single one of them printed 1.000000. Similarly for most other
>programming languages that I have tried. However, the mathematical definition
Since this was (cross)posted -for reasons that I can not imagine- also
to clpmisc, to bring it _slightly_ more on topic:
$ perl -le 'print 0**0'
1
BTW: my good 'ol faithful HP-28s tells me the same.
PS: the abondance of crankery this thread is revealing is tending to
make me feel homesick of my sci.math days... (has JSH pop out with an
FLT-based proof about 0^0 being... <whatever>?!?)
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Wed, 29 Dec 2004 13:38:59 +0100
From: Michael Mendelsohn <invalid@msgid.michael.mendelsohn.de>
Subject: Re: Is zero even or odd?
Message-Id: <41D2A563.AA0D3A4D@msgid.michael.mendelsohn.de>
John Fields schrieb:
> On Wed, 29 Dec 2004 03:03:12 +0000 (UTC), George Cox
> >John Fields wrote:
> >>
> >> x
> >> y = lim x->0 --- = 1
> >> x
> >
> >This is true, but it is true because
> >
> > x
> > y = lim x->0 --- = lim x->0 1 = 1.
> > x
> >
> >The "1" on the left of the equals sign is there because the two x's
> >cancelled.
>
> ---
> And if those x's were zeroes when they were cancelled, that still
> results in a quotient of 1, so 0/0 = 1
The point is that you can't cancel them when x may be 0, because
division by 0 is undefined. However, in the lim x->0 case x approaches
0, but never really equals zero, so the cancellation may be performed.
> >does not allow you to conclude that 0/0 = 1.
>
> ---
> It does if the case where X = 0 can result in a cancellation because
> the numerator and denominator were equal and a quotient of 1 resulted
> because of that cancellation.
It is desirable for mathematics not to allow two contradictory
statements such as 0/0=1 and 0/0=2 to be true at the same time; and your
resoning allows these statements to be true in some cases (we did this
in the Ohm's law episode, where you never said my reasoning was wrong,
it was merely not the thing you wanted to prove).
0/0=1 and 0/0=2 leads to 1=2, which is undesirable.
lim x->0 x/x = 1 and lim x->0 2x/x = 2 doesn't have this problem.
It is downright fine and dandy, because
2 lim x->0 x/x = lim x->0 2x/x
It is more inconvenient to write, so maybe you could agree to rephrasing
that 0/0=1 where 0/0 is shorthand for lim x->0 x/x ?
(You would decidedly be in a minority if you used that shorthand).
Cheers
Michael
--
Still an attentive ear he lent Her speech hath caused this pain
But could not fathom what she meant Easier I count it to explain
She was not deep, nor eloquent. The jargon of the howling main
-- from Lewis Carroll: The Three Usenet Trolls
------------------------------
Date: Wed, 29 Dec 2004 13:58:54 +0100
From: Michael Mendelsohn <invalid@msgid.michael.mendelsohn.de>
Subject: Re: Is zero even or odd?
Message-Id: <41D2AA0E.3CDC50E3@msgid.michael.mendelsohn.de>
John Fields schrieb:
> On Mon, 27 Dec 2004 20:58:44 +0100, Michael Mendelsohn
> <invalid@msgid.michael.mendelsohn.de> wrote:
>
> >Below, you remove the short from my diagram.
> >However, you also remove the power supply, which achieves the same
> >thing.
>
> ---
> I don't know what you mean, since the + and - terminals are there and
> I refer to the voltage across the resistance as being 1V.
You eventually lower the voltage to 0V.
That's what I achieved with the short.
> >> The proper circuit:
> >>
> >> +---(V)---+
> >> | |
> >> (-)---o---[R]---o---(A)---o---(+)
> >>
> >> Will yield the proper results if examined using Ohm's law.
> >>
> >> Assuming that the voltage across the resistance is 1V and the current
> >> through it is 1A, then the resistance will be:
> >>
> >> E 1V
> >> R = --- = ---- = 1 ohm (1)
> >> I 1A
> >>
> >
> >Assuming that the voltage across the resistance is 2V and the current
> >through it is 1A, then the resistance will be: 2 ohm.
>
> ---
> Why would I want to do that? I'm specifically setting up a set of
> conditions to illustrate _my_ point, not yours.
I am trying to illustrate that I can make a point that 0/0=2.
You cannot discard my point without adding extra information about your
set of conditions.
This extra information is not present in the 0/0 term, but it _is_
explicitly written in lim x->0 x/x and lim x->0 2x/x , respectively.
> >> Now, if we go to the more general case of:
> >>
> >> x
> >> y = ---
> >> x
> >>
> >> we can see that for any value of x, as x goes to zero, y will remain
> >> constant, and exactly equal to 1. Therefore,
> >>
> >>
> >> 0
> >> --- = 1
> >> 0
> >
> >This is only true because you assumed a resistor of 1 ohm. If you assume
> >a resistor of 2 ohm, then 0/0 = 2.
>
> ---
> Yes, of course. But I didn't "assume" a resistance of one ohm, I
> selected the voltage and current to force the resistance to one ohm.
> ---
>
> >Again, you can only state with concidence that 0/0 = 1 in this case
> >because you already *know* that the resistance is 1; you have not
> >computed it from 0/0, because the 0/0 quotient doesn't help you to know
> >that the resistance is 1 ohm.
>
> ---
> The game being to prove that 0/0 = 1, I'm not looking so much for a
> resistance of 1 ohm as I am a set of values which when divided by
> themselves will result in a quotient of 1.
You want 1 ohm, that's what you bring into the computation. You're
setting everything up so that 1 ohm results, which means it's circular
reasoning.
If you hadn't set everything up that way, the 0V/0A measurement would
leave you stumped as to the value of the resistor, and 0/0=??? then.
Again, the set of values that are divided by itself is x/x for all x in
R\{0}, and lim x->0 x/x = 1 as well.
> Let's make them each equal to 1E-40:
>
> 1E-40
> x = ------- = 1
> 1E-40
>
> Damn! That x is still equal to 1!
>
> It seems that no matter what we do, as long as the numerator and
> denominator are equal, the quotient will always be 1. So, if the
> smallest number we can come up with is 0, and if 0 = 0, then it seems
> we can say:
>
> 0
> x = --- = 1
> 0
You are doing the limit argument nicely.
Now you arrived at x=1 not by dividing by 0 outright, but by taking
larger values and going closer to 0. I would explicitly write what you
did, so your last formula would change to
r
x = lim --- = 1
r->0 r
This is mathematical shorthand for your reasoning that any nonzero value
plugged into r/r is 1, so it makes sense to take r/r=1 for r=0 as well.
> >> The value of x is unimportant. What does matter is that the numerator
> >> and denominator be numerically equal.
> >
> >No, it matters that they are algebraically equal.
>
> ---
> Yeah, good point. they have to have the same sign in order for the
> quotient to come out positive.
You misunderstood my point. My point is that you have to arrive at x/x
or r/r before you plug in the zero. Conmsider: if you had x=2r/r, put in
r=0 to get x=2*0/0 and use 2*0=0 to simplify to x=0/0, then the
numerator is algebraically 0=2r and the denominator is algebraically
0=r, and then
2r
x = lim ---- = 2
r->0 r
which would lead you to conclude that 0/0=2, in this case. You set your
case up so that x=r/r, i.e. numerator and denominator are algebraically
the same *before* you plug in the zero.
This is not true for R=E/I, which is why you can't make a measurement in
the E=0, I=0 case (unless you have extra information).
> >If I give you a resistor to measure, but no power supply, you will
> >measure 0A and 0V, but must the resistor always be 1 ohm, then?
>
> ---
> Since R = E/I, I won't be able to make a measurement, so the cat will
> be both dead and alive.
You seem to grasp that so well. You can certainly measure 0V and 0A, but
you can't determine R. For what reason do not grasp the analogy that 0/0
represents the same condition in mathematics?
Cheers
Michael
--
Still an attentive ear he lent Her speech hath caused this pain
But could not fathom what she meant Easier I count it to explain
She was not deep, nor eloquent. The jargon of the howling main
-- from Lewis Carroll: The Three Usenet Trolls
------------------------------
Date: Wed, 29 Dec 2004 13:19:09 +0100
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: Leak in Win32::ChangeNotify? [solved]
Message-Id: <41d2a0bd$0$786$bb690d87@news.main-rheiner.de>
Thomas Kratz wrote:
> === code start ===
> use strict;
> use warnings;
>
> $| = 1;
>
> use File::Spec::Functions qw/catfile/;
> use Win32::ChangeNotify;
>
> my $dir = 'd:/tmp/perl/chng';
> my $notify_fn = catfile($dir, 'bla.txt');
>
> my $last = 0;
> my $notify = Win32::ChangeNotify->new($dir, 0, 'LAST_WRITE');
> die 'cannot create notify object'
> unless ref($notify) eq 'Win32::ChangeNotify';
>
> while ( 1 ) {
>
> my $rc = $notify->wait(100);
> $notify->reset();
>
> last if $rc == -1;
>
> my @stat = stat($notify_fn);
>
> if ( $rc == 1 and $stat[9] > $last ) {
>
> print "$notify_fn has changed\n";
>
> $last = $stat[9];
> }
> }
> === code end ===
The problem was calling reset on the object even if there was no signalled
change event. Moving the "$notify->reset();" to the end of the "if ( $rc
== 1..." block, ended the leaking.
After looking at the XS code, it was clear that I used the module the
wrong way. Each call to reset() causes a Win32 API call to
FindNextChangeNotification and that only makes sense if the last Find was
successful.
So: no bug, wrong usage!
Thomas
--
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-
------------------------------
Date: Wed, 29 Dec 2004 11:15:21 +0100
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: Leak in Win32::ChangeNotify?
Message-Id: <41d283b9$0$782$bb690d87@news.main-rheiner.de>
Matt Garrish wrote:
>
> Strange. The first time I ran the script the nonpaged memory slowly grew
> (nothing like what you describe, though). I let it run up from ~10100K to
> ~11500K before killing script (at which point it dropped right back to where
> it started), but on subsequent restarts could not get the script to leak
> again (it stayed steady at ~10100 no matter what I did to the file).
>
> This was on XP Pro using v5.8.2.
Do you really mean 10100KB. The value should be about 1-2K. 10MB of
nonpaged memory is way too much.
I get the same results as yesterday on various machines. The strange thing
is, that after the second modification of the file it will take some time
before the nonepaged pool usage freaks out.
I think I will have a look into the xs code of Win32::ChangeNotify and
Win32::IPC on the weekend. Perhaps I'll get an idea, what could go wrong here.
Always creating a new object works fine as a workaround, so there is no
urgent need for a fix.
Thomas
--
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-
------------------------------
Date: Wed, 29 Dec 2004 04:31:21 -0500
From: "Roll" <lie_huo@hotmail.com>
Subject: Re: need help in programming linux with perl
Message-Id: <c8efe6d5cba466331b7c088f6128821e@localhost.talkaboutprogramming.com>
which is the script or file that i should be looking at as in what is the
file name and where is it located?
------------------------------
Date: Wed, 29 Dec 2004 12:39:08 +0000
From: Henry Law <lawshouse.public@btconnect.com>
Subject: Re: need help in programming linux with perl
Message-Id: <7395t05pocm7egedd6gnq7m9q8f07qha2e@4ax.com>
On Wed, 29 Dec 2004 04:31:21 -0500, "Roll" <lie_huo@hotmail.com>
wrote:
>which is the script or file that i should be looking at as in what is the
>file name and where is it located?
What people are suggesting is that you download webmin - the URL is
back in the thread somewhere - and look at it to find out what it does
and how it does it. This is a standard way programmers use to educate
themselves and I very much doubt you'll find anyone in this group who
will do it for you.
The best way to go about it is to find out - from the installation
documentation if it isn't obvious - which command invokes webmin (it
will probably be called "webmin"!) and find out which other programs
it calls to do various things. There should be comments and variables
with significant names that will help you.
After you've tried that if you're still stuck on some aspect of Perl
then post here saying what you've done and what you need help with and
you'll probably get it. Just don't ask people to do your work for
you.
--
Henry Law <>< Manchester, England
------------------------------
Date: Wed, 29 Dec 2004 03:41:07 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: save & restore cursor position in perl
Message-Id: <zKWdnbM5NvJLCk_cRVn-qw@comcast.com>
someone92 wrote:
> I'm trying to save and restore the current position of the console's
> cursor in perl on FreeBSD 4.10 using the escape sequences without
> success, FreeBSD do not seems to support it.
>
> sub savecursorpos { print "\x1B7m"; }
> sub restorecusorpos { print "\x1B8m"; }
That should be "\x1B7" and "\x1B8" (no "m" here).
Don't forget "\x1B[6n". http://www.inwap.com/pdp10/ansicode.txt
The `resize` program uses those escape sequences.
linux% script
Script started, file is typescript
% /usr/X11R6/bin/resize
% exit
linux% od -d typescript
------------------------------
Date: 28 Dec 2004 21:24:38 -0800
From: "justin.harper" <justin.harper@gmail.com>
Subject: Simple question - setting up services
Message-Id: <1104297878.377281.319460@f14g2000cwb.googlegroups.com>
I am trying to set up postfix using smtpprox as a proxy that will later
include a content filter, and it's working really well for me. The
only problem I'm having is that I'm new to linux, and I'm not totally
sure how I can start it so that it runs in the background like a
service. Right now, smtpprox is a perl script, so what I'm doing is
starting postfix and then running 'smtpprox localhost:10025
localhost:10026' from the shell. The only problem is, when I launch it
this way, it locks up the shell (i.e. just the command, and then
nothing until I ctrl-c...but I know it's working because the email is
working fine when I run it this way). I was hoping that you could
please let me know what a better way to start it to run in the
background would be. Thanks for your help! For anyone not familiar
with smtpprox, I'll copy the script below.
#!/usr/bin/perl -w
#
# This code is Copyright (C) 2001 Morgan Stanley Dean Witter, and
# is distributed according to the terms of the GNU Public License
# as found at <URL:http://www.fsf.org/copyleft/gpl.html>.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# Written by Bennett Todd <bet@rahul.net>
use strict;
use Getopt::Long;
use IO::File;
use lib '.';
use MSDW::SMTP::Server;
use MSDW::SMTP::Client;
=head1 NAME
smtprox -- Transparent SMTP proxy
=head1 SYNOPSIS
smtpprox [options] listen.addr:port talk.addr:port
options:
--children=16
--minperchild=100
--maxperchild=200
--debugtrace=filename_prefix
=head1 DESCRIPTION
smtpprox listens on the addr and port specified by its first arg,
and sends the traffic unmodified to the SMTP server whose addr and
port are listed as its second arg. The SMTP dialogue is propogated
literally, all commands from the client are copied to the server and
the responses from the server are copied back from to the client,
but the envelope info and message bodies are captured for analysis,
and code has the option of modifying the body before sending it on,
manipulating the envelope, or intervening in the SMTP dialogue to
reject senders, recipients, or content at the SMTP level. The
children option, defaulting to 16, allows adjusting how many child
processes will be maintained in the service pool. Each child will
kill itself after servicing some random number of messages between
minperchild and maxperchild (100-200 default), after which the
parent will immediately fork another child to pick up its share of
the load. If debugtrace is specified, the prefix will have the PID
appended to it for a separate logfile for each child, which will
capture all the SMTP dialogues that child services. It looks like a
snooper on the client side of the proxy. And if debugtracefile is
defined, it returns its own banner including its PID for debugging
at startup, otherwise it copies the server's banner back to the
client transparently.
=head1 EXAMPLE
smtpprox 127.0.0.1:10025 127.0.0.1:10026
=head1 WARNING
While the richness or lack thereof in the SMTP dialect spoken lies
in the hands of the next SMTP server down the chain, this proxy was
not designed to run on the front lines listening for traffic from
the internet; neither its performance characteristics nor its
paranoia were tuned for that role. Rather, it's designed as an
intermediate component, suitable for use as the framework for a
content-scanning proxy for use with Postfix's content-filtering
hooks.
=head1 PERFORMANCE NOTES
This proxy is tuned to some specific assumptions: execing perl is
wickedly expensive, forking perl is fairly expensive, messages will
vary rather widely in size, and memory footprint efficiency is
somewhat more important than CPU utilization. It uses Apache-style
preforking to almost entirely eliminate the need to fork perls,
with controlled child restart to defend against resource leaks in
children; it stores the body of the message in an unlinked file
under /tmp, which should be a tmpfs; this prevents the allocation
overhead associated with large strings (often 2-3x) and ensures that
space will be returned to the OS as soon as it's not needed.
=cut
my $syntax = "syntax: $0 [--children=16] [--minperchild=100] ".
"[--maxperchild=200] [--debugtrace=undef] ".
"listen.addr:port talk.addr:port\n";
my $children = 16;
my $minperchild = 100;
my $maxperchild = 200;
my $debugtrace = undef;
GetOptions("children=n" => \$children,
"minperchild=n" => \$minperchild,
"maxperchild=n" => \$maxperchild,
"debugtrace=s" => \$debugtrace) or die $syntax;
die $syntax unless @ARGV == 2;
my ($srcaddr, $srcport) = split /:/, $ARGV[0];
my ($dstaddr, $dstport) = split /:/, $ARGV[1];
die $syntax unless defined($srcport) and defined($dstport);
my $server = MSDW::SMTP::Server->new(interface => $srcaddr, port =>
$srcport);
# This should allow a kill on the parent to also blow away the
# children, I hope
my %children;
use vars qw($please_die);
$please_die = 0;
$SIG{TERM} = sub { $please_die = 1; };
# This block is the parent daemon, never does an accept, just herds
# a pool of children who accept and service connections, and
# occasionally kill themselves off
PARENT: while (1) {
while (scalar(keys %children) >= $children) {
my $child = wait;
delete $children{$child} if exists $children{$child};
if ($please_die) { kill 15, keys %children; exit 0; }
}
my $pid = fork;
die "$0: fork failed: $!\n" unless defined $pid;
last PARENT if $pid == 0;
$children{$pid} = 1;
select(undef, undef, undef, 0.1);
if ($please_die) { kill 15, keys %children; exit 0; }
}
# This block is a child service daemon. It inherited the bound
# socket created by SMTP::Server->new, it will service a random
# number of connection requests in [minperchild..maxperchild] then
# exit
my $lives = $minperchild + (rand($maxperchild - $minperchild));
my %opts;
if (defined $debugtrace) {
$opts{debug} = IO::File->new(">$debugtrace.$$");
$opts{debug}->autoflush(1);
}
while (1) {
$server->accept(%opts);
my $client = MSDW::SMTP::Client->new(interface => $dstaddr, port =>
$dstport);
my $banner = $client->hear;
$banner = "220 $debugtrace.$$" if defined $debugtrace;
$server->ok($banner);
while (my $what = $server->chat) {
if ($what eq '.') {
$client->yammer($server->{data});
} else {
$client->say($what);
}
$server->ok($client->hear);
}
$client = undef;
delete $server->{"s"};
exit 0 if $lives-- <= 0;
}
------------------------------
Date: 29 Dec 2004 08:28:15 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Simple question - setting up services
Message-Id: <slrnct4qku.an.abigail@alexandra.abigail.nl>
justin.harper (justin.harper@gmail.com) wrote on MMMMCXXXVIII September
MCMXCIII in <URL:news:1104297878.377281.319460@f14g2000cwb.googlegroups.com>:
{} I am trying to set up postfix using smtpprox as a proxy that will later
{} include a content filter, and it's working really well for me. The
{} only problem I'm having is that I'm new to linux, and I'm not totally
{} sure how I can start it so that it runs in the background like a
{} service. Right now, smtpprox is a perl script, so what I'm doing is
{} starting postfix and then running 'smtpprox localhost:10025
{} localhost:10026' from the shell. The only problem is, when I launch it
{} this way, it locks up the shell (i.e. just the command, and then
{} nothing until I ctrl-c...but I know it's working because the email is
{} working fine when I run it this way). I was hoping that you could
{} please let me know what a better way to start it to run in the
{} background would be. Thanks for your help! For anyone not familiar
{} with smtpprox, I'll copy the script below.
This is not a Perl question, but a Unix question, so I keep it brief.
If started by hand, do something like:
$ nohup smtpprox localhost:10025 localhost:10026 &
Or start it from the rc scripts. Many Linux vendors have utility to
start daemons. (For details, see your Linux distribution).
Abigail
--
my $qr = qr/^.+?(;).+?\1|;Just another Perl Hacker;|;.+$/;
$qr =~ s/$qr//g;
print $qr, "\n";
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 7591
***************************************