cmogstored dev/user discussion/issues/patches/etc
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: cmogstored-public@bogomips.org
Subject: [PATCH] http_put: gracefully handle path allocation errors
Date: Wed,  1 Jun 2016 22:32:37 +0000	[thread overview]
Message-ID: <20160601223237.14650-1-e@80x24.org> (raw)

Failing to allocate memory should be a temporary error and be
non-fatal.
---
 http_put.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/http_put.c b/http_put.c
index 92bc435..5084090 100644
--- a/http_put.c
+++ b/http_put.c
@@ -306,6 +306,8 @@ MOG_NOINLINE static void rnd_init_per_thread(void)
 static char *tmppath_for(struct mog_http *http, const char *path)
 {
 	int32_t result;
+	int rc;
+	char *s;
 
 	if (!rnd.ready)
 		rnd_init_per_thread();
@@ -313,8 +315,10 @@ static char *tmppath_for(struct mog_http *http, const char *path)
 	assert(http && "validation later"); /* TODO */
 	CHECK(int, 0, random_r(&rnd.data, &result));
 
-	return xasprintf("%s.%08x.%d.tmp",
-	                 path, (unsigned)result, (int)getpid());
+	rc = asprintf(&s, "%s.%08x.%d.tmp",
+			path, (unsigned)result, (int)getpid());
+
+	return rc >= 0 ? s : 0;
 }
 
 static struct mog_file * open_put(struct mog_http *http, char *path)
@@ -337,12 +341,17 @@ static struct mog_file * open_put(struct mog_http *http, char *path)
 		char *tmp = tmppath_for(http, path);
 		int fl = O_EXCL | O_TRUNC | O_CREAT;
 
+		if (!tmp)
+			return NULL;
+
 		http->forward = mog_file_open_put(http->svc, tmp, fl);
 
 		/* retry once on EEXIST, don't inf loop if RNG is broken */
 		if (http->forward == NULL && errno == EEXIST) {
 			free(tmp);
 			tmp = tmppath_for(http, path);
+			if (!tmp)
+				return NULL;
 			http->forward = mog_file_open_put(http->svc, tmp, fl);
 		}
 		if (http->forward == NULL) {
-- 
EW


                 reply	other threads:[~2016-06-01 22:32 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=20160601223237.14650-1-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).