2008-01-28 21:37:16 +00:00
|
|
|
/* source: xio-unix.c */
|
2014-03-26 11:48:27 +00:00
|
|
|
/* Copyright Gerhard Rieger */
|
2008-01-27 12:00:08 +00:00
|
|
|
/* Published under the GNU General Public License V.2, see file COPYING */
|
|
|
|
|
|
|
|
/* this file contains the source for opening addresses of UNIX socket type */
|
|
|
|
|
|
|
|
#include "xiosysincludes.h"
|
|
|
|
#include "xioopen.h"
|
|
|
|
|
|
|
|
#include "xio-socket.h"
|
|
|
|
#include "xio-listen.h"
|
|
|
|
#include "xio-unix.h"
|
|
|
|
#include "xio-named.h"
|
|
|
|
|
|
|
|
|
|
|
|
#if WITH_UNIX
|
|
|
|
|
2008-08-24 09:04:08 +00:00
|
|
|
/* to avoid unneccessary "live" if () conditionals when no abstract support is
|
|
|
|
compiled in (or at least to give optimizing compilers a good chance) we need
|
|
|
|
a constant that can be used in C expressions */
|
2008-01-27 12:00:08 +00:00
|
|
|
#if WITH_ABSTRACT_UNIXSOCKET
|
2008-08-24 09:04:08 +00:00
|
|
|
# define ABSTRACT 1
|
|
|
|
#else
|
|
|
|
# define ABSTRACT 0
|
|
|
|
#endif
|
|
|
|
static int xioopen_unix_connect(int argc, const char *argv[], struct opt *opts, int xioflags, xiofile_t *xxfd, unsigned groups, int abstract, int dummy2, int dummy3);
|
|
|
|
static int xioopen_unix_listen(int argc, const char *argv[], struct opt *opts, int xioflags, xiofile_t *xxfd, unsigned groups, int abstract, int dummy2, int dummy3);
|
|
|
|
static int xioopen_unix_sendto(int argc, const char *argv[], struct opt *opts, int xioflags, xiofile_t *xxfd, unsigned groups, int abstract, int dummy2, int dummy3);
|
|
|
|
static int xioopen_unix_recvfrom(int argc, const char *argv[], struct opt *opts, int xioflags, xiofile_t *xxfd, unsigned groups, int abstract, int dummy2, int dummy3);
|
2008-01-27 12:00:08 +00:00
|
|
|
static
|
2008-08-24 09:04:08 +00:00
|
|
|
int xioopen_unix_recv(int argc, const char *argv[], struct opt *opts,
|
|
|
|
int xioflags, xiofile_t *xxfd, unsigned groups,
|
|
|
|
int abstract, int dummy2, int dummy3);
|
2008-01-27 12:00:08 +00:00
|
|
|
static
|
2008-08-24 09:04:08 +00:00
|
|
|
int xioopen_unix_client(int argc, const char *argv[], struct opt *opts, int xioflags, xiofile_t *xxfd, unsigned groups, int abstract, int dummy2, int dummy3);
|
2008-01-27 12:00:08 +00:00
|
|
|
|
2008-08-24 09:04:08 +00:00
|
|
|
/* the first free parameter is 0 for "normal" unix domain sockets, or 1 for
|
2008-10-22 00:33:23 +00:00
|
|
|
abstract unix sockets (Linux); the second and third parameters are unsused */
|
|
|
|
static const struct xioaddr_endpoint_desc xioendpoint_unix_connect1 = { XIOADDR_SYS, "unix-connect", 1, XIOBIT_ALL, GROUP_FD|GROUP_NAMED|GROUP_SOCKET|GROUP_SOCK_UNIX|GROUP_RETRY, XIOSHUT_DOWN, XIOCLOSE_CLOSE, xioopen_unix_connect, 0, 0, 0 HELP(":<filename>") };
|
2008-02-17 13:59:16 +00:00
|
|
|
const union xioaddr_desc *xioaddrs_unix_connect[] = { (union xioaddr_desc *)&xioendpoint_unix_connect1, NULL };
|
2008-10-22 00:33:23 +00:00
|
|
|
|
2008-01-27 12:00:08 +00:00
|
|
|
#if WITH_LISTEN
|
2008-10-22 00:33:23 +00:00
|
|
|
static const struct xioaddr_endpoint_desc xioendpoint_unix_listen1 = { XIOADDR_SYS, "unix-listen", 1, XIOBIT_ALL, GROUP_FD|GROUP_NAMED|GROUP_SOCKET|GROUP_SOCK_UNIX|GROUP_LISTEN|GROUP_CHILD|GROUP_RETRY, XIOSHUT_DOWN, XIOCLOSE_CLOSE, xioopen_unix_listen, 0, 0, 0 HELP(":<filename>") };
|
2008-02-17 13:59:16 +00:00
|
|
|
const union xioaddr_desc *xioaddrs_unix_listen[] = { (union xioaddr_desc *)&xioendpoint_unix_listen1, NULL };
|
2008-01-27 12:00:08 +00:00
|
|
|
#endif /* WITH_LISTEN */
|
2008-10-22 00:33:23 +00:00
|
|
|
|
|
|
|
static const struct xioaddr_endpoint_desc xioendpoint_unix_sendto1 = { XIOADDR_SYS, "unix-sendto", 1, XIOBIT_WRONLY|XIOBIT_RDWR, GROUP_FD|GROUP_NAMED|GROUP_SOCKET|GROUP_SOCK_UNIX|GROUP_RETRY, XIOSHUT_DOWN, XIOCLOSE_CLOSE, xioopen_unix_sendto, 0, 0, 0 HELP(":<filename>") };
|
2008-02-17 13:59:16 +00:00
|
|
|
const union xioaddr_desc *xioaddrs_unix_sendto[] = { (union xioaddr_desc *)&xioendpoint_unix_sendto1, NULL };
|
2008-10-22 00:33:23 +00:00
|
|
|
|
|
|
|
static const struct xioaddr_endpoint_desc xioendpoint_unix_recvfrom1= { XIOADDR_SYS, "unix-recvfrom",1, XIOBIT_RDONLY|XIOBIT_RDWR, GROUP_FD|GROUP_NAMED|GROUP_SOCKET|GROUP_SOCK_UNIX|GROUP_RETRY|GROUP_CHILD, XIOSHUT_DOWN, XIOCLOSE_NONE, xioopen_unix_recvfrom, 0, 0, 0 HELP(":<filename>") };
|
2008-02-17 13:59:16 +00:00
|
|
|
const union xioaddr_desc *xioaddrs_unix_recvfrom[]= { (union xioaddr_desc *)&xioendpoint_unix_recvfrom1, NULL };
|
2008-10-22 00:33:23 +00:00
|
|
|
|
|
|
|
static const struct xioaddr_endpoint_desc xioendpoint_unix_recv1 = { XIOADDR_SYS, "unix-recv", 1, XIOBIT_RDONLY, GROUP_FD|GROUP_NAMED|GROUP_SOCKET|GROUP_SOCK_UNIX|GROUP_RETRY, XIOSHUT_DOWN, XIOCLOSE_NONE, xioopen_unix_recv, 0, 0, 0 HELP(":<filename>") };
|
2008-02-17 13:59:16 +00:00
|
|
|
const union xioaddr_desc *xioaddrs_unix_recv[] = { (union xioaddr_desc *)&xioendpoint_unix_recv1, NULL };
|
2008-10-22 00:33:23 +00:00
|
|
|
|
|
|
|
static const struct xioaddr_endpoint_desc xioendpoint_unix_client1 = { XIOADDR_SYS, "unix-client", 1, XIOBIT_ALL, GROUP_FD|GROUP_NAMED|GROUP_SOCKET|GROUP_SOCK_UNIX|GROUP_RETRY, XIOSHUT_DOWN, XIOCLOSE_CLOSE, xioopen_unix_client, 0, 0, 0 HELP(":<filename>") };
|
2008-02-17 13:59:16 +00:00
|
|
|
const union xioaddr_desc *xioaddrs_unix_client[] = { (union xioaddr_desc *)&xioendpoint_unix_client1, NULL };
|
|
|
|
|
2008-01-27 12:00:08 +00:00
|
|
|
#if WITH_ABSTRACT_UNIXSOCKET
|
2008-10-22 00:33:23 +00:00
|
|
|
static const struct xioaddr_endpoint_desc xioendpoint_abstract_connect1 = { XIOADDR_SYS, "abstract-connect", 1, XIOBIT_ALL, GROUP_FD|GROUP_SOCKET|GROUP_SOCK_UNIX|GROUP_RETRY, XIOSHUT_DOWN, XIOCLOSE_CLOSE, xioopen_unix_connect, 1, 0, 0 HELP(":<filename>") };
|
2008-02-17 13:59:16 +00:00
|
|
|
const union xioaddr_desc *xioaddrs_abstract_connect[] = { (union xioaddr_desc *)&xioendpoint_abstract_connect1, NULL };
|
2008-01-27 12:00:08 +00:00
|
|
|
#if WITH_LISTEN
|
2008-10-22 00:33:23 +00:00
|
|
|
static const struct xioaddr_endpoint_desc xioendpoint_abstract_listen1 = { XIOADDR_SYS, "abstract-listen", 1, XIOBIT_ALL, GROUP_FD|GROUP_SOCKET|GROUP_SOCK_UNIX|GROUP_LISTEN|GROUP_CHILD|GROUP_RETRY, XIOSHUT_DOWN, XIOCLOSE_CLOSE, xioopen_unix_listen, 1, 0, 0 HELP(":<filename>") };
|
2008-02-17 13:59:16 +00:00
|
|
|
const union xioaddr_desc *xioaddrs_abstract_listen[] = { (union xioaddr_desc *)&xioendpoint_abstract_listen1, NULL };
|
2008-01-27 12:00:08 +00:00
|
|
|
#endif /* WITH_LISTEN */
|
2008-10-22 00:33:23 +00:00
|
|
|
static const struct xioaddr_endpoint_desc xioendpoint_abstract_sendto1 = { XIOADDR_SYS, "abstract-sendto", 1, XIOBIT_WRONLY|XIOBIT_RDWR, GROUP_FD|GROUP_SOCKET|GROUP_SOCK_UNIX|GROUP_RETRY, XIOSHUT_DOWN, XIOCLOSE_CLOSE, xioopen_unix_sendto, 1, 0, 0 HELP(":<filename>") };
|
2008-02-17 13:59:16 +00:00
|
|
|
const union xioaddr_desc *xioaddrs_abstract_sendto[] = { (union xioaddr_desc *)&xioendpoint_abstract_sendto1, NULL };
|
2008-10-22 00:33:23 +00:00
|
|
|
static const struct xioaddr_endpoint_desc xioendpoint_abstract_recvfrom1= { XIOADDR_SYS, "abstract-recvfrom", 1, XIOBIT_RDONLY|XIOBIT_RDWR, GROUP_FD|GROUP_SOCKET|GROUP_SOCK_UNIX|GROUP_RETRY|GROUP_CHILD, XIOSHUT_DOWN, XIOCLOSE_NONE, xioopen_unix_recvfrom, 1, 0, 0 HELP(":<filename>") };
|
2008-02-17 13:59:16 +00:00
|
|
|
const union xioaddr_desc *xioaddrs_abstract_recvfrom[] = { (union xioaddr_desc *)&xioendpoint_abstract_recvfrom1, NULL };
|
2008-10-22 00:33:23 +00:00
|
|
|
static const struct xioaddr_endpoint_desc xioendpoint_abstract_recv1 = { XIOADDR_SYS, "abstract-recv", 1, XIOBIT_RDONLY, GROUP_FD|GROUP_SOCKET|GROUP_SOCK_UNIX|GROUP_RETRY, XIOSHUT_DOWN, XIOCLOSE_NONE, xioopen_unix_recv, 1, 0, 0 HELP(":<filename>") };
|
2008-02-17 13:59:16 +00:00
|
|
|
const union xioaddr_desc *xioaddrs_abstract_recv[] = { (union xioaddr_desc *)&xioendpoint_abstract_recv1, NULL };
|
2008-10-22 00:33:23 +00:00
|
|
|
static const struct xioaddr_endpoint_desc xioendpoint_abstract_client1 = { XIOADDR_SYS, "abstract-client", 1, XIOBIT_ALL, GROUP_FD|GROUP_SOCKET|GROUP_SOCK_UNIX|GROUP_RETRY, XIOSHUT_DOWN, XIOCLOSE_CLOSE, xioopen_unix_client, 1, 0, 0 HELP(":<filename>") };
|
2008-02-17 13:59:16 +00:00
|
|
|
const union xioaddr_desc *xioaddrs_abstract_client[] = { (union xioaddr_desc *)&xioendpoint_abstract_client1, NULL };
|
2008-01-27 12:00:08 +00:00
|
|
|
#endif /* WITH_ABSTRACT_UNIXSOCKET */
|
|
|
|
|
2015-03-31 16:21:45 +00:00
|
|
|
const struct optdesc xioopt_unix_tightsocklen = { "unix-tightsocklen", "tightsocklen", OPT_UNIX_TIGHTSOCKLEN, GROUP_SOCK_UNIX, PH_PREBIND, TYPE_BOOL, OFUNC_OFFSET, XIO_OFFSETOF(para.socket.un.tight), XIO_SIZEOF(para.socket.un.tight) };
|
2008-01-27 12:00:08 +00:00
|
|
|
|
|
|
|
|
2008-08-24 09:04:08 +00:00
|
|
|
/* fills the socket address struct and returns its effective length.
|
|
|
|
abstract is usually 0; != 0 generates an abstract socket address on Linux.
|
2008-09-20 21:47:06 +00:00
|
|
|
tight!=0 calculates the resulting length from the path length, not from the
|
2015-03-31 16:21:45 +00:00
|
|
|
structures length; this is more common (see option unix-tightsocklen)
|
2008-09-20 21:47:06 +00:00
|
|
|
the struct need not be initialized when calling this function.
|
2008-08-24 09:04:08 +00:00
|
|
|
*/
|
2008-01-27 12:00:08 +00:00
|
|
|
socklen_t
|
2008-09-20 21:47:06 +00:00
|
|
|
xiosetunix(int pf,
|
|
|
|
struct sockaddr_un *saun,
|
2008-01-27 12:00:08 +00:00
|
|
|
const char *path,
|
|
|
|
bool abstract,
|
|
|
|
bool tight) {
|
|
|
|
size_t pathlen;
|
|
|
|
socklen_t len;
|
|
|
|
|
2008-09-20 21:47:06 +00:00
|
|
|
socket_un_init(saun);
|
2008-08-24 09:04:08 +00:00
|
|
|
#ifdef WITH_ABSTRACT_UNIXSOCKET
|
|
|
|
if (abstract) {
|
2008-01-27 12:00:08 +00:00
|
|
|
if ((pathlen = strlen(path)) >= sizeof(saun->sun_path)) {
|
|
|
|
Warn2("socket address "F_Zu" characters long, truncating to "F_Zu"",
|
|
|
|
pathlen+1, sizeof(saun->sun_path));
|
|
|
|
}
|
|
|
|
saun->sun_path[0] = '\0'; /* so it's abstract */
|
2014-03-26 11:48:27 +00:00
|
|
|
strncpy(saun->sun_path+1, path, sizeof(saun->sun_path)-1); /* ok */
|
2008-01-27 12:00:08 +00:00
|
|
|
if (tight) {
|
|
|
|
len = sizeof(struct sockaddr_un)-sizeof(saun->sun_path)+
|
|
|
|
MIN(pathlen+1, sizeof(saun->sun_path));
|
2008-09-14 16:33:28 +00:00
|
|
|
#if HAVE_STRUCT_SOCKADDR_SALEN
|
|
|
|
saun->sun_len = len;
|
|
|
|
#endif
|
2008-01-27 12:00:08 +00:00
|
|
|
} else {
|
|
|
|
len = sizeof(struct sockaddr_un);
|
|
|
|
}
|
2008-08-24 09:04:08 +00:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
#endif /* WITH_ABSTRACT_UNIXSOCKET */
|
|
|
|
|
|
|
|
if ((pathlen = strlen(path)) > sizeof(saun->sun_path)) {
|
|
|
|
Warn2("unix socket address "F_Zu" characters long, truncating to "F_Zu"",
|
|
|
|
pathlen, sizeof(saun->sun_path));
|
|
|
|
}
|
2014-03-26 11:48:27 +00:00
|
|
|
strncpy(saun->sun_path, path, sizeof(saun->sun_path)); /* ok */
|
2008-08-24 09:04:08 +00:00
|
|
|
if (tight) {
|
|
|
|
len = sizeof(struct sockaddr_un)-sizeof(saun->sun_path)+
|
|
|
|
MIN(pathlen, sizeof(saun->sun_path));
|
2008-09-22 20:52:03 +00:00
|
|
|
#if HAVE_STRUCT_SOCKADDR_SALEN
|
|
|
|
saun->sun_len = len;
|
|
|
|
#endif
|
2008-08-24 09:04:08 +00:00
|
|
|
} else {
|
|
|
|
len = sizeof(struct sockaddr_un);
|
2008-01-27 12:00:08 +00:00
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if WITH_LISTEN
|
2008-08-24 09:04:08 +00:00
|
|
|
static int xioopen_unix_listen(int argc, const char *argv[], struct opt *opts, int xioflags, xiofile_t *xxfd, unsigned groups, int abstract, int dummy2, int dummy3) {
|
2008-01-27 12:00:08 +00:00
|
|
|
/* we expect the form: filename */
|
|
|
|
const char *name;
|
|
|
|
xiosingle_t *xfd = &xxfd->stream;
|
2008-08-24 09:04:08 +00:00
|
|
|
int pf = PF_UNIX;
|
|
|
|
int socktype = SOCK_STREAM;
|
|
|
|
int protocol = 0;
|
2008-01-27 12:00:08 +00:00
|
|
|
struct sockaddr_un us;
|
|
|
|
socklen_t uslen;
|
|
|
|
struct opt *opts0 = NULL;
|
2012-07-22 13:09:45 +00:00
|
|
|
pid_t pid = Getpid();
|
2008-01-27 12:00:08 +00:00
|
|
|
bool opt_unlink_early = false;
|
|
|
|
bool opt_unlink_close = true;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
if (argc != 2) {
|
|
|
|
Error2("%s: wrong number of parameters (%d instead of 1)",
|
|
|
|
argv[0], argc-1);
|
|
|
|
return STAT_NORETRY;
|
|
|
|
}
|
|
|
|
name = argv[1];
|
2015-03-31 16:21:45 +00:00
|
|
|
|
|
|
|
xfd->para.socket.un.tight = true;
|
2008-09-20 21:47:06 +00:00
|
|
|
retropt_socket_pf(opts, &pf);
|
2008-01-27 12:00:08 +00:00
|
|
|
|
2008-08-24 09:04:08 +00:00
|
|
|
if (!(ABSTRACT && abstract)) {
|
|
|
|
/* only for non abstract because abstract do not work in file system */
|
|
|
|
retropt_bool(opts, OPT_UNLINK_EARLY, &opt_unlink_early);
|
|
|
|
retropt_bool(opts, OPT_UNLINK_CLOSE, &opt_unlink_close);
|
2008-01-27 12:00:08 +00:00
|
|
|
}
|
|
|
|
|
2009-04-03 15:17:10 +00:00
|
|
|
if (applyopts_single(xfd, opts, PH_INIT) < 0) return STAT_NORETRY;
|
2008-01-27 12:00:08 +00:00
|
|
|
applyopts(-1, opts, PH_INIT);
|
2014-03-26 13:02:42 +00:00
|
|
|
applyopts_named(name, opts, PH_EARLY); /* umask! */
|
2015-03-31 16:21:45 +00:00
|
|
|
applyopts_offset(xfd, opts);
|
2008-01-27 12:00:08 +00:00
|
|
|
applyopts(-1, opts, PH_EARLY);
|
2015-03-31 16:21:45 +00:00
|
|
|
|
|
|
|
uslen = xiosetunix(pf, &us, name, abstract, xfd->para.socket.un.tight);
|
2008-01-27 12:00:08 +00:00
|
|
|
|
2008-08-24 09:04:08 +00:00
|
|
|
if (!(ABSTRACT && abstract)) {
|
|
|
|
if (opt_unlink_early) {
|
|
|
|
if (Unlink(name) < 0) {
|
|
|
|
if (errno == ENOENT) {
|
|
|
|
Warn2("unlink(\"%s\"): %s", name, strerror(errno));
|
|
|
|
} else {
|
|
|
|
Error2("unlink(\"%s\"): %s", name, strerror(errno));
|
|
|
|
}
|
2008-01-27 12:00:08 +00:00
|
|
|
}
|
2014-03-26 13:02:42 +00:00
|
|
|
} else {
|
|
|
|
struct stat buf;
|
|
|
|
if (Lstat(name, &buf) == 0) {
|
|
|
|
Error1("\"%s\" exists", name);
|
|
|
|
return STAT_RETRYLATER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (opt_unlink_close) {
|
|
|
|
if ((xfd->unlink_close = strdup(name)) == NULL) {
|
|
|
|
Error1("strdup(\"%s\"): out of memory", name);
|
|
|
|
}
|
|
|
|
xfd->opt_unlink_close = true;
|
2008-01-27 12:00:08 +00:00
|
|
|
}
|
|
|
|
|
2008-08-24 09:04:08 +00:00
|
|
|
/* trying to set user-early, perm-early etc. here is useless because
|
|
|
|
file system entry is available only past bind() call. */
|
|
|
|
}
|
2008-01-27 12:00:08 +00:00
|
|
|
|
|
|
|
opts0 = copyopts(opts, GROUP_ALL);
|
|
|
|
|
2014-03-26 13:02:42 +00:00
|
|
|
/* this may fork() */
|
2008-01-27 12:00:08 +00:00
|
|
|
if ((result =
|
|
|
|
xioopen_listen(xfd, xioflags,
|
|
|
|
(struct sockaddr *)&us, uslen,
|
2008-08-24 09:04:08 +00:00
|
|
|
opts, opts0, pf, socktype, protocol))
|
2008-01-27 12:00:08 +00:00
|
|
|
!= 0)
|
|
|
|
return result;
|
2012-07-22 13:09:45 +00:00
|
|
|
|
|
|
|
if (!(ABSTRACT && abstract)) {
|
|
|
|
if (opt_unlink_close) {
|
2014-03-26 13:02:42 +00:00
|
|
|
if (pid != Getpid()) {
|
|
|
|
/* in a child process - do not unlink-close here! */
|
|
|
|
xfd->opt_unlink_close = false;
|
2012-07-22 13:09:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-26 13:02:42 +00:00
|
|
|
|
2008-01-27 12:00:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* WITH_LISTEN */
|
|
|
|
|
|
|
|
|
2008-08-24 09:04:08 +00:00
|
|
|
static int xioopen_unix_connect(int argc, const char *argv[], struct opt *opts, int xioflags, xiofile_t *xxfd, unsigned groups, int abstract, int dummy2, int dummy3) {
|
2008-01-27 12:00:08 +00:00
|
|
|
/* we expect the form: filename */
|
|
|
|
const char *name;
|
|
|
|
struct single *xfd = &xxfd->stream;
|
2009-04-03 09:30:01 +00:00
|
|
|
int rw = (xioflags&XIO_ACCMODE);
|
2008-08-24 09:04:08 +00:00
|
|
|
int pf = PF_UNIX;
|
|
|
|
int socktype = SOCK_STREAM;
|
|
|
|
int protocol = 0;
|
2008-01-27 12:00:08 +00:00
|
|
|
struct sockaddr_un them, us;
|
2015-03-31 16:21:45 +00:00
|
|
|
socklen_t themlen, uslen = sizeof(us);
|
2008-01-27 12:00:08 +00:00
|
|
|
bool needbind = false;
|
|
|
|
bool opt_unlink_close = false;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
if (argc != 2) {
|
|
|
|
Error2("%s: wrong number of parameters (%d instead of 1)",
|
|
|
|
argv[0], argc-1);
|
|
|
|
return STAT_NORETRY;
|
|
|
|
}
|
|
|
|
|
|
|
|
name = argv[1];
|
2015-03-31 16:21:45 +00:00
|
|
|
|
|
|
|
xfd->para.socket.un.tight = true;
|
2008-09-20 21:47:06 +00:00
|
|
|
retropt_socket_pf(opts, &pf);
|
2015-03-31 16:21:45 +00:00
|
|
|
xfd->howtoshut = XIOSHUT_DOWN;
|
|
|
|
if (applyopts_single(xfd, opts, PH_INIT) < 0) return STAT_NORETRY;
|
|
|
|
applyopts(-1, opts, PH_INIT);
|
|
|
|
applyopts_offset(xfd, opts);
|
|
|
|
applyopts(-1, opts, PH_EARLY);
|
|
|
|
|
|
|
|
themlen = xiosetunix(pf, &them, name, abstract, xfd->para.socket.un.tight);
|
2008-08-24 09:04:08 +00:00
|
|
|
if (!(ABSTRACT && abstract)) {
|
|
|
|
/* only for non abstract because abstract do not work in file system */
|
|
|
|
retropt_bool(opts, OPT_UNLINK_CLOSE, &opt_unlink_close);
|
|
|
|
}
|
2015-03-31 16:21:45 +00:00
|
|
|
if (retropt_bind(opts, pf, socktype, protocol, (struct sockaddr *)&us, &uslen,
|
|
|
|
(abstract<<1)|xfd->para.socket.un.tight, 0, 0) == STAT_OK) {
|
2008-01-27 12:00:08 +00:00
|
|
|
needbind = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opt_unlink_close) {
|
|
|
|
if ((xfd->unlink_close = strdup(name)) == NULL) {
|
|
|
|
Error1("strdup(\"%s\"): out of memory", name);
|
|
|
|
}
|
|
|
|
xfd->opt_unlink_close = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((result =
|
|
|
|
xioopen_connect(xfd,
|
|
|
|
needbind?(struct sockaddr *)&us:NULL, uslen,
|
|
|
|
(struct sockaddr *)&them, themlen,
|
2008-08-24 09:04:08 +00:00
|
|
|
opts, pf, socktype, protocol, false)) != 0) {
|
2008-01-27 12:00:08 +00:00
|
|
|
return result;
|
|
|
|
}
|
2009-04-03 09:30:01 +00:00
|
|
|
if (XIOWITHWR(rw)) xfd->wfd = xfd->rfd;
|
|
|
|
if (!XIOWITHRD(rw)) xfd->rfd = -1;
|
2008-01-27 12:00:08 +00:00
|
|
|
if ((result = _xio_openlate(xfd, opts)) < 0) {
|
|
|
|
return result;
|
|
|
|
}
|
2008-08-17 21:28:11 +00:00
|
|
|
return STAT_OK;
|
2008-01-27 12:00:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-03 09:30:01 +00:00
|
|
|
/*
|
|
|
|
returns the resulting FD in xfd->rfd, independend of xioflags
|
|
|
|
*/
|
2008-08-24 09:04:08 +00:00
|
|
|
static int xioopen_unix_sendto(int argc, const char *argv[], struct opt *opts, int xioflags, xiofile_t *xxfd, unsigned groups, int abstract, int dummy, int dummy3) {
|
|
|
|
/* we expect the form: filename */
|
2008-01-27 12:00:08 +00:00
|
|
|
const char *name;
|
|
|
|
xiosingle_t *xfd = &xxfd->stream;
|
2009-04-03 09:30:01 +00:00
|
|
|
int rw = (xioflags&XIO_ACCMODE);
|
2008-08-24 09:04:08 +00:00
|
|
|
int pf = PF_UNIX;
|
|
|
|
int socktype = SOCK_DGRAM;
|
|
|
|
int protocol = 0;
|
2008-01-27 12:00:08 +00:00
|
|
|
union sockaddr_union us;
|
2015-03-31 16:21:45 +00:00
|
|
|
socklen_t uslen = sizeof(us);
|
2008-01-27 12:00:08 +00:00
|
|
|
bool needbind = false;
|
|
|
|
bool opt_unlink_close = false;
|
2009-04-03 09:30:01 +00:00
|
|
|
int result;
|
2008-01-27 12:00:08 +00:00
|
|
|
|
|
|
|
if (argc != 2) {
|
|
|
|
Error2("%s: wrong number of parameters (%d instead of 1)",
|
|
|
|
argv[0], argc-1);
|
|
|
|
return STAT_NORETRY;
|
|
|
|
}
|
|
|
|
|
|
|
|
uslen = socket_init(pf, &us);
|
|
|
|
xfd->salen = socket_init(pf, &xfd->peersa);
|
|
|
|
|
|
|
|
retropt_int(opts, OPT_SO_TYPE, &socktype);
|
|
|
|
|
|
|
|
name = argv[1];
|
2015-03-31 16:21:45 +00:00
|
|
|
|
|
|
|
xfd->para.socket.un.tight = true;
|
2008-09-20 21:47:06 +00:00
|
|
|
retropt_socket_pf(opts, &pf);
|
2015-03-31 16:21:45 +00:00
|
|
|
applyopts_offset(xfd, opts);
|
|
|
|
|
|
|
|
xfd->salen = xiosetunix(pf, &xfd->peersa.un, name, abstract, xfd->para.socket.un.tight);
|
2008-01-27 12:00:08 +00:00
|
|
|
|
2008-08-24 09:04:08 +00:00
|
|
|
if (!(ABSTRACT && abstract)) {
|
|
|
|
/* only for non abstract because abstract do not work in file system */
|
|
|
|
retropt_bool(opts, OPT_UNLINK_CLOSE, &opt_unlink_close);
|
|
|
|
}
|
2008-01-27 12:00:08 +00:00
|
|
|
|
|
|
|
xfd->dtype = XIODATA_RECVFROM;
|
|
|
|
|
2015-03-31 16:21:45 +00:00
|
|
|
if (retropt_bind(opts, pf, socktype, protocol, &us.soa, &uslen,
|
|
|
|
(abstract<<1)| xfd->para.socket.un.tight, 0, 0) == STAT_OK) {
|
2008-01-27 12:00:08 +00:00
|
|
|
needbind = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opt_unlink_close) {
|
|
|
|
if ((xfd->unlink_close = strdup(name)) == NULL) {
|
|
|
|
Error1("strdup(\"%s\"): out of memory", name);
|
|
|
|
}
|
|
|
|
xfd->opt_unlink_close = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (applyopts_single(xfd, opts, PH_INIT) < 0) return -1;
|
2009-04-03 15:17:10 +00:00
|
|
|
applyopts(-1, opts, PH_INIT);
|
2008-01-27 12:00:08 +00:00
|
|
|
|
2009-04-03 09:30:01 +00:00
|
|
|
if ((result =
|
|
|
|
_xioopen_dgram_sendto(needbind?&us:NULL, uslen,
|
|
|
|
opts, xioflags, xfd, groups,
|
|
|
|
pf, socktype, protocol)) != STAT_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
if (XIOWITHWR(rw)) xfd->wfd = xfd->rfd;
|
|
|
|
if (!XIOWITHRD(rw)) xfd->rfd = -1;
|
|
|
|
return STAT_OK;
|
2008-01-27 12:00:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
int xioopen_unix_recvfrom(int argc, const char *argv[], struct opt *opts,
|
2008-08-24 09:04:08 +00:00
|
|
|
int xioflags, xiofile_t *xxfd, unsigned groups,
|
|
|
|
int abstract, int dummy2, int dummy3) {
|
|
|
|
/* we expect the form: filename */
|
2008-01-27 12:00:08 +00:00
|
|
|
const char *name;
|
2008-08-24 09:04:08 +00:00
|
|
|
xiosingle_t *xfd = &xxfd->stream;
|
|
|
|
int pf = PF_UNIX;
|
|
|
|
int socktype = SOCK_DGRAM;
|
|
|
|
int protocol = 0;
|
2008-01-27 12:00:08 +00:00
|
|
|
struct sockaddr_un us;
|
|
|
|
socklen_t uslen;
|
|
|
|
bool needbind = true;
|
|
|
|
bool opt_unlink_early = false;
|
|
|
|
bool opt_unlink_close = true;
|
|
|
|
|
|
|
|
if (argc != 2) {
|
|
|
|
Error2("%s: wrong number of parameters (%d instead of 1)",
|
|
|
|
argv[0], argc-1);
|
|
|
|
return STAT_NORETRY;
|
|
|
|
}
|
|
|
|
name = argv[1];
|
|
|
|
|
2015-03-31 16:21:45 +00:00
|
|
|
xfd->para.socket.un.tight = true;
|
|
|
|
retropt_socket_pf(opts, &pf);
|
2008-01-27 12:00:08 +00:00
|
|
|
retropt_int(opts, OPT_SO_TYPE, &socktype);
|
2008-10-22 00:33:23 +00:00
|
|
|
|
2015-03-31 16:21:45 +00:00
|
|
|
if (applyopts_single(xfd, opts, PH_INIT) < 0) return STAT_NORETRY;
|
|
|
|
applyopts(-1, opts, PH_INIT);
|
|
|
|
applyopts_named(name, opts, PH_EARLY); /* umask! */
|
|
|
|
applyopts_offset(xfd, opts);
|
2008-01-27 12:00:08 +00:00
|
|
|
retropt_bool(opts, OPT_UNLINK_EARLY, &opt_unlink_early);
|
|
|
|
retropt_bool(opts, OPT_UNLINK_CLOSE, &opt_unlink_close);
|
|
|
|
|
2008-08-24 09:04:08 +00:00
|
|
|
if (!(ABSTRACT && abstract)) {
|
|
|
|
/* only for non abstract because abstract do not work in file system */
|
|
|
|
retropt_bool(opts, OPT_UNLINK_EARLY, &opt_unlink_early);
|
|
|
|
retropt_bool(opts, OPT_UNLINK_CLOSE, &opt_unlink_close);
|
2014-03-26 13:02:42 +00:00
|
|
|
}
|
2015-03-31 16:21:45 +00:00
|
|
|
applyopts(-1, opts, PH_EARLY);
|
|
|
|
|
|
|
|
uslen = xiosetunix(pf, &us, name, abstract, xfd->para.socket.un.tight);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (retropt_bind(opts, pf, socktype, protocol, (struct sockaddr *)&us, &uslen,
|
|
|
|
(abstract<<1)|xfd->para.socket.un.tight, 0, 0) == STAT_OK) {
|
|
|
|
}
|
|
|
|
#endif
|
2008-01-27 12:00:08 +00:00
|
|
|
|
2014-03-26 13:02:42 +00:00
|
|
|
if (!(ABSTRACT && abstract)) {
|
2008-08-24 09:04:08 +00:00
|
|
|
if (opt_unlink_early) {
|
|
|
|
if (Unlink(name) < 0) {
|
|
|
|
if (errno == ENOENT) {
|
|
|
|
Warn2("unlink(\"%s\"): %s", name, strerror(errno));
|
|
|
|
} else {
|
|
|
|
Error2("unlink(\"%s\"): %s", name, strerror(errno));
|
|
|
|
}
|
2008-01-27 12:00:08 +00:00
|
|
|
}
|
2014-03-26 13:02:42 +00:00
|
|
|
} else {
|
|
|
|
struct stat buf;
|
|
|
|
if (Lstat(name, &buf) == 0) {
|
|
|
|
Error1("\"%s\" exists", name);
|
|
|
|
return STAT_RETRYLATER;
|
|
|
|
}
|
2008-01-27 12:00:08 +00:00
|
|
|
}
|
2014-03-26 13:02:42 +00:00
|
|
|
if (opt_unlink_close) {
|
|
|
|
if ((xfd->unlink_close = strdup(name)) == NULL) {
|
|
|
|
Error1("strdup(\"%s\"): out of memory", name);
|
|
|
|
}
|
|
|
|
xfd->opt_unlink_close = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* trying to set user-early, perm-early etc. here is useless because
|
|
|
|
file system entry is available only past bind() call. */
|
2008-01-27 12:00:08 +00:00
|
|
|
}
|
2014-03-26 13:02:42 +00:00
|
|
|
applyopts_named(name, opts, PH_EARLY); /* umask! */
|
2008-01-27 12:00:08 +00:00
|
|
|
|
2008-08-24 09:04:08 +00:00
|
|
|
xfd->para.socket.la.soa.sa_family = pf;
|
2008-01-27 12:00:08 +00:00
|
|
|
|
2008-08-24 09:04:08 +00:00
|
|
|
xfd->dtype = XIODATA_RECVFROM_ONE;
|
2014-03-26 13:02:42 +00:00
|
|
|
|
|
|
|
/* this may fork */
|
2008-09-20 21:47:06 +00:00
|
|
|
return
|
|
|
|
_xioopen_dgram_recvfrom(xfd, xioflags,
|
|
|
|
needbind?(struct sockaddr *)&us:NULL, uslen,
|
|
|
|
opts, pf, socktype, protocol, E_ERROR);
|
2008-01-27 12:00:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
int xioopen_unix_recv(int argc, const char *argv[], struct opt *opts,
|
2008-08-24 09:04:08 +00:00
|
|
|
int xioflags, xiofile_t *xxfd, unsigned groups,
|
|
|
|
int abstract, int dummy2, int dummy3) {
|
|
|
|
/* we expect the form: filename */
|
2008-01-27 12:00:08 +00:00
|
|
|
const char *name;
|
2008-08-24 09:04:08 +00:00
|
|
|
xiosingle_t *xfd = &xxfd->stream;
|
|
|
|
int pf = PF_UNIX;
|
|
|
|
int socktype = SOCK_DGRAM;
|
|
|
|
int protocol = 0;
|
2008-01-27 12:00:08 +00:00
|
|
|
union sockaddr_union us;
|
|
|
|
socklen_t uslen;
|
|
|
|
bool opt_unlink_early = false;
|
|
|
|
bool opt_unlink_close = true;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
if (argc != 2) {
|
|
|
|
Error2("%s: wrong number of parameters (%d instead of 1)",
|
|
|
|
argv[0], argc-1);
|
|
|
|
return STAT_NORETRY;
|
|
|
|
}
|
|
|
|
name = argv[1];
|
|
|
|
|
2015-03-31 16:21:45 +00:00
|
|
|
xfd->para.socket.un.tight = true;
|
|
|
|
retropt_socket_pf(opts, &pf);
|
|
|
|
if (applyopts_single(xfd, opts, PH_INIT) < 0) return STAT_NORETRY;
|
|
|
|
applyopts(-1, opts, PH_INIT);
|
|
|
|
applyopts_named(name, opts, PH_EARLY); /* umask! */
|
|
|
|
applyopts_offset(xfd, opts);
|
2008-01-27 12:00:08 +00:00
|
|
|
|
2008-08-24 09:04:08 +00:00
|
|
|
if (!(ABSTRACT && abstract)) {
|
|
|
|
/* only for non abstract because abstract do not work in file system */
|
|
|
|
retropt_bool(opts, OPT_UNLINK_EARLY, &opt_unlink_early);
|
2014-03-26 13:02:42 +00:00
|
|
|
retropt_bool(opts, OPT_UNLINK_CLOSE, &opt_unlink_close);
|
|
|
|
|
2015-03-31 16:21:45 +00:00
|
|
|
}
|
|
|
|
applyopts(-1, opts, PH_EARLY);
|
|
|
|
|
|
|
|
uslen = xiosetunix(pf, &us.un, name, abstract, xfd->para.socket.un.tight);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (retropt_bind(opts, pf, socktype, protocol, &us.soa, &uslen,
|
|
|
|
(abstract<<1)|xfd->para.socket.un.tight, 0, 0)
|
|
|
|
== STAT_OK) {
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!(ABSTRACT && abstract)) {
|
2008-08-24 09:04:08 +00:00
|
|
|
if (opt_unlink_early) {
|
|
|
|
if (Unlink(name) < 0) {
|
|
|
|
if (errno == ENOENT) {
|
|
|
|
Warn2("unlink(\"%s\"): %s", name, strerror(errno));
|
|
|
|
} else {
|
|
|
|
Error2("unlink(\"%s\"): %s", name, strerror(errno));
|
|
|
|
}
|
2008-01-27 12:00:08 +00:00
|
|
|
}
|
2014-03-26 13:02:42 +00:00
|
|
|
} else {
|
|
|
|
struct stat buf;
|
|
|
|
if (Lstat(name, &buf) == 0) {
|
|
|
|
Error1("\"%s\" exists", name);
|
|
|
|
return STAT_RETRYLATER;
|
|
|
|
}
|
2008-01-27 12:00:08 +00:00
|
|
|
}
|
2008-08-24 09:04:08 +00:00
|
|
|
if (opt_unlink_close) {
|
|
|
|
if ((xfd->unlink_close = strdup(name)) == NULL) {
|
|
|
|
Error1("strdup(\"%s\"): out of memory", name);
|
|
|
|
}
|
|
|
|
xfd->opt_unlink_close = true;
|
2008-01-27 12:00:08 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-26 13:02:42 +00:00
|
|
|
applyopts_named(name, opts, PH_EARLY); /* umask! */
|
2008-01-27 12:00:08 +00:00
|
|
|
|
2008-08-24 09:04:08 +00:00
|
|
|
xfd->para.socket.la.soa.sa_family = pf;
|
2008-01-27 12:00:08 +00:00
|
|
|
|
2008-08-24 09:04:08 +00:00
|
|
|
xfd->dtype = XIODATA_RECV;
|
|
|
|
result = _xioopen_dgram_recv(xfd, xioflags, &us.soa, uslen,
|
|
|
|
opts, pf, socktype, protocol, E_ERROR);
|
2008-01-27 12:00:08 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-24 09:04:08 +00:00
|
|
|
static int xioopen_unix_client(int argc, const char *argv[], struct opt *opts, int xioflags, xiofile_t *xxfd, unsigned groups, int abstract, int dummy2, int dummy3) {
|
2008-01-27 12:00:08 +00:00
|
|
|
/* we expect the form: filename */
|
|
|
|
if (argc != 2) {
|
2008-09-20 21:47:06 +00:00
|
|
|
Error2("%s: wrong number of parameters (%d instead of 1)", argv[0], argc-1);
|
2008-01-27 12:00:08 +00:00
|
|
|
}
|
|
|
|
|
2008-09-20 21:47:06 +00:00
|
|
|
return
|
|
|
|
_xioopen_unix_client(&xxfd->stream, xioflags, groups, abstract, opts,
|
|
|
|
argv[1]);
|
2008-01-27 12:00:08 +00:00
|
|
|
}
|
|
|
|
|
2008-09-20 21:47:06 +00:00
|
|
|
/* establishes communication with an existing UNIX type socket. supports stream
|
|
|
|
and datagram socket types: first tries to connect(), but when this fails it
|
|
|
|
falls back to sendto().
|
|
|
|
applies and consumes the following option:
|
|
|
|
PH_INIT, PH_PASTSOCKET, PH_FD, PH_PREBIND, PH_BIND, PH_PASTBIND,
|
|
|
|
PH_CONNECTED, PH_LATE, ?PH_CONNECT
|
|
|
|
OFUNC_OFFSET,
|
|
|
|
OPT_PROTOCOL_FAMILY, OPT_UNIX_TIGHTSOCKLEN, OPT_UNLINK_CLOSE, OPT_BIND,
|
|
|
|
OPT_SO_TYPE, OPT_SO_PROTOTYPE, OPT_CLOEXEC, OPT_USER, OPT_GROUP, ?OPT_FORK,
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
_xioopen_unix_client(xiosingle_t *xfd, int xioflags, unsigned groups,
|
|
|
|
int abstract, struct opt *opts, const char *name) {
|
2009-04-03 09:30:01 +00:00
|
|
|
int rw = (xioflags&XIO_ACCMODE);
|
2008-01-27 12:00:08 +00:00
|
|
|
int pf = PF_UNIX;
|
2008-08-24 09:04:08 +00:00
|
|
|
int socktype = 0; /* to be determined by server socket type */
|
|
|
|
int protocol = 0;
|
2008-01-27 12:00:08 +00:00
|
|
|
union sockaddr_union them, us;
|
2015-03-31 16:21:45 +00:00
|
|
|
socklen_t themlen, uslen = sizeof(us);
|
2008-01-27 12:00:08 +00:00
|
|
|
bool needbind = false;
|
|
|
|
bool opt_unlink_close = false;
|
2008-09-20 21:47:06 +00:00
|
|
|
struct opt *opts0;
|
2008-01-27 12:00:08 +00:00
|
|
|
int result;
|
|
|
|
|
2015-03-31 16:21:45 +00:00
|
|
|
xfd->para.socket.un.tight = true;
|
2008-09-20 21:47:06 +00:00
|
|
|
retropt_socket_pf(opts, &pf);
|
2015-03-31 16:21:45 +00:00
|
|
|
if (applyopts_single(xfd, opts, PH_INIT) < 0) return STAT_NORETRY;
|
|
|
|
applyopts(-1, opts, PH_INIT);
|
|
|
|
applyopts_offset(xfd, opts);
|
|
|
|
applyopts(-1, opts, PH_EARLY);
|
2008-01-27 12:00:08 +00:00
|
|
|
|
2015-03-31 16:21:45 +00:00
|
|
|
themlen = xiosetunix(pf, &them.un, name, abstract, xfd->para.socket.un.tight);
|
2008-08-24 09:04:08 +00:00
|
|
|
if (!(ABSTRACT && abstract)) {
|
|
|
|
/* only for non abstract because abstract do not work in file system */
|
|
|
|
retropt_bool(opts, OPT_UNLINK_CLOSE, &opt_unlink_close);
|
|
|
|
}
|
2015-03-31 16:21:45 +00:00
|
|
|
if (retropt_bind(opts, pf, socktype, protocol, &us.soa, &uslen,
|
|
|
|
(abstract<<1)|xfd->para.socket.un.tight, 0, 0)
|
2008-01-27 12:00:08 +00:00
|
|
|
!= STAT_NOACTION) {
|
|
|
|
needbind = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opt_unlink_close) {
|
|
|
|
if ((xfd->unlink_close = strdup(name)) == NULL) {
|
|
|
|
Error1("strdup(\"%s\"): out of memory", name);
|
|
|
|
}
|
|
|
|
xfd->opt_unlink_close = true;
|
|
|
|
}
|
|
|
|
|
2008-09-20 21:47:06 +00:00
|
|
|
/* save options, because we might have to start again */
|
|
|
|
opts0 = copyopts(opts, GROUP_ALL);
|
2008-01-27 12:00:08 +00:00
|
|
|
|
|
|
|
/* xfd->dtype = DATA_STREAM; // is default */
|
|
|
|
if ((result =
|
|
|
|
xioopen_connect(xfd,
|
|
|
|
needbind?(struct sockaddr *)&us:NULL, uslen,
|
|
|
|
(struct sockaddr *)&them, themlen,
|
2008-08-24 09:04:08 +00:00
|
|
|
opts, pf, socktype?socktype:SOCK_STREAM, protocol,
|
|
|
|
false)) != 0) {
|
2008-01-27 12:00:08 +00:00
|
|
|
if (errno == EPROTOTYPE) {
|
|
|
|
if (needbind) {
|
|
|
|
Unlink(us.un.sun_path);
|
|
|
|
}
|
|
|
|
|
2008-09-20 21:47:06 +00:00
|
|
|
dropopts2(opts, PH_INIT, PH_SPEC); opts = opts0;
|
2008-01-27 12:00:08 +00:00
|
|
|
|
|
|
|
xfd->peersa = them;
|
|
|
|
xfd->salen = sizeof(struct sockaddr_un);
|
|
|
|
if ((result =
|
|
|
|
_xioopen_dgram_sendto(needbind?&us:NULL, uslen,
|
2008-08-24 09:04:08 +00:00
|
|
|
opts, xioflags, xfd, groups,
|
|
|
|
pf, socktype?socktype:SOCK_DGRAM, protocol))
|
2008-01-27 12:00:08 +00:00
|
|
|
!= 0) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
xfd->dtype = XIODATA_RECVFROM;
|
|
|
|
}
|
|
|
|
}
|
2009-04-03 09:30:01 +00:00
|
|
|
if (XIOWITHWR(rw)) xfd->wfd = xfd->rfd;
|
|
|
|
if (!XIOWITHRD(rw)) xfd->rfd = -1;
|
2008-01-27 12:00:08 +00:00
|
|
|
if ((result = _xio_openlate(xfd, opts)) < 0) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-22 20:17:55 +00:00
|
|
|
/* returns information that can be used for constructing an environment
|
|
|
|
variable describing the socket address.
|
|
|
|
if idx is 0, this function writes "ADDR" into namebuff and the path into
|
|
|
|
valuebuff, and returns 0 (which means that no more info is there).
|
|
|
|
if idx is != 0, it returns -1
|
|
|
|
namelen and valuelen contain the max. allowed length of output chars in the
|
|
|
|
respective buffer.
|
|
|
|
on error this function returns -1.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
xiosetsockaddrenv_unix(int idx, char *namebuff, size_t namelen,
|
|
|
|
char *valuebuff, size_t valuelen,
|
|
|
|
struct sockaddr_un *sa, socklen_t salen, int ipproto) {
|
|
|
|
if (idx != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
strcpy(namebuff, "ADDR");
|
|
|
|
sockaddr_unix_info(sa, salen, valuebuff, valuelen);
|
2008-01-27 12:00:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* WITH_UNIX */
|