[Lcdproc] Problems with CF634 usb
Joris Robijn
joris@robijn.net
Sun May 27 12:00:02 2007
On 26 May 2007 at 20:25, Peter Marschall wrote:
> As it was before my time, would you mind to elaborate a bit on the
> differences (i.e. advantages) of the current code and a simple, dump
> daemon() ?
Usually you set everything up (open tcp port, get things going) and then
when it runs you fork. This gives two identical processes of which one is
terminated (the parent obviously).
It seems the hardware port access is not inherited by a child process, so
the child has to gain the hardware port access (and thus initialization
of the drivers) after forking. However, this makes a mess of the messages
on the console if things don't go as planned.
In C terms it looks like below (read the comments). This is from just
after the processing of cmdline settings and config file settings and
starting the (delayed) report system.
I have also had a quick glance on some other code in main.c but I can
also not find something critical that has changed. I guess we'll have to
find out why it does not always work and maybe we'll have to change the
way the "wave to parent" is implemented.
Joris
/* Now, go into daemon mode (if we should)...
* We wait for the child to report it is running OK. This
mechanism
* is used because forking after starting the drivers causes the
* child to loose the (LPT) port access. */
if (!foreground_mode) {
report(RPT_INFO, "Server forking to background");
CHAIN(e, parent_pid = daemonize());
} else {
output_GPL_notice();
report(RPT_INFO, "Server running in foreground");
}
install_signal_handlers(!foreground_mode);
/* Only catch SIGHUP if not in foreground mode */
/* Startup the subparts of the server */
CHAIN(e, sock_init(bind_addr, bind_port));
CHAIN(e, screenlist_init());
CHAIN(e, init_drivers());
CHAIN(e, clients_init());
CHAIN(e, input_init());
CHAIN(e, menuscreens_init());
CHAIN(e, server_screen_init());
CHAIN_END(e, "Critical error while initializing, abort.");
if (!foreground_mode) {
/* Tell to parent that startup went OK. */
wave_to_parent(parent_pid);
}
drop_privs(user); /* This can't be done before, because sending a
signal to a process of a different user will fail
*/
do_mainloop();
/* This loop never stops; we'll get out only with a signal...*/
return 0;
--
Joris Robijn <joris@robijn.net>
Mobile: +31 6 288 41 964