mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
copiousoutput: cleanup after copiousoutput handling. Temporary files should
be deleted
This commit is contained in:
parent
c677bc010d
commit
4dc4ea47f2
@ -4,6 +4,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#ifdef HAVE_UNISTD_H
|
#ifdef HAVE_UNISTD_H
|
||||||
@ -375,6 +376,25 @@ shutdown_connection_stream(struct connection *conn)
|
|||||||
conn->stream_pipes[0] = conn->stream_pipes[1] = -1;
|
conn->stream_pipes[0] = conn->stream_pipes[1] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
close_popen(int fd)
|
||||||
|
{
|
||||||
|
struct popen_data *pop;
|
||||||
|
|
||||||
|
foreach (pop, copiousoutput_data) {
|
||||||
|
if (pop->fd == fd) {
|
||||||
|
del_from_list(pop);
|
||||||
|
pclose(pop->stream);
|
||||||
|
if (pop->filename) {
|
||||||
|
unlink(pop->filename);
|
||||||
|
mem_free(pop->filename);
|
||||||
|
}
|
||||||
|
mem_free(pop);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
free_connection_data(struct connection *conn)
|
free_connection_data(struct connection *conn)
|
||||||
{
|
{
|
||||||
@ -395,6 +415,7 @@ free_connection_data(struct connection *conn)
|
|||||||
if (conn->done)
|
if (conn->done)
|
||||||
conn->done(conn);
|
conn->done(conn);
|
||||||
|
|
||||||
|
if (conn->popen) close_popen(conn->socket->fd);
|
||||||
done_socket(conn->socket);
|
done_socket(conn->socket);
|
||||||
done_socket(conn->data_socket);
|
done_socket(conn->data_socket);
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@ struct connection {
|
|||||||
unsigned int running:1;
|
unsigned int running:1;
|
||||||
unsigned int unrestartable:1;
|
unsigned int unrestartable:1;
|
||||||
unsigned int detached:1;
|
unsigned int detached:1;
|
||||||
|
unsigned int popen:1;
|
||||||
|
|
||||||
/* Each document is downloaded with some priority. When downloading a
|
/* Each document is downloaded with some priority. When downloading a
|
||||||
* document, the existing connections are checked to see if a
|
* document, the existing connections are checked to see if a
|
||||||
@ -72,6 +73,16 @@ struct connection {
|
|||||||
void *info;
|
void *info;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct popen_data {
|
||||||
|
LIST_HEAD(struct popen_data);
|
||||||
|
|
||||||
|
int fd;
|
||||||
|
FILE *stream;
|
||||||
|
unsigned char *filename;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern struct list_head copiousoutput_data;
|
||||||
|
|
||||||
int register_check_queue(void);
|
int register_check_queue(void);
|
||||||
|
|
||||||
int get_connections_count(void);
|
int get_connections_count(void);
|
||||||
|
@ -213,6 +213,7 @@ read_special(struct connection *conn, int fd)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
conn->socket->fd = fd;
|
conn->socket->fd = fd;
|
||||||
|
conn->popen = 1;
|
||||||
rb = alloc_read_buffer(conn->socket);
|
rb = alloc_read_buffer(conn->socket);
|
||||||
if (!rb) {
|
if (!rb) {
|
||||||
abort_connection(conn, S_OUT_OF_MEM);
|
abort_connection(conn, S_OUT_OF_MEM);
|
||||||
@ -222,6 +223,7 @@ read_special(struct connection *conn, int fd)
|
|||||||
rb->length = 45;
|
rb->length = 45;
|
||||||
rb->freespace -= 45;
|
rb->freespace -= 45;
|
||||||
|
|
||||||
|
conn->unrestartable = 1;
|
||||||
conn->socket->state = SOCKET_END_ONCLOSE;
|
conn->socket->state = SOCKET_END_ONCLOSE;
|
||||||
read_from_socket(conn->socket, rb, S_SENT, http_got_header);
|
read_from_socket(conn->socket, rb, S_SENT, http_got_header);
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,8 @@
|
|||||||
|
|
||||||
INIT_LIST_HEAD(downloads);
|
INIT_LIST_HEAD(downloads);
|
||||||
|
|
||||||
|
INIT_LIST_HEAD(copiousoutput_data);
|
||||||
|
|
||||||
int
|
int
|
||||||
download_is_progressing(struct download *download)
|
download_is_progressing(struct download *download)
|
||||||
{
|
{
|
||||||
@ -302,16 +304,26 @@ abort_download_and_beep(struct file_download *file_download, struct terminal *te
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
read_from_popen(struct session *ses, unsigned char *handler)
|
read_from_popen(struct session *ses, unsigned char *handler, unsigned char *filename)
|
||||||
{
|
{
|
||||||
FILE *pop = popen(handler, "r");
|
FILE *stream = popen(handler, "r");
|
||||||
|
|
||||||
if (pop) {
|
if (stream) {
|
||||||
int fd = fileno(pop);
|
int fd = fileno(stream);
|
||||||
|
|
||||||
if (fd > 0) {
|
if (fd > 0) {
|
||||||
unsigned char buf[48];
|
unsigned char buf[48];
|
||||||
|
|
||||||
|
struct popen_data *data = mem_calloc(1, sizeof(*data));
|
||||||
|
|
||||||
|
if (!data) {
|
||||||
|
fclose(stream);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
data->fd = fd;
|
||||||
|
data->stream = stream;
|
||||||
|
if (filename) data->filename = stracpy(filename);
|
||||||
|
add_to_list(copiousoutput_data, data);
|
||||||
snprintf(buf, 48, "file:///dev/fd/%d", fd);
|
snprintf(buf, 48, "file:///dev/fd/%d", fd);
|
||||||
goto_url(ses, buf);
|
goto_url(ses, buf);
|
||||||
}
|
}
|
||||||
@ -357,7 +369,10 @@ download_data_store(struct download *download, struct file_download *file_downlo
|
|||||||
file_download->handle = -1;
|
file_download->handle = -1;
|
||||||
if (file_download->copiousoutput) {
|
if (file_download->copiousoutput) {
|
||||||
read_from_popen(file_download->ses,
|
read_from_popen(file_download->ses,
|
||||||
file_download->external_handler);
|
file_download->external_handler,
|
||||||
|
file_download->file);
|
||||||
|
file_download->delete = 0;
|
||||||
|
abort_download_and_beep(file_download, term);
|
||||||
} else {
|
} else {
|
||||||
exec_on_terminal(term, file_download->external_handler,
|
exec_on_terminal(term, file_download->external_handler,
|
||||||
file_download->file,
|
file_download->file,
|
||||||
@ -1016,7 +1031,7 @@ tp_open(struct type_query *type_query)
|
|||||||
|
|
||||||
if (handler) {
|
if (handler) {
|
||||||
if (type_query->copiousoutput)
|
if (type_query->copiousoutput)
|
||||||
read_from_popen(type_query->ses, handler);
|
read_from_popen(type_query->ses, handler, NULL);
|
||||||
else
|
else
|
||||||
exec_on_terminal(type_query->ses->tab->term,
|
exec_on_terminal(type_query->ses->tab->term,
|
||||||
handler, "", !!type_query->block);
|
handler, "", !!type_query->block);
|
||||||
|
Loading…
Reference in New Issue
Block a user