From bc3996f7275780970d2d5dc53da2fd5a8caad1e4 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Sun, 24 Sep 2023 01:24:19 +0300 Subject: [PATCH 2/3] Remember the value of read_process_output_max when a process is created * 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). (create_process): Make sure not to reduce the pipe's buffer, only increase it if our value is higher than the one set by the OS. * src/process.h (Lisp_Process): Add field readmax. --- src/process.c | 7 +++++-- src/process.h | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/process.c b/src/process.c index e932ecf7e43..d7aedcdf12d 100644 --- a/src/process.c +++ b/src/process.c @@ -2193,6 +2193,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, PTRDIFF_MAX); + /* Set up stdout for the child process. */ if (ptychannel >= 0 && p->pty_out) { @@ -2208,7 +2210,8 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) #if (defined (GNU_LINUX) || defined __ANDROID__) \ && defined (F_SETPIPE_SZ) - fcntl (inchannel, F_SETPIPE_SZ, read_process_output_max); + if (p->readmax > fcntl (inchannel, F_GETPIPE_SZ, read_process_output_max)) + fcntl (inchannel, F_SETPIPE_SZ, p->readmax); #endif /* (GNU_LINUX || __ANDROID__) && F_SETPIPE_SZ */ } @@ -6138,7 +6141,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 bbe4528dc31..980c7216689 100644 --- a/src/process.h +++ b/src/process.h @@ -153,6 +153,8 @@ #define EMACS_PROCESS_H 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.37.2