[BACK]Return to rumpclient.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / librumpclient

Annotation of src/lib/librumpclient/rumpclient.c, Revision 1.45

1.45    ! alnsn       1: /*      $NetBSD: rumpclient.c,v 1.44 2011/03/15 09:35:05 pooka Exp $   */
1.1       pooka       2:
                      3: /*
1.11      pooka       4:  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
1.1       pooka       5:  *
                      6:  * Redistribution and use in source and binary forms, with or without
                      7:  * modification, are permitted provided that the following conditions
                      8:  * are met:
                      9:  * 1. Redistributions of source code must retain the above copyright
                     10:  *    notice, this list of conditions and the following disclaimer.
                     11:  * 2. Redistributions in binary form must reproduce the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer in the
                     13:  *    documentation and/or other materials provided with the distribution.
                     14:  *
                     15:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
                     16:  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
                     17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
                     18:  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
                     19:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     20:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
                     21:  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     22:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     23:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     24:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     25:  * SUCH DAMAGE.
                     26:  */
                     27:
                     28: /*
                     29:  * Client side routines for rump syscall proxy.
                     30:  */
                     31:
                     32: #include <sys/cdefs.h>
1.45    ! alnsn      33: __RCSID("$NetBSD: rumpclient.c,v 1.44 2011/03/15 09:35:05 pooka Exp $");
1.1       pooka      34:
1.5       pooka      35: #include <sys/param.h>
1.15      pooka      36: #include <sys/event.h>
1.1       pooka      37: #include <sys/mman.h>
                     38: #include <sys/socket.h>
                     39:
                     40: #include <arpa/inet.h>
                     41: #include <netinet/in.h>
                     42: #include <netinet/tcp.h>
                     43:
                     44: #include <assert.h>
1.13      pooka      45: #include <dlfcn.h>
1.34      pooka      46: #include <err.h>
1.1       pooka      47: #include <errno.h>
                     48: #include <fcntl.h>
1.13      pooka      49: #include <link.h>
1.1       pooka      50: #include <poll.h>
                     51: #include <pthread.h>
1.11      pooka      52: #include <signal.h>
1.1       pooka      53: #include <stdarg.h>
1.18      pooka      54: #include <stdbool.h>
1.1       pooka      55: #include <stdio.h>
                     56: #include <stdlib.h>
                     57: #include <string.h>
                     58: #include <unistd.h>
                     59:
                     60: #include <rump/rumpclient.h>
                     61:
1.13      pooka      62: #define HOSTOPS
                     63: int    (*host_socket)(int, int, int);
                     64: int    (*host_close)(int);
                     65: int    (*host_connect)(int, const struct sockaddr *, socklen_t);
1.15      pooka      66: int    (*host_fcntl)(int, int, ...);
1.13      pooka      67: int    (*host_poll)(struct pollfd *, nfds_t, int);
                     68: ssize_t        (*host_read)(int, void *, size_t);
1.39      pooka      69: ssize_t (*host_sendmsg)(int, const struct msghdr *, int);
1.13      pooka      70: int    (*host_setsockopt)(int, int, int, const void *, socklen_t);
1.27      pooka      71: int    (*host_dup)(int);
1.13      pooka      72:
1.17      pooka      73: int    (*host_kqueue)(void);
                     74: int    (*host_kevent)(int, const struct kevent *, size_t,
                     75:                       struct kevent *, size_t, const struct timespec *);
                     76:
1.30      pooka      77: int    (*host_execve)(const char *, char *const[], char *const[]);
                     78:
1.1       pooka      79: #include "sp_common.c"
                     80:
1.11      pooka      81: static struct spclient clispc = {
                     82:        .spc_fd = -1,
                     83: };
1.1       pooka      84:
1.18      pooka      85: static int kq = -1;
1.15      pooka      86: static sigset_t fullset;
1.12      pooka      87:
1.44      pooka      88: static int doconnect(void);
1.29      pooka      89: static int handshake_req(struct spclient *, int, void *, int, bool);
1.18      pooka      90:
1.32      pooka      91: /*
                     92:  * Default: don't retry.  Most clients can't handle it
                     93:  * (consider e.g. fds suddenly going missing).
                     94:  */
                     95: static time_t retrytimo = 0;
1.18      pooka      96:
1.44      pooka      97: /* always defined to nothingness for now */
                     98: #define ERRLOG(a)
                     99:
1.18      pooka     100: static int
1.39      pooka     101: send_with_recon(struct spclient *spc, struct iovec *iov, size_t iovlen)
1.18      pooka     102: {
1.20      pooka     103:        struct timeval starttime, curtime;
                    104:        time_t prevreconmsg;
                    105:        unsigned reconretries;
1.18      pooka     106:        int rv;
                    107:
1.20      pooka     108:        for (prevreconmsg = 0, reconretries = 0;;) {
1.39      pooka     109:                rv = dosend(spc, iov, iovlen);
1.18      pooka     110:                if (__predict_false(rv == ENOTCONN || rv == EBADF)) {
1.20      pooka     111:                        /* no persistent connections */
1.32      pooka     112:                        if (retrytimo == 0) {
                    113:                                rv = ENOTCONN;
1.20      pooka     114:                                break;
1.32      pooka     115:                        }
1.24      pooka     116:                        if (retrytimo == RUMPCLIENT_RETRYCONN_DIE)
1.43      pooka     117:                                _exit(1);
1.20      pooka     118:
                    119:                        if (!prevreconmsg) {
                    120:                                prevreconmsg = time(NULL);
                    121:                                gettimeofday(&starttime, NULL);
                    122:                        }
                    123:                        if (reconretries == 1) {
                    124:                                if (retrytimo == RUMPCLIENT_RETRYCONN_ONCE) {
                    125:                                        rv = ENOTCONN;
                    126:                                        break;
                    127:                                }
                    128:                                fprintf(stderr, "rump_sp: connection to "
                    129:                                    "kernel lost, trying to reconnect ...\n");
                    130:                        } else if (time(NULL) - prevreconmsg > 120) {
                    131:                                fprintf(stderr, "rump_sp: still trying to "
                    132:                                    "reconnect ...\n");
                    133:                                prevreconmsg = time(NULL);
                    134:                        }
                    135:
                    136:                        /* check that we aren't over the limit */
                    137:                        if (retrytimo > 0) {
                    138:                                struct timeval tmp;
                    139:
                    140:                                gettimeofday(&curtime, NULL);
                    141:                                timersub(&curtime, &starttime, &tmp);
                    142:                                if (tmp.tv_sec >= retrytimo) {
                    143:                                        fprintf(stderr, "rump_sp: reconnect "
                    144:                                            "failed, %lld second timeout\n",
                    145:                                            (long long)retrytimo);
                    146:                                        return ENOTCONN;
                    147:                                }
                    148:                        }
                    149:
                    150:                        /* adhoc backoff timer */
                    151:                        if (reconretries < 10) {
                    152:                                usleep(100000 * reconretries);
                    153:                        } else {
                    154:                                sleep(MIN(10, reconretries-9));
                    155:                        }
                    156:                        reconretries++;
                    157:
1.44      pooka     158:                        if ((rv = doconnect()) != 0)
1.18      pooka     159:                                continue;
1.29      pooka     160:                        if ((rv = handshake_req(&clispc, HANDSHAKE_GUEST,
                    161:                            NULL, 0, true)) != 0)
1.18      pooka     162:                                continue;
1.20      pooka     163:
                    164:                        /*
                    165:                         * ok, reconnect succesful.  we need to return to
                    166:                         * the upper layer to get the entire PDU resent.
                    167:                         */
                    168:                        if (reconretries != 1)
                    169:                                fprintf(stderr, "rump_sp: reconnected!\n");
                    170:                        rv = EAGAIN;
                    171:                        break;
                    172:                } else {
                    173:                        _DIAGASSERT(errno != EAGAIN);
1.18      pooka     174:                        break;
                    175:                }
1.20      pooka     176:        }
1.18      pooka     177:
                    178:        return rv;
                    179: }
                    180:
