#include "process.h"
#include "syssignal.h"
#include "systty.h"
+#include "syswait.h"
#include "blockinput.h"
#include "frame.h"
#include "termhooks.h"
#include "nsterm.h"
#endif
-#ifdef HAVE_SETPGID
-#if !defined (USG)
-#undef setpgrp
-#define setpgrp setpgid
-#endif
-#endif
-
/* Pattern used by call-process-region to make temp files. */
static Lisp_Object Vtemp_file_name_pattern;
path = Fsubstring (path, make_number (2), Qnil);
new_argv = SAFE_ALLOCA ((nargs > 4 ? nargs - 2 : 2) * sizeof *new_argv);
- if (nargs > 4)
- {
- ptrdiff_t i;
- struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
- GCPRO5 (infile, buffer, current_dir, path, error_file);
- argument_coding.dst_multibyte = 0;
- for (i = 4; i < nargs; i++)
- {
- argument_coding.src_multibyte = STRING_MULTIBYTE (args[i]);
- if (CODING_REQUIRE_ENCODING (&argument_coding))
- /* We must encode this argument. */
- args[i] = encode_coding_string (&argument_coding, args[i], 1);
- }
- UNGCPRO;
- for (i = 4; i < nargs; i++)
- new_argv[i - 3] = SDATA (args[i]);
- new_argv[i - 3] = 0;
- }
- else
- new_argv[1] = 0;
- new_argv[0] = SDATA (path);
+ {
+ struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
+
+ GCPRO5 (infile, buffer, current_dir, path, error_file);
+ if (nargs > 4)
+ {
+ ptrdiff_t i;
+
+ argument_coding.dst_multibyte = 0;
+ for (i = 4; i < nargs; i++)
+ {
+ argument_coding.src_multibyte = STRING_MULTIBYTE (args[i]);
+ if (CODING_REQUIRE_ENCODING (&argument_coding))
+ /* We must encode this argument. */
+ args[i] = encode_coding_string (&argument_coding, args[i], 1);
+ }
+ for (i = 4; i < nargs; i++)
+ new_argv[i - 3] = SDATA (args[i]);
+ new_argv[i - 3] = 0;
+ }
+ else
+ new_argv[1] = 0;
+ if (STRING_MULTIBYTE (path))
+ path = ENCODE_FILE (path);
+ new_argv[0] = SDATA (path);
+ UNGCPRO;
+ }
#ifdef MSDOS /* MW, July 1993 */
0, current_dir);
#else /* not WINDOWSNT */
- BLOCK_INPUT;
+ block_input ();
/* vfork, and prevent local vars from being clobbered by the vfork. */
{
{
if (fd[0] >= 0)
emacs_close (fd[0]);
+
#ifdef HAVE_SETSID
setsid ();
-#endif
-#if defined (USG)
- setpgrp ();
#else
- setpgrp (pid, pid);
-#endif /* USG */
+ setpgid (0, 0);
+#endif
- /* GConf causes us to ignore SIGPIPE, make sure it is restored
- in the child. */
+ /* Emacs ignores SIGPIPE, but the child should not. */
signal (SIGPIPE, SIG_DFL);
child_setup (filefd, fd1, fd_error, (char **) new_argv,
0, current_dir);
}
- UNBLOCK_INPUT;
+ unblock_input ();
#endif /* not WINDOWSNT */
{
USE_SAFE_ALLOCA;
Lisp_Object pattern = Fexpand_file_name (Vtemp_file_name_pattern, tmpdir);
- char *tempfile = SAFE_ALLOCA (SBYTES (pattern) + 1);
- memcpy (tempfile, SDATA (pattern), SBYTES (pattern) + 1);
+ Lisp_Object encoded_tem = ENCODE_FILE (pattern);
+ char *tempfile = SAFE_ALLOCA (SBYTES (encoded_tem) + 1);
+ memcpy (tempfile, SDATA (encoded_tem), SBYTES (encoded_tem) + 1);
coding_systems = Qt;
#ifdef HAVE_MKSTEMP
{
int fd;
- BLOCK_INPUT;
+ block_input ();
fd = mkstemp (tempfile);
- UNBLOCK_INPUT;
+ unblock_input ();
if (fd == -1)
report_file_error ("Failed to open temporary file",
Fcons (build_string (tempfile), Qnil));
close (fd);
}
#else
+ errno = 0;
mktemp (tempfile);
+ if (!*tempfile)
+ {
+ if (!errno)
+ errno = EEXIST;
+ report_file_error ("Failed to open temporary file using pattern",
+ Fcons (pattern, Qnil));
+ }
#endif
filename_string = build_string (tempfile);
if (err != in && err != out)
emacs_close (err);
-#if defined (USG)
-#ifndef SETPGRP_RELEASES_CTTY
- setpgrp (); /* No arguments but equivalent in this case */
+#if defined HAVE_SETPGID || ! (defined USG && defined SETPGRP_RELEASES_CTTY)
+ setpgid (pid, pid);
#endif
-#else /* not USG */
- setpgrp (pid, pid);
-#endif /* not USG */
/* setpgrp_of_tty is incorrect here; it uses input_fd. */
tcsetpgrp (0, pid);