From 50edd2cf7d0f549e86072622268b474025f9d479 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Sun, 9 Jun 2024 02:51:47 +0300 Subject: [PATCH] Remember the value of read_process_output_max when process is created * src/process.h (Lisp_Process): Add field readmax. * src/process.c (read_process_output): Use it. (create_process): Save the value of read_process_output_max to it when the process is created (bug#66020). Use for pipe size. (cherry picked from commit 8cf6e311b87fabeba70d59647883a86c8c92b86f) --- src/process.c | 11 +++++------ src/process.h | 2 ++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/process.c b/src/process.c index 2e8dd758b3c..fd09bb98c60 100644 --- a/src/process.c +++ b/src/process.c @@ -2194,6 +2194,8 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) outchannel = p->open_fd[WRITE_TO_SUBPROCESS]; } + p->readmax = clip_to_bounds (1, read_process_output_max, INT_MAX); + /* Set up stdout for the child process. */ if (ptychannel >= 0 && p->pty_out) { @@ -2210,11 +2212,8 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) #if defined(F_SETPIPE_SZ) && defined(F_GETPIPE_SZ) /* If they requested larger reads than the default system pipe capacity, try enlarging the capacity to match the request. */ - if (read_process_output_max > fcntl (inchannel, F_GETPIPE_SZ)) - { - int readmax = clip_to_bounds (1, read_process_output_max, INT_MAX); - fcntl (inchannel, F_SETPIPE_SZ, readmax); - } + if (p->readmax > fcntl (inchannel, F_GETPIPE_SZ)) + fcntl (inchannel, F_SETPIPE_SZ, p->readmax); #endif } @@ -6171,7 +6170,7 @@ read_process_output (Lisp_Object proc, int channel) eassert (0 <= channel && channel < FD_SETSIZE); struct coding_system *coding = proc_decode_coding_system[channel]; int carryover = p->decoding_carryover; - ptrdiff_t readmax = clip_to_bounds (1, read_process_output_max, PTRDIFF_MAX); + ptrdiff_t readmax = p->readmax; specpdl_ref count = SPECPDL_INDEX (); Lisp_Object odeactivate; char *chars; diff --git a/src/process.h b/src/process.h index 3f56b087084..f497a64c3d1 100644 --- a/src/process.h +++ b/src/process.h @@ -153,6 +153,8 @@ struct Lisp_Process unsigned int adaptive_read_buffering : 2; /* Skip reading this process on next read. */ bool_bf read_output_skip : 1; + /* Maximum number of bytes to read in a single chunk. */ + ptrdiff_t readmax; /* True means kill silently if Emacs is exited. This is the inverse of the `query-on-exit' flag. */ bool_bf kill_without_query : 1; -- 2.39.2