1.12      pooka     181: static int
1.18      pooka     182: cliwaitresp(struct spclient *spc, struct respwait *rw, sigset_t *mask,
                    183:        bool keeplock)
1.12      pooka     184: {
1.18      pooka     185:        uint64_t mygen;
                    186:        bool imalive = true;
1.12      pooka     187:
1.15      pooka     188:        pthread_mutex_lock(&spc->spc_mtx);
1.18      pooka     189:        if (!keeplock)
                    190:                sendunlockl(spc);
                    191:        mygen = spc->spc_generation;
1.12      pooka     192:
                    193:        rw->rw_error = 0;
1.18      pooka     194:        while (!rw->rw_done && rw->rw_error == 0) {
                    195:                if (__predict_false(spc->spc_generation != mygen || !imalive))
                    196:                        break;
                    197:
1.12      pooka     198:                /* are we free to receive? */
                    199:                if (spc->spc_istatus == SPCSTATUS_FREE) {
1.15      pooka     200:                        struct kevent kev[8];
                    201:                        int gotresp, dosig, rv, i;
                    202:
1.12      pooka     203:                        spc->spc_istatus = SPCSTATUS_BUSY;
                    204:                        pthread_mutex_unlock(&spc->spc_mtx);
                    205:
1.15      pooka     206:                        dosig = 0;
                    207:                        for (gotresp = 0; !gotresp; ) {
1.40      pooka     208:                                /*
                    209:                                 * typically we don't have a frame waiting
                    210:                                 * when we come in here, so call kevent now
                    211:                                 */
                    212:                                rv = host_kevent(kq, NULL, 0,
                    213:                                    kev, __arraycount(kev), NULL);
                    214:
                    215:                                if (__predict_false(rv == -1)) {
                    216:                                        goto activity;
                    217:                                }
                    218:
                    219:                                /*
                    220:                                 * XXX: don't know how this can happen
                    221:                                 * (timeout cannot expire since there
                    222:                                 * isn't one), but it does happen.
                    223:                                 * treat it as an expectional condition
                    224:                                 * and go through tryread to determine
                    225:                                 * alive status.
                    226:                                 */
                    227:                                if (__predict_false(rv == 0))
                    228:                                        goto activity;
                    229:
                    230:                                for (i = 0; i < rv; i++) {
                    231:                                        if (kev[i].filter == EVFILT_SIGNAL)
                    232:                                                dosig++;
                    233:                                }
                    234:                                if (dosig)
                    235:                                        goto cleanup;
                    236:
                    237:                                /*
                    238:                                 * ok, activity.  try to read a frame to
                    239:                                 * determine what happens next.
                    240:                                 */
                    241:  activity:
1.15      pooka     242:                                switch (readframe(spc)) {
                    243:                                case 0:
                    244:                                        continue;
                    245:                                case -1:
1.18      pooka     246:                                        imalive = false;
1.15      pooka     247:                                        goto cleanup;
                    248:                                default:
1.40      pooka     249:                                        /* case 1 */
1.15      pooka     250:                                        break;
                    251:                                }
1.12      pooka     252:
1.15      pooka     253:                                switch (spc->spc_hdr.rsp_class) {
1.12      pooka     254:                                case RUMPSP_RESP:
                    255:                                case RUMPSP_ERROR:
                    256:                                        kickwaiter(spc);
1.15      pooka     257:                                        gotresp = spc->spc_hdr.rsp_reqno ==
                    258:                                            rw->rw_reqno;
1.12      pooka     259:                                        break;
                    260:                                case RUMPSP_REQ:
                    261:                                        handlereq(spc);
                    262:                                        break;
                    263:                                default:
                    264:                                        /* panic */
                    265:                                        break;
1.15      pooka     266:                                }
1.12      pooka     267:                        }
                    268:
1.15      pooka     269:  cleanup:
                    270:                        pthread_mutex_lock(&spc->spc_mtx);
                    271:                        if (spc->spc_istatus == SPCSTATUS_WANTED)
                    272:                                kickall(spc);
                    273:                        spc->spc_istatus = SPCSTATUS_FREE;
                    274:
                    275:                        /* take one for the team */
                    276:                        if (dosig) {
                    277:                                pthread_mutex_unlock(&spc->spc_mtx);
                    278:                                pthread_sigmask(SIG_SETMASK, mask, NULL);
                    279:                                pthread_sigmask(SIG_SETMASK, &fullset, NULL);
                    280:                                pthread_mutex_lock(&spc->spc_mtx);
                    281:                        }
1.12      pooka     282:                } else {
                    283:                        spc->spc_istatus = SPCSTATUS_WANTED;
                    284:                        pthread_cond_wait(&rw->rw_cv, &spc->spc_mtx);
                    285:                }
                    286:        }
                    287:        TAILQ_REMOVE(&spc->spc_respwait, rw, rw_entries);
                    288:        pthread_mutex_unlock(&spc->spc_mtx);
                    289:        pthread_cond_destroy(&rw->rw_cv);
                    290:
1.18      pooka     291:        if (spc->spc_generation != mygen || !imalive) {
1.12      pooka     292:                return ENOTCONN;
1.18      pooka     293:        }
1.12      pooka     294:        return rw->rw_error;
                    295: }
                    296:
