aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c112
1 files changed, 55 insertions, 57 deletions
diff --git a/src/process.c b/src/process.c
index 8589acaa8b5..f4ae662468b 100644
--- a/src/process.c
+++ b/src/process.c
@@ -841,7 +841,7 @@ nil, indicating the current buffer's process. */)
841 p->raw_status_new = 0; 841 p->raw_status_new = 0;
842 if (NETCONN1_P (p) || SERIALCONN1_P (p)) 842 if (NETCONN1_P (p) || SERIALCONN1_P (p))
843 { 843 {
844 pset_status (p, Fcons (Qexit, Fcons (make_number (0), Qnil))); 844 pset_status (p, list2 (Qexit, make_number (0)));
845 p->tick = ++process_tick; 845 p->tick = ++process_tick;
846 status_notify (p); 846 status_notify (p);
847 redisplay_preserve_echo_area (13); 847 redisplay_preserve_echo_area (13);
@@ -1206,11 +1206,11 @@ list of keywords. */)
1206 if ((!NETCONN_P (process) && !SERIALCONN_P (process)) || EQ (key, Qt)) 1206 if ((!NETCONN_P (process) && !SERIALCONN_P (process)) || EQ (key, Qt))
1207 return contact; 1207 return contact;
1208 if (NILP (key) && NETCONN_P (process)) 1208 if (NILP (key) && NETCONN_P (process))
1209 return Fcons (Fplist_get (contact, QChost), 1209 return list2 (Fplist_get (contact, QChost),
1210 Fcons (Fplist_get (contact, QCservice), Qnil)); 1210 Fplist_get (contact, QCservice));
1211 if (NILP (key) && SERIALCONN_P (process)) 1211 if (NILP (key) && SERIALCONN_P (process))
1212 return Fcons (Fplist_get (contact, QCport), 1212 return list2 (Fplist_get (contact, QCport),
1213 Fcons (Fplist_get (contact, QCspeed), Qnil)); 1213 Fplist_get (contact, QCspeed));
1214 return Fplist_get (contact, key); 1214 return Fplist_get (contact, key);
1215} 1215}
1216 1216
@@ -1341,7 +1341,7 @@ DEFUN ("process-list", Fprocess_list, Sprocess_list, 0, 0, 0,
1341 1341
1342/* Starting asynchronous inferior processes. */ 1342/* Starting asynchronous inferior processes. */
1343 1343
1344static Lisp_Object start_process_unwind (Lisp_Object proc); 1344static void start_process_unwind (Lisp_Object proc);
1345 1345
1346DEFUN ("start-process", Fstart_process, Sstart_process, 3, MANY, 0, 1346DEFUN ("start-process", Fstart_process, Sstart_process, 3, MANY, 0,
1347 doc: /* Start a program in a subprocess. Return the process object for it. 1347 doc: /* Start a program in a subprocess. Return the process object for it.
@@ -1397,7 +1397,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1397 current_dir = expand_and_dir_to_file (current_dir, Qnil); 1397 current_dir = expand_and_dir_to_file (current_dir, Qnil);
1398 if (NILP (Ffile_accessible_directory_p (current_dir))) 1398 if (NILP (Ffile_accessible_directory_p (current_dir)))
1399 report_file_error ("Setting current directory", 1399 report_file_error ("Setting current directory",
1400 Fcons (BVAR (current_buffer, directory), Qnil)); 1400 BVAR (current_buffer, directory));
1401 1401
1402 UNGCPRO; 1402 UNGCPRO;
1403 } 1403 }
@@ -1519,7 +1519,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1519 openp (Vexec_path, program, Vexec_suffixes, &tem, make_number (X_OK)); 1519 openp (Vexec_path, program, Vexec_suffixes, &tem, make_number (X_OK));
1520 UNGCPRO; 1520 UNGCPRO;
1521 if (NILP (tem)) 1521 if (NILP (tem))
1522 report_file_error ("Searching for program", Fcons (program, Qnil)); 1522 report_file_error ("Searching for program", program);
1523 tem = Fexpand_file_name (tem, Qnil); 1523 tem = Fexpand_file_name (tem, Qnil);
1524 } 1524 }
1525 else 1525 else
@@ -1542,7 +1542,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1542 1542
1543 /* Encode the file name and put it in NEW_ARGV. 1543 /* Encode the file name and put it in NEW_ARGV.
1544 That's where the child will use it to execute the program. */ 1544 That's where the child will use it to execute the program. */
1545 tem = Fcons (ENCODE_FILE (tem), Qnil); 1545 tem = list1 (ENCODE_FILE (tem));
1546 1546
1547 /* Here we encode arguments by the coding system used for sending 1547 /* Here we encode arguments by the coding system used for sending
1548 data to the process. We don't support using different coding 1548 data to the process. We don't support using different coding
@@ -1590,7 +1590,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1590 PROC doesn't have its pid set, then we know someone has signaled 1590 PROC doesn't have its pid set, then we know someone has signaled
1591 an error and the process wasn't started successfully, so we should 1591 an error and the process wasn't started successfully, so we should
1592 remove it from the process list. */ 1592 remove it from the process list. */
1593static Lisp_Object 1593static void
1594start_process_unwind (Lisp_Object proc) 1594start_process_unwind (Lisp_Object proc)
1595{ 1595{
1596 if (!PROCESSP (proc)) 1596 if (!PROCESSP (proc))
@@ -1600,8 +1600,6 @@ start_process_unwind (Lisp_Object proc)
1600 -2 is used for a pty with no process, eg for gdb. */ 1600 -2 is used for a pty with no process, eg for gdb. */
1601 if (XPROCESS (proc)->pid <= 0 && XPROCESS (proc)->pid != -2) 1601 if (XPROCESS (proc)->pid <= 0 && XPROCESS (proc)->pid != -2)
1602 remove_process (proc); 1602 remove_process (proc);
1603
1604 return Qnil;
1605} 1603}
1606 1604
1607static void 1605static void
@@ -1651,11 +1649,11 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1651 else 1649 else
1652#endif /* HAVE_PTYS */ 1650#endif /* HAVE_PTYS */
1653 { 1651 {
1654 if (pipe2 (sv, O_CLOEXEC) != 0) 1652 if (emacs_pipe (sv) != 0)
1655 report_file_error ("Creating pipe", Qnil); 1653 report_file_error ("Creating pipe", Qnil);
1656 inchannel = sv[0]; 1654 inchannel = sv[0];
1657 forkout = sv[1]; 1655 forkout = sv[1];
1658 if (pipe2 (sv, O_CLOEXEC) != 0) 1656 if (emacs_pipe (sv) != 0)
1659 { 1657 {
1660 int pipe_errno = errno; 1658 int pipe_errno = errno;
1661 emacs_close (inchannel); 1659 emacs_close (inchannel);
@@ -1667,7 +1665,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1667 } 1665 }
1668 1666
1669#ifndef WINDOWSNT 1667#ifndef WINDOWSNT
1670 if (pipe2 (wait_child_setup, O_CLOEXEC) != 0) 1668 if (emacs_pipe (wait_child_setup) != 0)
1671 report_file_error ("Creating pipe", Qnil); 1669 report_file_error ("Creating pipe", Qnil);
1672#endif 1670#endif
1673 1671
@@ -2323,8 +2321,12 @@ set_socket_option (int s, Lisp_Object opt, Lisp_Object val)
2323 } 2321 }
2324 2322
2325 if (ret < 0) 2323 if (ret < 0)
2326 report_file_error ("Cannot set network option", 2324 {
2327 Fcons (opt, Fcons (val, Qnil))); 2325 int setsockopt_errno = errno;
2326 report_file_errno ("Cannot set network option", list2 (opt, val),
2327 setsockopt_errno);
2328 }
2329
2328 return (1 << sopt->optbit); 2330 return (1 << sopt->optbit);
2329} 2331}
2330 2332
@@ -2456,16 +2458,6 @@ usage: (serial-process-configure &rest ARGS) */)
2456 return Qnil; 2458 return Qnil;
2457} 2459}
2458 2460
2459/* Used by make-serial-process to recover from errors. */
2460static Lisp_Object
2461make_serial_process_unwind (Lisp_Object proc)
2462{
2463 if (!PROCESSP (proc))
2464 emacs_abort ();
2465 remove_process (proc);
2466 return Qnil;
2467}
2468
2469DEFUN ("make-serial-process", Fmake_serial_process, Smake_serial_process, 2461DEFUN ("make-serial-process", Fmake_serial_process, Smake_serial_process,
2470 0, MANY, 0, 2462 0, MANY, 0,
2471 doc: /* Create and return a serial port process. 2463 doc: /* Create and return a serial port process.
@@ -2571,10 +2563,10 @@ usage: (make-serial-process &rest ARGS) */)
2571 CHECK_STRING (name); 2563 CHECK_STRING (name);
2572 proc = make_process (name); 2564 proc = make_process (name);
2573 specpdl_count = SPECPDL_INDEX (); 2565 specpdl_count = SPECPDL_INDEX ();
2574 record_unwind_protect (make_serial_process_unwind, proc); 2566 record_unwind_protect (remove_process, proc);
2575 p = XPROCESS (proc); 2567 p = XPROCESS (proc);
2576 2568
2577 fd = serial_open (SSDATA (port)); 2569 fd = serial_open (port);
2578 p->infd = fd; 2570 p->infd = fd;
2579 p->outfd = fd; 2571 p->outfd = fd;
2580 if (fd > max_process_desc) 2572 if (fd > max_process_desc)
@@ -3007,7 +2999,7 @@ usage: (make-network-process &rest ARGS) */)
3007#ifdef POLL_FOR_INPUT 2999#ifdef POLL_FOR_INPUT
3008 if (socktype != SOCK_DGRAM) 3000 if (socktype != SOCK_DGRAM)
3009 { 3001 {
3010 record_unwind_protect (unwind_stop_other_atimers, Qnil); 3002 record_unwind_protect_void (run_all_atimers);
3011 bind_polling_period (10); 3003 bind_polling_period (10);
3012 } 3004 }
3013#endif 3005#endif
@@ -3167,7 +3159,7 @@ usage: (make-network-process &rest ARGS) */)
3167#endif 3159#endif
3168 3160
3169 /* Make us close S if quit. */ 3161 /* Make us close S if quit. */
3170 record_unwind_protect (close_file_unwind, make_number (s)); 3162 record_unwind_protect_int (close_file_unwind, s);
3171 3163
3172 /* Parse network options in the arg list. 3164 /* Parse network options in the arg list.
3173 We simply ignore anything which isn't a known option (including other keywords). 3165 We simply ignore anything which isn't a known option (including other keywords).
@@ -3258,16 +3250,16 @@ usage: (make-network-process &rest ARGS) */)
3258 if (errno == EINTR) 3250 if (errno == EINTR)
3259 goto retry_select; 3251 goto retry_select;
3260 else 3252 else
3261 report_file_error ("select failed", Qnil); 3253 report_file_error ("Failed select", Qnil);
3262 } 3254 }
3263 eassert (sc > 0); 3255 eassert (sc > 0);
3264 3256
3265 len = sizeof xerrno; 3257 len = sizeof xerrno;
3266 eassert (FD_ISSET (s, &fdset)); 3258 eassert (FD_ISSET (s, &fdset));
3267 if (getsockopt (s, SOL_SOCKET, SO_ERROR, &xerrno, &len) < 0) 3259 if (getsockopt (s, SOL_SOCKET, SO_ERROR, &xerrno, &len) < 0)
3268 report_file_error ("getsockopt failed", Qnil); 3260 report_file_error ("Failed getsockopt", Qnil);
3269 if (xerrno) 3261 if (xerrno)
3270 report_file_errno ("error during connect", Qnil, xerrno); 3262 report_file_errno ("Failed connect", Qnil, xerrno);
3271 break; 3263 break;
3272 } 3264 }
3273#endif /* !WINDOWSNT */ 3265#endif /* !WINDOWSNT */
@@ -3534,10 +3526,13 @@ format; see the description of ADDRESS in `make-network-process'. */)
3534 ptrdiff_t buf_size = 512; 3526 ptrdiff_t buf_size = 512;
3535 int s; 3527 int s;
3536 Lisp_Object res; 3528 Lisp_Object res;
3529 ptrdiff_t count;
3537 3530
3538 s = socket (AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0); 3531 s = socket (AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
3539 if (s < 0) 3532 if (s < 0)
3540 return Qnil; 3533 return Qnil;
3534 count = SPECPDL_INDEX ();
3535 record_unwind_protect_int (close_file_unwind, s);
3541 3536
3542 do 3537 do
3543 { 3538 {
@@ -3553,9 +3548,7 @@ format; see the description of ADDRESS in `make-network-process'. */)
3553 } 3548 }
3554 while (ifconf.ifc_len == buf_size); 3549 while (ifconf.ifc_len == buf_size);
3555 3550
3556 emacs_close (s); 3551 res = unbind_to (count, Qnil);
3557
3558 res = Qnil;
3559 ifreq = ifconf.ifc_req; 3552 ifreq = ifconf.ifc_req;
3560 while ((char *) ifreq < (char *) ifconf.ifc_req + ifconf.ifc_len) 3553 while ((char *) ifreq < (char *) ifconf.ifc_req + ifconf.ifc_len)
3561 { 3554 {
@@ -3680,6 +3673,7 @@ FLAGS is the current flags of the interface. */)
3680 Lisp_Object elt; 3673 Lisp_Object elt;
3681 int s; 3674 int s;
3682 bool any = 0; 3675 bool any = 0;
3676 ptrdiff_t count;
3683#if (! (defined SIOCGIFHWADDR && defined HAVE_STRUCT_IFREQ_IFR_HWADDR) \ 3677#if (! (defined SIOCGIFHWADDR && defined HAVE_STRUCT_IFREQ_IFR_HWADDR) \
3684 && defined HAVE_GETIFADDRS && defined LLADDR) 3678 && defined HAVE_GETIFADDRS && defined LLADDR)
3685 struct ifaddrs *ifap; 3679 struct ifaddrs *ifap;
@@ -3694,6 +3688,8 @@ FLAGS is the current flags of the interface. */)
3694 s = socket (AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0); 3688 s = socket (AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
3695 if (s < 0) 3689 if (s < 0)
3696 return Qnil; 3690 return Qnil;
3691 count = SPECPDL_INDEX ();
3692 record_unwind_protect_int (close_file_unwind, s);
3697 3693
3698 elt = Qnil; 3694 elt = Qnil;
3699#if defined (SIOCGIFFLAGS) && defined (HAVE_STRUCT_IFREQ_IFR_FLAGS) 3695#if defined (SIOCGIFFLAGS) && defined (HAVE_STRUCT_IFREQ_IFR_FLAGS)
@@ -3810,9 +3806,7 @@ FLAGS is the current flags of the interface. */)
3810#endif 3806#endif
3811 res = Fcons (elt, res); 3807 res = Fcons (elt, res);
3812 3808
3813 emacs_close (s); 3809 return unbind_to (count, any ? res : Qnil);
3814
3815 return any ? res : Qnil;
3816} 3810}
3817#endif 3811#endif
3818#endif /* defined (HAVE_NET_IF_H) */ 3812#endif /* defined (HAVE_NET_IF_H) */
@@ -3986,6 +3980,7 @@ server_accept_connection (Lisp_Object server, int channel)
3986#endif 3980#endif
3987 } saddr; 3981 } saddr;
3988 socklen_t len = sizeof saddr; 3982 socklen_t len = sizeof saddr;
3983 ptrdiff_t count;
3989 3984
3990 s = accept4 (channel, &saddr.sa, &len, SOCK_CLOEXEC); 3985 s = accept4 (channel, &saddr.sa, &len, SOCK_CLOEXEC);
3991 3986
@@ -4008,6 +4003,9 @@ server_accept_connection (Lisp_Object server, int channel)
4008 return; 4003 return;
4009 } 4004 }
4010 4005
4006 count = SPECPDL_INDEX ();
4007 record_unwind_protect_int (close_file_unwind, s);
4008
4011 connect_counter++; 4009 connect_counter++;
4012 4010
4013 /* Setup a new process to handle the connection. */ 4011 /* Setup a new process to handle the connection. */
@@ -4124,6 +4122,10 @@ server_accept_connection (Lisp_Object server, int channel)
4124 pset_filter (p, ps->filter); 4122 pset_filter (p, ps->filter);
4125 pset_command (p, Qnil); 4123 pset_command (p, Qnil);
4126 p->pid = 0; 4124 p->pid = 0;
4125
4126 /* Discard the unwind protect for closing S. */
4127 specpdl_ptr = specpdl + count;
4128
4127 p->infd = s; 4129 p->infd = s;
4128 p->outfd = s; 4130 p->outfd = s;
4129 pset_status (p, Qrun); 4131 pset_status (p, Qrun);
@@ -4177,11 +4179,10 @@ server_accept_connection (Lisp_Object server, int channel)
4177 when not inside wait_reading_process_output. */ 4179 when not inside wait_reading_process_output. */
4178static int waiting_for_user_input_p; 4180static int waiting_for_user_input_p;
4179 4181
4180static Lisp_Object 4182static void
4181wait_reading_process_output_unwind (Lisp_Object data) 4183wait_reading_process_output_unwind (int data)
4182{ 4184{
4183 waiting_for_user_input_p = XINT (data); 4185 waiting_for_user_input_p = data;
4184 return Qnil;
4185} 4186}
4186 4187
4187/* This is here so breakpoints can be put on it. */ 4188/* This is here so breakpoints can be put on it. */
@@ -4259,8 +4260,8 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4259 if (wait_proc != NULL) 4260 if (wait_proc != NULL)
4260 wait_channel = wait_proc->infd; 4261 wait_channel = wait_proc->infd;
4261 4262
4262 record_unwind_protect (wait_reading_process_output_unwind, 4263 record_unwind_protect_int (wait_reading_process_output_unwind,
4263 make_number (waiting_for_user_input_p)); 4264 waiting_for_user_input_p);
4264 waiting_for_user_input_p = read_kbd; 4265 waiting_for_user_input_p = read_kbd;
4265 4266
4266 if (time_limit < 0) 4267 if (time_limit < 0)
@@ -4625,7 +4626,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4625 else if (xerrno == EBADF) 4626 else if (xerrno == EBADF)
4626 emacs_abort (); 4627 emacs_abort ();
4627 else 4628 else
4628 error ("select error: %s", emacs_strerror (xerrno)); 4629 report_file_errno ("Failed select", Qnil, xerrno);
4629 } 4630 }
4630 4631
4631 if (no_avail) 4632 if (no_avail)
@@ -5124,9 +5125,7 @@ read_and_dispose_of_process_output (struct Lisp_Process *p, char *chars,
5124 sometimes it's simply wrong to wrap (e.g. when called from 5125 sometimes it's simply wrong to wrap (e.g. when called from
5125 accept-process-output). */ 5126 accept-process-output). */
5126 internal_condition_case_1 (read_process_output_call, 5127 internal_condition_case_1 (read_process_output_call,
5127 Fcons (outstream, 5128 list3 (outstream, make_lisp_proc (p), text),
5128 Fcons (make_lisp_proc (p),
5129 Fcons (text, Qnil))),
5130 !NILP (Vdebug_on_error) ? Qnil : Qerror, 5129 !NILP (Vdebug_on_error) ? Qnil : Qerror,
5131 read_process_output_error_handler); 5130 read_process_output_error_handler);
5132 5131
@@ -5296,7 +5295,7 @@ write_queue_push (struct Lisp_Process *p, Lisp_Object input_obj,
5296 if (front) 5295 if (front)
5297 pset_write_queue (p, Fcons (entry, p->write_queue)); 5296 pset_write_queue (p, Fcons (entry, p->write_queue));
5298 else 5297 else
5299 pset_write_queue (p, nconc2 (p->write_queue, Fcons (entry, Qnil))); 5298 pset_write_queue (p, nconc2 (p->write_queue, list1 (entry)));
5300} 5299}
5301 5300
5302/* Remove the first element in the write_queue of process P, put its 5301/* Remove the first element in the write_queue of process P, put its
@@ -5469,7 +5468,7 @@ send_process (Lisp_Object proc, const char *buf, ptrdiff_t len,
5469 if (rv >= 0) 5468 if (rv >= 0)
5470 written = rv; 5469 written = rv;
5471 else if (errno == EMSGSIZE) 5470 else if (errno == EMSGSIZE)
5472 report_file_error ("sending datagram", Fcons (proc, Qnil)); 5471 report_file_error ("Sending datagram", proc);
5473 } 5472 }
5474 else 5473 else
5475#endif 5474#endif
@@ -5546,7 +5545,7 @@ send_process (Lisp_Object proc, const char *buf, ptrdiff_t len,
5546 } 5545 }
5547 else 5546 else
5548 /* This is a real error. */ 5547 /* This is a real error. */
5549 report_file_error ("writing to process", Fcons (proc, Qnil)); 5548 report_file_error ("Writing to process", proc);
5550 } 5549 }
5551 cur_buf += written; 5550 cur_buf += written;
5552 cur_len -= written; 5551 cur_len -= written;
@@ -6040,7 +6039,7 @@ process has been transmitted to the serial port. */)
6040 { 6039 {
6041#ifndef WINDOWSNT 6040#ifndef WINDOWSNT
6042 if (tcdrain (XPROCESS (proc)->outfd) != 0) 6041 if (tcdrain (XPROCESS (proc)->outfd) != 0)
6043 error ("tcdrain() failed: %s", emacs_strerror (errno)); 6042 report_file_error ("Failed tcdrain", Qnil);
6044#endif /* not WINDOWSNT */ 6043#endif /* not WINDOWSNT */
6045 /* Do nothing on Windows because writes are blocking. */ 6044 /* Do nothing on Windows because writes are blocking. */
6046 } 6045 }
@@ -6272,8 +6271,7 @@ exec_sentinel (Lisp_Object proc, Lisp_Object reason)
6272 running_asynch_code = 1; 6271 running_asynch_code = 1;
6273 6272
6274 internal_condition_case_1 (read_process_output_call, 6273 internal_condition_case_1 (read_process_output_call,
6275 Fcons (sentinel, 6274 list3 (sentinel, proc, reason),
6276 Fcons (proc, Fcons (reason, Qnil))),
6277 !NILP (Vdebug_on_error) ? Qnil : Qerror, 6275 !NILP (Vdebug_on_error) ? Qnil : Qerror,
6278 exec_sentinel_error_handler); 6276 exec_sentinel_error_handler);
6279 6277
@@ -6737,7 +6735,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
6737 if (xerrno == EINTR) 6735 if (xerrno == EINTR)
6738 FD_ZERO (&waitchannels); 6736 FD_ZERO (&waitchannels);
6739 else 6737 else
6740 error ("select error: %s", emacs_strerror (xerrno)); 6738 report_file_errno ("Failed select", Qnil, xerrno);
6741 } 6739 }
6742 6740
6743 /* Check for keyboard input */ 6741 /* Check for keyboard input */