summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Ratchov <ratchov@cvs.openbsd.org>2015-10-02 09:21:47 +0000
committerAlexandre Ratchov <ratchov@cvs.openbsd.org>2015-10-02 09:21:47 +0000
commitb7549d84c68bfb7cfbfc1c51e32097c733811e4f (patch)
tree6b54bbead925c4f314bc88eb6688dba01642910e
parent9e0c2fe2e5cd702c54a81b4d3cdf84182707a9d2 (diff)
use macros instead of hard-coded strings for unix sockets paths
-rw-r--r--lib/libsndio/amsg.h16
-rw-r--r--lib/libsndio/aucat.c6
-rw-r--r--usr.bin/sndiod/sndiod.c8
3 files changed, 20 insertions, 10 deletions
diff --git a/lib/libsndio/amsg.h b/lib/libsndio/amsg.h
index d15eaa78272..1a8d6bcabec 100644
--- a/lib/libsndio/amsg.h
+++ b/lib/libsndio/amsg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: amsg.h,v 1.7 2015/10/02 09:04:36 ratchov Exp $ */
+/* $OpenBSD: amsg.h,v 1.8 2015/10/02 09:21:46 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -19,10 +19,20 @@
#include <stdint.h>
+/*
+ * unix-domain socket name is:
+ *
+ * DIR [ '-' UID ] '/' FILE UNIT
+ *
+ * example: "/tmp/aucat-1000/aucat0"
+ *
+ */
+#define SOCKPATH_DIR "/tmp/aucat"
+#define SOCKPATH_FILE "aucat"
+
/*
- * socket and option names
+ * server TCP base port number
*/
-#define AUCAT_PATH "aucat"
#define AUCAT_PORT 11025
/*
diff --git a/lib/libsndio/aucat.c b/lib/libsndio/aucat.c
index 36215f07c84..aa182803a4a 100644
--- a/lib/libsndio/aucat.c
+++ b/lib/libsndio/aucat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: aucat.c,v 1.64 2015/10/01 06:38:19 ratchov Exp $ */
+/* $OpenBSD: aucat.c,v 1.65 2015/10/02 09:21:46 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -337,7 +337,7 @@ aucat_connect_un(struct aucat *hdl, unsigned int unit)
uid = geteuid();
snprintf(ca.sun_path, sizeof(ca.sun_path),
- "/tmp/aucat-%u/%s%u", uid, AUCAT_PATH, unit);
+ SOCKPATH_DIR "-%u/%s%u", uid, SOCKPATH_FILE, unit);
ca.sun_family = AF_UNIX;
s = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
if (s < 0)
@@ -348,7 +348,7 @@ aucat_connect_un(struct aucat *hdl, unsigned int unit)
DPERROR(ca.sun_path);
/* try shared server */
snprintf(ca.sun_path, sizeof(ca.sun_path),
- "/tmp/aucat/%s%u", AUCAT_PATH, unit);
+ SOCKPATH_DIR "/%s%u", SOCKPATH_FILE, unit);
while (connect(s, (struct sockaddr *)&ca, len) < 0) {
if (errno == EINTR)
continue;
diff --git a/usr.bin/sndiod/sndiod.c b/usr.bin/sndiod/sndiod.c
index 50c68ff8012..f99a3e2efc6 100644
--- a/usr.bin/sndiod/sndiod.c
+++ b/usr.bin/sndiod/sndiod.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sndiod.c,v 1.8 2015/04/26 17:26:59 dcoppa Exp $ */
+/* $OpenBSD: sndiod.c,v 1.9 2015/10/02 09:21:46 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -260,10 +260,10 @@ getbasepath(char *base, size_t size)
uid = geteuid();
if (uid == 0) {
mask = 022;
- snprintf(base, PATH_MAX, "/tmp/aucat");
+ snprintf(base, PATH_MAX, SOCKPATH_DIR);
} else {
mask = 077;
- snprintf(base, PATH_MAX, "/tmp/aucat-%u", uid);
+ snprintf(base, PATH_MAX, SOCKPATH_DIR "-%u", uid);
}
if (mkdir(base, 0777 & ~mask) < 0) {
if (errno != EEXIST)
@@ -466,7 +466,7 @@ main(int argc, char **argv)
mode, vol, mmc, dup);
}
getbasepath(base, sizeof(base));
- snprintf(path, PATH_MAX, "%s/%s%u", base, AUCAT_PATH, unit);
+ snprintf(path, PATH_MAX, "%s/%s%u", base, SOCKPATH_FILE, unit);
listen_new_un(path);
if (geteuid() == 0)
privdrop();