From c145fb5a171f701b1079a7a74664f126d500c2bb Mon Sep 17 00:00:00 2001 From: pooka Date: Thu, 30 Nov 2006 05:37:48 +0000 Subject: [PATCH] summon daemon(3) in mainloop unless the nodaemon flag is given --- lib/libpuffs/puffs.c | 12 +++++++++--- lib/libpuffs/puffs.h | 14 ++++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/libpuffs/puffs.c b/lib/libpuffs/puffs.c index d4e4e7ec042a..e738f31387ce 100644 --- a/lib/libpuffs/puffs.c +++ b/lib/libpuffs/puffs.c @@ -1,4 +1,4 @@ -/* $NetBSD: puffs.c,v 1.8 2006/11/18 12:40:35 pooka Exp $ */ +/* $NetBSD: puffs.c,v 1.9 2006/11/30 05:37:48 pooka Exp $ */ /* * Copyright (c) 2005, 2006 Antti Kantee. All Rights Reserved. @@ -34,12 +34,13 @@ #include #if !defined(lint) -__RCSID("$NetBSD: puffs.c,v 1.8 2006/11/18 12:40:35 pooka Exp $"); +__RCSID("$NetBSD: puffs.c,v 1.9 2006/11/30 05:37:48 pooka Exp $"); #endif /* !lint */ #include #include +#include #include #include #include @@ -70,6 +71,7 @@ puffs_mount(struct puffs_vfsops *pvfs, struct puffs_vnops *pvn, fd = open("/dev/puffs", O_RDONLY); if (fd == -1) return NULL; + assert(fd > 2); pargs.pa_vers = 0; /* XXX: for now */ pargs.pa_flags = PUFFSFLAG_KERN(pflags); @@ -118,7 +120,7 @@ puffs_mount(struct puffs_vfsops *pvfs, struct puffs_vnops *pvn, } int -puffs_mainloop(struct puffs_usermount *pu) +puffs_mainloop(struct puffs_usermount *pu, int flags) { uint8_t *buf; int rv; @@ -127,6 +129,10 @@ puffs_mainloop(struct puffs_usermount *pu) if (!buf) return -1; + if ((flags & PUFFSLOOP_NODAEMON) == 0) + if (daemon(0, 0) == -1) + return -1; + for (;;) if ((rv = puffs_oneop(pu, buf, pu->pu_maxreqlen)) != 0) return rv; diff --git a/lib/libpuffs/puffs.h b/lib/libpuffs/puffs.h index 4465cb218e7f..4a6303019c0f 100644 --- a/lib/libpuffs/puffs.h +++ b/lib/libpuffs/puffs.h @@ -1,4 +1,4 @@ -/* $NetBSD: puffs.h,v 1.11 2006/11/23 16:44:28 pooka Exp $ */ +/* $NetBSD: puffs.h,v 1.12 2006/11/30 05:37:48 pooka Exp $ */ /* * Copyright (c) 2005, 2006 Antti Kantee. All Rights Reserved. @@ -175,21 +175,27 @@ struct puffs_usermount { void *pu_privdata; }; -#define PUFFSFLAG_KERN(a) ((a) & 0xffff) -#define PUFFSFLAG_OPDUMP 0x10000 /* dump all operations */ +#define PUFFSFLAG_KERN(a) ((a) & 0x0000ffff) +#define PUFFSFLAG_LIB(a) ((a) & 0xffff0000) + +#define PUFFSFLAG_OPDUMP 0x80000000 /* dump all operations */ struct puffs_usermount *puffs_mount(struct puffs_vfsops *, struct puffs_vnops *, const char *, int, const char *, uint32_t, size_t); -int puffs_mainloop(struct puffs_usermount *); +int puffs_mainloop(struct puffs_usermount *, int); int puffs_oneop(struct puffs_usermount *, uint8_t *, size_t); int puffs_getselectable(struct puffs_usermount *); int puffs_setblockingmode(struct puffs_usermount *, int); void puffs_dummyops(struct puffs_vnops *); +/* blocking mode argument */ #define PUFFSDEV_BLOCK 0 #define PUFFSDEV_NONBLOCK 1 +/* mainloop flags */ +#define PUFFSLOOP_NODAEMON 0x01 + struct puffs_node * puffs_newpnode(struct puffs_usermount *, void *, enum vtype); void puffs_putpnode(struct puffs_node *);