Skip to content

Commit

Permalink
cgi-io: merge changes from luci2-io-helper
Browse files Browse the repository at this point in the history
luci2-io-helper: bugfix buckup script read timeout

Reading files from stdin will block for ever. The uhttpd is killing the
backup process after script_timeout.

Switching read to non blocking mode and add a waitpid for the slave
process does not end in a script_timeout anymore.

Signed-off-by: Florian Eckert <Eckert.Florian@googlemail.com>
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
  • Loading branch information
dangowrt committed Jun 19, 2017
1 parent 7b15883 commit 504a51f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=cgi-io
PKG_RELEASE:=2
PKG_RELEASE:=3

PKG_LICENSE:=GPL-2.0+

Expand Down
13 changes: 10 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ main_backup(int argc, char **argv)
pid_t pid;
time_t now;
int len;
int status;
int fds[2];
char buf[4096];
char datestr[16] = { 0 };
Expand Down Expand Up @@ -610,6 +611,7 @@ main_backup(int argc, char **argv)
return -1;

default:
fcntl(fds[0], F_SETFL, fcntl(fds[0], F_GETFL) | O_NONBLOCK);
now = time(NULL);
strftime(datestr, sizeof(datestr) - 1, "%Y-%m-%d", localtime(&now));

Expand All @@ -621,10 +623,15 @@ main_backup(int argc, char **argv)
printf("Content-Disposition: attachment; "
"filename=\"backup-%s-%s.tar.gz\"\r\n\r\n", hostname, datestr);

while ((len = read(fds[0], buf, sizeof(buf))) > 0)
fwrite(buf, len, 1, stdout);
do {
waitpid(pid, &status, 0);

waitpid(pid, NULL, 0);
while ((len = read(fds[0], buf, sizeof(buf))) > 0) {
fwrite(buf, len, 1, stdout);
fflush(stdout);
}

} while (!WIFEXITED(status));

close(fds[0]);
close(fds[1]);
Expand Down

0 comments on commit 504a51f

Please sign in to comment.