aboutsummaryrefslogtreecommitdiffstats
path: root/src/callproc.c
diff options
context:
space:
mode:
authorJoakim Verona2013-08-23 20:12:26 +0200
committerJoakim Verona2013-08-23 20:12:26 +0200
commitaedb3873bb150227acd4b9496127a2e250d9da66 (patch)
treece857f619470ef47e1ddbe5f9ad92320fd20b8bb /src/callproc.c
parent0fd8418c4004d593b9f37c55ed5b9c5ca221c72b (diff)
parentc365c3558065fca4c11c3f46605d1045763485ab (diff)
downloademacs-aedb3873bb150227acd4b9496127a2e250d9da66.tar.gz
emacs-aedb3873bb150227acd4b9496127a2e250d9da66.zip
merge from trunk
Diffstat (limited to 'src/callproc.c')
-rw-r--r--src/callproc.c59
1 files changed, 37 insertions, 22 deletions
diff --git a/src/callproc.c b/src/callproc.c
index fca4216b5f7..d4b4a26ec3a 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -123,6 +123,37 @@ unblock_child_signal (void)
123 pthread_sigmask (SIG_SETMASK, &empty_mask, 0); 123 pthread_sigmask (SIG_SETMASK, &empty_mask, 0);
124} 124}
125 125
126/* Return the current buffer's working directory, or the home
127 directory if it's unreachable, as a string suitable for a system call.
128 Signal an error if the result would not be an accessible directory. */
129
130Lisp_Object
131encode_current_directory (void)
132{
133 Lisp_Object dir;
134 struct gcpro gcpro1;
135
136 dir = BVAR (current_buffer, directory);
137 GCPRO1 (dir);
138
139 dir = Funhandled_file_name_directory (dir);
140
141 /* If the file name handler says that dir is unreachable, use
142 a sensible default. */
143 if (NILP (dir))
144 dir = build_string ("~");
145
146 dir = expand_and_dir_to_file (dir, Qnil);
147
148 if (STRING_MULTIBYTE (dir))
149 dir = ENCODE_FILE (dir);
150 if (! file_accessible_directory_p (SSDATA (dir)))
151 report_file_error ("Setting current directory",
152 BVAR (current_buffer, directory));
153
154 RETURN_UNGCPRO (dir);
155}
156
126/* If P is reapable, record it as a deleted process and kill it. 157/* If P is reapable, record it as a deleted process and kill it.
127 Do this in a critical section. Unless PID is wedged it will be 158 Do this in a critical section. Unless PID is wedged it will be
128 reaped on receipt of the first SIGCHLD after the critical section. */ 159 reaped on receipt of the first SIGCHLD after the critical section. */
@@ -408,24 +439,10 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd,
408 { 439 {
409 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 440 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
410 441
411 current_dir = BVAR (current_buffer, directory); 442 current_dir = encode_current_directory ();
412 443
413 GCPRO4 (buffer, current_dir, error_file, output_file); 444 GCPRO4 (buffer, current_dir, error_file, output_file);
414 445
415 current_dir = Funhandled_file_name_directory (current_dir);
416 if (NILP (current_dir))
417 /* If the file name handler says that current_dir is unreachable, use
418 a sensible default. */
419 current_dir = build_string ("~/");
420 current_dir = expand_and_dir_to_file (current_dir, Qnil);
421 current_dir = Ffile_name_as_directory (current_dir);
422
423 if (NILP (Ffile_accessible_directory_p (current_dir)))
424 report_file_error ("Setting current directory",
425 BVAR (current_buffer, directory));
426
427 if (STRING_MULTIBYTE (current_dir))
428 current_dir = ENCODE_FILE (current_dir);
429 if (STRINGP (error_file) && STRING_MULTIBYTE (error_file)) 446 if (STRINGP (error_file) && STRING_MULTIBYTE (error_file))
430 error_file = ENCODE_FILE (error_file); 447 error_file = ENCODE_FILE (error_file);
431 if (STRINGP (output_file) && STRING_MULTIBYTE (output_file)) 448 if (STRINGP (output_file) && STRING_MULTIBYTE (output_file))
@@ -1176,23 +1193,21 @@ child_setup (int in, int out, int err, char **new_argv, bool set_pgrp,
1176 static variables as if the superior had done alloca and will be 1193 static variables as if the superior had done alloca and will be
1177 cleaned up in the usual way. */ 1194 cleaned up in the usual way. */
1178 { 1195 {
1179 register char *temp; 1196 char *temp;
1180 size_t i; /* size_t, because ptrdiff_t might overflow here! */ 1197 ptrdiff_t i;
1181 1198
1182 i = SBYTES (current_dir); 1199 i = SBYTES (current_dir);
1183#ifdef MSDOS 1200#ifdef MSDOS
1184 /* MSDOS must have all environment variables malloc'ed, because 1201 /* MSDOS must have all environment variables malloc'ed, because
1185 low-level libc functions that launch subsidiary processes rely 1202 low-level libc functions that launch subsidiary processes rely
1186 on that. */ 1203 on that. */
1187 pwd_var = xmalloc (i + 6); 1204 pwd_var = xmalloc (i + 5);
1188#else 1205#else
1189 pwd_var = alloca (i + 6); 1206 pwd_var = alloca (i + 5);
1190#endif 1207#endif
1191 temp = pwd_var + 4; 1208 temp = pwd_var + 4;
1192 memcpy (pwd_var, "PWD=", 4); 1209 memcpy (pwd_var, "PWD=", 4);
1193 memcpy (temp, SDATA (current_dir), i); 1210 strcpy (temp, SSDATA (current_dir));
1194 if (!IS_DIRECTORY_SEP (temp[i - 1])) temp[i++] = DIRECTORY_SEP;
1195 temp[i] = 0;
1196 1211
1197#ifndef DOS_NT 1212#ifndef DOS_NT
1198 /* We can't signal an Elisp error here; we're in a vfork. Since 1213 /* We can't signal an Elisp error here; we're in a vfork. Since