delete created file when fallocate fails
parent
db4f4980c5
commit
ec5b9dc003
12
src/main.c
12
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue