example: only close output fd after request completion if -O was not used
authorFelix Fietkau <nbd@openwrt.org>
Sun, 4 May 2014 18:41:22 +0000 (20:41 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Sun, 4 May 2014 18:41:25 +0000 (20:41 +0200)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
uclient-example.c

index 144696c..5e478c3 100644 (file)
@@ -86,7 +86,7 @@ static int open_output_file(const char *path, bool create)
 
 static void request_done(struct uclient *cl)
 {
-       if (output_fd >= 0) {
+       if (output_fd >= 0 && !output_file) {
                close(output_fd);
                output_fd = -1;
        }
@@ -327,6 +327,9 @@ int main(int argc, char **argv)
 
        uclient_free(cl);
 
+       if (output_fd >= 0 && output_fd != STDOUT_FILENO)
+               close(output_fd);
+
        if (ssl_ctx)
                ssl_ops->context_free(ssl_ctx);