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"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
@ -375,6 +376,25 @@ shutdown_connection_stream(struct connection *conn)
|
||||
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
|
||||
free_connection_data(struct connection *conn)
|
||||
{
|
||||
@ -395,6 +415,7 @@ free_connection_data(struct connection *conn)
|
||||
if (conn->done)
|
||||
conn->done(conn);
|
||||
|
||||
if (conn->popen) close_popen(conn->socket->fd);
|
||||
done_socket(conn->socket);
|
||||
done_socket(conn->data_socket);
|
||||
|
||||
|
@ -56,6 +56,7 @@ struct connection {
|
||||
unsigned int running:1;
|
||||
unsigned int unrestartable:1;
|
||||
unsigned int detached:1;
|
||||
unsigned int popen:1;
|
||||
|
||||
/* Each document is downloaded with some priority. When downloading a
|
||||
* document, the existing connections are checked to see if a
|
||||
@ -72,6 +73,16 @@ struct connection {
|
||||
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 get_connections_count(void);
|
||||
|
@ -213,6 +213,7 @@ read_special(struct connection *conn, int fd)
|
||||
return;
|
||||
}
|
||||
conn->socket->fd = fd;
|
||||
conn->popen = 1;
|
||||
rb = alloc_read_buffer(conn->socket);
|
||||
if (!rb) {
|
||||
abort_connection(conn, S_OUT_OF_MEM);
|
||||
@ -222,6 +223,7 @@ read_special(struct connection *conn, int fd)
|
||||
rb->length = 45;
|
||||
rb->freespace -= 45;
|
||||
|
||||
conn->unrestartable = 1;
|
||||
conn->socket->state = SOCKET_END_ONCLOSE;
|
||||
read_from_socket(conn->socket, rb, S_SENT, http_got_header);
|
||||
}
|
||||
|
@ -64,6 +64,8 @@
|
||||
|
||||
INIT_LIST_HEAD(downloads);
|
||||
|
||||
INIT_LIST_HEAD(copiousoutput_data);
|
||||
|
||||
int
|
||||
download_is_progressing(struct download *download)
|
||||
{
|
||||
@ -302,16 +304,26 @@ abort_download_and_beep(struct file_download *file_download, struct terminal *te
|
||||
}
|
||||
|
||||
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) {
|
||||
int fd = fileno(pop);
|
||||
if (stream) {
|
||||
int fd = fileno(stream);
|
||||
|
||||
if (fd > 0) {
|
||||
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);
|
||||
goto_url(ses, buf);
|
||||
}
|
||||
@ -357,7 +369,10 @@ download_data_store(struct download *download, struct file_download *file_downlo
|
||||
file_download->handle = -1;
|
||||
if (file_download->copiousoutput) {
|
||||
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 {
|
||||
exec_on_terminal(term, file_download->external_handler,
|
||||
file_download->file,
|
||||
@ -1016,7 +1031,7 @@ tp_open(struct type_query *type_query)
|
||||
|
||||
if (handler) {
|
||||
if (type_query->copiousoutput)
|
||||
read_from_popen(type_query->ses, handler);
|
||||
read_from_popen(type_query->ses, handler, NULL);
|
||||
else
|
||||
exec_on_terminal(type_query->ses->tab->term,
|
||||
handler, "", !!type_query->block);
|
||||
|
Loading…
Reference in New Issue
Block a user