| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | When are socket handles inherited ? |
* Crossposted in OS2PROG
* Crossposted in OS2.PROG.GER
* Crossposted in OS2NET.PROGRAMMIERUNG.GER
======================================================================
* Forwarded von Thomas Seeling (2:244/1130.42)
* Area : emx
======================================================================
From: "Hans-Michael Stahl"
Sockets created with address family AF_UNIX disappear after a fork if the parent
does an exec but the child keeps listening to the socket. Is this intended
behaviour ?
The doc clearly says "socket handles are not inherited across exec and
spawn",
but I do a fork before and the doc says "Note that a process created by fork()
inherits the socket handles of its parent process".
Here's the code:
sock = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock < 0)
{
perror("socket");
goto fail_socket_setup;
}
memset(&sunaddr, 0, AF_UNIX_SIZE(sunaddr));
sunaddr.sun_family = AF_UNIX;
strncpy(sunaddr.sun_path, socket_name, sizeof(sunaddr.sun_path));
if (bind(sock, (struct sockaddr *)&sunaddr, AF_UNIX_SIZE(sunaddr)) < 0)
{
perror("bind");
close(sock);
goto fail_socket_setup;
}
if (listen(sock, 5) < 0)
{
perror("listen");
close(sock);
goto fail_socket_setup;
}
/* Everything ok so far, so permit forking. */
creation_failed = 0;
fail_socket_setup:
/* If not creation_failed, fork, and have the parent execute the command.
The child continues as the authentication agent. If creation failed,
don't fork the child and forget the socket */
if (creation_failed || fork() != 0)
{ /* Parent - execute the given command. */
if (!creation_failed)
{
sprintf(buf, "SSH_AUTHENTICATION_SOCKET=%s", socket_name);
putenv(buf);
}
/* >>>> under OS/2 execvp makes the socket disappear!
<<<<< */
execvp(av[1], av + 1);
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
perror(av[1]);
exit(1);
}
new_socket(AUTH_SOCKET, sock);
signal(SIGALRM, check_parent_exists);
....
(Please no comment on the style of the code - I did not write it -
I only try to port it to OS/2)
--- Hans Michael "Maik" Stahl ------------------------
--- Berlin ___&___
--- Germany ||| |||
=== http://www.snafu.de/~hmstahl/ ==================--
-------------
To unsubscribe send a message to majordomo{at}IAEhv.nl with in the body:
unsubscribe emx
Report serious problems at: emx-owner{at}.IAEhv.nl.
======================================================================
--- E3-32/1.11-32/2.51+
* Origin: Die TeX-Box +49-6034-930021 V.34 -930022 ISDN 24h (2:244/1130.42)SEEN-BY: 50/99 54/99 270/101 620/243 625/0 160 711/401 409 410 413 430 808 SEEN-BY: 711/809 934 955 712/311 407 505 506 517 623 624 704 713/317 800/1 @PATH: 244/1130 1634 24/888 396/1 270/101 712/624 711/808 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.