Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/librumpuser Unlink unix socket as part of server exit.
details: https://anonhg.NetBSD.org/src/rev/081e34d10081
branches: trunk
changeset: 759547:081e34d10081
user: pooka <pooka%NetBSD.org@localhost>
date: Sun Dec 12 17:58:28 2010 +0000
description:
Unlink unix socket as part of server exit.
(whatever happened to the code that was supposed to do it automatically
when the binding process exits?)
diffstat:
lib/librumpuser/rumpuser_sp.c | 11 ++++++++-
lib/librumpuser/sp_common.c | 48 ++++++++++++++++++++++++++++++++++++------
2 files changed, 50 insertions(+), 9 deletions(-)
diffs (147 lines):
diff -r ff55de0f06ae -r 081e34d10081 lib/librumpuser/rumpuser_sp.c
--- a/lib/librumpuser/rumpuser_sp.c Sun Dec 12 17:30:23 2010 +0000
+++ b/lib/librumpuser/rumpuser_sp.c Sun Dec 12 17:58:28 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rumpuser_sp.c,v 1.24 2010/12/12 17:10:36 pooka Exp $ */
+/* $NetBSD: rumpuser_sp.c,v 1.25 2010/12/12 17:58:28 pooka Exp $ */
/*
* Copyright (c) 2010 Antti Kantee. All Rights Reserved.
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: rumpuser_sp.c,v 1.24 2010/12/12 17:10:36 pooka Exp $");
+__RCSID("$NetBSD: rumpuser_sp.c,v 1.25 2010/12/12 17:58:28 pooka Exp $");
#include <sys/types.h>
#include <sys/atomic.h>
@@ -806,6 +806,8 @@
return NULL;
}
+static unsigned cleanupidx;
+static struct sockaddr *cleanupsa;
int
rumpuser_sp_init(const struct rumpuser_sp_ops *spopsp, const char *url)
{
@@ -838,6 +840,9 @@
sarg->sps_sock = s;
sarg->sps_connhook = parsetab[idx].connhook;
+ cleanupidx = idx;
+ cleanupsa = sap;
+
/* sloppy error recovery */
/*LINTED*/
@@ -845,6 +850,7 @@
fprintf(stderr, "rump_sp: server bind failed\n");
return errno;
}
+
if (listen(s, MAXCLI) == -1) {
fprintf(stderr, "rump_sp: server listen failed\n");
return errno;
@@ -864,6 +870,7 @@
{
if (spclist[0].spc_fd) {
+ parsetab[cleanupidx].cleanup(cleanupsa);
shutdown(spclist[0].spc_fd, SHUT_RDWR);
spfini = 1;
}
diff -r ff55de0f06ae -r 081e34d10081 lib/librumpuser/sp_common.c
--- a/lib/librumpuser/sp_common.c Sun Dec 12 17:30:23 2010 +0000
+++ b/lib/librumpuser/sp_common.c Sun Dec 12 17:58:28 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sp_common.c,v 1.14 2010/11/30 20:33:43 pooka Exp $ */
+/* $NetBSD: sp_common.c,v 1.15 2010/12/12 17:58:28 pooka Exp $ */
/*
* Copyright (c) 2010 Antti Kantee. All Rights Reserved.
@@ -36,6 +36,7 @@
#include <sys/queue.h>
#include <sys/socket.h>
#include <sys/un.h>
+#include <sys/syslimits.h>
#include <arpa/inet.h>
#include <netinet/in.h>
@@ -156,6 +157,7 @@
typedef int (*addrparse_fn)(const char *, struct sockaddr **, int);
typedef int (*connecthook_fn)(int);
+typedef void (*cleanup_fn)(struct sockaddr *);
static int readframe(struct spclient *);
static void handlereq(struct spclient *);
@@ -571,12 +573,29 @@
/*
* The pathname can be all kinds of spaghetti elementals,
- * so meek and obidient we accept everything.
+ * so meek and obidient we accept everything. However, use
+ * full path for easy cleanup in case someone gives a relative
+ * one and the server does a chdir() between now than the
+ * cleanup.
*/
memset(&sun, 0, sizeof(sun));
sun.sun_family = AF_LOCAL;
- strlcpy(sun.sun_path, addr, sizeof(sun.sun_path));
- sun.sun_len = slen = SUN_LEN(&sun);
+ if (*addr != '/') {
+ char mywd[PATH_MAX];
+
+ if (getcwd(mywd, sizeof(mywd)) == NULL) {
+ fprintf(stderr, "warning: cannot determine cwd, "
+ "omitting socket cleanup\n");
+ } else {
+ if (strlen(addr) + strlen(mywd) > sizeof(sun.sun_path))
+ return ENAMETOOLONG;
+ strlcpy(sun.sun_path, mywd, sizeof(sun.sun_path));
+ strlcat(sun.sun_path, "/", sizeof(sun.sun_path));
+ }
+ }
+ strlcat(sun.sun_path, addr, sizeof(sun.sun_path));
+ sun.sun_len = SUN_LEN(&sun);
+ slen = sun.sun_len+1; /* get the 0 too */
*sa = malloc(slen);
if (*sa == NULL)
@@ -586,6 +605,19 @@
return 0;
}
+static void
+unix_cleanup(struct sockaddr *sa)
+{
+ struct sockaddr_un *sun = (void *)sa;
+
+ /*
+ * cleanup only absolute paths. see unix_parse() above
+ */
+ if (*sun->sun_path == '/') {
+ unlink(sun->sun_path);
+ }
+}
+
/*ARGSUSED*/
static int
notsupp(void)
@@ -607,10 +639,12 @@
int domain;
addrparse_fn ap;
connecthook_fn connhook;
+ cleanup_fn cleanup;
} parsetab[] = {
- { "tcp", PF_INET, tcp_parse, tcp_connecthook },
- { "unix", PF_LOCAL, unix_parse, (connecthook_fn)success },
- { "tcp6", PF_INET6, (addrparse_fn)notsupp, (connecthook_fn)success },
+ { "tcp", PF_INET, tcp_parse, tcp_connecthook, (cleanup_fn)success },
+ { "unix", PF_LOCAL, unix_parse, (connecthook_fn)success, unix_cleanup },
+ { "tcp6", PF_INET6, (addrparse_fn)notsupp, (connecthook_fn)success,
+ (cleanup_fn)success },
};
#define NPARSE (sizeof(parsetab)/sizeof(parsetab[0]))
Home |
Main Index |
Thread Index |
Old Index