From 2aa84c3f3e9fd8e5732045c48bbaa633250f25ee Mon Sep 17 00:00:00 2001 From: neilbrown Date: Mon, 22 Nov 2004 05:36:08 +0000 Subject: [PATCH] more idmapd updates --- ChangeLog | 4 ++++ utils/idmapd/idmapd.c | 44 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 62a22f9..424cd55 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,10 @@ * utils/idmapd/idmapd.c: don't allow Default domain and anon-uid or -gid to be specified on command line. * utils/idmapd/idmapd.c: improve error messages + * utils/idmapd/idmapd.c: Reopen nfsd files on sighup. Allows us + to start up client side only (even when nfsd module not loaded), + and then sighup later after insmodding nfsd module. + 2004-11-22 NeilBrown diff --git a/utils/idmapd/idmapd.c b/utils/idmapd/idmapd.c index d2ecbeb..e965563 100644 --- a/utils/idmapd/idmapd.c +++ b/utils/idmapd/idmapd.c @@ -109,6 +109,7 @@ TAILQ_HEAD(idmap_clientq, idmap_client); static void dirscancb(int, short, void *); static void clntscancb(int, short, void *); +static void svrreopen(int, short, void *); static int nfsopen(struct idmap_client *); static void nfscb(int, short, void *); static void nfsdcb(int, short, void *); @@ -122,6 +123,7 @@ static void nametoidres(struct idmap_msg *); static int nfsdopen(char *); static int nfsdopenone(struct idmap_client *, short, char *); +static void nfsdreopen(void); size_t strlcat(char *, const char *, size_t); size_t strlcpy(char *, const char *, size_t); @@ -144,7 +146,7 @@ main(int argc, char **argv) { int fd = 0, opt, fg = 0, nfsdret = -1; struct idmap_clientq icq; - struct event rootdirev, clntdirev; + struct event rootdirev, clntdirev, svrdirev; struct event initialize; struct passwd *pw; struct group *gr; @@ -279,6 +281,8 @@ main(int argc, char **argv) signal_add(&rootdirev, NULL); signal_set(&clntdirev, SIGUSR2, clntscancb, &icq); signal_add(&clntdirev, NULL); + signal_set(&svrdirev, SIGHUP, svrreopen, NULL); + signal_add(&svrdirev, NULL); /* Fetch current state */ /* (Delay till start of event_dispatch to avoid possibly losing @@ -372,6 +376,12 @@ dirscancb(int fd, short which, void *data) return; } +static void +svrreopen(int fd, short which, void *data) +{ + nfsdreopen(); +} + static void clntscancb(int fd, short which, void *data) { @@ -568,6 +578,38 @@ out: event_add(&ic->ic_event, NULL); } +static void +nfsdreopen_one(struct idmap_client *ic) +{ + int fd; + + if (verbose > 0) + warnx("ReOpening %s", ic->ic_path); + if ((fd = open(ic->ic_path, O_RDWR, 0)) != -1) { + if (ic->ic_fd != -1) + close(ic->ic_fd); + ic->ic_event.ev_fd = ic->ic_fd = fd; + if ((ic->ic_event.ev_flags & EVLIST_INIT) == 0) { + event_set(&ic->ic_event, ic->ic_fd, EV_READ, nfsdcb, ic); + event_add(&ic->ic_event, NULL); + } + } else { + warnx("nfsdreopen: Opening '%s' failed: errno %d (%s)", + ic->ic_path, errno, strerror(errno)); + } +} + +/* + * Note: nfsdreopen assumes nfsdopen has already been called + */ +static void +nfsdreopen() +{ + nfsdreopen_one(&nfsd_ic[IC_NAMEID]); + nfsdreopen_one(&nfsd_ic[IC_IDNAME]); + return; +} + static int nfsdopen(char *path) { -- 2.39.5