1.1       pooka     297: static int
1.26      pooka     298: syscall_req(struct spclient *spc, sigset_t *omask, int sysnum,
1.3       pooka     299:        const void *data, size_t dlen, void **resp)
1.1       pooka     300: {
                    301:        struct rsp_hdr rhdr;
1.3       pooka     302:        struct respwait rw;
1.39      pooka     303:        struct iovec iov[2];
1.3       pooka     304:        int rv;
1.1       pooka     305:
                    306:        rhdr.rsp_len = sizeof(rhdr) + dlen;
1.3       pooka     307:        rhdr.rsp_class = RUMPSP_REQ;
                    308:        rhdr.rsp_type = RUMPSP_SYSCALL;
1.1       pooka     309:        rhdr.rsp_sysnum = sysnum;
                    310:
1.39      pooka     311:        IOVPUT(iov[0], rhdr);
                    312:        IOVPUT_WITHSIZE(iov[1], __UNCONST(data), dlen);
                    313:
1.6       pooka     314:        do {
                    315:                putwait(spc, &rw, &rhdr);
1.39      pooka     316:                if ((rv = send_with_recon(spc, iov, __arraycount(iov))) != 0) {
1.6       pooka     317:                        unputwait(spc, &rw);
1.18      pooka     318:                        continue;
1.6       pooka     319:                }
                    320:
1.26      pooka     321:                rv = cliwaitresp(spc, &rw, omask, false);
1.20      pooka     322:                if (rv == ENOTCONN)
                    323:                        rv = EAGAIN;
                    324:        } while (rv == EAGAIN);
1.3       pooka     325:
                    326:        *resp = rw.rw_data;
                    327:        return rv;
1.1       pooka     328: }
                    329:
                    330: static int
1.29      pooka     331: handshake_req(struct spclient *spc, int type, void *data,
                    332:        int cancel, bool haslock)
1.10      pooka     333: {
1.11      pooka     334:        struct handshake_fork rf;
1.43      pooka     335:        const char *myprogname = NULL; /* XXXgcc */
1.10      pooka     336:        struct rsp_hdr rhdr;
                    337:        struct respwait rw;
1.12      pooka     338:        sigset_t omask;
1.21      pooka     339:        size_t bonus;
1.39      pooka     340:        struct iovec iov[2];
1.10      pooka     341:        int rv;
                    342:
1.29      pooka     343:        if (type == HANDSHAKE_FORK) {
1.21      pooka     344:                bonus = sizeof(rf);
                    345:        } else {
1.39      pooka     346:                myprogname = getprogname();
                    347:                bonus = strlen(myprogname)+1;
1.21      pooka     348:        }
                    349:
1.10      pooka     350:        /* performs server handshake */
1.21      pooka     351:        rhdr.rsp_len = sizeof(rhdr) + bonus;
1.10      pooka     352:        rhdr.rsp_class = RUMPSP_REQ;
                    353:        rhdr.rsp_type = RUMPSP_HANDSHAKE;
1.29      pooka     354:        rhdr.rsp_handshake = type;
1.10      pooka     355:
1.39      pooka     356:        IOVPUT(iov[0], rhdr);
                    357:
1.12      pooka     358:        pthread_sigmask(SIG_SETMASK, &fullset, &omask);
1.18      pooka     359:        if (haslock)
                    360:                putwait_locked(spc, &rw, &rhdr);
                    361:        else
                    362:                putwait(spc, &rw, &rhdr);
1.29      pooka     363:        if (type == HANDSHAKE_FORK) {
                    364:                memcpy(rf.rf_auth, data, sizeof(rf.rf_auth)); /* uh, why? */
1.11      pooka     365:                rf.rf_cancel = cancel;
1.39      pooka     366:                IOVPUT(iov[1], rf);
1.21      pooka     367:        } else {
1.43      pooka     368:                IOVPUT_WITHSIZE(iov[1], __UNCONST(myprogname), bonus);
1.11      pooka     369:        }
1.39      pooka     370:        rv = send_with_recon(spc, iov, __arraycount(iov));
1.18      pooka     371:        if (rv || cancel) {
                    372:                if (haslock)
                    373:                        unputwait_locked(spc, &rw);
                    374:                else
                    375:                        unputwait(spc, &rw);
                    376:                if (cancel) {
1.26      pooka     377:                        goto out;
1.18      pooka     378:                }
                    379:        } else {
                    380:                rv = cliwaitresp(spc, &rw, &omask, haslock);
1.10      pooka     381:        }
                    382:        if (rv)
1.26      pooka     383:                goto out;
1.10      pooka     384:
                    385:        rv = *(int *)rw.rw_data;
                    386:        free(rw.rw_data);
                    387:
1.26      pooka     388:  out:
                    389:        pthread_sigmask(SIG_SETMASK, &omask, NULL);
1.10      pooka     390:        return rv;
                    391: }
                    392:
                    393: static int
