FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian Development

 
 
LinkBack Thread Tools
 
Old 07-19-2008, 05:35 PM
Stephen Gran
 
Default Clarification about bug #463538 is needed

This one time, at band camp, Sergei Golovan said:
> On 7/19/08, Martijn van Oosterhout <kleptog@gmail.com> wrote:
> >
> > Umm, if that patch fixes it (removing the TIOCSCTTY) then it seems to
> > me that the erlang-based service will instead exit when the user who
> > installed the server logs out. Evidently the services in erlang are
> > not properly disassociating themselves from the terminal and this
> > patch just makes it more obvious...
>
> Erlang does exactly the following when detaches from a terminal:
>
> if (start_detached) {
> int status = fork();
> if (status != 0)
> return 0;
> status = fork();
> if (status != 0)
> return 0;
>
> close(0);
> open("/dev/null", O_RDONLY);
> close(1);
> open("/dev/null", O_WRONLY);
> close(2);
> open("/dev/null", O_WRONLY);
> }
> {
> execv(emu, Eargsp); /* executing the main Erlang emulator */
> }
>
> Is this behavior incorrect?

I don't see setsid?
--
-----------------------------------------------------------------
| ,'`. Stephen Gran |
| : :' : sgran@debian.org |
| `. `' Debian user, admin, and developer |
| `- http://www.debian.org |
-----------------------------------------------------------------
 
Old 07-19-2008, 05:40 PM
Mike Hommey
 
Default Clarification about bug #463538 is needed

On Sat, Jul 19, 2008 at 09:28:03PM +0400, Sergei Golovan wrote:
> On 7/19/08, Martijn van Oosterhout <kleptog@gmail.com> wrote:
> >
> > Umm, if that patch fixes it (removing the TIOCSCTTY) then it seems to
> > me that the erlang-based service will instead exit when the user who
> > installed the server logs out. Evidently the services in erlang are
> > not properly disassociating themselves from the terminal and this
> > patch just makes it more obvious...
>
> Erlang does exactly the following when detaches from a terminal:
>
> if (start_detached) {
> int status = fork();
> if (status != 0)
> return 0;
> status = fork();
> if (status != 0)
> return 0;
>
> close(0);
> open("/dev/null", O_RDONLY);
> close(1);
> open("/dev/null", O_WRONLY);
> close(2);
> open("/dev/null", O_WRONLY);
> }
> {
> execv(emu, Eargsp); /* executing the main Erlang emulator */
> }
>
> Is this behavior incorrect?

It should also open /dev/tty and ioctl(fd, TIOCNOTTY, 0) on it.

Mike


--
To UNSUBSCRIBE, email to debian-devel-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 07-19-2008, 06:51 PM
Vincent Bernat
 
Default Clarification about bug #463538 is needed

OoO Pendant le repas du samedi 19 juillet 2008, vers 19:28, "Sergei
Golovan" <sgolovan@nes.ru> disait*:

> Erlang does exactly the following when detaches from a terminal:

> if (start_detached) {
> int status = fork();
> if (status != 0)
> return 0;
> status = fork();
> if (status != 0)
> return 0;

> close(0);
> open("/dev/null", O_RDONLY);
> close(1);
> open("/dev/null", O_WRONLY);
> close(2);
> open("/dev/null", O_WRONLY);
> }
> {
> execv(emu, Eargsp); /* executing the main Erlang emulator */
> }

> Is this behavior incorrect?

This can be replaced by a call to daemon() that just does the right
thing. For example, it misses chdir() and setsid().
--
BOFH excuse #372:
Forced to support NT servers; sysadmins quit.
 
Old 07-19-2008, 07:08 PM
Russ Allbery
 
Default Clarification about bug #463538 is needed

"Sergei Golovan" <sgolovan@nes.ru> writes:

> Erlang does exactly the following when detaches from a terminal:
>
> if (start_detached) {
> int status = fork();
> if (status != 0)
> return 0;
> status = fork();
> if (status != 0)
> return 0;
>
> close(0);
> open("/dev/null", O_RDONLY);
> close(1);
> open("/dev/null", O_WRONLY);
> close(2);
> open("/dev/null", O_WRONLY);
> }
> {
> execv(emu, Eargsp); /* executing the main Erlang emulator */
> }
>
> Is this behavior incorrect?

It's missing either setsid or ioctl("/dev/tty", TIOCNOTTY). The
semi-standard daemon() function does the right thing. Here's a public
domain replacement (which assumes you have an Autoconf probe for whether
setsid is available). It depends on a wrapper around standard system
headers, but I expect you get the idea and could fix that.

/* $Id: daemon.c 4022 2008-03-31 06:11:07Z rra $
*
* Replacement for a missing daemon.
*
* Provides the same functionality as the library function daemon for those
* systems that don't have it.
*
* Written by Russ Allbery <rra@stanford.edu>
* This work is hereby placed in the public domain by its author.
*/

#include <config.h>
#include <portable/system.h>

#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/stat.h>

int
daemon(int nochdir, int noclose)
{
int status, fd;

/*
* Fork and exit in the parent to disassociate from the current process
* group and become the leader of a new process group.
*/
status = fork();
if (status < 0)
return -1;
else if (status > 0)
_exit(0);

/*
* setsid() should take care of disassociating from the controlling
* terminal, and FreeBSD at least doesn't like TIOCNOTTY if you don't
* already have a controlling terminal. So only use the older TIOCNOTTY
* method if setsid() isn't available.
*/
#if HAVE_SETSID
if (setsid() < 0)
return -1;
#elif defined(TIOCNOTTY)
fd = open("/dev/tty", O_RDWR);
if (fd >= 0) {
if (ioctl(fd, TIOCNOTTY, NULL) < 0) {
status = errno;
close(fd);
errno = status;
return -1;
}
close(fd);
}
#endif /* defined(TIOCNOTTY) */

if (!nochdir && chdir("/") < 0)
return -1;

if (!noclose) {
fd = open("/dev/null", O_RDWR, 0);
if (fd < 0)
return -1;
else {
if (dup2(fd, STDIN_FILENO) < 0)
return -1;
if (dup2(fd, STDOUT_FILENO) < 0)
return -1;
if (dup2(fd, STDERR_FILENO) < 0)
return -1;
if (fd > 2)
close(fd);
}
}
return 0;
}

--
Russ Allbery (rra@debian.org) <http://www.eyrie.org/~eagle/>


--
To UNSUBSCRIBE, email to debian-devel-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 07-19-2008, 11:14 PM
Brian May
 
Default Clarification about bug #463538 is needed

Sergei Golovan wrote:

int status = fork();
if (status != 0)
return 0;
status = fork();
if (status != 0)
return 0;

Apart from what everyone else has said, I can't help put being slightly
puzzled that it calls fork two times. This just seems weird...


Or did I miss something?

Brian May


--
To UNSUBSCRIBE, email to debian-devel-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 07-19-2008, 11:26 PM
The Fungi
 
Default Clarification about bug #463538 is needed

On Sun, Jul 20, 2008 at 09:14:48AM +1000, Brian May wrote:
> Apart from what everyone else has said, I can't help put being slightly
> puzzled that it calls fork two times. This just seems weird...
>
> Or did I miss something?

See chapter 13 from "Advanced Programming in the UNIX Environment"
(ISBN 0201563177):

"Under System V–based systems, some people recommend calling fork
again at this point and having the parent terminate. The second
child continues as the daemon. This guarantees that the daemon is
not a session leader, which prevents it from acquiring a controlling
terminal under the System V rules (Section 9.6). Alternatively, to
avoid acquiring a controlling terminal, be sure to specify O_NOCTTY
whenever opening a terminal device."
--
{ IRL(Jeremy_Stanley); PGP(9E8DFF2E4F5995F8FEADDC5829ABF7441FB84657);
SMTP(fungi@yuggoth.org); IRC(fungi@irc.yuggoth.org#ccl); ICQ(114362511);
AIM(dreadazathoth); YAHOO(crawlingchaoslabs); FINGER(fungi@yuggoth.org);
MUD(fungi@katarsis.mudpy.org:6669); WWW(http://fungi.yuggoth.org/); }


--
To UNSUBSCRIBE, email to debian-devel-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 07-20-2008, 04:06 AM
"Sergei Golovan"
 
Default Clarification about bug #463538 is needed

On 7/19/08, Russ Allbery <rra@debian.org> wrote:
> It's missing either setsid or ioctl("/dev/tty", TIOCNOTTY). The
> semi-standard daemon() function does the right thing. Here's a public
> domain replacement (which assumes you have an Autoconf probe for whether
> setsid is available). It depends on a wrapper around standard system
> headers, but I expect you get the idea and could fix that.

Huge thanks to all of you who took your time to answer! Indeed if I
add a call to setsid() the services become starting and daemonizing
fine. So, it's really a bug in Erlang and I'm going to report it
upstream (together with fixing in current version in unstable and
eventually in testing).

--
Sergei Golovan


--
To UNSUBSCRIBE, email to debian-devel-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 

Thread Tools




All times are GMT. The time now is 07:53 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org