From: Eric Wong <e@80x24.org>
To: cmogstored-public@bogomips.org
Subject: [PATCH] dev.c: fail gracefully on out-of-memory errors
Date: Mon, 17 Aug 2015 06:00:30 +0000 [thread overview]
Message-ID: <1439791230-21138-1-git-send-email-e@80x24.org> (raw)
The rest of cmogstored shall be updated to fail gracefully on OOM
in due time. It may take a while, since not many systems encounter
this, but we shall become more robust as time goes on.
---
dev.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/dev.c b/dev.c
index cd14db9..5b3888b 100644
--- a/dev.c
+++ b/dev.c
@@ -169,8 +169,17 @@ int mog_dev_mkusage(const struct mog_dev *dev, struct mog_svc *svc)
if (!svc->mgmt_mfd)
return 0;
- usage_path = xasprintf("/dev%u/usage", (unsigned)dev->devid);
- tmp_path = xasprintf("%s.%x", usage_path, (unsigned)getpid());
+ if (asprintf(&usage_path, "/dev%u/usage", (unsigned)dev->devid) < 0) {
+ syslog(LOG_ERR, "error generating path: /dev%u/usage (%m)",
+ (unsigned)dev->devid);
+ return 0;
+ }
+ if (asprintf(&tmp_path, "%s.%x", usage_path, (unsigned)getpid()) < 0) {
+ syslog(LOG_ERR, "error generating path: /dev%u/usage.%u (%m)",
+ (unsigned)dev->devid, (unsigned)getpid());
+ free(usage_path);
+ return 0;
+ }
if (mog_unlink(svc, tmp_path) < 0 && errno != ENOENT) goto out;
--
EW
reply other threads:[~2015-08-17 6:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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
List information: https://yhbt.net/cmogstored/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1439791230-21138-1-git-send-email-e@80x24.org \
--to=e@80x24.org \
--cc=cmogstored-public@bogomips.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.
Code repositories for project(s) associated with this public inbox
https://yhbt.net/cmogstored.git/
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 read-only IMAP folder(s) and NNTP newsgroup(s).