summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2022-09-28 17:22:50 +0200
committerJose M. Guisado <jguisado@soleta.eu>2022-09-29 17:03:23 +0200
commitec5b9dc003c5490365f04bf2bf50951cc1d054e4 (patch)
tree1bbb1f265828d741d4c6b5b7d491b9d1e6b2dae7 /src/main.c
parentdb4f4980c5ee29a9fc74b3fe745ed74f58173a6f (diff)
delete created file when fallocate fails
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index a9fba30..85f2969 100644
--- a/src/main.c
+++ b/src/main.c
@@ -241,6 +241,17 @@ static int tip_client_get_payload(struct tip_client *cli)
return 1;
}
+static int delete_file(const char *filename)
+{
+ if (unlink(filename) < 0) {
+ syslog(LOG_ERR, "cannot delete file %s: %s",
+ filename, strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+
static int tip_client_head_hdr(struct tip_client *cli)
{
char *ptr;
@@ -277,6 +288,7 @@ static int tip_client_head_hdr(struct tip_client *cli)
if (fallocate(cli->fd, 0, 0, cli->content_len) < 0) {
syslog(LOG_ERR, "failed to allocate room for file %s: %s",
filename, strerror(errno));
+ delete_file(filename);
return -1;
}