1.26      pooka     394: prefork_req(struct spclient *spc, sigset_t *omask, void **resp)
1.11      pooka     395: {
                    396:        struct rsp_hdr rhdr;
                    397:        struct respwait rw;
1.39      pooka     398:        struct iovec iov[1];
1.11      pooka     399:        int rv;
                    400:
                    401:        rhdr.rsp_len = sizeof(rhdr);
                    402:        rhdr.rsp_class = RUMPSP_REQ;
                    403:        rhdr.rsp_type = RUMPSP_PREFORK;
                    404:        rhdr.rsp_error = 0;
                    405:
1.39      pooka     406:        IOVPUT(iov[0], rhdr);
                    407:
1.18      pooka     408:        do {
                    409:                putwait(spc, &rw, &rhdr);
1.39      pooka     410:                rv = send_with_recon(spc, iov, __arraycount(iov));
1.18      pooka     411:                if (rv != 0) {
                    412:                        unputwait(spc, &rw);
                    413:                        continue;
                    414:                }
1.11      pooka     415:
1.26      pooka     416:                rv = cliwaitresp(spc, &rw, omask, false);
1.20      pooka     417:                if (rv == ENOTCONN)
                    418:                        rv = EAGAIN;
                    419:        } while (rv == EAGAIN);
1.18      pooka     420:
1.11      pooka     421:        *resp = rw.rw_data;
                    422:        return rv;
                    423: }
                    424:
1.18      pooka     425: /*
                    426:  * prevent response code from deadlocking with reconnect code
                    427:  */
1.11      pooka     428: static int
1.18      pooka     429: resp_sendlock(struct spclient *spc)
                    430: {
                    431:        int rv = 0;
                    432:
                    433:        pthread_mutex_lock(&spc->spc_mtx);
                    434:        while (spc->spc_ostatus != SPCSTATUS_FREE) {
                    435:                if (__predict_false(spc->spc_reconnecting)) {
                    436:                        rv = EBUSY;
                    437:                        goto out;
                    438:                }
                    439:                spc->spc_ostatus = SPCSTATUS_WANTED;
                    440:                pthread_cond_wait(&spc->spc_cv, &spc->spc_mtx);
                    441:        }
                    442:        spc->spc_ostatus = SPCSTATUS_BUSY;
                    443:
                    444:  out:
                    445:        pthread_mutex_unlock(&spc->spc_mtx);
                    446:        return rv;
                    447: }
                    448:
                    449: static void
1.5       pooka     450: send_copyin_resp(struct spclient *spc, uint64_t reqno, void *data, size_t dlen,
                    451:        int wantstr)
1.1       pooka     452: {
                    453:        struct rsp_hdr rhdr;
1.39      pooka     454:        struct iovec iov[2];
1.1       pooka     455:
1.5       pooka     456:        if (wantstr)
                    457:                dlen = MIN(dlen, strlen(data)+1);
                    458:
1.1       pooka     459:        rhdr.rsp_len = sizeof(rhdr) + dlen;
                    460:        rhdr.rsp_reqno = reqno;
1.3       pooka     461:        rhdr.rsp_class = RUMPSP_RESP;
                    462:        rhdr.rsp_type = RUMPSP_COPYIN;
1.1       pooka     463:        rhdr.rsp_sysnum = 0;
                    464:
1.39      pooka     465:        IOVPUT(iov[0], rhdr);
                    466:        IOVPUT_WITHSIZE(iov[1], data, dlen);
                    467:
1.18      pooka     468:        if (resp_sendlock(spc) != 0)
                    469:                return;
1.39      pooka     470:        (void)SENDIOV(spc, iov);
1.3       pooka     471:        sendunlock(spc);
1.1       pooka     472: }
                    473:
1.18      pooka     474: static void
1.1       pooka     475: send_anonmmap_resp(struct spclient *spc, uint64_t reqno, void *addr)
                    476: {
                    477:        struct rsp_hdr rhdr;
1.39      pooka     478:        struct iovec iov[2];
1.1       pooka     479:
                    480:        rhdr.rsp_len = sizeof(rhdr) + sizeof(addr);
                    481:        rhdr.rsp_reqno = reqno;
1.3       pooka     482:        rhdr.rsp_class = RUMPSP_RESP;
                    483:        rhdr.rsp_type = RUMPSP_ANONMMAP;
1.1       pooka     484:        rhdr.rsp_sysnum = 0;
                    485:
1.39      pooka     486:        IOVPUT(iov[0], rhdr);
                    487:        IOVPUT(iov[1], addr);
                    488:
1.18      pooka     489:        if (resp_sendlock(spc) != 0)
                    490:                return;
1.39      pooka     491:        (void)SENDIOV(spc, iov);
1.3       pooka     492:        sendunlock(spc);
1.1       pooka     493: }
                    494:
                    495: int
                    496: rumpclient_syscall(int sysnum, const void *data, size_t dlen,
                    497:        register_t *retval)
                    498: {
                    499:        struct rsp_sysresp *resp;
1.26      pooka     500:        sigset_t omask;
1.3       pooka     501:        void *rdata;
                    502:        int rv;
                    503:
1.26      pooka     504:        pthread_sigmask(SIG_SETMASK, &fullset, &omask);
                    505:
1.3       pooka     506:        DPRINTF(("rumpsp syscall_req: syscall %d with %p/%zu\n",
                    507:            sysnum, data, dlen));
                    508:
1.26      pooka     509:        rv = syscall_req(&clispc, &omask, sysnum, data, dlen, &rdata);
1.3       pooka     510:        if (rv)
1.26      pooka     511:                goto out;
1.3       pooka     512:
                    513:        resp = rdata;
                    514:        DPRINTF(("rumpsp syscall_resp: syscall %d error %d, rv: %d/%d\n",
                    515:            sysnum, rv, resp->rsys_retval[0], resp->rsys_retval[1]));
1.1       pooka     516:
1.3       pooka     517:        memcpy(retval, &resp->rsys_retval, sizeof(resp->rsys_retval));
                    518:        rv = resp->rsys_error;
                    519:        free(rdata);
1.1       pooka     520:
1.26      pooka     521:  out:
                    522:        pthread_sigmask(SIG_SETMASK, &omask, NULL);
1.3       pooka     523:        return rv;
                    524: }
