Module Name: src Committed By: pooka Date: Thu Jan 17 20:47:44 UTC 2013
Modified Files: src/lib/librumpclient: rumpclient.c rumpclient.h Log Message: Solaris 10 fixes To generate a diff of this commit: cvs rdiff -u -r1.53 -r1.54 src/lib/librumpclient/rumpclient.c cvs rdiff -u -r1.12 -r1.13 src/lib/librumpclient/rumpclient.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/librumpclient/rumpclient.c diff -u src/lib/librumpclient/rumpclient.c:1.53 src/lib/librumpclient/rumpclient.c:1.54 --- src/lib/librumpclient/rumpclient.c:1.53 Thu Jan 17 16:29:44 2013 +++ src/lib/librumpclient/rumpclient.c Thu Jan 17 20:47:44 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: rumpclient.c,v 1.53 2013/01/17 16:29:44 pooka Exp $ */ +/* $NetBSD: rumpclient.c,v 1.54 2013/01/17 20:47:44 pooka Exp $ */ /* * Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved. @@ -48,8 +48,7 @@ #define USE_KQUEUE #endif -#include <sys/cdefs.h> -__RCSID("$NetBSD: rumpclient.c,v 1.53 2013/01/17 16:29:44 pooka Exp $"); +__RCSID("$NetBSD: rumpclient.c,v 1.54 2013/01/17 20:47:44 pooka Exp $"); #include <sys/param.h> #include <sys/mman.h> @@ -66,7 +65,6 @@ __RCSID("$NetBSD: rumpclient.c,v 1.53 20 #include <assert.h> #include <dlfcn.h> -#include <err.h> #include <errno.h> #include <fcntl.h> #include <poll.h> @@ -159,11 +157,13 @@ send_with_recon(struct spclient *spc, st /* check that we aren't over the limit */ if (retrytimo > 0) { - struct timeval tmp; + time_t tdiff; gettimeofday(&curtime, NULL); - timersub(&curtime, &starttime, &tmp); - if (tmp.tv_sec >= retrytimo) { + tdiff = curtime.tv_sec - starttime.tv_sec; + if (starttime.tv_usec > curtime.tv_usec) + tdiff--; + if (tdiff >= retrytimo) { fprintf(stderr, "rump_sp: reconnect " "failed, %lld second timeout\n", (long long)retrytimo); @@ -844,9 +844,11 @@ rumpclient_init(void) #_syscall_)) == NULL) { \ if (rumphijack_dlsym == rumpclient__dlsym) \ host_##_name_ = _name_; /* static fallback */ \ - if (host_##_name_ == NULL) \ - errx(1, "cannot find %s: %s", #_syscall_, \ + if (host_##_name_ == NULL) { \ + fprintf(stderr,"cannot find %s: %s", #_syscall_,\ dlerror()); \ + exit(1); \ + } \ } #else #define FINDSYM2(_name_,_syscall) \ @@ -1150,6 +1152,10 @@ rumpclient_exec(const char *path, char * return rv; } +/* + * daemon() is handwritten for the benefit of platforms which + * do not support daemon(). + */ int rumpclient_daemon(int nochdir, int noclose) { @@ -1159,15 +1165,37 @@ rumpclient_daemon(int nochdir, int noclo if ((rf = rumpclient_prefork()) == NULL) return -1; - if (daemon(nochdir, noclose) == -1) { - sverrno = errno; - rumpclient_fork_cancel(rf); - errno = sverrno; - return -1; + switch (fork()) { + case 0: + break; + case -1: + goto daemonerr; + default: + _exit(0); } + if (setsid() == -1) + goto daemonerr; + if (!nochdir && chdir("/") == -1) + goto daemonerr; + if (!noclose) { + int fd = open("/dev/null", O_RDWR); + dup2(fd, 0); + dup2(fd, 1); + dup2(fd, 2); + if (fd > 2) + close(fd); + } + + /* note: fork is either completed or cancelled by the call */ if (rumpclient_fork_init(rf) == -1) return -1; return 0; + + daemonerr: + sverrno = errno; + rumpclient_fork_cancel(rf); + errno = sverrno; + return -1; } Index: src/lib/librumpclient/rumpclient.h diff -u src/lib/librumpclient/rumpclient.h:1.12 src/lib/librumpclient/rumpclient.h:1.13 --- src/lib/librumpclient/rumpclient.h:1.12 Fri Aug 3 11:31:34 2012 +++ src/lib/librumpclient/rumpclient.h Thu Jan 17 20:47:44 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: rumpclient.h,v 1.12 2012/08/03 11:31:34 pooka Exp $ */ +/* $NetBSD: rumpclient.h,v 1.13 2013/01/17 20:47:44 pooka Exp $ */ /*- * Copyright (c) 2010 Antti Kantee. All Rights Reserved. @@ -42,7 +42,11 @@ struct rumpclient_fork; #define rumpclient_vfork() rumpclient__dofork(vfork) +#ifdef __BEGIN_DECLS __BEGIN_DECLS +#else +extern "C" { +#endif int rumpclient_syscall(int, const void *, size_t, register_t *); int rumpclient_init(void); @@ -102,6 +106,10 @@ rumpclient__dofork(pid_t (*forkfn)(void) return pid; } +#ifdef __END_DECLS __END_DECLS +#else +} +#endif #endif /* _RUMP_RUMPCLIENT_H_ */