Changed IsoExternalFilterCommand.behavior bit0.

The filter does not get installed if input size is 0.
This resembles more the other behavior bits.
This commit is contained in:
Thomas Schmitt 2009-04-02 09:14:21 +02:00
parent 806ea7b82e
commit 0a265d9d4f
2 changed files with 47 additions and 22 deletions

View File

@ -46,7 +46,11 @@ typedef struct
int out_eof; int out_eof;
uint8_t pipebuf[2048]; /* buffers in case of EAGAIN on write() */ uint8_t pipebuf[2048]; /* buffers in case of EAGAIN on write() */
int pipebuf_fill; int pipebuf_fill;
#ifdef Libisofs_extf_old_behavior_bit_0
int is_0_run; int is_0_run;
#endif
} ExternalFilterRuntime; } ExternalFilterRuntime;
@ -68,7 +72,11 @@ int extf_running_new(ExternalFilterRuntime **running, int send_fd, int recv_fd,
o->out_eof = 0; o->out_eof = 0;
memset(o->pipebuf, 0, sizeof(o->pipebuf)); memset(o->pipebuf, 0, sizeof(o->pipebuf));
o->pipebuf_fill = 0; o->pipebuf_fill = 0;
#ifdef Libisofs_extf_old_behavior_bit_0
o->is_0_run = 0; o->is_0_run = 0;
#endif
return 1; return 1;
} }
@ -124,6 +132,8 @@ int extf_stream_open_flag(IsoStream *stream, int flag)
if (data->running != NULL) { if (data->running != NULL) {
return ISO_FILE_ALREADY_OPENED; return ISO_FILE_ALREADY_OPENED;
} }
#ifdef Libisofs_extf_old_behavior_bit_0
if (data->cmd->behavior & 1) { if (data->cmd->behavior & 1) {
if (iso_stream_get_size(data->orig) == 0) { if (iso_stream_get_size(data->orig) == 0) {
/* Do not fork. Place message for .read and .close */; /* Do not fork. Place message for .read and .close */;
@ -136,6 +146,8 @@ int extf_stream_open_flag(IsoStream *stream, int flag)
return 1; return 1;
} }
} }
#endif /* Libisofs_extf_old_behavior_bit_0 */
if (data->size < 0 && !(flag & 1)) { if (data->size < 0 && !(flag & 1)) {
/* Do the size determination run now, so that the size gets cached /* Do the size determination run now, so that the size gets cached
and .get_size() will not fail on an opened stream. and .get_size() will not fail on an opened stream.
@ -167,31 +179,11 @@ int extf_stream_open_flag(IsoStream *stream, int flag)
if (child_pid != 0) { if (child_pid != 0) {
/* parent */ /* parent */
#ifndef NIX
ret = extf_running_new(&running, send_pipe[1], recv_pipe[0], child_pid, ret = extf_running_new(&running, send_pipe[1], recv_pipe[0], child_pid,
0); 0);
if (ret < 0) { if (ret < 0) {
goto parent_failed; goto parent_failed;
} }
#else
running = calloc(sizeof(ExternalFilterRuntime), 1);
if (running == NULL) {
ret = ISO_OUT_OF_MEM;
goto parent_failed;
}
running->send_fd = send_pipe[1];
running->recv_fd = recv_pipe[0];
running->pid = child_pid;
running->in_counter = 0;
running->in_eof = 0;
running->out_counter = 0;
running->out_eof = 0;
memset(running->pipebuf, 0, sizeof(running->pipebuf));
running->pipebuf_fill = 0;
running->is_0_run = 0;
#endif /* NIX */
data->running = running; data->running = running;
/* Give up the child-side pipe ends */ /* Give up the child-side pipe ends */
@ -267,7 +259,12 @@ int extf_stream_open(IsoStream *stream)
static static
int extf_stream_close(IsoStream *stream) int extf_stream_close(IsoStream *stream)
{ {
int ret, status, is_0_run; int ret, status;
#ifdef Libisofs_extf_old_behavior_bit_0
int is_0_run;
#endif
ExternalFilterStreamData *data; ExternalFilterStreamData *data;
if (stream == NULL) { if (stream == NULL) {
@ -278,8 +275,12 @@ int extf_stream_close(IsoStream *stream)
if (data->running == NULL) { if (data->running == NULL) {
return 1; return 1;
} }
#ifdef Libisofs_extf_old_behavior_bit_0
is_0_run = data->running->is_0_run; is_0_run = data->running->is_0_run;
if (!is_0_run) { if (!is_0_run) {
#endif
if(data->running->recv_fd != -1) if(data->running->recv_fd != -1)
close(data->running->recv_fd); close(data->running->recv_fd);
if(data->running->send_fd != -1) if(data->running->send_fd != -1)
@ -290,11 +291,19 @@ int extf_stream_close(IsoStream *stream)
kill(data->running->pid, SIGKILL); kill(data->running->pid, SIGKILL);
waitpid(data->running->pid, &status, 0); waitpid(data->running->pid, &status, 0);
} }
#ifdef Libisofs_extf_old_behavior_bit_0
} }
#endif
free(data->running); free(data->running);
data->running = NULL; data->running = NULL;
#ifdef Libisofs_extf_old_behavior_bit_0
if (is_0_run) if (is_0_run)
return 1; return 1;
#endif
return iso_stream_close(data->orig); return iso_stream_close(data->orig);
} }
@ -315,7 +324,13 @@ int extf_stream_read(IsoStream *stream, void *buf, size_t desired)
if (running == NULL) { if (running == NULL) {
return ISO_FILE_NOT_OPENED; return ISO_FILE_NOT_OPENED;
} }
#ifdef Libisofs_extf_old_behavior_bit_0
if (running->out_eof || running->is_0_run) { if (running->out_eof || running->is_0_run) {
#else
if (running->out_eof) {
#endif
return 0; return 0;
} }
@ -617,7 +632,11 @@ int iso_file_add_external_filter(IsoFile *file, IsoExternalFilterCommand *cmd,
IsoStream *stream; IsoStream *stream;
off_t original_size = 0, filtered_size = 0; off_t original_size = 0, filtered_size = 0;
#ifdef Libisofs_extf_old_behavior_bit_0
if (cmd->behavior & (2 | 4)) { if (cmd->behavior & (2 | 4)) {
#else
if (cmd->behavior & (1 | 2 | 4)) {
#endif
original_size = iso_file_get_size(file); original_size = iso_file_get_size(file);
if (original_size <= 0 || if (original_size <= 0 ||
((cmd->behavior & 4) && original_size <= 2048)) { ((cmd->behavior & 4) && original_size <= 2048)) {

View File

@ -4709,8 +4709,14 @@ struct iso_external_filter_command
char **argv; char **argv;
/* A bit field which controls behavior variations: /* A bit field which controls behavior variations:
#ifdef Libisofs_extf_old_behavior_bit_0
* bit0= Shortcut: 0 sized input will surely yield 0 sized output * bit0= Shortcut: 0 sized input will surely yield 0 sized output
* bit1= Do not install filter if the output is not smaller than the input #else
* bit0= Do not install filter if the input has size 0.
#endif
* bit1= Do not install filter if the output is not smaller than the input.
* bit2= Do not install filter if the number of output blocks is * bit2= Do not install filter if the number of output blocks is
* not smaller than the number of input blocks. Block size is 2048. * not smaller than the number of input blocks. Block size is 2048.
* Assume that non-empty input yields non-empty output and thus do * Assume that non-empty input yields non-empty output and thus do