1.1       pooka     525:
1.3       pooka     526: static void
                    527: handlereq(struct spclient *spc)
                    528: {
                    529:        struct rsp_copydata *copydata;
1.16      pooka     530:        struct rsp_hdr *rhdr = &spc->spc_hdr;
1.3       pooka     531:        void *mapaddr;
                    532:        size_t maplen;
1.5       pooka     533:        int reqtype = spc->spc_hdr.rsp_type;
1.1       pooka     534:
1.5       pooka     535:        switch (reqtype) {
1.3       pooka     536:        case RUMPSP_COPYIN:
1.5       pooka     537:        case RUMPSP_COPYINSTR:
1.3       pooka     538:                /*LINTED*/
                    539:                copydata = (struct rsp_copydata *)spc->spc_buf;
                    540:                DPRINTF(("rump_sp handlereq: copyin request: %p/%zu\n",
                    541:                    copydata->rcp_addr, copydata->rcp_len));
                    542:                send_copyin_resp(spc, spc->spc_hdr.rsp_reqno,
1.5       pooka     543:                    copydata->rcp_addr, copydata->rcp_len,
                    544:                    reqtype == RUMPSP_COPYINSTR);
1.3       pooka     545:                break;
                    546:        case RUMPSP_COPYOUT:
1.5       pooka     547:        case RUMPSP_COPYOUTSTR:
1.3       pooka     548:                /*LINTED*/
                    549:                copydata = (struct rsp_copydata *)spc->spc_buf;
                    550:                DPRINTF(("rump_sp handlereq: copyout request: %p/%zu\n",
                    551:                    copydata->rcp_addr, copydata->rcp_len));
                    552:                /*LINTED*/
                    553:                memcpy(copydata->rcp_addr, copydata->rcp_data,
                    554:                    copydata->rcp_len);
                    555:                break;
                    556:        case RUMPSP_ANONMMAP:
                    557:                /*LINTED*/
                    558:                maplen = *(size_t *)spc->spc_buf;
                    559:                mapaddr = mmap(NULL, maplen, PROT_READ|PROT_WRITE,
                    560:                    MAP_ANON, -1, 0);
                    561:                if (mapaddr == MAP_FAILED)
                    562:                        mapaddr = NULL;
                    563:                DPRINTF(("rump_sp handlereq: anonmmap: %p\n", mapaddr));
                    564:                send_anonmmap_resp(spc, spc->spc_hdr.rsp_reqno, mapaddr);
                    565:                break;
1.16      pooka     566:        case RUMPSP_RAISE:
                    567:                DPRINTF(("rump_sp handlereq: raise sig %d\n", rhdr->rsp_signo));
1.18      pooka     568:                raise((int)rhdr->rsp_signo);
1.16      pooka     569:                /*
                    570:                 * We most likely have signals blocked, but the signal
                    571:                 * will be handled soon enough when we return.
                    572:                 */
                    573:                break;
1.3       pooka     574:        default:
1.12      pooka     575:                printf("PANIC: INVALID TYPE %d\n", reqtype);
1.3       pooka     576:                abort();
                    577:                break;
1.1       pooka     578:        }
                    579:
1.6       pooka     580:        spcfreebuf(spc);
1.1       pooka     581: }
                    582:
1.11      pooka     583: static unsigned ptab_idx;
                    584: static struct sockaddr *serv_sa;
                    585:
1.27      pooka     586: /* dup until we get a "good" fd which does not collide with stdio */
                    587: static int
1.28      pooka     588: dupgood(int myfd, int mustchange)
1.27      pooka     589: {
1.28      pooka     590:        int ofds[4];
1.27      pooka     591:        int i;
1.45    ! alnsn     592:        int sverrno;
1.27      pooka     593:
1.28      pooka     594:        for (i = 0; (myfd <= 2 || mustchange) && myfd != -1; i++) {
1.27      pooka     595:                assert(i < __arraycount(ofds));
                    596:                ofds[i] = myfd;
                    597:                myfd = host_dup(myfd);
1.28      pooka     598:                if (mustchange) {
                    599:                        i--; /* prevent closing old fd */
                    600:                        mustchange = 0;
                    601:                }
1.27      pooka     602:        }
                    603:
1.45    ! alnsn     604:        sverrno = 0;
        !           605:        if (myfd == -1 && i > 0)
        !           606:                sverrno = errno;
        !           607:
1.27      pooka     608:        for (i--; i >= 0; i--) {
                    609:                host_close(ofds[i]);
                    610:        }
                    611:
1.45    ! alnsn     612:        if (sverrno)
        !           613:                errno = sverrno;
        !           614:
1.27      pooka     615:        return myfd;
                    616: }
                    617:
