aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJim Porter2021-07-04 15:32:03 +0200
committerLars Ingebrigtsen2021-07-04 15:32:03 +0200
commit2f2afa0b310bbce43a8703f5467b2638082abdd9 (patch)
treedee76d7ecf541721635f7e9195e6e38960006c12 /src
parent46d4ddd1767284e8a42b01e7880c2658c5957ab1 (diff)
downloademacs-2f2afa0b310bbce43a8703f5467b2638082abdd9.tar.gz
emacs-2f2afa0b310bbce43a8703f5467b2638082abdd9.zip
Ensure 'call-process' interprets INFILE as a local path
* src/callproc.c (get_current_directory): Rename from 'encode_current_directory' and add boolean ENCODE flag. (Fcall_process): Interpret INFILE relative to the working directory from which PROGRAM is run, not 'default-directory'. (call_process): Use 'get_current_directory'. * src/process.c (Fmake_process): Use 'get_current_directory'. * src/process.h (get_current_directory): Rename decl from 'encode_current_directory'. * src/sysdep.c (sys_subshell): Use 'get_current_directory' (bug#49283).
Diffstat (limited to 'src')
-rw-r--r--src/callproc.c25
-rw-r--r--src/process.c2
-rw-r--r--src/process.h2
-rw-r--r--src/sysdep.c2
4 files changed, 18 insertions, 13 deletions
diff --git a/src/callproc.c b/src/callproc.c
index aabc39313b8..675b78daf3e 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -116,11 +116,13 @@ static CHILD_SETUP_TYPE child_setup (int, int, int, char **, char **,
116 const char *); 116 const char *);
117 117
118/* Return the current buffer's working directory, or the home 118/* Return the current buffer's working directory, or the home
119 directory if it's unreachable, as a string suitable for a system call. 119 directory if it's unreachable. If ENCODE is true, return as a string
120 Signal an error if the result would not be an accessible directory. */ 120 suitable for a system call; otherwise, return a string in its
121 internal representation. Signal an error if the result would not be
122 an accessible directory. */
121 123
122Lisp_Object 124Lisp_Object
123encode_current_directory (void) 125get_current_directory (bool encode)
124{ 126{
125 Lisp_Object curdir = BVAR (current_buffer, directory); 127 Lisp_Object curdir = BVAR (current_buffer, directory);
126 Lisp_Object dir = Funhandled_file_name_directory (curdir); 128 Lisp_Object dir = Funhandled_file_name_directory (curdir);
@@ -131,12 +133,12 @@ encode_current_directory (void)
131 dir = build_string ("~"); 133 dir = build_string ("~");
132 134
133 dir = expand_and_dir_to_file (dir); 135 dir = expand_and_dir_to_file (dir);
134 dir = ENCODE_FILE (remove_slash_colon (dir)); 136 Lisp_Object encoded_dir = ENCODE_FILE (remove_slash_colon (dir));
135 137
136 if (! file_accessible_directory_p (dir)) 138 if (! file_accessible_directory_p (encoded_dir))
137 report_file_error ("Setting current directory", curdir); 139 report_file_error ("Setting current directory", curdir);
138 140
139 return dir; 141 return encode ? encoded_dir : dir;
140} 142}
141 143
142/* If P is reapable, record it as a deleted process and kill it. 144/* If P is reapable, record it as a deleted process and kill it.
@@ -225,8 +227,9 @@ DEFUN ("call-process", Fcall_process, Scall_process, 1, MANY, 0,
225The remaining arguments are optional. 227The remaining arguments are optional.
226 228
227The program's input comes from file INFILE (nil means `null-device'). 229The program's input comes from file INFILE (nil means `null-device').
228If you want to make the input come from an Emacs buffer, use 230If INFILE is a relative path, it will be looked for relative to the
229`call-process-region' instead. 231directory where the process is run (see below). If you want to make the
232input come from an Emacs buffer, use `call-process-region' instead.
230 233
231Third argument DESTINATION specifies how to handle program's output. 234Third argument DESTINATION specifies how to handle program's output.
232If DESTINATION is a buffer, or t that stands for the current buffer, 235If DESTINATION is a buffer, or t that stands for the current buffer,
@@ -270,7 +273,9 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) *
270 273
271 if (nargs >= 2 && ! NILP (args[1])) 274 if (nargs >= 2 && ! NILP (args[1]))
272 { 275 {
273 infile = Fexpand_file_name (args[1], BVAR (current_buffer, directory)); 276 /* Expand infile relative to the current buffer's current
277 directory, or its unhandled equivalent ("~"). */
278 infile = Fexpand_file_name (args[1], get_current_directory (false));
274 CHECK_STRING (infile); 279 CHECK_STRING (infile);
275 } 280 }
276 else 281 else
@@ -439,7 +444,7 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd,
439 buffer's current directory, or its unhandled equivalent. We 444 buffer's current directory, or its unhandled equivalent. We
440 can't just have the child check for an error when it does the 445 can't just have the child check for an error when it does the
441 chdir, since it's in a vfork. */ 446 chdir, since it's in a vfork. */
442 current_dir = encode_current_directory (); 447 current_dir = get_current_directory (true);
443 448
444 if (STRINGP (error_file)) 449 if (STRINGP (error_file))
445 { 450 {
diff --git a/src/process.c b/src/process.c
index c354f3a90da..b8c3e4ecfbc 100644
--- a/src/process.c
+++ b/src/process.c
@@ -1755,7 +1755,7 @@ usage: (make-process &rest ARGS) */)
1755 buffer's current directory, or its unhandled equivalent. We 1755 buffer's current directory, or its unhandled equivalent. We
1756 can't just have the child check for an error when it does the 1756 can't just have the child check for an error when it does the
1757 chdir, since it's in a vfork. */ 1757 chdir, since it's in a vfork. */
1758 current_dir = encode_current_directory (); 1758 current_dir = get_current_directory (true);
1759 1759
1760 name = Fplist_get (contact, QCname); 1760 name = Fplist_get (contact, QCname);
1761 CHECK_STRING (name); 1761 CHECK_STRING (name);
diff --git a/src/process.h b/src/process.h
index 0890f253a40..4a25d13d268 100644
--- a/src/process.h
+++ b/src/process.h
@@ -264,7 +264,7 @@ enum
264 264
265/* Defined in callproc.c. */ 265/* Defined in callproc.c. */
266 266
267extern Lisp_Object encode_current_directory (void); 267extern Lisp_Object get_current_directory (bool);
268extern void record_kill_process (struct Lisp_Process *, Lisp_Object); 268extern void record_kill_process (struct Lisp_Process *, Lisp_Object);
269 269
270/* Defined in sysdep.c. */ 270/* Defined in sysdep.c. */
diff --git a/src/sysdep.c b/src/sysdep.c
index 51d8b5eeedc..b8ec22d9dd9 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -657,7 +657,7 @@ sys_subshell (void)
657#endif 657#endif
658 pid_t pid; 658 pid_t pid;
659 struct save_signal saved_handlers[5]; 659 struct save_signal saved_handlers[5];
660 char *str = SSDATA (encode_current_directory ()); 660 char *str = SSDATA (get_current_directory (true));
661 661
662#ifdef DOS_NT 662#ifdef DOS_NT
663 pid = 0; 663 pid = 0;