summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libsndio/aucat.c67
-rw-r--r--lib/libsndio/aucat.h2
-rw-r--r--lib/libsndio/mio_aucat.c10
-rw-r--r--lib/libsndio/sio_aucat.c4
4 files changed, 46 insertions, 37 deletions
diff --git a/lib/libsndio/aucat.c b/lib/libsndio/aucat.c
index b2baa8d753e..4466dddb896 100644
--- a/lib/libsndio/aucat.c
+++ b/lib/libsndio/aucat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: aucat.c,v 1.44 2011/04/16 10:52:22 ratchov Exp $ */
+/* $OpenBSD: aucat.c,v 1.45 2011/04/18 23:57:35 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -192,58 +192,68 @@ aucat_wdata(struct aucat *hdl, const void *buf, size_t len, unsigned wbpf, int *
}
int
-aucat_open(struct aucat *hdl, const char *str, char *sock, unsigned mode, int nbio)
+aucat_connect_un(struct aucat *hdl, char *unit, int isaudio)
{
- extern char *__progname;
- int s, eof;
- char unit[4], *sep, *opt;
struct sockaddr_un ca;
socklen_t len = sizeof(struct sockaddr_un);
+ char *sock;
uid_t uid;
+ int s;
- sep = strchr(str, '.');
- if (sep == NULL) {
- opt = "default";
- strlcpy(unit, str, sizeof(unit));
- } else {
- opt = sep + 1;
- if (sep - str >= sizeof(unit)) {
- DPRINTF("aucat_init: %s: too long\n", str);
- return 0;
- }
- strlcpy(unit, str, opt - str);
- }
- DPRINTF("aucat_init: trying %s -> %s.%s\n", str, unit, opt);
uid = geteuid();
- if (strchr(str, '/') != NULL)
- return 0;
+ sock = isaudio ? AUCAT_PATH : MIDICAT_PATH;
snprintf(ca.sun_path, sizeof(ca.sun_path),
"/tmp/aucat-%u/%s%s", uid, sock, unit);
ca.sun_family = AF_UNIX;
-
s = socket(AF_UNIX, SOCK_STREAM, 0);
if (s < 0)
- goto bad_free;
+ return 0;
while (connect(s, (struct sockaddr *)&ca, len) < 0) {
if (errno == EINTR)
continue;
- DPERROR("aucat_init: connect");
+ DPERROR(ca.sun_path);
/* try shared server */
snprintf(ca.sun_path, sizeof(ca.sun_path),
"/tmp/aucat/%s%s", sock, unit);
while (connect(s, (struct sockaddr *)&ca, len) < 0) {
if (errno == EINTR)
continue;
- DPERROR("aucat_init: connect");
- goto bad_connect;
+ DPERROR(ca.sun_path);
+ close(s);
+ return 0;
}
break;
}
- if (fcntl(s, F_SETFD, FD_CLOEXEC) < 0) {
+ hdl->fd = s;
+ return 1;
+}
+
+int
+aucat_open(struct aucat *hdl, const char *str, unsigned mode, int isaudio)
+{
+ extern char *__progname;
+ int eof;
+ char unit[4], *sep, *opt;
+
+ sep = strchr(str, '.');
+ if (sep == NULL) {
+ opt = "default";
+ strlcpy(unit, str, sizeof(unit));
+ } else {
+ opt = sep + 1;
+ if (sep - str >= sizeof(unit)) {
+ DPRINTF("aucat_init: %s: too long\n", str);
+ return 0;
+ }
+ strlcpy(unit, str, opt - str);
+ }
+ DPRINTF("aucat_init: trying %s -> %s.%s\n", str, unit, opt);
+ if (!aucat_connect_un(hdl, unit, isaudio))
+ return 0;
+ if (fcntl(hdl->fd, F_SETFD, FD_CLOEXEC) < 0) {
DPERROR("FD_CLOEXEC");
goto bad_connect;
}
- hdl->fd = s;
hdl->rstate = RSTATE_MSG;
hdl->rtodo = sizeof(struct amsg);
hdl->wstate = WSTATE_IDLE;
@@ -274,9 +284,8 @@ aucat_open(struct aucat *hdl, const char *str, char *sock, unsigned mode, int nb
}
return 1;
bad_connect:
- while (close(s) < 0 && errno == EINTR)
+ while (close(hdl->fd) < 0 && errno == EINTR)
; /* retry */
- bad_free:
return 0;
}
diff --git a/lib/libsndio/aucat.h b/lib/libsndio/aucat.h
index aef23e00101..ab180303592 100644
--- a/lib/libsndio/aucat.h
+++ b/lib/libsndio/aucat.h
@@ -20,7 +20,7 @@ int aucat_rmsg(struct aucat *, int *);
int aucat_wmsg(struct aucat *, int *);
size_t aucat_rdata(struct aucat *, void *, size_t, int *);
size_t aucat_wdata(struct aucat *, const void *, size_t, unsigned, int *);
-int aucat_open(struct aucat *, const char *, char *, unsigned, int);
+int aucat_open(struct aucat *, const char *, unsigned, int);
void aucat_close(struct aucat *, int);
int aucat_pollfd(struct aucat *, struct pollfd *, int);
int aucat_revents(struct aucat *, struct pollfd *);
diff --git a/lib/libsndio/mio_aucat.c b/lib/libsndio/mio_aucat.c
index 498849d2d4e..bccc94b7ffd 100644
--- a/lib/libsndio/mio_aucat.c
+++ b/lib/libsndio/mio_aucat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mio_aucat.c,v 1.3 2011/04/16 11:51:47 ratchov Exp $ */
+/* $OpenBSD: mio_aucat.c,v 1.4 2011/04/18 23:57:35 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -52,14 +52,14 @@ static struct mio_ops mio_aucat_ops = {
};
static struct mio_hdl *
-mio_xxx_open(const char *str, char *sock, unsigned mode, int nbio)
+mio_xxx_open(const char *str, unsigned mode, int nbio, int isaudio)
{
struct mio_aucat_hdl *hdl;
hdl = malloc(sizeof(struct mio_aucat_hdl));
if (hdl == NULL)
return NULL;
- if (!aucat_open(&hdl->aucat, str, sock, mode, nbio))
+ if (!aucat_open(&hdl->aucat, str, mode, isaudio))
goto bad;
mio_create(&hdl->mio, &mio_aucat_ops, mode, nbio);
if (!aucat_setfl(&hdl->aucat, nbio, &hdl->mio.eof))
@@ -73,13 +73,13 @@ bad:
struct mio_hdl *
mio_midithru_open(const char *str, unsigned mode, int nbio)
{
- return mio_xxx_open(str, MIDICAT_PATH, mode, nbio);
+ return mio_xxx_open(str, mode, nbio, 0);
}
struct mio_hdl *
mio_aucat_open(const char *str, unsigned mode, int nbio)
{
- return mio_xxx_open(str, AUCAT_PATH, mode, nbio);
+ return mio_xxx_open(str, mode, nbio, 1);
}
static void
diff --git a/lib/libsndio/sio_aucat.c b/lib/libsndio/sio_aucat.c
index 83b73bd8545..abdce5efb64 100644
--- a/lib/libsndio/sio_aucat.c
+++ b/lib/libsndio/sio_aucat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sio_aucat.c,v 1.4 2011/04/16 11:51:47 ratchov Exp $ */
+/* $OpenBSD: sio_aucat.c,v 1.5 2011/04/18 23:57:35 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -146,7 +146,7 @@ sio_aucat_open(const char *str, unsigned mode, int nbio)
hdl = malloc(sizeof(struct sio_aucat_hdl));
if (hdl == NULL)
return NULL;
- if (!aucat_open(&hdl->aucat, str, AUCAT_PATH, mode, nbio)) {
+ if (!aucat_open(&hdl->aucat, str, mode, 1)) {
free(hdl);
return NULL;
}