1.11      pooka     618: static int
1.44      pooka     619: doconnect(void)
1.1       pooka     620: {
1.18      pooka     621:        struct respwait rw;
                    622:        struct rsp_hdr rhdr;
1.15      pooka     623:        struct kevent kev[NSIG+1];
1.9       pooka     624:        char banner[MAXBANNER];
1.18      pooka     625:        struct pollfd pfd;
1.15      pooka     626:        int s, error, flags, i;
1.9       pooka     627:        ssize_t n;
1.1       pooka     628:
1.18      pooka     629:        if (kq != -1)
                    630:                host_close(kq);
                    631:        kq = -1;
1.19      pooka     632:        s = -1;
1.18      pooka     633:
                    634:        if (clispc.spc_fd != -1)
                    635:                host_close(clispc.spc_fd);
                    636:        clispc.spc_fd = -1;
                    637:
                    638:        /*
                    639:         * for reconnect, gate everyone out of the receiver code
                    640:         */
                    641:        putwait_locked(&clispc, &rw, &rhdr);
                    642:
                    643:        pthread_mutex_lock(&clispc.spc_mtx);
                    644:        clispc.spc_reconnecting = 1;
                    645:        pthread_cond_broadcast(&clispc.spc_cv);
                    646:        clispc.spc_generation++;
                    647:        while (clispc.spc_istatus != SPCSTATUS_FREE) {
                    648:                clispc.spc_istatus = SPCSTATUS_WANTED;
                    649:                pthread_cond_wait(&rw.rw_cv, &clispc.spc_mtx);
                    650:        }
                    651:        kickall(&clispc);
                    652:
                    653:        /*
                    654:         * we can release it already since we hold the
                    655:         * send lock during reconnect
                    656:         * XXX: assert it
                    657:         */
                    658:        clispc.spc_istatus = SPCSTATUS_FREE;
                    659:        pthread_mutex_unlock(&clispc.spc_mtx);
                    660:        unputwait_locked(&clispc, &rw);
                    661:
                    662:        free(clispc.spc_buf);
                    663:        clispc.spc_off = 0;
                    664:
1.28      pooka     665:        s = dupgood(host_socket(parsetab[ptab_idx].domain, SOCK_STREAM, 0), 0);
1.11      pooka     666:        if (s == -1)
1.2       pooka     667:                return -1;
1.1       pooka     668:
1.18      pooka     669:        pfd.fd = s;
                    670:        pfd.events = POLLIN;
                    671:        while (host_connect(s, serv_sa, (socklen_t)serv_sa->sa_len) == -1) {
                    672:                if (errno == EINTR)
                    673:                        continue;
1.44      pooka     674:                ERRLOG(("rump_sp: client connect failed: %s\n",
                    675:                    strerror(errno)));
1.20      pooka     676:                return -1;
1.2       pooka     677:        }
1.1       pooka     678:
1.11      pooka     679:        if ((error = parsetab[ptab_idx].connhook(s)) != 0) {
1.44      pooka     680:                ERRLOG(("rump_sp: connect hook failed\n"));
1.2       pooka     681:                return -1;
1.1       pooka     682:        }
1.4       pooka     683:
1.45    ! alnsn     684:        if ((n = host_read(s, banner, sizeof(banner)-1)) <= 0) {
1.44      pooka     685:                ERRLOG(("rump_sp: failed to read banner\n"));
1.2       pooka     686:                return -1;
1.1       pooka     687:        }
1.9       pooka     688:
                    689:        if (banner[n-1] != '\n') {
1.44      pooka     690:                ERRLOG(("rump_sp: invalid banner\n"));
1.9       pooka     691:                return -1;
                    692:        }
                    693:        banner[n] = '\0';
1.45    ! alnsn     694:        /* XXX parse the banner some day */
1.9       pooka     695:
1.15      pooka     696:        flags = host_fcntl(s, F_GETFL, 0);
                    697:        if (host_fcntl(s, F_SETFL, flags | O_NONBLOCK) == -1) {
1.44      pooka     698:                ERRLOG(("rump_sp: socket fd NONBLOCK: %s\n", strerror(errno)));
1.15      pooka     699:                return -1;
                    700:        }
1.18      pooka     701:        clispc.spc_fd = s;
                    702:        clispc.spc_state = SPCSTATE_RUNNING;
                    703:        clispc.spc_reconnecting = 0;
1.15      pooka     704:
                    705:        /* setup kqueue, we want all signals and the fd */
1.28      pooka     706:        if ((kq = dupgood(host_kqueue(), 0)) == -1) {
1.44      pooka     707:                ERRLOG(("rump_sp: cannot setup kqueue"));
1.15      pooka     708:                return -1;
                    709:        }
                    710:
                    711:        for (i = 0; i < NSIG; i++) {
                    712:                EV_SET(&kev[i], i+1, EVFILT_SIGNAL, EV_ADD|EV_ENABLE, 0, 0, 0);
                    713:        }
1.18      pooka     714:        EV_SET(&kev[NSIG], clispc.spc_fd,
                    715:            EVFILT_READ, EV_ADD|EV_ENABLE, 0, 0, 0);
1.17      pooka     716:        if (host_kevent(kq, kev, NSIG+1, NULL, 0, NULL) == -1) {
1.44      pooka     717:                ERRLOG(("rump_sp: kevent() failed"));
1.15      pooka     718:                return -1;
                    719:        }
                    720:
1.18      pooka     721:        return 0;
                    722: }
                    723:
                    724: static int
                    725: doinit(void)
                    726: {
                    727:
1.11      pooka     728:        TAILQ_INIT(&clispc.spc_respwait);
                    729:        pthread_mutex_init(&clispc.spc_mtx, NULL);
                    730:        pthread_cond_init(&clispc.spc_cv, NULL);
                    731:
                    732:        return 0;
                    733: }
                    734:
1.35      pooka     735: void *rumpclient__dlsym(void *, const char *);
                    736: void *rumphijack_dlsym(void *, const char *);
                    737: void *
                    738: rumpclient__dlsym(void *handle, const char *symbol)
                    739: {
                    740:
                    741:        return dlsym(handle, symbol);
                    742: }
                    743: __weak_alias(rumphijack_dlsym,rumpclient__dlsym);
                    744:
