[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Passing File Descriptors?

Worky Workerson

3/19/2007 4:43:00 PM

Is there a ruby way to pass file descriptors to separate processes?
I'm thinking of interfacing with a C program, which uses the
SCM_RIGHTS cmsg over a unix-domain socket ... is this idiom
implemented in Ruby? How would I marshall an IO object into (and out
of) the integer file descriptor, or does this "just work"?

Thanks!
-Mike

17 Answers

Robert Klemme

3/19/2007 5:24:00 PM

0

On 19.03.2007 17:43, Worky Workerson wrote:
> Is there a ruby way to pass file descriptors to separate processes?
> I'm thinking of interfacing with a C program, which uses the
> SCM_RIGHTS cmsg over a unix-domain socket ... is this idiom
> implemented in Ruby? How would I marshall an IO object into (and out
> of) the integer file descriptor, or does this "just work"?

Untested: You can determine the descriptor id via io.fileno. The you
can pass that to the child process via main's args when you exec after
fork. Then the child should be able to reuse that descriptor.
Alternatively you can of course transport the descriptor id via an
environment variable.

Kind regards

robert

Gary Wright

3/19/2007 10:07:00 PM

0


On Mar 19, 2007, at 12:43 PM, Worky Workerson wrote:
> Is there a ruby way to pass file descriptors to separate processes?
> I'm thinking of interfacing with a C program, which uses the
> SCM_RIGHTS cmsg over a unix-domain socket ... is this idiom
> implemented in Ruby? How would I marshall an IO object into (and out
> of) the integer file descriptor, or does this "just work"?

After a little investigation, this turned out to be easier than
I thought. The following code was tested on Mac OS X with ruby 1.8.5.
There are three files below, don't cut and paste the whole thing:

socketpair.rb # example with parent/child

server.rb # example with unrelated processes
client.rb

Socketpair.rb and client.rb both take a single argument, the name
of the data file to open.

Start server.rb before running client.rb.

If you try this on something other than Mac OS X ruby 1.8.5, let us
know how it works.

Gary Wright


$ cat socketpair.rb
# Scenario 1: parent and child related via fork
require 'socket'

read, write = UNIXSocket.pair

puts "parent end: #{read.inspect}, #{read.fileno}"
puts "child end: #{write.inspect}, #{write.fileno}"

pid = fork {
file = File.open(ARGV[0])
puts "child is sending: #{file.inspect}/#{file.fileno} connected
to #{ARGV[0]}"
write.send_io(file)
exit
}

thefile = read.recv_io
puts "parent received: #{thefile.inspect}/#{thefile.fileno}, contents:"
puts thefile.read

# end of scenario 1

$ cat server.rb
require 'socket'

serv = UNIXServer.new("/tmp/server")
p "server listening for connections: #{serv.inspect}"

client = serv.accept
p "received connection: #{client.inspect}"

clientfile = client.recv_io
puts "parent received fd: #{clientfile.fileno}, contents:"

puts clientfile.read
# end of server.rb


$ cat client.rb
require 'socket'

server = UNIXSocket.new("/tmp/server")
puts "connected to : #{server.inspect}"

fd = File.open(ARGV[0])
puts "child is sending fd: #{fd.fileno} connected to #{ARGV[0]}"

server.send_io(fd) # we are *not* sending the data!

exit


Gary Wright

3/19/2007 10:17:00 PM

0


On Mar 19, 2007, at 12:43 PM, Worky Workerson wrote:

> Is there a ruby way to pass file descriptors to separate processes?
> I'm thinking of interfacing with a C program, which uses the
> SCM_RIGHTS cmsg over a unix-domain socket ... is this idiom
> implemented in Ruby? How would I marshall an IO object into (and out
> of) the integer file descriptor, or does this "just work"?

In case folks were looking for a use case.

A client makes a request to a server which opens the file
and sends the opened file descriptor back to the client.
Presumably the server process has special permissions to allow it
access to the files that the client doesn't have. The server
can also implement any additional security controls.

The client gets to read and write a file without having had
permission to open the file directly.

This only works via Unix Domain sockets and so it only
works between processes on the same machine. It won't work
across a network.

Gary Wright




Worky Workerson

3/20/2007 5:13:00 PM

0

On 3/19/07, Gary Wright <gwtmp01@mac.com> wrote:
>
> On Mar 19, 2007, at 12:43 PM, Worky Workerson wrote:
> > Is there a ruby way to pass file descriptors to separate processes?
> > I'm thinking of interfacing with a C program, which uses the
> > SCM_RIGHTS cmsg over a unix-domain socket ... is this idiom
> > implemented in Ruby? How would I marshall an IO object into (and out
> > of) the integer file descriptor, or does this "just work"?
>
> After a little investigation, this turned out to be easier than
> I thought.
...
> clientfile = client.recv_io
> puts "parent received fd: #{clientfile.fileno}, contents:"

Sweet, thanks! I guess I had missed the {send,recv}_io methods.
They're not in the Ruby book ... guess I should have done to the
online docs. Ruby does make this trivial ... even works with my
existing C program.

-Mike

BeamMeUpScotty

10/23/2013 1:34:00 PM

0

On 10/23/2013 3:46 AM, Winston_Smith wrote:
> On Tue, 22 Oct 2013 23:58:05 -0500, Jeff M wrote:
>> On 10/22/2013 11:16 PM, Winston_Smith wrote:
>
>>> As someone else here wrote at some length, they will have to process
>>> something like 110,000 people per day, every day, for the three months
>>> to get only 10 million of the 30-40 million people ObamaCare was
>>> designed to include. THAT, while possible, is going to be some doing.
>>> He has already given a years delay to everything but individuals.
>>>
>>> 10,000,000/90 days=110K. No matter how they interface, they have to
>>> get an account created in the ObamaPuter by hook or by crook.
>>
>> If Amazon can handle 300 sales per second, then, yes, I suppose it can
>> be done. But I'm sure not without many other glitches, problems and
>> delays cropping up.
>
> Excellent reference point. Leaving us to ponder why the proponents of
> ObamaCare thought it could go from zero to done in 3 months? In two
> languages. With calls to a dozen other systems for each ''sale''.
> Amazon started selling books only. The guy that started it envisioned
> an ''everything store'' but took it one step at a time.
>
> I suspect they anticipated extensive after passage attacks and blindly
> hoped the gods of goodness would come to their rescue. Once it's
> actually implemented it's a harder target.
>
The Liberals have the intelligence of a 6 year old child....

Reality scares them so they ignore it by closing their eyes.





JohnJohnsn

10/23/2013 3:51:00 PM

0

In article <grme6995v5d29lqiu29vndv6s8k5csbaen@4ax.com>,
the DNC quisling Sheila Bryant, posting as "GOP_Decline_and_Fall"
<Decepticon1@propagandists.dnc.org> says...
>
> On Tue, 22 Oct 2013 23:12:47 -0500, Johnny Johnson
> <TopCop1988@yahoo.com> wrote:
>
>> In article <32he691co3ap37ghsjn3f5fgu6db9f9kd6@4ax.com>, the
>> DNC quisling Sheila Bryant, posting as "GOP_Decline_and_Fall"
>> <Decepticon1@propagandists.dnc.org> says...
>>
>>> On Tue, 22 Oct 2013 16:39:07 -0500, Johnny Johnson
>>> <TopCop1988@yahoo.com> wrote:
>>>
>>>> In article <XnsA2617D3C5620BHopewell@216.196.121.131>,
>>>> RD Sandman says...
>>>>
>>>>> Winston_Smith <invalid@butterfly.net> wrote in
>>>>> news:o4ob69h7lbc2r977ftn0lfe4fj3upjmd61@4ax.com:
>>>>>
>>>>>> On Mon, 21 Oct 2013 13:23:13 -0500, Jeff M wrote:
>>>>>>
>>>>>>> On 10/21/2013 1:16 PM, Winston_Smith wrote:
>>>>>>>
>>>>>>>> On Sun, 20 Oct 2013 00:30:10 -0500, Jeff M wrote:
>>>>>>>>
>>>>>>>>> Yeah, my banks can't even keep my online accounts
>>>>>>>>> straight.
>>>>>>>>> But the problem isn't limited to the government.
>>>>>>>>> It is found in pretty much every large institution, banks,
>>>>>>>>> hospitals, insurance companies, universities, etc.
>>>>>>>>> I've seen such a screw-up bring down a very large
>>>>>>>>> medical center.
>>>>>>>>
>>>>>>>> Yet Ebay and Amazon manage to keep trudging along.
>>>>>>>> It seems there ARE programmers that can make it work.
>>>>>>>
>>>>>>> I believe the problems will be largely sorted out fairly soon,
>>>>>>> but that other problems will continue to occur from time to time,
>>>>>>> just a they do on EBay and Amazon.
>>>>>>
>>>>>> But it does say something about "we have to have them" institutions
>>>>>> vs. commerce where a lost sale is forever. Latter seems to have better
>>>>>> results. Being able to go out of business because of bad performance
>>>>>> is a great motivator.
>>>>>>
>>>>>>> In the meantime, people can still also sign up for insurance by
phone,
>>>>>>> mail, in person or through agents, just as they have always done.
>>>>>>
>>>>>> Obama did acknowledge the problem in a news conference today.
>>>>>> He's planning to bring in IT people from the commercial world to fix
>>>>>> it for him. To late he gets smart but at least he has a clue now.
>>>>>
>>>>> He is bringing in Verizon folks.
>>>>
>>>> ROTFL!
>>>>
>>>> Verizon is a UK-controlled (Vodaphone) company -- at least until next
>>>> year, when Cellco Partnership buys out Vodaphone's remaining Verizon
>>>> stock.
>>>>
>>>> Just checked: Cellco has bought down Vodaphone's interests since
>>>> I left there in 2010 -- they're now down to 45% control.
>>>>
>>>>>> Some states have as few as a half dozen people fully trained to walk
>>>>>> people though the choices. Training them has not gone as slick as
>>>>>> promised either. I suspect he never anticipated something like half
>>>>>> the states opting out and telling the feds to take care of it.
>>>>>>
>>>>>> You might be right but the list of choices I heard on NPR today did
>>>>>> not include mail. If I had to sign up, that's the choice I'd prefer.
>>>>
>>>> It was reported today that New York, which runs its own sign up program,
>>>> hasn't had anyone actually *buy* ObabaDoesn'tCare insurance yet.
>>>
>>> You just love posting nonsense don't you?
>>>
>>> 150,000 Sign Ups Under New York Obamacare Exchange
>>
>>"You stupid woman!"
>> -- Ren? Fran?ois Artois
>>
>> Did you moss the word "*buy*", Sheila?
>>
>> Signing up is *not* the same thing as buying.
>
> No but you clearly missed " "Thousands of New Yorkers have not only
> registered, but actually enrolled in and purchased insurance coverage
> through the NY State of Health website"
>
No, Sheila -- nor did I miss the included caveat:

"Officials will not say how many [purchased insurance coverage], and have
promised that number soon."

But apparently you choose to ignore it; `cause, in your eyes, "Obama Can Do
No Wrong" and anything and everything the Democrats put out is to be taken as
gospel --*unless* it doesn't fit *your* agenda.

And just *who* is the "official" putting out the propaganda for "the NY State
of Health website"?

Democratic Gov. Andrew Cuomo's appointee Donna Frescatore; who also stated:

"These [ACA insurance] plans and rates deliver on the promise that the
exchange will offer quality health insurance coverage at a price that works
for New Yorkers."

Looks like she has a biased reason to *lie* for Obama and Cuomo; doesn't she,
Sheila?

What's *your* reason, though?
>
>> according to the state Health Department.
>>
>> These systems are set up requiring anyone interested in *buying*
>> ObamaDoesn'tCare - The Abominable Care-less Act insurance *must*
>> sign up; providing all their information; *before* they are quoted prices.
>>
>> It's *after* receiving these inflated prices that the "signers-up" in have
>> decided "No Wayno" about shelling out the dinero to "*buy*" the crap.
>>>
>>>http://talkingpointsmemo.com/livewire/150-000-sign-ups-under...
obamacare-exchange
>>> October 22, 2013, 7:01 AM EDT5804
>>>
>>> Three weeks since the Affordable Care Act's Oct. 1 rollout, at least
>>> 150,000 people have successfully signed up for a health insurance plan
>>> using New York state's website, according to the Albany Times Union.
>>>
>>> "In less than three weeks since the launch of NY State of Health,
>>> already nearly 150,000 New Yorkers have signed up for quality, low-cost
>>> health insurance," said Donna Frescatore, executive director of the
>>> state online marketplace, in an emailed statement. "Thousands of
>>< New Yorkers have not only registered, but actually enrolled in and
>>> purchased insurance coverage through the NY State of Health website,
>>> according to the state Health Department. Officials will not say how
>>> many, and have promised that number soon."
>>>
>>"Talking Points Memo," eh, Sheila?
>>
>> Come back when you have something from the Lamestream media.
>
> The statement from the Executive Director is clear enough.
>
Which was "qualified" as to its truthfulness with:

"Officials will not say how many [purchased insurance coverage], and have
promised that number soon."
>
>> Moreover: "Officials will not say how many [purchased insurance coverage],
>> and have promised that number soon."
>>
>> Sounds like Jay Carnaly. <snicker> ;)
>>
>>> The website works just fine.
>>>
>>> https://nystateofheal...
>>>
>>>> Also:
>>>>
>>>> Big insurers avoid many state health exchanges
>>>> By Jayne O'Donnell and Annika McGinnis, USA TODAY
>>>> 4:29 p.m. EDT October 21, 2013
>>>> Some insurers pulled out of the exchanges required by the Affordable
>>>> Care Act as the Oct. 1 launch approached, leaving an uneven patchwork
>>>> of providers.
>>>>http://www.usatoday.com/story/news/nation/2013/10/20/little-co...
nsurers-some-states-obamacare-plans/2986795/
>>>
>>> Are we supposed to be sobbing for them because they can't compete?
>>
>> What makes you think "little insurers" can pay up when necessary?
>>
>> <Cough>"Death_Panels<Cough>
>
> That Palinesque garbage is a little passe don't you think?
>
Really, Sheila?

Then you believe that every single healthcare procedure from those "48
million {+/-) uninsured" who actually manage to *buy* ACA insurance will be
automatically paid?

"What a maroon, what an ignoranimus!
Will ya get a load of this Maroon"
--Bugs Bunny

Like I wrote earlier; come back when you have documentable *proof* that
"Thousands of New Yorkers have not only registered, but actually enrolled in
and purchased insurance coverage through the NY State of Health website."

And merely your restating DEMOCRAT Frescatore's *unsubstantiated* claims will
not stand as *evidence*.

Scout

10/23/2013 4:57:00 PM

0



"Steve Rothstein" <stephan_rothstein@hotmail.com> wrote in message
news:NMednUvyr60PufrPnZ2dnUVZ_hmdnZ2d@earthlink.com...
> On 10/21/2013 9:25 PM, Winston_Smith wrote:
>
>> Some states have as few as a half dozen people fully trained to walk
>> people though the choices. Training them has not gone as slick as
>> promised either. I suspect he never anticipated something like half
>> the states opting out and telling the feds to take care of it.
>
> This lack of planning might have been excused two or three years ago. I am
> sure when he planned the law he did not think states would even be able to
> opt out, but the time limit on that excuse ran out about a month after the
> SCOTUS ruled that states could tell him no.
>
> There is no excuse for his not planning on the feds having to run the
> exchanges since the states told him they would not do it more than two
> years ago. And there is no excuse for the lack of planning that said they
> could build a site that could only handle 50-60,000 people a day. After
> all, their own numbers said there were 30-40 million people without
> insurance in the US and the government required them all to buy insurance
> during a single three month period. I will grant that they might have
> thought a few would still refuse, a few would already have bought through
> other means, and a few would use the phone system instead of the internet.
> But, even if I give them a generous allowance for this and say they
> thought three quarters of the people who were uninsured would fall into
> those categories, that leaves 10,000,000 people who would have needed to
> sign up. Planning for as few as they did was just pure stupidity.
>
> Steve Rothstein

Heck, just run it on a commercial cloud server that will scale in real time
as needed based on the current demand.

Or, just coop the NSA's new server farm for a couple of months. Since they
can handle all electronic communications occurring the US, I bet handling a
couple of million users won't stress the system.


benj

10/23/2013 6:46:00 PM

0

On 10/23/2013 12:56 PM, Scout wrote:
>
>
> "Steve Rothstein" <stephan_rothstein@hotmail.com> wrote in message

>> There is no excuse for his not planning on the feds having to run the
>> exchanges since the states told him they would not do it more than two
>> years ago. And there is no excuse for the lack of planning that said
>> they could build a site that could only handle 50-60,000 people a day.
>> After all, their own numbers said there were 30-40 million people
>> without insurance in the US and the government required them all to
>> buy insurance during a single three month period. I will grant that
>> they might have thought a few would still refuse, a few would already
>> have bought through other means, and a few would use the phone system
>> instead of the internet. But, even if I give them a generous allowance
>> for this and say they thought three quarters of the people who were
>> uninsured would fall into those categories, that leaves 10,000,000
>> people who would have needed to sign up. Planning for as few as they
>> did was just pure stupidity.
>>
>> Steve Rothstein

"pure stupidity" and Democrat lefty liberals. I think you are on to
something here, Steve.

> Heck, just run it on a commercial cloud server that will scale in real
> time as needed based on the current demand.
>
> Or, just coop the NSA's new server farm for a couple of months. Since
> they can handle all electronic communications occurring the US, I bet
> handling a couple of million users won't stress the system.

<snort>

You said it Scout. Hey NSA grabbed all the phone calls in France without
missing a beat. Obamacare wouldn't even make the system breathe hard.


BeamMeUpScotty

10/23/2013 11:07:00 PM

0

On 10/23/2013 2:46 PM, benj wrote:
> On 10/23/2013 12:56 PM, Scout wrote:
>>
>>
>> "Steve Rothstein" <stephan_rothstein@hotmail.com> wrote in message
>
>>> There is no excuse for his not planning on the feds having to run the
>>> exchanges since the states told him they would not do it more than two
>>> years ago. And there is no excuse for the lack of planning that said
>>> they could build a site that could only handle 50-60,000 people a day.
>>> After all, their own numbers said there were 30-40 million people
>>> without insurance in the US and the government required them all to
>>> buy insurance during a single three month period. I will grant that
>>> they might have thought a few would still refuse, a few would already
>>> have bought through other means, and a few would use the phone system
>>> instead of the internet. But, even if I give them a generous allowance
>>> for this and say they thought three quarters of the people who were
>>> uninsured would fall into those categories, that leaves 10,000,000
>>> people who would have needed to sign up. Planning for as few as they
>>> did was just pure stupidity.
>>>
>>> Steve Rothstein
>
> "pure stupidity" and Democrat lefty liberals. I think you are on to
> something here, Steve.
>
>> Heck, just run it on a commercial cloud server that will scale in real
>> time as needed based on the current demand.
>>
>> Or, just coop the NSA's new server farm for a couple of months. Since
>> they can handle all electronic communications occurring the US, I bet
>> handling a couple of million users won't stress the system.
>
> <snort>
>
> You said it Scout. Hey NSA grabbed all the phone calls in France without
> missing a beat. Obamacare wouldn't even make the system breathe hard.
>
>
But it was bought and designed before Obama was out of diapers and they
weren't "all" Liberals doing it while saying they don't need anyone that
knows how to do it like ObamaCare was done.




GOP_Decline_and_Fall

10/25/2013 2:20:00 AM

0

On Tue, 22 Oct 2013 14:17:18 -0500, RD Sandman
<rdsandman[remove]comcast.net> wrote:

>GOP_Decline_and_Fall <Dev@null.net> wrote in
>news:mdmb69145j1jmefc7b9sh9aeanh381h3t2@4ax.com:
>
>> On Mon, 21 Oct 2013 13:04:28 -0500, RD Sandman
>> <rdsandman[remove]comcast.net> wrote:
>>
>>>Mighty Wannabe <MightyWannabe@NoReply.com> wrote in news:l4202j$vs7$2
>>>@speranza.aioe.org:
>>>
>>>> rbowman wrote:
>>>>> Jeff M wrote:
>>>>>
>>>>>> Yeah, my banks can't even keep my online accounts straight. But
>>>>>> the problem isn't limited to the government. It is found in
>>>>>> pretty much every large institution, banks, hospitals, insurance
>>>>>> companies, universities, etc. I've seen such a screw-up bring
>>>>>> down a very large medical center.
>>>>>>
>>>>>
>>>>> I'm lucky to have had very little to do with hospitals in my
>>>>> lifetime. However, I managed to schedule a little outpatient
>>>>> surgery with the hospital's switchover to a new computer system.
>>>>> Wasn't that ever fun.
>>>>>
>>>>
>>>> That kind of shit would never happens in Canada. I walk in and out
>>>> of doctor's office and hospitals without ever seeing the bills. They
>>>> file insurance claims to OHIP for every citizen's health related
>>>> services through a very efficient computer system.
>>>
>>>And if you pay taxes, you are paying for all that. If you don't pay
>>>taxes, you are a leach.
>>
>> Children, babies,invalids, housewives etc are "leaches" in your view?
>
>My point was that it was addressed to a specific individual which you
>should have been able to figure out if you knew what the thread was
>about. That person was Wannabe and Wannabe was talking about healthcare
>in Canada which he/she claimed was free and paid for by the government.
>All I said was that if he paid taxes for that it wasn't free and if he
>didn't he was a leach. I doubt he is a child, baby or invalid. That
>leaves housewife and if there is a housewife, there is usually a house
>husband.

Ah...you singular not plural ..ok.
>
>> That sounds more like Plimpton's disgusting nonsense than your usual
>> balanced view.
>
>It would probably look more like my view if you had been able to figure
>out what it was addressing. ;)

Probably

The board's signal/noise ratio currently is pretty poor.

>
>>>> The US is fast becoming a faled state. Bush's damage to the Republic
>>>> is immense. Pity. I weep for you.
>>>>
>>>> OHIP - Ontario Health Insurance Plan:
>>>> * http://en.wikipedia.org/wiki/Ontario_Health_Insu... *
>>>>
>>>>
>>>>
>>>>
>>