]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
mlmmj-receive: deduplicate code
authorBaptiste Daroussin <bapt@FreeBSD.org>
Thu, 6 Jul 2023 13:11:38 +0000 (15:11 +0200)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Thu, 6 Jul 2023 13:11:38 +0000 (15:11 +0200)
src/mlmmj-receive.c

index bb4d2cb58cea1850e39406eb57a3f336c6d593bd..c7e002728967b80e1e909fef613e057e5e194007 100644 (file)
@@ -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);