From: Doug Nazar <nazard@nazar.ca>
To: linux-nfs@vger.kernel.org
Subject: [PATCH 01/11] Add error handling to libevent allocations.
Date: Sat, 18 Jul 2020 05:24:11 -0400 [thread overview]
Message-ID: <20200718092421.31691-2-nazard@nazar.ca> (raw)
In-Reply-To: <20200718092421.31691-1-nazard@nazar.ca>
Signed-off-by: Doug Nazar <nazard@nazar.ca>
---
utils/gssd/gssd.c | 37 +++++++++++++++++++++++++++----------
utils/idmapd/idmapd.c | 32 ++++++++++++++++++++++++++++++++
utils/nfsdcld/nfsdcld.c | 18 +++++++++++++++++-
3 files changed, 76 insertions(+), 11 deletions(-)
diff --git a/utils/gssd/gssd.c b/utils/gssd/gssd.c
index 3c7c703a..85bc4b07 100644
--- a/utils/gssd/gssd.c
+++ b/utils/gssd/gssd.c
@@ -560,14 +560,9 @@ static int
gssd_scan_clnt(struct clnt_info *clp)
{
int clntfd;
- bool gssd_was_closed;
- bool krb5_was_closed;
printerr(3, "scanning client %s\n", clp->relpath);
- gssd_was_closed = clp->gssd_fd < 0 ? true : false;
- krb5_was_closed = clp->krb5_fd < 0 ? true : false;
-
clntfd = openat(pipefs_fd, clp->relpath, O_RDONLY);
if (clntfd < 0) {
if (errno != ENOENT)
@@ -582,16 +577,30 @@ gssd_scan_clnt(struct clnt_info *clp)
if (clp->gssd_fd == -1 && clp->krb5_fd == -1)
clp->krb5_fd = openat(clntfd, "krb5", O_RDWR | O_NONBLOCK);
- if (gssd_was_closed && clp->gssd_fd >= 0) {
+ if (!clp->gssd_ev && clp->gssd_fd >= 0) {
clp->gssd_ev = event_new(evbase, clp->gssd_fd, EV_READ | EV_PERSIST,
gssd_clnt_gssd_cb, clp);
- event_add(clp->gssd_ev, NULL);
+ if (!clp->gssd_ev) {
+ printerr(0, "ERROR: %s: can't create gssd event for %s: %s\n",
+ __FUNCTION__, clp->relpath, strerror(errno));
+ close(clp->gssd_fd);
+ clp->gssd_fd = -1;
+ } else {
+ event_add(clp->gssd_ev, NULL);
+ }
}
- if (krb5_was_closed && clp->krb5_fd >= 0) {
+ if (!clp->krb5_ev && clp->krb5_fd >= 0) {
clp->krb5_ev = event_new(evbase, clp->krb5_fd, EV_READ | EV_PERSIST,
gssd_clnt_krb5_cb, clp);
- event_add(clp->krb5_ev, NULL);
+ if (!clp->krb5_ev) {
+ printerr(0, "ERROR: %s: can't create krb5 event for %s: %s\n",
+ __FUNCTION__, clp->relpath, strerror(errno));
+ close(clp->krb5_fd);
+ clp->krb5_fd = -1;
+ } else {
+ event_add(clp->krb5_ev, NULL);
+ }
}
if (clp->krb5_fd == -1 && clp->gssd_fd == -1)
@@ -1086,7 +1095,7 @@ main(int argc, char *argv[])
evbase = event_base_new();
if (!evbase) {
- printerr(0, "ERROR: failed to create event base\n");
+ printerr(0, "ERROR: failed to create event base: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
@@ -1111,9 +1120,17 @@ main(int argc, char *argv[])
signal(SIGINT, sig_die);
signal(SIGTERM, sig_die);
sighup_ev = evsignal_new(evbase, SIGHUP, gssd_scan_cb, NULL);
+ if (!sighup_ev) {
+ printerr(0, "ERROR: failed to create SIGHUP event: %s\n", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
evsignal_add(sighup_ev, NULL);
inotify_ev = event_new(evbase, inotify_fd, EV_READ | EV_PERSIST,
gssd_inotify_cb, NULL);
+ if (!inotify_ev) {
+ printerr(0, "ERROR: failed to create inotify event: %s\n", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
event_add(inotify_ev, NULL);
TAILQ_INIT(&topdir_list);
diff --git a/utils/idmapd/idmapd.c b/utils/idmapd/idmapd.c
index 12648f67..491ef54c 100644
--- a/utils/idmapd/idmapd.c
+++ b/utils/idmapd/idmapd.c
@@ -400,13 +400,21 @@ main(int argc, char **argv)
/* These events are persistent */
rootdirev = evsignal_new(evbase, SIGUSR1, dirscancb, &icq);
+ if (rootdirev == NULL)
+ errx(1, "Failed to create SIGUSR1 event.");
evsignal_add(rootdirev, NULL);
clntdirev = evsignal_new(evbase, SIGUSR2, clntscancb, &icq);
+ if (clntdirev == NULL)
+ errx(1, "Failed to create SIGUSR2 event.");
evsignal_add(clntdirev, NULL);
svrdirev = evsignal_new(evbase, SIGHUP, svrreopen, NULL);
+ if (svrdirev == NULL)
+ errx(1, "Failed to create SIGHUP event.");
evsignal_add(svrdirev, NULL);
if ( wd >= 0) {
inotifyev = event_new(evbase, inotify_fd, EV_READ, dirscancb, &icq);
+ if (inotifyev == NULL)
+ errx(1, "Failed to create inotify read event.");
event_add(inotifyev, NULL);
}
@@ -414,6 +422,8 @@ main(int argc, char **argv)
/* (Delay till start of event_dispatch to avoid possibly losing
* a SIGUSR1 between here and the call to event_dispatch().) */
initialize = evtimer_new(evbase, dirscancb, &icq);
+ if (initialize == NULL)
+ errx(1, "Failed to create initialize event.");
evtimer_add(initialize, &now);
}
@@ -768,6 +778,13 @@ nfsdreopen_one(struct idmap_client *ic)
ic->ic_fd = fd;
ic->ic_event = event_new(evbase, ic->ic_fd, EV_READ, nfsdcb, ic);
+ if (ic->ic_event == NULL) {
+ xlog_warn("nfsdreopen: Failed to create event for '%s'",
+ ic->ic_path);
+ close(ic->ic_fd);
+ ic->ic_fd = -1;
+ return;
+ }
event_add(ic->ic_event, NULL);
} else {
xlog_warn("nfsdreopen: Opening '%s' failed: errno %d (%s)",
@@ -802,6 +819,14 @@ nfsdopenone(struct idmap_client *ic)
}
ic->ic_event = event_new(evbase, ic->ic_fd, EV_READ, nfsdcb, ic);
+ if (ic->ic_event == NULL) {
+ if (verbose > 0)
+ xlog_warn("nfsdopenone: Create event for %s failed",
+ ic->ic_path);
+ close(ic->ic_fd);
+ ic->ic_fd = -1;
+ return (-1);
+ }
event_add(ic->ic_event, NULL);
if (verbose > 0)
@@ -826,6 +851,13 @@ nfsopen(struct idmap_client *ic)
}
} else {
ic->ic_event = event_new(evbase, ic->ic_fd, EV_READ, nfscb, ic);
+ if (ic->ic_event == NULL) {
+ xlog_warn("nfsdopenone: Create event for %s failed",
+ ic->ic_path);
+ close(ic->ic_fd);
+ ic->ic_fd = -1;
+ return -1;
+ }
event_add(ic->ic_event, NULL);
fcntl(ic->ic_dirfd, F_NOTIFY, 0);
fcntl(ic->ic_dirfd, F_SETSIG, 0);
diff --git a/utils/nfsdcld/nfsdcld.c b/utils/nfsdcld/nfsdcld.c
index 6cefcf24..5ad94ce2 100644
--- a/utils/nfsdcld/nfsdcld.c
+++ b/utils/nfsdcld/nfsdcld.c
@@ -142,6 +142,7 @@ static int
cld_pipe_open(struct cld_client *clnt)
{
int fd;
+ struct event *ev;
xlog(D_GENERAL, "%s: opening upcall pipe %s", __func__, pipepath);
fd = open(pipepath, O_RDWR, 0);
@@ -150,6 +151,13 @@ cld_pipe_open(struct cld_client *clnt)
return -errno;
}
+ ev = event_new(evbase, fd, EV_READ, cldcb, clnt);
+ if (ev == NULL) {
+ xlog(D_GENERAL, "%s: failed to create event for %s", __func__, pipepath);
+ close(fd);
+ return -ENOMEM;
+ }
+
if (clnt->cl_event && event_initialized(clnt->cl_event)) {
event_del(clnt->cl_event);
event_free(clnt->cl_event);
@@ -158,7 +166,7 @@ cld_pipe_open(struct cld_client *clnt)
close(clnt->cl_fd);
clnt->cl_fd = fd;
- clnt->cl_event = event_new(evbase, clnt->cl_fd, EV_READ, cldcb, clnt);
+ clnt->cl_event = ev;
/* event_add is done by the caller */
return 0;
}
@@ -304,6 +312,10 @@ cld_pipe_init(struct cld_client *clnt)
/* set event for inotify read */
pipedir_event = event_new(evbase, inotify_fd, EV_READ, cld_inotify_cb, clnt);
+ if (pipedir_event == NULL) {
+ close(inotify_fd);
+ return -ENOMEM;
+ }
event_add(pipedir_event, NULL);
out:
return ret;
@@ -768,6 +780,10 @@ main(int argc, char **argv)
}
evbase = event_base_new();
+ if (evbase == NULL) {
+ fprintf(stderr, "%s: unable to allocate event base.\n", argv[0]);
+ return 1;
+ }
xlog_syslog(0);
xlog_stderr(1);
--
2.26.2
next prev parent reply other threads:[~2020-07-18 9:25 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-18 9:24 [PATCH 00/11] nfs-utils: Misc cleanups & fixes Doug Nazar
2020-07-18 9:24 ` Doug Nazar [this message]
2020-07-18 9:24 ` [PATCH 02/11] gssd: Fix cccache buffer size Doug Nazar
2020-07-20 14:43 ` Steve Dickson
2020-07-20 15:41 ` Doug Nazar
2020-07-18 9:24 ` [PATCH 03/11] gssd: Fix handling of failed allocations Doug Nazar
2020-07-18 9:24 ` [PATCH 04/11] gssd: srchost should never be * Doug Nazar
2020-07-18 9:24 ` [PATCH 05/11] xlog: Reorganize xlog_backend() to work around -Wmaybe-uninitialized Doug Nazar
2020-07-18 9:24 ` [PATCH 06/11] nfsdcld: Add graceful exit handling and resource cleanup Doug Nazar
2020-07-18 9:24 ` [PATCH 07/11] nfsdcld: Don't copy more data than exists in column Doug Nazar
2020-07-18 9:24 ` [PATCH 08/11] svcgssd: Convert to using libevent Doug Nazar
2020-07-18 9:24 ` [PATCH 09/11] nfsidmap: Add support to cleanup resources on exit Doug Nazar
2020-07-20 15:49 ` Steve Dickson
2020-07-20 15:58 ` Doug Nazar
2020-07-20 17:31 ` Steve Dickson
2020-07-18 9:24 ` [PATCH 10/11] svcgssd: Cleanup global " Doug Nazar
2020-07-18 9:24 ` [PATCH 11/11] svcgssd: Wait for nullrpc channel if not available Doug Nazar
2020-07-18 15:55 ` J. Bruce Fields
2020-07-18 18:07 ` Doug Nazar
2020-07-27 14:42 ` [PATCH 00/11] nfs-utils: Misc cleanups & fixes Steve Dickson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200718092421.31691-2-nazard@nazar.ca \
--to=nazard@nazar.ca \
--cc=linux-nfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).