* Ada daemon
@ 2008-07-25 20:35 Thomas
2008-07-25 23:14 ` anon
2008-07-29 9:05 ` Jacob Sparre Andersen
0 siblings, 2 replies; 4+ messages in thread
From: Thomas @ 2008-07-25 20:35 UTC (permalink / raw)
Hey group,
My good friend Dwight and I are wondering about how to create a daemon
in Ada. So far we've only been able to locate this example:
http://www.pegasoft.ca/resources/boblap/16.html#16.26
which honestly looks both hideous and unpleasant, to us. Yes, it might
be because we're just a bunch of beginners, but still we were hoping for
a "prettier", more Ada like approach. This one seems to rely on a lot of
pragma import C stuff.
So, is this the only way to create a simple daemon, or can you point us
in other directions?
--
/Thomas L�cke
-- The major difference between a thing that might go wrong
-- and a thing that cannot possibly go wrong is that when a
-- thing that cannot possibly go wrong goes wrong it usually
-- turns out to be impossible to get at or repair.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Ada daemon
2008-07-25 20:35 Ada daemon Thomas
@ 2008-07-25 23:14 ` anon
2008-07-29 9:05 ` Jacob Sparre Andersen
1 sibling, 0 replies; 4+ messages in thread
From: anon @ 2008-07-25 23:14 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1507 bytes --]
Yes, it can hideous and unpleasant if you just use Gnat.Sockets and its
children only. Just take any Client/Server written in C and do a line to
line converting to the Ada corresponding routine.
Now, if you really want to get hurt and do it the GNAT Ada way. Try using
Cobra, in the Polyorb PCS package. And for a just simple messaging try the
MOM, or SOAP sub-system, also include in the Polyorb package.
Also, Polyorb does have examples that work for all protocols.
Now, you can find Polyorb source package on "libre.adacore.com" download
page. Just download, unpack and build the PCS system.
In <488a3916$0$15889$edfadb0f@dtext01.news.tele.dk>, Thomas <me@pancon.dk> writes:
>Hey group,
>
>My good friend Dwight and I are wondering about how to create a daemon
>in Ada. So far we've only been able to locate this example:
>
>http://www.pegasoft.ca/resources/boblap/16.html#16.26
>
>which honestly looks both hideous and unpleasant, to us. Yes, it might
>be because we're just a bunch of beginners, but still we were hoping for
>a "prettier", more Ada like approach. This one seems to rely on a lot of
>pragma import C stuff.
>
>So, is this the only way to create a simple daemon, or can you point us
>in other directions?
>
>--
>/Thomas L�cke
>
>-- The major difference between a thing that might go wrong
>-- and a thing that cannot possibly go wrong is that when a
>-- thing that cannot possibly go wrong goes wrong it usually
>-- turns out to be impossible to get at or repair.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Ada daemon
2008-07-25 20:35 Ada daemon Thomas
2008-07-25 23:14 ` anon
@ 2008-07-29 9:05 ` Jacob Sparre Andersen
2008-07-29 9:29 ` Thomas Locke
1 sibling, 1 reply; 4+ messages in thread
From: Jacob Sparre Andersen @ 2008-07-29 9:05 UTC (permalink / raw)
Thomas wrote:
> My good friend Dwight and I are wondering about how to create a daemon
> in Ada. So far we've only been able to locate this example:
>
> http://www.pegasoft.ca/resources/boblap/16.html#16.26
>
> which honestly looks both hideous and unpleasant, to us.
Systems programming isn't always beautiful. The trick is to notice
that almost all the code you see is actually a reusable library.
Also, several of the subprograms in the library do actually exist in
the POSIX packages, so there's no need to manually bind to the C
versions of the subprograms.
In practice the important part of daemonizing a process is to
disconnect Standard_Input, Standard_Output and Standard_Error. You
can do this with:
POSIX.IO.Close (File => POSIX.IO.Standard_Input);
POSIX.IO.Close (File => POSIX.IO.Standard_Output);
POSIX.IO.Close (File => POSIX.IO.Standard_Error);
> Yes, it might
> be because we're just a bunch of beginners, but still we were hoping for
> a "prettier", more Ada like approach. This one seems to rely on a lot of
> pragma import C stuff.
Using the POSIX standard packages definitely makes it prettier.
> So, is this the only way to create a simple daemon, or can you point us
> in other directions?
Here's an (untested) implementation of Daemonize using "pure" Ada:
with
POSIX.IO,
POSIX.Process_Environment,
POSIX.Process_Identification,
POSIX.Unsafe_Process_Primitives;
procedure Daemonize is
begin
POSIX.Process_Environment.Change_Working_Directory ("/");
for File in POSIX.IO.File_Descriptor'Range loop
if POSIX.IO.Is_Open (File) then
POSIX.IO.Close (File);
end if;
end loop;
case POSIX.Unsafe_Process_Primitives.Fork is
when -1 =>
POSIX.Process_Primitives.Exit_Process
(POSIX.Process_Primitives.Failed_Creation_Exit);
when 0 =>
declare
Session_Leader :
POSIX.Process_Identification.Process_Group_ID;
begin
POSIX.Process_Identification.Create_Session
(Session_Leader);
end;
when others =>
POSIX.Process_Primitives.Exit_Process;
end case;
end Daemonize;
On Debian you need to install the package "libflorist-dev", to have
access to the POSIX packages.
/Jacob
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-07-29 9:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-25 20:35 Ada daemon Thomas
2008-07-25 23:14 ` anon
2008-07-29 9:05 ` Jacob Sparre Andersen
2008-07-29 9:29 ` Thomas Locke
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox