From 3b47160297316bffa0fd5079aa10eebfc1012557 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Thu, 6 Jul 2023 15:11:38 +0200 Subject: [PATCH] mlmmj-receive: deduplicate code --- src/mlmmj-receive.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mlmmj-receive.c b/src/mlmmj-receive.c index bb4d2cb5..c7e00272 100644 --- a/src/mlmmj-receive.c +++ b/src/mlmmj-receive.c @@ -58,7 +58,7 @@ static void print_help(const char *prg) int main(int argc, char **argv) { char *infilename = NULL, *listdir = NULL; - char *randomstr = random_str(); + char *randomstr = NULL; char *mlmmjprocess, *bindir; int fd, opt, noprocess = 0, nofork = 0; int incfd, listfd; @@ -108,12 +108,12 @@ int main(int argc, char **argv) if (incfd == -1) err(EXIT_FAILURE, "Cannot open(%s/incoming)", listdir); - fd = openat(incfd, randomstr, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR); - while(fd < 0 && errno == EEXIST) { + do { free(randomstr); randomstr = random_str(); fd = openat(incfd, randomstr, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR); - } + } while(fd < 0 && errno == EEXIST); + xasprintf(&infilename, "%s/incoming/%s", listdir, randomstr); free(randomstr); -- 2.47.2