1.38      pooka     745: static pid_t init_done = 0;
1.13      pooka     746:
1.11      pooka     747: int
                    748: rumpclient_init()
                    749: {
                    750:        char *p;
                    751:        int error;
1.29      pooka     752:        int rv = -1;
                    753:        int hstype;
1.38      pooka     754:        pid_t mypid;
1.29      pooka     755:
1.38      pooka     756:        /*
                    757:         * Make sure we're not riding the context of a previous
                    758:         * host fork.  Note: it's *possible* that after n>1 forks
                    759:         * we have the same pid as one of our exited parents, but
                    760:         * I'm pretty sure there are 0 practical implications, since
                    761:         * it means generations would have to skip rumpclient init.
                    762:         */
                    763:        if (init_done == (mypid = getpid()))
1.29      pooka     764:                return 0;
1.38      pooka     765:
                    766:        /* kq does not traverse fork() */
                    767:        if (init_done != 0)
                    768:                kq = -1;
                    769:        init_done = mypid;
1.11      pooka     770:
1.25      pooka     771:        sigfillset(&fullset);
                    772:
1.13      pooka     773:        /*
                    774:         * sag mir, wo die symbol sind.  zogen fort, der krieg beginnt.
                    775:         * wann wird man je verstehen?  wann wird man je verstehen?
                    776:         */
                    777: #define FINDSYM2(_name_,_syscall_)                                     \
1.35      pooka     778:        if ((host_##_name_ = rumphijack_dlsym(RTLD_NEXT,                \
1.34      pooka     779:            #_syscall_)) == NULL) {                                     \
1.36      pooka     780:                if (rumphijack_dlsym == rumpclient__dlsym)              \
1.34      pooka     781:                        host_##_name_ = _name_; /* static fallback */   \
1.36      pooka     782:                if (host_##_name_ == NULL)                              \
1.34      pooka     783:                        errx(1, "cannot find %s: %s", #_syscall_,       \
                    784:                            dlerror());                                 \
                    785:        }
1.13      pooka     786: #define FINDSYM(_name_) FINDSYM2(_name_,_name_)
1.34      pooka     787:        FINDSYM2(socket,__socket30)
                    788:        FINDSYM(close)
                    789:        FINDSYM(connect)
                    790:        FINDSYM(fcntl)
                    791:        FINDSYM(poll)
                    792:        FINDSYM(read)
1.39      pooka     793:        FINDSYM(sendmsg)
1.34      pooka     794:        FINDSYM(setsockopt)
                    795:        FINDSYM(dup)
                    796:        FINDSYM(kqueue)
                    797:        FINDSYM(execve)
1.22      pooka     798: #if !__NetBSD_Prereq__(5,99,7)
1.34      pooka     799:        FINDSYM(kevent)
1.22      pooka     800: #else
1.34      pooka     801:        FINDSYM2(kevent,_sys___kevent50)
1.22      pooka     802: #endif
1.13      pooka     803: #undef FINDSYM
                    804: #undef FINDSY2
                    805:
1.28      pooka     806:        if ((p = getenv("RUMP__PARSEDSERVER")) == NULL) {
                    807:                if ((p = getenv("RUMP_SERVER")) == NULL) {
                    808:                        errno = ENOENT;
1.29      pooka     809:                        goto out;
1.28      pooka     810:                }
1.11      pooka     811:        }
                    812:
                    813:        if ((error = parseurl(p, &serv_sa, &ptab_idx, 0)) != 0) {
                    814:                errno = error;
1.29      pooka     815:                goto out;
1.11      pooka     816:        }
                    817:
1.18      pooka     818:        if (doinit() == -1)
1.29      pooka     819:                goto out;
1.28      pooka     820:
                    821:        if ((p = getenv("RUMPCLIENT__EXECFD")) != NULL) {
                    822:                sscanf(p, "%d,%d", &clispc.spc_fd, &kq);
                    823:                unsetenv("RUMPCLIENT__EXECFD");
1.29      pooka     824:                hstype = HANDSHAKE_EXEC;
                    825:        } else {
1.44      pooka     826:                if (doconnect() == -1)
1.29      pooka     827:                        goto out;
                    828:                hstype = HANDSHAKE_GUEST;
1.28      pooka     829:        }
                    830:
1.29      pooka     831:        error = handshake_req(&clispc, hstype, NULL, 0, false);
1.11      pooka     832:        if (error) {
                    833:                pthread_mutex_destroy(&clispc.spc_mtx);
                    834:                pthread_cond_destroy(&clispc.spc_cv);
1.18      pooka     835:                if (clispc.spc_fd != -1)
                    836:                        host_close(clispc.spc_fd);
1.10      pooka     837:                errno = error;
1.29      pooka     838:                goto out;
1.10      pooka     839:        }
1.29      pooka     840:        rv = 0;
1.10      pooka     841:
1.29      pooka     842:  out:
                    843:        if (rv == -1)
                    844:                init_done = 0;
                    845:        return rv;
1.11      pooka     846: }
                    847:
                    848: struct rumpclient_fork {
                    849:        uint32_t fork_auth[AUTHLEN];
1.31      pooka     850:        struct spclient fork_spc;
                    851:        int fork_kq;
1.11      pooka     852: };
                    853:
                    854: struct rumpclient_fork *
                    855: rumpclient_prefork(void)
                    856: {
                    857:        struct rumpclient_fork *rpf;
1.26      pooka     858:        sigset_t omask;
1.11      pooka     859:        void *resp;
                    860:        int rv;
                    861:
1.26      pooka     862:        pthread_sigmask(SIG_SETMASK, &fullset, &omask);
1.11      pooka     863:        rpf = malloc(sizeof(*rpf));
                    864:        if (rpf == NULL)
1.30      pooka     865:                goto out;
1.11      pooka     866:
1.26      pooka     867:        if ((rv = prefork_req(&clispc, &omask, &resp)) != 0) {
1.11      pooka     868:                free(rpf);
                    869:                errno = rv;
1.26      pooka     870:                rpf = NULL;
                    871:                goto out;
1.11      pooka     872:        }
                    873:
                    874:        memcpy(rpf->fork_auth, resp, sizeof(rpf->fork_auth));
                    875:        free(resp);
                    876:
1.31      pooka     877:        rpf->fork_spc = clispc;
                    878:        rpf->fork_kq = kq;
                    879:
1.26      pooka     880:  out:
                    881:        pthread_sigmask(SIG_SETMASK, &omask, NULL);
1.11      pooka     882:        return rpf;
                    883: }
                    884:
                    885: int
                    886: rumpclient_fork_init(struct rumpclient_fork *rpf)
                    887: {
                    888:        int error;
1.23      pooka     889:        int osock;
1.11      pooka     890:
1.23      pooka     891:        osock = clispc.spc_fd;
1.11      pooka     892:        memset(&clispc, 0, sizeof(clispc));
1.23      pooka     893:        clispc.spc_fd = osock;
                    894:
                    895:        kq = -1; /* kqueue descriptor is not copied over fork() */
1.11      pooka     896:
1.18      pooka     897:        if (doinit() == -1)
                    898:                return -1;
1.44      pooka     899:        if (doconnect() == -1)
1.11      pooka     900:                return -1;
1.10      pooka     901:
1.29      pooka     902:        error = handshake_req(&clispc, HANDSHAKE_FORK, rpf->fork_auth,
                    903:            0, false);
1.10      pooka     904:        if (error) {
                    905:                pthread_mutex_destroy(&clispc.spc_mtx);
                    906:                pthread_cond_destroy(&clispc.spc_cv);
1.11      pooka     907:                errno = error;
                    908:                return -1;
1.10      pooka     909:        }
1.11      pooka     910:
                    911:        return 0;
1.1       pooka     912: }
1.20      pooka     913:
1.42      pooka     914: /*ARGSUSED*/
1.20      pooka     915: void
1.31      pooka     916: rumpclient_fork_cancel(struct rumpclient_fork *rpf)
                    917: {
                    918:
                    919:        /* EUNIMPL */
                    920: }
                    921:
                    922: void
                    923: rumpclient_fork_vparent(struct rumpclient_fork *rpf)
                    924: {
                    925:
                    926:        clispc = rpf->fork_spc;
                    927:        kq = rpf->fork_kq;
                    928: }
                    929:
                    930: void
1.20      pooka     931: rumpclient_setconnretry(time_t timeout)
                    932: {
                    933:
1.24      pooka     934:        if (timeout < RUMPCLIENT_RETRYCONN_DIE)
1.20      pooka     935:                return; /* gigo */
                    936:
                    937:        retrytimo = timeout;
                    938: }
1.28      pooka     939:
                    940: int
                    941: rumpclient__closenotify(int *fdp, enum rumpclient_closevariant variant)
                    942: {
                    943:        int fd = *fdp;
                    944:        int untilfd, rv;
                    945:        int newfd;
                    946:
                    947:        switch (variant) {
                    948:        case RUMPCLIENT_CLOSE_FCLOSEM:
                    949:                untilfd = MAX(clispc.spc_fd, kq);
                    950:                for (; fd <= untilfd; fd++) {
                    951:                        if (fd == clispc.spc_fd || fd == kq)
                    952:                                continue;
                    953:                        rv = host_close(fd);
                    954:                        if (rv == -1)
                    955:                                return -1;
                    956:                }
                    957:                *fdp = fd;
                    958:                break;
                    959:
                    960:        case RUMPCLIENT_CLOSE_CLOSE:
                    961:        case RUMPCLIENT_CLOSE_DUP2:
                    962:                if (fd == clispc.spc_fd) {
                    963:                        struct kevent kev[2];
                    964:
                    965:                        newfd = dupgood(clispc.spc_fd, 1);
                    966:                        if (newfd == -1)
                    967:                                return -1;
                    968:                        /*
                    969:                         * now, we have a new socket number, so change
                    970:                         * the file descriptor that kqueue is
                    971:                         * monitoring.  remove old and add new.
                    972:                         */
                    973:                        EV_SET(&kev[0], clispc.spc_fd,
                    974:                            EVFILT_READ, EV_DELETE, 0, 0, 0);
                    975:                        EV_SET(&kev[1], newfd,
                    976:                            EVFILT_READ, EV_ADD|EV_ENABLE, 0, 0, 0);
                    977:                        if (host_kevent(kq, kev, 2, NULL, 0, NULL) == -1) {
                    978:                                int sverrno = errno;
                    979:                                host_close(newfd);
                    980:                                errno = sverrno;
                    981:                                return -1;
                    982:                        }
                    983:                        clispc.spc_fd = newfd;
                    984:                }
                    985:                if (fd == kq) {
                    986:                        newfd = dupgood(kq, 1);
                    987:                        if (newfd == -1)
                    988:                                return -1;
                    989:                        kq = newfd;
                    990:                }
                    991:                break;
                    992:        }
                    993:
                    994:        return 0;
                    995: }
                    996:
1.30      pooka     997: pid_t
1.31      pooka     998: rumpclient_fork()
1.30      pooka     999: {
                   1000:
1.31      pooka    1001:        return rumpclient__dofork(fork);
1.30      pooka    1002: }
                   1003:
1.28      pooka    1004: /*
                   1005:  * Process is about to exec.  Save info about our existing connection
                   1006:  * in the env.  rumpclient will check for this info in init().
                   1007:  * This is mostly for the benefit of rumphijack, but regular applications
                   1008:  * may use it as well.
                   1009:  */
                   1010: int
1.30      pooka    1011: rumpclient_exec(const char *path, char *const argv[], char *const envp[])
1.28      pooka    1012: {
                   1013:        char buf[4096];
                   1014:        char **newenv;
                   1015:        char *envstr, *envstr2;
1.30      pooka    1016:        size_t nelem;
                   1017:        int rv, sverrno;
1.28      pooka    1018:
                   1019:        snprintf(buf, sizeof(buf), "RUMPCLIENT__EXECFD=%d,%d",
                   1020:            clispc.spc_fd, kq);
                   1021:        envstr = malloc(strlen(buf)+1);
                   1022:        if (envstr == NULL) {
                   1023:                return ENOMEM;
                   1024:        }
                   1025:        strcpy(envstr, buf);
                   1026:
                   1027:        /* do we have a fully parsed url we want to forward in the env? */
                   1028:        if (*parsedurl != '\0') {
                   1029:                snprintf(buf, sizeof(buf),
                   1030:                    "RUMP__PARSEDSERVER=%s", parsedurl);
                   1031:                envstr2 = malloc(strlen(buf)+1);
                   1032:                if (envstr2 == NULL) {
                   1033:                        free(envstr);
                   1034:                        return ENOMEM;
                   1035:                }
                   1036:                strcpy(envstr2, buf);
                   1037:        } else {
                   1038:                envstr2 = NULL;
                   1039:        }
                   1040:
1.30      pooka    1041:        for (nelem = 0; envp && envp[nelem]; nelem++)
                   1042:                continue;
1.28      pooka    1043:
1.33      pooka    1044:        newenv = malloc(sizeof(*newenv) * (nelem+3));
1.28      pooka    1045:        if (newenv == NULL) {
                   1046:                free(envstr2);
                   1047:                free(envstr);
                   1048:                return ENOMEM;
                   1049:        }
1.30      pooka    1050:        memcpy(&newenv[0], envp, nelem*sizeof(*envp));
1.28      pooka    1051:
1.30      pooka    1052:        newenv[nelem] = envstr;
                   1053:        newenv[nelem+1] = envstr2;
                   1054:        newenv[nelem+2] = NULL;
                   1055:
                   1056:        rv = host_execve(path, argv, newenv);
                   1057:
                   1058:        _DIAGASSERT(rv != 0);
                   1059:        sverrno = errno;
                   1060:        free(envstr2);
                   1061:        free(envstr);
                   1062:        free(newenv);
                   1063:        errno = sverrno;
                   1064:        return rv;
1.28      pooka    1065: }
1.31      pooka    1066:
                   1067: int
                   1068: rumpclient_daemon(int nochdir, int noclose)
                   1069: {
                   1070:        struct rumpclient_fork *rf;
                   1071:        int sverrno;
                   1072:
                   1073:        if ((rf = rumpclient_prefork()) == NULL)
                   1074:                return -1;
                   1075:
                   1076:        if (daemon(nochdir, noclose) == -1) {
                   1077:                sverrno = errno;
                   1078:                rumpclient_fork_cancel(rf);
                   1079:                errno = sverrno;
                   1080:                return -1;
                   1081:        }
                   1082:
                   1083:        if (rumpclient_fork_init(rf) == -1)
                   1084:                return -1;
                   1085:
                   1086:        return 0;
                   1087: }

CVSweb <webmaster@jp.NetBSD.org>