This improves the I/O performance when outputting large backups.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
include $(TOPDIR)/rules.mk
PKG_NAME:=cgi-io
include $(TOPDIR)/rules.mk
PKG_NAME:=cgi-io
PKG_LICENSE:=GPL-2.0-or-later
PKG_LICENSE:=GPL-2.0-or-later
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#define _GNU_SOURCE /* splice(), SPLICE_F_MORE */
+
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int len;
int status;
int fds[2];
int len;
int status;
int fds[2];
char datestr[16] = { 0 };
char hostname[64] = { 0 };
char *fields[] = { "sessionid", NULL };
char datestr[16] = { 0 };
char hostname[64] = { 0 };
char *fields[] = { "sessionid", NULL };
- 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));
now = time(NULL);
strftime(datestr, sizeof(datestr) - 1, "%Y-%m-%d", localtime(&now));
printf("Content-Disposition: attachment; "
"filename=\"backup-%s-%s.tar.gz\"\r\n\r\n", hostname, datestr);
printf("Content-Disposition: attachment; "
"filename=\"backup-%s-%s.tar.gz\"\r\n\r\n", hostname, datestr);
- do {
- waitpid(pid, &status, 0);
- while ((len = read(fds[0], buf, sizeof(buf))) > 0) {
- fwrite(buf, len, 1, stdout);
- fflush(stdout);
- }
+ do {
+ len = splice(fds[0], NULL, 1, NULL, 4096, SPLICE_F_MORE);
+ } while (len > 0);
- } while (!WIFEXITED(status));
+ waitpid(pid, &status, 0);
close(fds[0]);
close(fds[1]);
close(fds[0]);
close(fds[1]);