aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c675
1 files changed, 228 insertions, 447 deletions
diff --git a/src/process.c b/src/process.c
index ca29145bfd4..5a26bf43146 100644
--- a/src/process.c
+++ b/src/process.c
@@ -24,17 +24,16 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
24#include <stdio.h> 24#include <stdio.h>
25#include <errno.h> 25#include <errno.h>
26#include <setjmp.h> 26#include <setjmp.h>
27#include <sys/types.h> /* some typedefs are used in sys/file.h */ 27#include <sys/types.h> /* Some typedefs are used in sys/file.h. */
28#include <sys/file.h> 28#include <sys/file.h>
29#include <sys/stat.h> 29#include <sys/stat.h>
30#include <setjmp.h> 30#include <setjmp.h>
31#ifdef HAVE_INTTYPES_H
32#include <inttypes.h>
33#endif
34 31
35#include <unistd.h> 32#include <unistd.h>
36#include <fcntl.h> 33#include <fcntl.h>
37 34
35#include "lisp.h"
36
38/* Only MS-DOS does not define `subprocesses'. */ 37/* Only MS-DOS does not define `subprocesses'. */
39#ifdef subprocesses 38#ifdef subprocesses
40 39
@@ -79,7 +78,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
79 78
80#endif /* subprocesses */ 79#endif /* subprocesses */
81 80
82#include "lisp.h"
83#include "systime.h" 81#include "systime.h"
84#include "systty.h" 82#include "systty.h"
85 83
@@ -128,21 +126,23 @@ int inhibit_sentinels;
128#ifdef subprocesses 126#ifdef subprocesses
129 127
130Lisp_Object Qprocessp; 128Lisp_Object Qprocessp;
131Lisp_Object Qrun, Qstop, Qsignal; 129static Lisp_Object Qrun, Qstop, Qsignal;
132Lisp_Object Qopen, Qclosed, Qconnect, Qfailed, Qlisten; 130static Lisp_Object Qopen, Qclosed, Qconnect, Qfailed, Qlisten;
133Lisp_Object Qlocal, Qipv4, Qdatagram, Qseqpacket; 131Lisp_Object Qlocal;
134Lisp_Object Qreal, Qnetwork, Qserial; 132static Lisp_Object Qipv4, Qdatagram, Qseqpacket;
133static Lisp_Object Qreal, Qnetwork, Qserial;
135#ifdef AF_INET6 134#ifdef AF_INET6
136Lisp_Object Qipv6; 135static Lisp_Object Qipv6;
137#endif 136#endif
138Lisp_Object QCport, QCspeed, QCprocess; 137static Lisp_Object QCport, QCprocess;
138Lisp_Object QCspeed;
139Lisp_Object QCbytesize, QCstopbits, QCparity, Qodd, Qeven; 139Lisp_Object QCbytesize, QCstopbits, QCparity, Qodd, Qeven;
140Lisp_Object QCflowcontrol, Qhw, Qsw, QCsummary; 140Lisp_Object QCflowcontrol, Qhw, Qsw, QCsummary;
141Lisp_Object QCbuffer, QChost, QCservice; 141static Lisp_Object QCbuffer, QChost, QCservice;
142Lisp_Object QClocal, QCremote, QCcoding; 142static Lisp_Object QClocal, QCremote, QCcoding;
143Lisp_Object QCserver, QCnowait, QCnoquery, QCstop; 143static Lisp_Object QCserver, QCnowait, QCnoquery, QCstop;
144Lisp_Object QCsentinel, QClog, QCoptions, QCplist; 144static Lisp_Object QCsentinel, QClog, QCoptions, QCplist;
145Lisp_Object Qlast_nonmenu_event; 145static Lisp_Object Qlast_nonmenu_event;
146/* QCfamily is declared and initialized in xfaces.c, 146/* QCfamily is declared and initialized in xfaces.c,
147 QCfilter in keyboard.c. */ 147 QCfilter in keyboard.c. */
148extern Lisp_Object QCfamily, QCfilter; 148extern Lisp_Object QCfamily, QCfilter;
@@ -159,25 +159,14 @@ extern Lisp_Object QCfilter;
159#define SERIALCONN_P(p) (EQ (XPROCESS (p)->type, Qserial)) 159#define SERIALCONN_P(p) (EQ (XPROCESS (p)->type, Qserial))
160#define SERIALCONN1_P(p) (EQ ((p)->type, Qserial)) 160#define SERIALCONN1_P(p) (EQ ((p)->type, Qserial))
161 161
162/* Define first descriptor number available for subprocesses. */
163#define FIRST_PROC_DESC 3
164
165extern const char *get_operating_system_release (void);
166
167/* From sysdep.c or w32.c */
168extern int serial_open (char *port);
169extern void serial_configure (struct Lisp_Process *p, Lisp_Object contact);
170
171#ifndef HAVE_H_ERRNO 162#ifndef HAVE_H_ERRNO
172extern int h_errno; 163extern int h_errno;
173#endif 164#endif
174 165
175/* These next two vars are non-static since sysdep.c uses them in the
176 emulation of `select'. */
177/* Number of events of change of status of a process. */ 166/* Number of events of change of status of a process. */
178int process_tick; 167static int process_tick;
179/* Number of events for which the user or sentinel has been notified. */ 168/* Number of events for which the user or sentinel has been notified. */
180int update_tick; 169static int update_tick;
181 170
182/* Define NON_BLOCKING_CONNECT if we can support non-blocking connects. */ 171/* Define NON_BLOCKING_CONNECT if we can support non-blocking connects. */
183 172
@@ -244,7 +233,11 @@ static int process_output_skip;
244#define process_output_delay_count 0 233#define process_output_delay_count 0
245#endif 234#endif
246 235
236static Lisp_Object Fget_process (Lisp_Object);
237static void create_process (Lisp_Object, char **, Lisp_Object);
238#ifdef SIGIO
247static int keyboard_bit_set (SELECT_TYPE *); 239static int keyboard_bit_set (SELECT_TYPE *);
240#endif
248static void deactivate_process (Lisp_Object); 241static void deactivate_process (Lisp_Object);
249static void status_notify (struct Lisp_Process *); 242static void status_notify (struct Lisp_Process *);
250static int read_process_output (Lisp_Object, int); 243static int read_process_output (Lisp_Object, int);
@@ -284,10 +277,6 @@ static SELECT_TYPE connect_wait_mask;
284 277
285/* Number of bits set in connect_wait_mask. */ 278/* Number of bits set in connect_wait_mask. */
286static int num_pending_connects; 279static int num_pending_connects;
287
288#define IF_NON_BLOCKING_CONNECT(s) s
289#else /* NON_BLOCKING_CONNECT */
290#define IF_NON_BLOCKING_CONNECT(s)
291#endif /* NON_BLOCKING_CONNECT */ 280#endif /* NON_BLOCKING_CONNECT */
292 281
293/* The largest descriptor currently in use for a process object. */ 282/* The largest descriptor currently in use for a process object. */
@@ -297,10 +286,10 @@ static int max_process_desc;
297static int max_input_desc; 286static int max_input_desc;
298 287
299/* Indexed by descriptor, gives the process (if any) for that descriptor */ 288/* Indexed by descriptor, gives the process (if any) for that descriptor */
300Lisp_Object chan_process[MAXDESC]; 289static Lisp_Object chan_process[MAXDESC];
301 290
302/* Alist of elements (NAME . PROCESS) */ 291/* Alist of elements (NAME . PROCESS) */
303Lisp_Object Vprocess_alist; 292static Lisp_Object Vprocess_alist;
304 293
305/* Buffered-ahead input char from process, indexed by channel. 294/* Buffered-ahead input char from process, indexed by channel.
306 -1 means empty (no char is buffered). 295 -1 means empty (no char is buffered).
@@ -308,8 +297,7 @@ Lisp_Object Vprocess_alist;
308 output from the process is to read at least one char. 297 output from the process is to read at least one char.
309 Always -1 on systems that support FIONREAD. */ 298 Always -1 on systems that support FIONREAD. */
310 299
311/* Don't make static; need to access externally. */ 300static int proc_buffered_char[MAXDESC];
312int proc_buffered_char[MAXDESC];
313 301
314/* Table of `struct coding-system' for each process. */ 302/* Table of `struct coding-system' for each process. */
315static struct coding_system *proc_decode_coding_system[MAXDESC]; 303static struct coding_system *proc_decode_coding_system[MAXDESC];
@@ -317,7 +305,7 @@ static struct coding_system *proc_encode_coding_system[MAXDESC];
317 305
318#ifdef DATAGRAM_SOCKETS 306#ifdef DATAGRAM_SOCKETS
319/* Table of `partner address' for datagram sockets. */ 307/* Table of `partner address' for datagram sockets. */
320struct sockaddr_and_len { 308static struct sockaddr_and_len {
321 struct sockaddr *sa; 309 struct sockaddr *sa;
322 int len; 310 int len;
323} datagram_address[MAXDESC]; 311} datagram_address[MAXDESC];
@@ -333,7 +321,7 @@ static int pty_max_bytes;
333 321
334 322
335 323
336struct fd_callback_data 324static struct fd_callback_data
337{ 325{
338 fd_callback func; 326 fd_callback func;
339 void *data; 327 void *data;
@@ -499,7 +487,7 @@ status_message (struct Lisp_Process *p)
499 string = (code_convert_string_norecord 487 string = (code_convert_string_norecord
500 (string, Vlocale_coding_system, 0)); 488 (string, Vlocale_coding_system, 0));
501 c1 = STRING_CHAR (SDATA (string)); 489 c1 = STRING_CHAR (SDATA (string));
502 c2 = DOWNCASE (c1); 490 c2 = downcase (c1);
503 if (c1 != c2) 491 if (c1 != c2)
504 Faset (string, make_number (0), make_number (c2)); 492 Faset (string, make_number (0), make_number (c2));
505 } 493 }
@@ -541,17 +529,16 @@ static char pty_name[24];
541static int 529static int
542allocate_pty (void) 530allocate_pty (void)
543{ 531{
544 register int c, i;
545 int fd; 532 int fd;
546 533
547#ifdef PTY_ITERATION 534#ifdef PTY_ITERATION
548 PTY_ITERATION 535 PTY_ITERATION
549#else 536#else
537 register int c, i;
550 for (c = FIRST_PTY_LETTER; c <= 'z'; c++) 538 for (c = FIRST_PTY_LETTER; c <= 'z'; c++)
551 for (i = 0; i < 16; i++) 539 for (i = 0; i < 16; i++)
552#endif 540#endif
553 { 541 {
554 struct stat stb; /* Used in some PTY_OPEN. */
555#ifdef PTY_NAME_SPRINTF 542#ifdef PTY_NAME_SPRINTF
556 PTY_NAME_SPRINTF 543 PTY_NAME_SPRINTF
557#else 544#else
@@ -568,6 +555,7 @@ allocate_pty (void)
568 three failures in a row before deciding that we've reached the 555 three failures in a row before deciding that we've reached the
569 end of the ptys. */ 556 end of the ptys. */
570 int failed_count = 0; 557 int failed_count = 0;
558 struct stat stb;
571 559
572 if (stat (pty_name, &stb) < 0) 560 if (stat (pty_name, &stb) < 0)
573 { 561 {
@@ -719,7 +707,7 @@ get_process (register Lisp_Object name)
719 { 707 {
720 proc = Fget_buffer_process (obj); 708 proc = Fget_buffer_process (obj);
721 if (NILP (proc)) 709 if (NILP (proc))
722 error ("Buffer %s has no process", SDATA (XBUFFER (obj)->name)); 710 error ("Buffer %s has no process", SDATA (BVAR (XBUFFER (obj), name)));
723 } 711 }
724 else 712 else
725 { 713 {
@@ -1096,7 +1084,7 @@ DEFUN ("process-query-on-exit-flag",
1096} 1084}
1097 1085
1098#ifdef DATAGRAM_SOCKETS 1086#ifdef DATAGRAM_SOCKETS
1099Lisp_Object Fprocess_datagram_address (Lisp_Object process); 1087static Lisp_Object Fprocess_datagram_address (Lisp_Object);
1100#endif 1088#endif
1101 1089
1102DEFUN ("process-contact", Fprocess_contact, Sprocess_contact, 1090DEFUN ("process-contact", Fprocess_contact, Sprocess_contact,
@@ -1198,25 +1186,26 @@ Returns nil if format of ADDRESS is invalid. */)
1198 if (VECTORP (address)) /* AF_INET or AF_INET6 */ 1186 if (VECTORP (address)) /* AF_INET or AF_INET6 */
1199 { 1187 {
1200 register struct Lisp_Vector *p = XVECTOR (address); 1188 register struct Lisp_Vector *p = XVECTOR (address);
1189 EMACS_UINT size = p->header.size;
1201 Lisp_Object args[10]; 1190 Lisp_Object args[10];
1202 int nargs, i; 1191 int nargs, i;
1203 1192
1204 if (p->size == 4 || (p->size == 5 && !NILP (omit_port))) 1193 if (size == 4 || (size == 5 && !NILP (omit_port)))
1205 { 1194 {
1206 args[0] = build_string ("%d.%d.%d.%d"); 1195 args[0] = build_string ("%d.%d.%d.%d");
1207 nargs = 4; 1196 nargs = 4;
1208 } 1197 }
1209 else if (p->size == 5) 1198 else if (size == 5)
1210 { 1199 {
1211 args[0] = build_string ("%d.%d.%d.%d:%d"); 1200 args[0] = build_string ("%d.%d.%d.%d:%d");
1212 nargs = 5; 1201 nargs = 5;
1213 } 1202 }
1214 else if (p->size == 8 || (p->size == 9 && !NILP (omit_port))) 1203 else if (size == 8 || (size == 9 && !NILP (omit_port)))
1215 { 1204 {
1216 args[0] = build_string ("%x:%x:%x:%x:%x:%x:%x:%x"); 1205 args[0] = build_string ("%x:%x:%x:%x:%x:%x:%x:%x");
1217 nargs = 8; 1206 nargs = 8;
1218 } 1207 }
1219 else if (p->size == 9) 1208 else if (size == 9)
1220 { 1209 {
1221 args[0] = build_string ("[%x:%x:%x:%x:%x:%x:%x:%x]:%d"); 1210 args[0] = build_string ("[%x:%x:%x:%x:%x:%x:%x:%x]:%d");
1222 nargs = 9; 1211 nargs = 9;
@@ -1252,248 +1241,6 @@ Returns nil if format of ADDRESS is invalid. */)
1252 1241
1253 return Qnil; 1242 return Qnil;
1254} 1243}
1255
1256static Lisp_Object
1257list_processes_1 (Lisp_Object query_only)
1258{
1259 register Lisp_Object tail, tem;
1260 Lisp_Object proc, minspace, tem1;
1261 register struct Lisp_Process *p;
1262 char tembuf[300];
1263 int w_proc, w_buffer, w_tty;
1264 int exited = 0;
1265 Lisp_Object i_status, i_buffer, i_tty, i_command;
1266
1267 w_proc = 4; /* Proc */
1268 w_buffer = 6; /* Buffer */
1269 w_tty = 0; /* Omit if no ttys */
1270
1271 for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail))
1272 {
1273 int i;
1274
1275 proc = Fcdr (XCAR (tail));
1276 p = XPROCESS (proc);
1277 if (NILP (p->type))
1278 continue;
1279 if (!NILP (query_only) && p->kill_without_query)
1280 continue;
1281 if (STRINGP (p->name)
1282 && ( i = SCHARS (p->name), (i > w_proc)))
1283 w_proc = i;
1284 if (!NILP (p->buffer))
1285 {
1286 if (NILP (XBUFFER (p->buffer)->name))
1287 {
1288 if (w_buffer < 8)
1289 w_buffer = 8; /* (Killed) */
1290 }
1291 else if ((i = SCHARS (XBUFFER (p->buffer)->name), (i > w_buffer)))
1292 w_buffer = i;
1293 }
1294 if (STRINGP (p->tty_name)
1295 && (i = SCHARS (p->tty_name), (i > w_tty)))
1296 w_tty = i;
1297 }
1298
1299 XSETFASTINT (i_status, w_proc + 1);
1300 XSETFASTINT (i_buffer, XFASTINT (i_status) + 9);
1301 if (w_tty)
1302 {
1303 XSETFASTINT (i_tty, XFASTINT (i_buffer) + w_buffer + 1);
1304 XSETFASTINT (i_command, XFASTINT (i_tty) + w_tty + 1);
1305 }
1306 else
1307 {
1308 i_tty = Qnil;
1309 XSETFASTINT (i_command, XFASTINT (i_buffer) + w_buffer + 1);
1310 }
1311
1312 XSETFASTINT (minspace, 1);
1313
1314 set_buffer_internal (XBUFFER (Vstandard_output));
1315 current_buffer->undo_list = Qt;
1316
1317 current_buffer->truncate_lines = Qt;
1318
1319 write_string ("Proc", -1);
1320 Findent_to (i_status, minspace); write_string ("Status", -1);
1321 Findent_to (i_buffer, minspace); write_string ("Buffer", -1);
1322 if (!NILP (i_tty))
1323 {
1324 Findent_to (i_tty, minspace); write_string ("Tty", -1);
1325 }
1326 Findent_to (i_command, minspace); write_string ("Command", -1);
1327 write_string ("\n", -1);
1328
1329 write_string ("----", -1);
1330 Findent_to (i_status, minspace); write_string ("------", -1);
1331 Findent_to (i_buffer, minspace); write_string ("------", -1);
1332 if (!NILP (i_tty))
1333 {
1334 Findent_to (i_tty, minspace); write_string ("---", -1);
1335 }
1336 Findent_to (i_command, minspace); write_string ("-------", -1);
1337 write_string ("\n", -1);
1338
1339 for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail))
1340 {
1341 Lisp_Object symbol;
1342
1343 proc = Fcdr (XCAR (tail));
1344 p = XPROCESS (proc);
1345 if (NILP (p->type))
1346 continue;
1347 if (!NILP (query_only) && p->kill_without_query)
1348 continue;
1349
1350 Finsert (1, &p->name);
1351 Findent_to (i_status, minspace);
1352
1353 if (p->raw_status_new)
1354 update_status (p);
1355 symbol = p->status;
1356 if (CONSP (p->status))
1357 symbol = XCAR (p->status);
1358
1359 if (EQ (symbol, Qsignal))
1360 {
1361 Lisp_Object tem;
1362 tem = Fcar (Fcdr (p->status));
1363 Fprinc (symbol, Qnil);
1364 }
1365 else if (NETCONN1_P (p) || SERIALCONN1_P (p))
1366 {
1367 if (EQ (symbol, Qexit))
1368 write_string ("closed", -1);
1369 else if (EQ (p->command, Qt))
1370 write_string ("stopped", -1);
1371 else if (EQ (symbol, Qrun))
1372 write_string ("open", -1);
1373 else
1374 Fprinc (symbol, Qnil);
1375 }
1376 else if (SERIALCONN1_P (p))
1377 {
1378 write_string ("running", -1);
1379 }
1380 else
1381 Fprinc (symbol, Qnil);
1382
1383 if (EQ (symbol, Qexit))
1384 {
1385 Lisp_Object tem;
1386 tem = Fcar (Fcdr (p->status));
1387 if (XFASTINT (tem))
1388 {
1389 sprintf (tembuf, " %d", (int) XFASTINT (tem));
1390 write_string (tembuf, -1);
1391 }
1392 }
1393
1394 if (EQ (symbol, Qsignal) || EQ (symbol, Qexit) || EQ (symbol, Qclosed))
1395 exited++;
1396
1397 Findent_to (i_buffer, minspace);
1398 if (NILP (p->buffer))
1399 insert_string ("(none)");
1400 else if (NILP (XBUFFER (p->buffer)->name))
1401 insert_string ("(Killed)");
1402 else
1403 Finsert (1, &XBUFFER (p->buffer)->name);
1404
1405 if (!NILP (i_tty))
1406 {
1407 Findent_to (i_tty, minspace);
1408 if (STRINGP (p->tty_name))
1409 Finsert (1, &p->tty_name);
1410 }
1411
1412 Findent_to (i_command, minspace);
1413
1414 if (EQ (p->status, Qlisten))
1415 {
1416 Lisp_Object port = Fplist_get (p->childp, QCservice);
1417 if (INTEGERP (port))
1418 port = Fnumber_to_string (port);
1419 if (NILP (port))
1420 port = Fformat_network_address (Fplist_get (p->childp, QClocal), Qnil);
1421 sprintf (tembuf, "(network %s server on %s)\n",
1422 (DATAGRAM_CHAN_P (p->infd) ? "datagram" : "stream"),
1423 (STRINGP (port) ? SSDATA (port) : "?"));
1424 insert_string (tembuf);
1425 }
1426 else if (NETCONN1_P (p))
1427 {
1428 /* For a local socket, there is no host name,
1429 so display service instead. */
1430 Lisp_Object host = Fplist_get (p->childp, QChost);
1431 if (!STRINGP (host))
1432 {
1433 host = Fplist_get (p->childp, QCservice);
1434 if (INTEGERP (host))
1435 host = Fnumber_to_string (host);
1436 }
1437 if (NILP (host))
1438 host = Fformat_network_address (Fplist_get (p->childp, QCremote), Qnil);
1439 sprintf (tembuf, "(network %s connection to %s)\n",
1440 (DATAGRAM_CHAN_P (p->infd) ? "datagram" : "stream"),
1441 (STRINGP (host) ? SSDATA (host) : "?"));
1442 insert_string (tembuf);
1443 }
1444 else if (SERIALCONN1_P (p))
1445 {
1446 Lisp_Object port = Fplist_get (p->childp, QCport);
1447 Lisp_Object speed = Fplist_get (p->childp, QCspeed);
1448 insert_string ("(serial port ");
1449 if (STRINGP (port))
1450 insert_string (SSDATA (port));
1451 else
1452 insert_string ("?");
1453 if (INTEGERP (speed))
1454 {
1455 sprintf (tembuf, " at %ld b/s", (long) XINT (speed));
1456 insert_string (tembuf);
1457 }
1458 insert_string (")\n");
1459 }
1460 else
1461 {
1462 tem = p->command;
1463 while (1)
1464 {
1465 tem1 = Fcar (tem);
1466 if (NILP (tem1))
1467 break;
1468 Finsert (1, &tem1);
1469 tem = Fcdr (tem);
1470 if (NILP (tem))
1471 break;
1472 insert_string (" ");
1473 }
1474 insert_string ("\n");
1475 }
1476 }
1477 if (exited)
1478 {
1479 status_notify (NULL);
1480 redisplay_preserve_echo_area (13);
1481 }
1482 return Qnil;
1483}
1484
1485DEFUN ("list-processes", Flist_processes, Slist_processes, 0, 1, "P",
1486 doc: /* Display a list of all processes.
1487If optional argument QUERY-ONLY is non-nil, only processes with
1488the query-on-exit flag set will be listed.
1489Any process listed as exited or signaled is actually eliminated
1490after the listing is made. */)
1491 (Lisp_Object query_only)
1492{
1493 internal_with_output_to_temp_buffer ("*Process List*",
1494 list_processes_1, query_only);
1495 return Qnil;
1496}
1497 1244
1498DEFUN ("process-list", Fprocess_list, Sprocess_list, 0, 0, 0, 1245DEFUN ("process-list", Fprocess_list, Sprocess_list, 0, 0, 0,
1499 doc: /* Return a list of all processes. */) 1246 doc: /* Return a list of all processes. */)
@@ -1516,20 +1263,20 @@ at end of BUFFER, unless you specify an output stream or filter
1516function to handle the output. BUFFER may also be nil, meaning that 1263function to handle the output. BUFFER may also be nil, meaning that
1517this process is not associated with any buffer. 1264this process is not associated with any buffer.
1518 1265
1519PROGRAM is the program file name. It is searched for in PATH. If 1266PROGRAM is the program file name. It is searched for in `exec-path'
1520nil, just associate a pty with the buffer. Remaining arguments are 1267(which see). If nil, just associate a pty with the buffer. Remaining
1521strings to give program as arguments. 1268arguments are strings to give program as arguments.
1522 1269
1523If you want to separate standard output from standard error, invoke 1270If you want to separate standard output from standard error, invoke
1524the command through a shell and redirect one of them using the shell 1271the command through a shell and redirect one of them using the shell
1525syntax. 1272syntax.
1526 1273
1527usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */) 1274usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1528 (int nargs, register Lisp_Object *args) 1275 (ptrdiff_t nargs, Lisp_Object *args)
1529{ 1276{
1530 Lisp_Object buffer, name, program, proc, current_dir, tem; 1277 Lisp_Object buffer, name, program, proc, current_dir, tem;
1531 register unsigned char **new_argv; 1278 register unsigned char **new_argv;
1532 register int i; 1279 ptrdiff_t i;
1533 int count = SPECPDL_INDEX (); 1280 int count = SPECPDL_INDEX ();
1534 1281
1535 buffer = args[1]; 1282 buffer = args[1];
@@ -1548,7 +1295,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1548 { 1295 {
1549 struct gcpro gcpro1, gcpro2; 1296 struct gcpro gcpro1, gcpro2;
1550 1297
1551 current_dir = current_buffer->directory; 1298 current_dir = BVAR (current_buffer, directory);
1552 1299
1553 GCPRO2 (buffer, current_dir); 1300 GCPRO2 (buffer, current_dir);
1554 1301
@@ -1560,7 +1307,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1560 current_dir = expand_and_dir_to_file (current_dir, Qnil); 1307 current_dir = expand_and_dir_to_file (current_dir, Qnil);
1561 if (NILP (Ffile_accessible_directory_p (current_dir))) 1308 if (NILP (Ffile_accessible_directory_p (current_dir)))
1562 report_file_error ("Setting current directory", 1309 report_file_error ("Setting current directory",
1563 Fcons (current_buffer->directory, Qnil)); 1310 Fcons (BVAR (current_buffer, directory), Qnil));
1564 1311
1565 UNGCPRO; 1312 UNGCPRO;
1566 } 1313 }
@@ -1638,7 +1385,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1638 { 1385 {
1639 if (EQ (coding_systems, Qt)) 1386 if (EQ (coding_systems, Qt))
1640 { 1387 {
1641 args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof args2); 1388 args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2);
1642 args2[0] = Qstart_process; 1389 args2[0] = Qstart_process;
1643 for (i = 0; i < nargs; i++) args2[i + 1] = args[i]; 1390 for (i = 0; i < nargs; i++) args2[i + 1] = args[i];
1644 GCPRO2 (proc, current_dir); 1391 GCPRO2 (proc, current_dir);
@@ -1660,9 +1407,9 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1660 } 1407 }
1661 1408
1662 1409
1663 XPROCESS (proc)->decoding_buf = make_uninit_string (0); 1410 XPROCESS (proc)->decoding_buf = empty_unibyte_string;
1664 XPROCESS (proc)->decoding_carryover = 0; 1411 XPROCESS (proc)->decoding_carryover = 0;
1665 XPROCESS (proc)->encoding_buf = make_uninit_string (0); 1412 XPROCESS (proc)->encoding_buf = empty_unibyte_string;
1666 1413
1667 XPROCESS (proc)->inherit_coding_system_flag 1414 XPROCESS (proc)->inherit_coding_system_flag
1668 = !(NILP (buffer) || !inherit_process_coding_system); 1415 = !(NILP (buffer) || !inherit_process_coding_system);
@@ -1735,7 +1482,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1735 new_argv = (unsigned char **) alloca ((nargs - 1) * sizeof (char *)); 1482 new_argv = (unsigned char **) alloca ((nargs - 1) * sizeof (char *));
1736 new_argv[nargs - 2] = 0; 1483 new_argv[nargs - 2] = 0;
1737 1484
1738 for (i = nargs - 3; i >= 0; i--) 1485 for (i = nargs - 2; i-- != 0; )
1739 { 1486 {
1740 new_argv[i] = SDATA (XCAR (tem)); 1487 new_argv[i] = SDATA (XCAR (tem));
1741 tem = XCDR (tem); 1488 tem = XCDR (tem);
@@ -1773,7 +1520,7 @@ create_process_1 (struct atimer *timer)
1773} 1520}
1774 1521
1775 1522
1776void 1523static void
1777create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) 1524create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1778{ 1525{
1779 int inchannel, outchannel; 1526 int inchannel, outchannel;
@@ -1786,6 +1533,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1786 sigset_t blocked; 1533 sigset_t blocked;
1787 struct sigaction sigint_action; 1534 struct sigaction sigint_action;
1788 struct sigaction sigquit_action; 1535 struct sigaction sigquit_action;
1536 struct sigaction sigpipe_action;
1789#ifdef AIX 1537#ifdef AIX
1790 struct sigaction sighup_action; 1538 struct sigaction sighup_action;
1791#endif 1539#endif
@@ -1898,6 +1646,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1898 and record the current handlers so they can be restored later. */ 1646 and record the current handlers so they can be restored later. */
1899 sigaddset (&blocked, SIGINT ); sigaction (SIGINT , 0, &sigint_action ); 1647 sigaddset (&blocked, SIGINT ); sigaction (SIGINT , 0, &sigint_action );
1900 sigaddset (&blocked, SIGQUIT); sigaction (SIGQUIT, 0, &sigquit_action); 1648 sigaddset (&blocked, SIGQUIT); sigaction (SIGQUIT, 0, &sigquit_action);
1649 sigaddset (&blocked, SIGPIPE); sigaction (SIGPIPE, 0, &sigpipe_action);
1901#ifdef AIX 1650#ifdef AIX
1902 sigaddset (&blocked, SIGHUP ); sigaction (SIGHUP , 0, &sighup_action ); 1651 sigaddset (&blocked, SIGHUP ); sigaction (SIGHUP , 0, &sighup_action );
1903#endif 1652#endif
@@ -1923,8 +1672,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1923 /* child_setup must clobber environ on systems with true vfork. 1672 /* child_setup must clobber environ on systems with true vfork.
1924 Protect it from permanent change. */ 1673 Protect it from permanent change. */
1925 char **save_environ = environ; 1674 char **save_environ = environ;
1926 1675 volatile Lisp_Object encoded_current_dir = ENCODE_FILE (current_dir);
1927 current_dir = ENCODE_FILE (current_dir);
1928 1676
1929#ifndef WINDOWSNT 1677#ifndef WINDOWSNT
1930 pid = vfork (); 1678 pid = vfork ();
@@ -2054,6 +1802,9 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
2054 1802
2055 signal (SIGINT, SIG_DFL); 1803 signal (SIGINT, SIG_DFL);
2056 signal (SIGQUIT, SIG_DFL); 1804 signal (SIGQUIT, SIG_DFL);
1805 /* GConf causes us to ignore SIGPIPE, make sure it is restored
1806 in the child. */
1807 signal (SIGPIPE, SIG_DFL);
2057 1808
2058 /* Stop blocking signals in the child. */ 1809 /* Stop blocking signals in the child. */
2059 sigprocmask (SIG_SETMASK, &procmask, 0); 1810 sigprocmask (SIG_SETMASK, &procmask, 0);
@@ -2062,13 +1813,13 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
2062 child_setup_tty (xforkout); 1813 child_setup_tty (xforkout);
2063#ifdef WINDOWSNT 1814#ifdef WINDOWSNT
2064 pid = child_setup (xforkin, xforkout, xforkout, 1815 pid = child_setup (xforkin, xforkout, xforkout,
2065 new_argv, 1, current_dir); 1816 new_argv, 1, encoded_current_dir);
2066#else /* not WINDOWSNT */ 1817#else /* not WINDOWSNT */
2067#ifdef FD_CLOEXEC 1818#ifdef FD_CLOEXEC
2068 emacs_close (wait_child_setup[0]); 1819 emacs_close (wait_child_setup[0]);
2069#endif 1820#endif
2070 child_setup (xforkin, xforkout, xforkout, 1821 child_setup (xforkin, xforkout, xforkout,
2071 new_argv, 1, current_dir); 1822 new_argv, 1, encoded_current_dir);
2072#endif /* not WINDOWSNT */ 1823#endif /* not WINDOWSNT */
2073 } 1824 }
2074 environ = save_environ; 1825 environ = save_environ;
@@ -2142,6 +1893,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
2142 /* Restore the parent's signal handlers. */ 1893 /* Restore the parent's signal handlers. */
2143 sigaction (SIGINT, &sigint_action, 0); 1894 sigaction (SIGINT, &sigint_action, 0);
2144 sigaction (SIGQUIT, &sigquit_action, 0); 1895 sigaction (SIGQUIT, &sigquit_action, 0);
1896 sigaction (SIGPIPE, &sigpipe_action, 0);
2145#ifdef AIX 1897#ifdef AIX
2146 sigaction (SIGHUP, &sighup_action, 0); 1898 sigaction (SIGHUP, &sighup_action, 0);
2147#endif 1899#endif
@@ -2158,10 +1910,7 @@ void
2158create_pty (Lisp_Object process) 1910create_pty (Lisp_Object process)
2159{ 1911{
2160 int inchannel, outchannel; 1912 int inchannel, outchannel;
2161 1913 int pty_flag = 0;
2162 /* Use volatile to protect variables from being clobbered by longjmp. */
2163 volatile int forkin, forkout;
2164 volatile int pty_flag = 0;
2165 1914
2166 inchannel = outchannel = -1; 1915 inchannel = outchannel = -1;
2167 1916
@@ -2177,11 +1926,11 @@ create_pty (Lisp_Object process)
2177#ifdef O_NOCTTY 1926#ifdef O_NOCTTY
2178 /* Don't let this terminal become our controlling terminal 1927 /* Don't let this terminal become our controlling terminal
2179 (in case we don't have one). */ 1928 (in case we don't have one). */
2180 forkout = forkin = emacs_open (pty_name, O_RDWR | O_NOCTTY, 0); 1929 int forkout = emacs_open (pty_name, O_RDWR | O_NOCTTY, 0);
2181#else 1930#else
2182 forkout = forkin = emacs_open (pty_name, O_RDWR, 0); 1931 int forkout = emacs_open (pty_name, O_RDWR, 0);
2183#endif 1932#endif
2184 if (forkin < 0) 1933 if (forkout < 0)
2185 report_file_error ("Opening pty", Qnil); 1934 report_file_error ("Opening pty", Qnil);
2186#if defined (DONT_REOPEN_PTY) 1935#if defined (DONT_REOPEN_PTY)
2187 /* In the case that vfork is defined as fork, the parent process 1936 /* In the case that vfork is defined as fork, the parent process
@@ -2189,8 +1938,6 @@ create_pty (Lisp_Object process)
2189 tty options setup. So we setup tty before forking. */ 1938 tty options setup. So we setup tty before forking. */
2190 child_setup_tty (forkout); 1939 child_setup_tty (forkout);
2191#endif /* DONT_REOPEN_PTY */ 1940#endif /* DONT_REOPEN_PTY */
2192#else
2193 forkin = forkout = -1;
2194#endif /* not USG, or USG_SUBTTY_WORKS */ 1941#endif /* not USG, or USG_SUBTTY_WORKS */
2195 pty_flag = 1; 1942 pty_flag = 1;
2196 } 1943 }
@@ -2316,13 +2063,13 @@ get_lisp_to_sockaddr_size (Lisp_Object address, int *familyp)
2316 if (VECTORP (address)) 2063 if (VECTORP (address))
2317 { 2064 {
2318 p = XVECTOR (address); 2065 p = XVECTOR (address);
2319 if (p->size == 5) 2066 if (p->header.size == 5)
2320 { 2067 {
2321 *familyp = AF_INET; 2068 *familyp = AF_INET;
2322 return sizeof (struct sockaddr_in); 2069 return sizeof (struct sockaddr_in);
2323 } 2070 }
2324#ifdef AF_INET6 2071#ifdef AF_INET6
2325 else if (p->size == 9) 2072 else if (p->header.size == 9)
2326 { 2073 {
2327 *familyp = AF_INET6; 2074 *familyp = AF_INET6;
2328 return sizeof (struct sockaddr_in6); 2075 return sizeof (struct sockaddr_in6);
@@ -2341,7 +2088,7 @@ get_lisp_to_sockaddr_size (Lisp_Object address, int *familyp)
2341 struct sockaddr *sa; 2088 struct sockaddr *sa;
2342 *familyp = XINT (XCAR (address)); 2089 *familyp = XINT (XCAR (address));
2343 p = XVECTOR (XCDR (address)); 2090 p = XVECTOR (XCDR (address));
2344 return p->size + sizeof (sa->sa_family); 2091 return p->header.size + sizeof (sa->sa_family);
2345 } 2092 }
2346 return 0; 2093 return 0;
2347} 2094}
@@ -2689,7 +2436,7 @@ Examples:
2689\(serial-process-configure :port "\\\\.\\COM13" :bytesize 7) 2436\(serial-process-configure :port "\\\\.\\COM13" :bytesize 7)
2690 2437
2691usage: (serial-process-configure &rest ARGS) */) 2438usage: (serial-process-configure &rest ARGS) */)
2692 (int nargs, Lisp_Object *args) 2439 (ptrdiff_t nargs, Lisp_Object *args)
2693{ 2440{
2694 struct Lisp_Process *p; 2441 struct Lisp_Process *p;
2695 Lisp_Object contact = Qnil; 2442 Lisp_Object contact = Qnil;
@@ -2724,7 +2471,8 @@ usage: (serial-process-configure &rest ARGS) */)
2724} 2471}
2725 2472
2726/* Used by make-serial-process to recover from errors. */ 2473/* Used by make-serial-process to recover from errors. */
2727Lisp_Object make_serial_process_unwind (Lisp_Object proc) 2474static Lisp_Object
2475make_serial_process_unwind (Lisp_Object proc)
2728{ 2476{
2729 if (!PROCESSP (proc)) 2477 if (!PROCESSP (proc))
2730 abort (); 2478 abort ();
@@ -2806,7 +2554,7 @@ Examples:
2806\(make-serial-process :port "/dev/tty.BlueConsole-SPP-1" :speed nil) 2554\(make-serial-process :port "/dev/tty.BlueConsole-SPP-1" :speed nil)
2807 2555
2808usage: (make-serial-process &rest ARGS) */) 2556usage: (make-serial-process &rest ARGS) */)
2809 (int nargs, Lisp_Object *args) 2557 (ptrdiff_t nargs, Lisp_Object *args)
2810{ 2558{
2811 int fd = -1; 2559 int fd = -1;
2812 Lisp_Object proc, contact, port; 2560 Lisp_Object proc, contact, port;
@@ -2892,8 +2640,8 @@ usage: (make-serial-process &rest ARGS) */)
2892 } 2640 }
2893 else if (!NILP (Vcoding_system_for_read)) 2641 else if (!NILP (Vcoding_system_for_read))
2894 val = Vcoding_system_for_read; 2642 val = Vcoding_system_for_read;
2895 else if ((!NILP (buffer) && NILP (XBUFFER (buffer)->enable_multibyte_characters)) 2643 else if ((!NILP (buffer) && NILP (BVAR (XBUFFER (buffer), enable_multibyte_characters)))
2896 || (NILP (buffer) && NILP (buffer_defaults.enable_multibyte_characters))) 2644 || (NILP (buffer) && NILP (BVAR (&buffer_defaults, enable_multibyte_characters))))
2897 val = Qnil; 2645 val = Qnil;
2898 p->decode_coding_system = val; 2646 p->decode_coding_system = val;
2899 2647
@@ -2906,15 +2654,15 @@ usage: (make-serial-process &rest ARGS) */)
2906 } 2654 }
2907 else if (!NILP (Vcoding_system_for_write)) 2655 else if (!NILP (Vcoding_system_for_write))
2908 val = Vcoding_system_for_write; 2656 val = Vcoding_system_for_write;
2909 else if ((!NILP (buffer) && NILP (XBUFFER (buffer)->enable_multibyte_characters)) 2657 else if ((!NILP (buffer) && NILP (BVAR (XBUFFER (buffer), enable_multibyte_characters)))
2910 || (NILP (buffer) && NILP (buffer_defaults.enable_multibyte_characters))) 2658 || (NILP (buffer) && NILP (BVAR (&buffer_defaults, enable_multibyte_characters))))
2911 val = Qnil; 2659 val = Qnil;
2912 p->encode_coding_system = val; 2660 p->encode_coding_system = val;
2913 2661
2914 setup_process_coding_systems (proc); 2662 setup_process_coding_systems (proc);
2915 p->decoding_buf = make_uninit_string (0); 2663 p->decoding_buf = empty_unibyte_string;
2916 p->decoding_carryover = 0; 2664 p->decoding_carryover = 0;
2917 p->encoding_buf = make_uninit_string (0); 2665 p->encoding_buf = empty_unibyte_string;
2918 p->inherit_coding_system_flag 2666 p->inherit_coding_system_flag
2919 = !(!NILP (tem) || NILP (buffer) || !inherit_process_coding_system); 2667 = !(!NILP (tem) || NILP (buffer) || !inherit_process_coding_system);
2920 2668
@@ -3084,7 +2832,7 @@ The original argument list, modified with the actual connection
3084information, is available via the `process-contact' function. 2832information, is available via the `process-contact' function.
3085 2833
3086usage: (make-network-process &rest ARGS) */) 2834usage: (make-network-process &rest ARGS) */)
3087 (int nargs, Lisp_Object *args) 2835 (ptrdiff_t nargs, Lisp_Object *args)
3088{ 2836{
3089 Lisp_Object proc; 2837 Lisp_Object proc;
3090 Lisp_Object contact; 2838 Lisp_Object contact;
@@ -3292,7 +3040,7 @@ usage: (make-network-process &rest ARGS) */)
3292 portstring = "0"; 3040 portstring = "0";
3293 else if (INTEGERP (service)) 3041 else if (INTEGERP (service))
3294 { 3042 {
3295 sprintf (portbuf, "%ld", (long) XINT (service)); 3043 sprintf (portbuf, "%"pI"d", XINT (service));
3296 portstring = portbuf; 3044 portstring = portbuf;
3297 } 3045 }
3298 else 3046 else
@@ -3400,9 +3148,12 @@ usage: (make-network-process &rest ARGS) */)
3400 3148
3401 for (lres = res; lres; lres = lres->ai_next) 3149 for (lres = res; lres; lres = lres->ai_next)
3402 { 3150 {
3403 int optn, optbits; 3151 ptrdiff_t optn;
3152 int optbits;
3404 3153
3154#ifdef WINDOWSNT
3405 retry_connect: 3155 retry_connect:
3156#endif
3406 3157
3407 s = socket (lres->ai_family, lres->ai_socktype, lres->ai_protocol); 3158 s = socket (lres->ai_family, lres->ai_socktype, lres->ai_protocol);
3408 if (s < 0) 3159 if (s < 0)
@@ -3466,7 +3217,7 @@ usage: (make-network-process &rest ARGS) */)
3466 if (EQ (service, Qt)) 3217 if (EQ (service, Qt))
3467 { 3218 {
3468 struct sockaddr_in sa1; 3219 struct sockaddr_in sa1;
3469 int len1 = sizeof (sa1); 3220 socklen_t len1 = sizeof (sa1);
3470 if (getsockname (s, (struct sockaddr *)&sa1, &len1) == 0) 3221 if (getsockname (s, (struct sockaddr *)&sa1, &len1) == 0)
3471 { 3222 {
3472 ((struct sockaddr_in *)(lres->ai_addr))->sin_port = sa1.sin_port; 3223 ((struct sockaddr_in *)(lres->ai_addr))->sin_port = sa1.sin_port;
@@ -3513,7 +3264,8 @@ usage: (make-network-process &rest ARGS) */)
3513 /* Unlike most other syscalls connect() cannot be called 3264 /* Unlike most other syscalls connect() cannot be called
3514 again. (That would return EALREADY.) The proper way to 3265 again. (That would return EALREADY.) The proper way to
3515 wait for completion is select(). */ 3266 wait for completion is select(). */
3516 int sc, len; 3267 int sc;
3268 socklen_t len;
3517 SELECT_TYPE fdset; 3269 SELECT_TYPE fdset;
3518 retry_select: 3270 retry_select:
3519 FD_ZERO (&fdset); 3271 FD_ZERO (&fdset);
@@ -3586,7 +3338,7 @@ usage: (make-network-process &rest ARGS) */)
3586 if (!is_server) 3338 if (!is_server)
3587 { 3339 {
3588 struct sockaddr_in sa1; 3340 struct sockaddr_in sa1;
3589 int len1 = sizeof (sa1); 3341 socklen_t len1 = sizeof (sa1);
3590 if (getsockname (s, (struct sockaddr *)&sa1, &len1) == 0) 3342 if (getsockname (s, (struct sockaddr *)&sa1, &len1) == 0)
3591 contact = Fplist_put (contact, QClocal, 3343 contact = Fplist_put (contact, QClocal,
3592 conv_sockaddr_to_lisp ((struct sockaddr *)&sa1, len1)); 3344 conv_sockaddr_to_lisp ((struct sockaddr *)&sa1, len1));
@@ -3704,10 +3456,10 @@ usage: (make-network-process &rest ARGS) */)
3704 3456
3705 { 3457 {
3706 /* Setup coding systems for communicating with the network stream. */ 3458 /* Setup coding systems for communicating with the network stream. */
3707 struct gcpro gcpro1; 3459 struct gcpro inner_gcpro1;
3708 /* Qt denotes we have not yet called Ffind_operation_coding_system. */ 3460 /* Qt denotes we have not yet called Ffind_operation_coding_system. */
3709 Lisp_Object coding_systems = Qt; 3461 Lisp_Object coding_systems = Qt;
3710 Lisp_Object args[5], val; 3462 Lisp_Object fargs[5], val;
3711 3463
3712 if (!NILP (tem)) 3464 if (!NILP (tem))
3713 { 3465 {
@@ -3717,8 +3469,8 @@ usage: (make-network-process &rest ARGS) */)
3717 } 3469 }
3718 else if (!NILP (Vcoding_system_for_read)) 3470 else if (!NILP (Vcoding_system_for_read))
3719 val = Vcoding_system_for_read; 3471 val = Vcoding_system_for_read;
3720 else if ((!NILP (buffer) && NILP (XBUFFER (buffer)->enable_multibyte_characters)) 3472 else if ((!NILP (buffer) && NILP (BVAR (XBUFFER (buffer), enable_multibyte_characters)))
3721 || (NILP (buffer) && NILP (buffer_defaults.enable_multibyte_characters))) 3473 || (NILP (buffer) && NILP (BVAR (&buffer_defaults, enable_multibyte_characters))))
3722 /* We dare not decode end-of-line format by setting VAL to 3474 /* We dare not decode end-of-line format by setting VAL to
3723 Qraw_text, because the existing Emacs Lisp libraries 3475 Qraw_text, because the existing Emacs Lisp libraries
3724 assume that they receive bare code including a sequene of 3476 assume that they receive bare code including a sequene of
@@ -3730,11 +3482,11 @@ usage: (make-network-process &rest ARGS) */)
3730 coding_systems = Qnil; 3482 coding_systems = Qnil;
3731 else 3483 else
3732 { 3484 {
3733 args[0] = Qopen_network_stream, args[1] = name, 3485 fargs[0] = Qopen_network_stream, fargs[1] = name,
3734 args[2] = buffer, args[3] = host, args[4] = service; 3486 fargs[2] = buffer, fargs[3] = host, fargs[4] = service;
3735 GCPRO1 (proc); 3487 GCPRO1_VAR (proc, inner_gcpro);
3736 coding_systems = Ffind_operation_coding_system (5, args); 3488 coding_systems = Ffind_operation_coding_system (5, fargs);
3737 UNGCPRO; 3489 UNGCPRO_VAR (inner_gcpro);
3738 } 3490 }
3739 if (CONSP (coding_systems)) 3491 if (CONSP (coding_systems))
3740 val = XCAR (coding_systems); 3492 val = XCAR (coding_systems);
@@ -3753,7 +3505,7 @@ usage: (make-network-process &rest ARGS) */)
3753 } 3505 }
3754 else if (!NILP (Vcoding_system_for_write)) 3506 else if (!NILP (Vcoding_system_for_write))
3755 val = Vcoding_system_for_write; 3507 val = Vcoding_system_for_write;
3756 else if (NILP (current_buffer->enable_multibyte_characters)) 3508 else if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
3757 val = Qnil; 3509 val = Qnil;
3758 else 3510 else
3759 { 3511 {
@@ -3763,11 +3515,11 @@ usage: (make-network-process &rest ARGS) */)
3763 coding_systems = Qnil; 3515 coding_systems = Qnil;
3764 else 3516 else
3765 { 3517 {
3766 args[0] = Qopen_network_stream, args[1] = name, 3518 fargs[0] = Qopen_network_stream, fargs[1] = name,
3767 args[2] = buffer, args[3] = host, args[4] = service; 3519 fargs[2] = buffer, fargs[3] = host, fargs[4] = service;
3768 GCPRO1 (proc); 3520 GCPRO1_VAR (proc, inner_gcpro);
3769 coding_systems = Ffind_operation_coding_system (5, args); 3521 coding_systems = Ffind_operation_coding_system (5, fargs);
3770 UNGCPRO; 3522 UNGCPRO_VAR (inner_gcpro);
3771 } 3523 }
3772 } 3524 }
3773 if (CONSP (coding_systems)) 3525 if (CONSP (coding_systems))
@@ -3781,9 +3533,9 @@ usage: (make-network-process &rest ARGS) */)
3781 } 3533 }
3782 setup_process_coding_systems (proc); 3534 setup_process_coding_systems (proc);
3783 3535
3784 p->decoding_buf = make_uninit_string (0); 3536 p->decoding_buf = empty_unibyte_string;
3785 p->decoding_carryover = 0; 3537 p->decoding_carryover = 0;
3786 p->encoding_buf = make_uninit_string (0); 3538 p->encoding_buf = empty_unibyte_string;
3787 3539
3788 p->inherit_coding_system_flag 3540 p->inherit_coding_system_flag
3789 = !(!NILP (tem) || NILP (buffer) || !inherit_process_coding_system); 3541 = !(!NILP (tem) || NILP (buffer) || !inherit_process_coding_system);
@@ -3947,7 +3699,7 @@ FLAGS is the current flags of the interface. */)
3947 CHECK_STRING (ifname); 3699 CHECK_STRING (ifname);
3948 3700
3949 memset (rq.ifr_name, 0, sizeof rq.ifr_name); 3701 memset (rq.ifr_name, 0, sizeof rq.ifr_name);
3950 strncpy (rq.ifr_name, SDATA (ifname), sizeof (rq.ifr_name)); 3702 strncpy (rq.ifr_name, SSDATA (ifname), sizeof (rq.ifr_name));
3951 3703
3952 s = socket (AF_INET, SOCK_STREAM, 0); 3704 s = socket (AF_INET, SOCK_STREAM, 0);
3953 if (s < 0) 3705 if (s < 0)
@@ -3961,7 +3713,7 @@ FLAGS is the current flags of the interface. */)
3961 const struct ifflag_def *fp; 3713 const struct ifflag_def *fp;
3962 int fnum; 3714 int fnum;
3963 3715
3964 any++; 3716 any = 1;
3965 for (fp = ifflag_table; flags != 0 && fp->flag_sym; fp++) 3717 for (fp = ifflag_table; flags != 0 && fp->flag_sym; fp++)
3966 { 3718 {
3967 if (flags & fp->flag_bit) 3719 if (flags & fp->flag_bit)
@@ -3970,9 +3722,9 @@ FLAGS is the current flags of the interface. */)
3970 flags -= fp->flag_bit; 3722 flags -= fp->flag_bit;
3971 } 3723 }
3972 } 3724 }
3973 for (fnum = 0; flags && fnum < 32; fnum++) 3725 for (fnum = 0; flags && fnum < 32; flags >>= 1, fnum++)
3974 { 3726 {
3975 if (flags & (1 << fnum)) 3727 if (flags & 1)
3976 { 3728 {
3977 elt = Fcons (make_number (fnum), elt); 3729 elt = Fcons (make_number (fnum), elt);
3978 } 3730 }
@@ -3989,7 +3741,7 @@ FLAGS is the current flags of the interface. */)
3989 register struct Lisp_Vector *p = XVECTOR (hwaddr); 3741 register struct Lisp_Vector *p = XVECTOR (hwaddr);
3990 int n; 3742 int n;
3991 3743
3992 any++; 3744 any = 1;
3993 for (n = 0; n < 6; n++) 3745 for (n = 0; n < 6; n++)
3994 p->contents[n] = make_number (((unsigned char *)&rq.ifr_hwaddr.sa_data[0])[n]); 3746 p->contents[n] = make_number (((unsigned char *)&rq.ifr_hwaddr.sa_data[0])[n]);
3995 elt = Fcons (make_number (rq.ifr_hwaddr.sa_family), hwaddr); 3747 elt = Fcons (make_number (rq.ifr_hwaddr.sa_family), hwaddr);
@@ -4001,7 +3753,7 @@ FLAGS is the current flags of the interface. */)
4001#if defined(SIOCGIFNETMASK) && (defined(HAVE_STRUCT_IFREQ_IFR_NETMASK) || defined(HAVE_STRUCT_IFREQ_IFR_ADDR)) 3753#if defined(SIOCGIFNETMASK) && (defined(HAVE_STRUCT_IFREQ_IFR_NETMASK) || defined(HAVE_STRUCT_IFREQ_IFR_ADDR))
4002 if (ioctl (s, SIOCGIFNETMASK, &rq) == 0) 3754 if (ioctl (s, SIOCGIFNETMASK, &rq) == 0)
4003 { 3755 {
4004 any++; 3756 any = 1;
4005#ifdef HAVE_STRUCT_IFREQ_IFR_NETMASK 3757#ifdef HAVE_STRUCT_IFREQ_IFR_NETMASK
4006 elt = conv_sockaddr_to_lisp (&rq.ifr_netmask, sizeof (rq.ifr_netmask)); 3758 elt = conv_sockaddr_to_lisp (&rq.ifr_netmask, sizeof (rq.ifr_netmask));
4007#else 3759#else
@@ -4015,7 +3767,7 @@ FLAGS is the current flags of the interface. */)
4015#if defined(SIOCGIFBRDADDR) && defined(HAVE_STRUCT_IFREQ_IFR_BROADADDR) 3767#if defined(SIOCGIFBRDADDR) && defined(HAVE_STRUCT_IFREQ_IFR_BROADADDR)
4016 if (ioctl (s, SIOCGIFBRDADDR, &rq) == 0) 3768 if (ioctl (s, SIOCGIFBRDADDR, &rq) == 0)
4017 { 3769 {
4018 any++; 3770 any = 1;
4019 elt = conv_sockaddr_to_lisp (&rq.ifr_broadaddr, sizeof (rq.ifr_broadaddr)); 3771 elt = conv_sockaddr_to_lisp (&rq.ifr_broadaddr, sizeof (rq.ifr_broadaddr));
4020 } 3772 }
4021#endif 3773#endif
@@ -4025,7 +3777,7 @@ FLAGS is the current flags of the interface. */)
4025#if defined(SIOCGIFADDR) && defined(HAVE_STRUCT_IFREQ_IFR_ADDR) 3777#if defined(SIOCGIFADDR) && defined(HAVE_STRUCT_IFREQ_IFR_ADDR)
4026 if (ioctl (s, SIOCGIFADDR, &rq) == 0) 3778 if (ioctl (s, SIOCGIFADDR, &rq) == 0)
4027 { 3779 {
4028 any++; 3780 any = 1;
4029 elt = conv_sockaddr_to_lisp (&rq.ifr_addr, sizeof (rq.ifr_addr)); 3781 elt = conv_sockaddr_to_lisp (&rq.ifr_addr, sizeof (rq.ifr_addr));
4030 } 3782 }
4031#endif 3783#endif
@@ -4040,7 +3792,7 @@ FLAGS is the current flags of the interface. */)
4040 3792
4041/* Turn off input and output for process PROC. */ 3793/* Turn off input and output for process PROC. */
4042 3794
4043void 3795static void
4044deactivate_process (Lisp_Object proc) 3796deactivate_process (Lisp_Object proc)
4045{ 3797{
4046 register int inchannel, outchannel; 3798 register int inchannel, outchannel;
@@ -4191,7 +3943,7 @@ server_accept_connection (Lisp_Object server, int channel)
4191 struct sockaddr_un un; 3943 struct sockaddr_un un;
4192#endif 3944#endif
4193 } saddr; 3945 } saddr;
4194 int len = sizeof saddr; 3946 socklen_t len = sizeof saddr;
4195 3947
4196 s = accept (channel, &saddr.sa, &len); 3948 s = accept (channel, &saddr.sa, &len);
4197 3949
@@ -4358,9 +4110,9 @@ server_accept_connection (Lisp_Object server, int channel)
4358 p->encode_coding_system = ps->encode_coding_system; 4110 p->encode_coding_system = ps->encode_coding_system;
4359 setup_process_coding_systems (proc); 4111 setup_process_coding_systems (proc);
4360 4112
4361 p->decoding_buf = make_uninit_string (0); 4113 p->decoding_buf = empty_unibyte_string;
4362 p->decoding_carryover = 0; 4114 p->decoding_carryover = 0;
4363 p->encoding_buf = make_uninit_string (0); 4115 p->encoding_buf = empty_unibyte_string;
4364 4116
4365 p->inherit_coding_system_flag 4117 p->inherit_coding_system_flag
4366 = (NILP (buffer) ? 0 : ps->inherit_coding_system_flag); 4118 = (NILP (buffer) ? 0 : ps->inherit_coding_system_flag);
@@ -4410,7 +4162,7 @@ wait_reading_process_output_1 (void)
4410 impossible to step through wait_reading_process_output. */ 4162 impossible to step through wait_reading_process_output. */
4411 4163
4412#ifndef select 4164#ifndef select
4413static INLINE int 4165static inline int
4414select_wrapper (int n, fd_set *rfd, fd_set *wfd, fd_set *xfd, struct timeval *tmo) 4166select_wrapper (int n, fd_set *rfd, fd_set *wfd, fd_set *xfd, struct timeval *tmo)
4415{ 4167{
4416 return select (n, rfd, wfd, xfd, tmo); 4168 return select (n, rfd, wfd, xfd, tmo);
@@ -4552,7 +4304,7 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4552 struct buffer *old_buffer = current_buffer; 4304 struct buffer *old_buffer = current_buffer;
4553 Lisp_Object old_window = selected_window; 4305 Lisp_Object old_window = selected_window;
4554 4306
4555 timer_delay = timer_check (1); 4307 timer_delay = timer_check ();
4556 4308
4557 /* If a timer has run, this might have changed buffers 4309 /* If a timer has run, this might have changed buffers
4558 an alike. Make read_key_sequence aware of that. */ 4310 an alike. Make read_key_sequence aware of that. */
@@ -4779,6 +4531,22 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4779 &Available, 4531 &Available,
4780 (check_write ? &Writeok : (SELECT_TYPE *)0), 4532 (check_write ? &Writeok : (SELECT_TYPE *)0),
4781 (SELECT_TYPE *)0, &timeout); 4533 (SELECT_TYPE *)0, &timeout);
4534
4535#ifdef HAVE_GNUTLS
4536 /* GnuTLS buffers data internally. In lowat mode it leaves
4537 some data in the TCP buffers so that select works, but
4538 with custom pull/push functions we need to check if some
4539 data is available in the buffers manually. */
4540 if (nfds == 0 &&
4541 wait_proc && wait_proc->gnutls_p /* Check for valid process. */
4542 /* Do we have pending data? */
4543 && emacs_gnutls_record_check_pending (wait_proc->gnutls_state) > 0)
4544 {
4545 nfds = 1;
4546 /* Set to Available. */
4547 FD_SET (wait_proc->infd, &Available);
4548 }
4549#endif
4782 } 4550 }
4783 4551
4784 xerrno = errno; 4552 xerrno = errno;
@@ -4927,8 +4695,6 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4927 d->func (channel, d->data, 0); 4695 d->func (channel, d->data, 0);
4928 } 4696 }
4929 4697
4930 /* Really FIRST_PROC_DESC should be 0 on Unix,
4931 but this is safer in the short run. */
4932 for (channel = 0; channel <= max_process_desc; channel++) 4698 for (channel = 0; channel <= max_process_desc; channel++)
4933 { 4699 {
4934 if (FD_ISSET (channel, &Available) 4700 if (FD_ISSET (channel, &Available)
@@ -5058,7 +4824,7 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
5058 /* getsockopt(,,SO_ERROR,,) is said to hang on some systems. 4824 /* getsockopt(,,SO_ERROR,,) is said to hang on some systems.
5059 So only use it on systems where it is known to work. */ 4825 So only use it on systems where it is known to work. */
5060 { 4826 {
5061 int xlen = sizeof (xerrno); 4827 socklen_t xlen = sizeof (xerrno);
5062 if (getsockopt (channel, SOL_SOCKET, SO_ERROR, &xerrno, &xlen)) 4828 if (getsockopt (channel, SOL_SOCKET, SO_ERROR, &xerrno, &xlen))
5063 xerrno = errno; 4829 xerrno = errno;
5064 } 4830 }
@@ -5127,9 +4893,9 @@ read_process_output_call (Lisp_Object fun_and_args)
5127} 4893}
5128 4894
5129static Lisp_Object 4895static Lisp_Object
5130read_process_output_error_handler (Lisp_Object error) 4896read_process_output_error_handler (Lisp_Object error_val)
5131{ 4897{
5132 cmd_error_internal (error, "error in process filter: "); 4898 cmd_error_internal (error_val, "error in process filter: ");
5133 Vinhibit_quit = Qt; 4899 Vinhibit_quit = Qt;
5134 update_echo_area (); 4900 update_echo_area ();
5135 Fsleep_for (make_number (2), Qnil); 4901 Fsleep_for (make_number (2), Qnil);
@@ -5150,7 +4916,7 @@ read_process_output_error_handler (Lisp_Object error)
5150static int 4916static int
5151read_process_output (Lisp_Object proc, register int channel) 4917read_process_output (Lisp_Object proc, register int channel)
5152{ 4918{
5153 register int nbytes; 4919 register ssize_t nbytes;
5154 char *chars; 4920 char *chars;
5155 register Lisp_Object outstream; 4921 register Lisp_Object outstream;
5156 register struct Lisp_Process *p = XPROCESS (proc); 4922 register struct Lisp_Process *p = XPROCESS (proc);
@@ -5170,21 +4936,28 @@ read_process_output (Lisp_Object proc, register int channel)
5170 /* We have a working select, so proc_buffered_char is always -1. */ 4936 /* We have a working select, so proc_buffered_char is always -1. */
5171 if (DATAGRAM_CHAN_P (channel)) 4937 if (DATAGRAM_CHAN_P (channel))
5172 { 4938 {
5173 int len = datagram_address[channel].len; 4939 socklen_t len = datagram_address[channel].len;
5174 nbytes = recvfrom (channel, chars + carryover, readmax, 4940 nbytes = recvfrom (channel, chars + carryover, readmax,
5175 0, datagram_address[channel].sa, &len); 4941 0, datagram_address[channel].sa, &len);
5176 } 4942 }
5177 else 4943 else
5178#endif 4944#endif
5179 if (proc_buffered_char[channel] < 0)
5180 { 4945 {
4946 int buffered = 0 <= proc_buffered_char[channel];
4947 if (buffered)
4948 {
4949 chars[carryover] = proc_buffered_char[channel];
4950 proc_buffered_char[channel] = -1;
4951 }
5181#ifdef HAVE_GNUTLS 4952#ifdef HAVE_GNUTLS
5182 if (XPROCESS (proc)->gnutls_p) 4953 if (XPROCESS (proc)->gnutls_p)
5183 nbytes = emacs_gnutls_read (channel, XPROCESS (proc), 4954 nbytes = emacs_gnutls_read (XPROCESS (proc),
5184 chars + carryover, readmax); 4955 chars + carryover + buffered,
4956 readmax - buffered);
5185 else 4957 else
5186#endif 4958#endif
5187 nbytes = emacs_read (channel, chars + carryover, readmax); 4959 nbytes = emacs_read (channel, chars + carryover + buffered,
4960 readmax - buffered);
5188#ifdef ADAPTIVE_READ_BUFFERING 4961#ifdef ADAPTIVE_READ_BUFFERING
5189 if (nbytes > 0 && p->adaptive_read_buffering) 4962 if (nbytes > 0 && p->adaptive_read_buffering)
5190 { 4963 {
@@ -5198,7 +4971,7 @@ read_process_output (Lisp_Object proc, register int channel)
5198 delay += READ_OUTPUT_DELAY_INCREMENT * 2; 4971 delay += READ_OUTPUT_DELAY_INCREMENT * 2;
5199 } 4972 }
5200 } 4973 }
5201 else if (delay > 0 && (nbytes == readmax)) 4974 else if (delay > 0 && nbytes == readmax - buffered)
5202 { 4975 {
5203 delay -= READ_OUTPUT_DELAY_INCREMENT; 4976 delay -= READ_OUTPUT_DELAY_INCREMENT;
5204 if (delay == 0) 4977 if (delay == 0)
@@ -5212,22 +4985,8 @@ read_process_output (Lisp_Object proc, register int channel)
5212 } 4985 }
5213 } 4986 }
5214#endif 4987#endif
5215 } 4988 nbytes += buffered;
5216 else 4989 nbytes += buffered && nbytes <= 0;
5217 {
5218 chars[carryover] = proc_buffered_char[channel];
5219 proc_buffered_char[channel] = -1;
5220#ifdef HAVE_GNUTLS
5221 if (XPROCESS (proc)->gnutls_p)
5222 nbytes = emacs_gnutls_read (channel, XPROCESS (proc),
5223 chars + carryover + 1, readmax - 1);
5224 else
5225#endif
5226 nbytes = emacs_read (channel, chars + carryover + 1, readmax - 1);
5227 if (nbytes < 0)
5228 nbytes = 1;
5229 else
5230 nbytes = nbytes + 1;
5231 } 4990 }
5232 4991
5233 p->decoding_carryover = 0; 4992 p->decoding_carryover = 0;
@@ -5254,15 +5013,17 @@ read_process_output (Lisp_Object proc, register int channel)
5254 outstream = p->filter; 5013 outstream = p->filter;
5255 if (!NILP (outstream)) 5014 if (!NILP (outstream))
5256 { 5015 {
5257 Lisp_Object obuffer, okeymap;
5258 Lisp_Object text; 5016 Lisp_Object text;
5259 int outer_running_asynch_code = running_asynch_code; 5017 int outer_running_asynch_code = running_asynch_code;
5260 int waiting = waiting_for_user_input_p; 5018 int waiting = waiting_for_user_input_p;
5261 5019
5262 /* No need to gcpro these, because all we do with them later 5020 /* No need to gcpro these, because all we do with them later
5263 is test them for EQness, and none of them should be a string. */ 5021 is test them for EQness, and none of them should be a string. */
5022#if 0
5023 Lisp_Object obuffer, okeymap;
5264 XSETBUFFER (obuffer, current_buffer); 5024 XSETBUFFER (obuffer, current_buffer);
5265 okeymap = current_buffer->keymap; 5025 okeymap = BVAR (current_buffer, keymap);
5026#endif
5266 5027
5267 /* We inhibit quit here instead of just catching it so that 5028 /* We inhibit quit here instead of just catching it so that
5268 hitting ^G when a filter happens to be running won't screw 5029 hitting ^G when a filter happens to be running won't screw
@@ -5287,7 +5048,7 @@ read_process_output (Lisp_Object proc, register int channel)
5287 save the match data in a special nonrecursive fashion. */ 5048 save the match data in a special nonrecursive fashion. */
5288 running_asynch_code = 1; 5049 running_asynch_code = 1;
5289 5050
5290 decode_coding_c_string (coding, chars, nbytes, Qt); 5051 decode_coding_c_string (coding, (unsigned char *) chars, nbytes, Qt);
5291 text = coding->dst_object; 5052 text = coding->dst_object;
5292 Vlast_coding_system_used = CODING_ID_NAME (coding->id); 5053 Vlast_coding_system_used = CODING_ID_NAME (coding->id);
5293 /* A new coding system might be found. */ 5054 /* A new coding system might be found. */
@@ -5353,7 +5114,7 @@ read_process_output (Lisp_Object proc, register int channel)
5353 } 5114 }
5354 5115
5355 /* If no filter, write into buffer if it isn't dead. */ 5116 /* If no filter, write into buffer if it isn't dead. */
5356 else if (!NILP (p->buffer) && !NILP (XBUFFER (p->buffer)->name)) 5117 else if (!NILP (p->buffer) && !NILP (BVAR (XBUFFER (p->buffer), name)))
5357 { 5118 {
5358 Lisp_Object old_read_only; 5119 Lisp_Object old_read_only;
5359 EMACS_INT old_begv, old_zv; 5120 EMACS_INT old_begv, old_zv;
@@ -5366,13 +5127,13 @@ read_process_output (Lisp_Object proc, register int channel)
5366 Fset_buffer (p->buffer); 5127 Fset_buffer (p->buffer);
5367 opoint = PT; 5128 opoint = PT;
5368 opoint_byte = PT_BYTE; 5129 opoint_byte = PT_BYTE;
5369 old_read_only = current_buffer->read_only; 5130 old_read_only = BVAR (current_buffer, read_only);
5370 old_begv = BEGV; 5131 old_begv = BEGV;
5371 old_zv = ZV; 5132 old_zv = ZV;
5372 old_begv_byte = BEGV_BYTE; 5133 old_begv_byte = BEGV_BYTE;
5373 old_zv_byte = ZV_BYTE; 5134 old_zv_byte = ZV_BYTE;
5374 5135
5375 current_buffer->read_only = Qnil; 5136 BVAR (current_buffer, read_only) = Qnil;
5376 5137
5377 /* Insert new output into buffer 5138 /* Insert new output into buffer
5378 at the current end-of-output marker, 5139 at the current end-of-output marker,
@@ -5391,7 +5152,7 @@ read_process_output (Lisp_Object proc, register int channel)
5391 if (! (BEGV <= PT && PT <= ZV)) 5152 if (! (BEGV <= PT && PT <= ZV))
5392 Fwiden (); 5153 Fwiden ();
5393 5154
5394 decode_coding_c_string (coding, chars, nbytes, Qt); 5155 decode_coding_c_string (coding, (unsigned char *) chars, nbytes, Qt);
5395 text = coding->dst_object; 5156 text = coding->dst_object;
5396 Vlast_coding_system_used = CODING_ID_NAME (coding->id); 5157 Vlast_coding_system_used = CODING_ID_NAME (coding->id);
5397 /* A new coding system might be found. See the comment in the 5158 /* A new coding system might be found. See the comment in the
@@ -5417,7 +5178,7 @@ read_process_output (Lisp_Object proc, register int channel)
5417 p->decoding_carryover = coding->carryover_bytes; 5178 p->decoding_carryover = coding->carryover_bytes;
5418 } 5179 }
5419 /* Adjust the multibyteness of TEXT to that of the buffer. */ 5180 /* Adjust the multibyteness of TEXT to that of the buffer. */
5420 if (NILP (current_buffer->enable_multibyte_characters) 5181 if (NILP (BVAR (current_buffer, enable_multibyte_characters))
5421 != ! STRING_MULTIBYTE (text)) 5182 != ! STRING_MULTIBYTE (text))
5422 text = (STRING_MULTIBYTE (text) 5183 text = (STRING_MULTIBYTE (text)
5423 ? Fstring_as_unibyte (text) 5184 ? Fstring_as_unibyte (text)
@@ -5461,7 +5222,7 @@ read_process_output (Lisp_Object proc, register int channel)
5461 Fnarrow_to_region (make_number (old_begv), make_number (old_zv)); 5222 Fnarrow_to_region (make_number (old_begv), make_number (old_zv));
5462 5223
5463 5224
5464 current_buffer->read_only = old_read_only; 5225 BVAR (current_buffer, read_only) = old_read_only;
5465 SET_PT_BOTH (opoint, opoint_byte); 5226 SET_PT_BOTH (opoint, opoint_byte);
5466 } 5227 }
5467 /* Handling the process output should not deactivate the mark. */ 5228 /* Handling the process output should not deactivate the mark. */
@@ -5473,10 +5234,14 @@ read_process_output (Lisp_Object proc, register int channel)
5473 5234
5474/* Sending data to subprocess */ 5235/* Sending data to subprocess */
5475 5236
5476jmp_buf send_process_frame; 5237static jmp_buf send_process_frame;
5477Lisp_Object process_sent_to; 5238static Lisp_Object process_sent_to;
5239
5240#ifndef FORWARD_SIGNAL_TO_MAIN_THREAD
5241static void send_process_trap (int) NO_RETURN;
5242#endif
5478 5243
5479SIGTYPE 5244static void
5480send_process_trap (int ignore) 5245send_process_trap (int ignore)
5481{ 5246{
5482 SIGNAL_THREAD_CHECK (SIGPIPE); 5247 SIGNAL_THREAD_CHECK (SIGPIPE);
@@ -5495,15 +5260,15 @@ send_process_trap (int ignore)
5495 This function can evaluate Lisp code and can garbage collect. */ 5260 This function can evaluate Lisp code and can garbage collect. */
5496 5261
5497static void 5262static void
5498send_process (volatile Lisp_Object proc, const unsigned char *volatile buf, 5263send_process (volatile Lisp_Object proc, const char *volatile buf,
5499 volatile EMACS_INT len, volatile Lisp_Object object) 5264 volatile EMACS_INT len, volatile Lisp_Object object)
5500{ 5265{
5501 /* Use volatile to protect variables from being clobbered by longjmp. */ 5266 /* Use volatile to protect variables from being clobbered by longjmp. */
5502 struct Lisp_Process *p = XPROCESS (proc); 5267 struct Lisp_Process *p = XPROCESS (proc);
5503 EMACS_INT rv; 5268 ssize_t rv;
5504 struct coding_system *coding; 5269 struct coding_system *coding;
5505 struct gcpro gcpro1; 5270 struct gcpro gcpro1;
5506 SIGTYPE (*volatile old_sigpipe) (int); 5271 void (*volatile old_sigpipe) (int);
5507 5272
5508 GCPRO1 (object); 5273 GCPRO1 (object);
5509 5274
@@ -5519,7 +5284,7 @@ send_process (volatile Lisp_Object proc, const unsigned char *volatile buf,
5519 5284
5520 if ((STRINGP (object) && STRING_MULTIBYTE (object)) 5285 if ((STRINGP (object) && STRING_MULTIBYTE (object))
5521 || (BUFFERP (object) 5286 || (BUFFERP (object)
5522 && !NILP (XBUFFER (object)->enable_multibyte_characters)) 5287 && !NILP (BVAR (XBUFFER (object), enable_multibyte_characters)))
5523 || EQ (object, Qt)) 5288 || EQ (object, Qt))
5524 { 5289 {
5525 p->encode_coding_system 5290 p->encode_coding_system
@@ -5573,7 +5338,7 @@ send_process (volatile Lisp_Object proc, const unsigned char *volatile buf,
5573 set_buffer_internal (XBUFFER (object)); 5338 set_buffer_internal (XBUFFER (object));
5574 save_pt = PT, save_pt_byte = PT_BYTE; 5339 save_pt = PT, save_pt_byte = PT_BYTE;
5575 5340
5576 from_byte = PTR_BYTE_POS (buf); 5341 from_byte = PTR_BYTE_POS ((unsigned char *) buf);
5577 from = BYTE_TO_CHAR (from_byte); 5342 from = BYTE_TO_CHAR (from_byte);
5578 to = BYTE_TO_CHAR (from_byte + len); 5343 to = BYTE_TO_CHAR (from_byte + len);
5579 TEMP_SET_PT_BOTH (from, from_byte); 5344 TEMP_SET_PT_BOTH (from, from_byte);
@@ -5595,7 +5360,7 @@ send_process (volatile Lisp_Object proc, const unsigned char *volatile buf,
5595 5360
5596 len = coding->produced; 5361 len = coding->produced;
5597 object = coding->dst_object; 5362 object = coding->dst_object;
5598 buf = SDATA (object); 5363 buf = SSDATA (object);
5599 } 5364 }
5600 5365
5601 if (pty_max_bytes == 0) 5366 if (pty_max_bytes == 0)
@@ -5616,6 +5381,8 @@ send_process (volatile Lisp_Object proc, const unsigned char *volatile buf,
5616 when returning with longjmp despite being declared volatile. */ 5381 when returning with longjmp despite being declared volatile. */
5617 if (!setjmp (send_process_frame)) 5382 if (!setjmp (send_process_frame))
5618 { 5383 {
5384 p = XPROCESS (proc); /* Repair any setjmp clobbering. */
5385
5619 process_sent_to = proc; 5386 process_sent_to = proc;
5620 while (len > 0) 5387 while (len > 0)
5621 { 5388 {
@@ -5624,15 +5391,18 @@ send_process (volatile Lisp_Object proc, const unsigned char *volatile buf,
5624 /* Send this batch, using one or more write calls. */ 5391 /* Send this batch, using one or more write calls. */
5625 while (this > 0) 5392 while (this > 0)
5626 { 5393 {
5394 EMACS_INT written = 0;
5627 int outfd = p->outfd; 5395 int outfd = p->outfd;
5628 old_sigpipe = (SIGTYPE (*) (int)) signal (SIGPIPE, send_process_trap); 5396 old_sigpipe = (void (*) (int)) signal (SIGPIPE, send_process_trap);
5629#ifdef DATAGRAM_SOCKETS 5397#ifdef DATAGRAM_SOCKETS
5630 if (DATAGRAM_CHAN_P (outfd)) 5398 if (DATAGRAM_CHAN_P (outfd))
5631 { 5399 {
5632 rv = sendto (outfd, (char *) buf, this, 5400 rv = sendto (outfd, buf, this,
5633 0, datagram_address[outfd].sa, 5401 0, datagram_address[outfd].sa,
5634 datagram_address[outfd].len); 5402 datagram_address[outfd].len);
5635 if (rv < 0 && errno == EMSGSIZE) 5403 if (0 <= rv)
5404 written = rv;
5405 else if (errno == EMSGSIZE)
5636 { 5406 {
5637 signal (SIGPIPE, old_sigpipe); 5407 signal (SIGPIPE, old_sigpipe);
5638 report_file_error ("sending datagram", 5408 report_file_error ("sending datagram",
@@ -5644,12 +5414,12 @@ send_process (volatile Lisp_Object proc, const unsigned char *volatile buf,
5644 { 5414 {
5645#ifdef HAVE_GNUTLS 5415#ifdef HAVE_GNUTLS
5646 if (XPROCESS (proc)->gnutls_p) 5416 if (XPROCESS (proc)->gnutls_p)
5647 rv = emacs_gnutls_write (outfd, 5417 written = emacs_gnutls_write (XPROCESS (proc),
5648 XPROCESS (proc), 5418 buf, this);
5649 (char *) buf, this);
5650 else 5419 else
5651#endif 5420#endif
5652 rv = emacs_write (outfd, (char *) buf, this); 5421 written = emacs_write (outfd, buf, this);
5422 rv = (written ? 0 : -1);
5653#ifdef ADAPTIVE_READ_BUFFERING 5423#ifdef ADAPTIVE_READ_BUFFERING
5654 if (p->read_output_delay > 0 5424 if (p->read_output_delay > 0
5655 && p->adaptive_read_buffering == 1) 5425 && p->adaptive_read_buffering == 1)
@@ -5676,7 +5446,7 @@ send_process (volatile Lisp_Object proc, const unsigned char *volatile buf,
5676 that may allow the program 5446 that may allow the program
5677 to finish doing output and read more. */ 5447 to finish doing output and read more. */
5678 { 5448 {
5679 int offset = 0; 5449 EMACS_INT offset = 0;
5680 5450
5681#ifdef BROKEN_PTY_READ_AFTER_EAGAIN 5451#ifdef BROKEN_PTY_READ_AFTER_EAGAIN
5682 /* A gross hack to work around a bug in FreeBSD. 5452 /* A gross hack to work around a bug in FreeBSD.
@@ -5706,9 +5476,10 @@ send_process (volatile Lisp_Object proc, const unsigned char *volatile buf,
5706 /* Running filters might relocate buffers or strings. 5476 /* Running filters might relocate buffers or strings.
5707 Arrange to relocate BUF. */ 5477 Arrange to relocate BUF. */
5708 if (BUFFERP (object)) 5478 if (BUFFERP (object))
5709 offset = BUF_PTR_BYTE_POS (XBUFFER (object), buf); 5479 offset = BUF_PTR_BYTE_POS (XBUFFER (object),
5480 (unsigned char *) buf);
5710 else if (STRINGP (object)) 5481 else if (STRINGP (object))
5711 offset = buf - SDATA (object); 5482 offset = buf - SSDATA (object);
5712 5483
5713#ifdef EMACS_HAS_USECS 5484#ifdef EMACS_HAS_USECS
5714 wait_reading_process_output (0, 20000, 0, 0, Qnil, NULL, 0); 5485 wait_reading_process_output (0, 20000, 0, 0, Qnil, NULL, 0);
@@ -5717,19 +5488,18 @@ send_process (volatile Lisp_Object proc, const unsigned char *volatile buf,
5717#endif 5488#endif
5718 5489
5719 if (BUFFERP (object)) 5490 if (BUFFERP (object))
5720 buf = BUF_BYTE_ADDRESS (XBUFFER (object), offset); 5491 buf = (char *) BUF_BYTE_ADDRESS (XBUFFER (object),
5492 offset);
5721 else if (STRINGP (object)) 5493 else if (STRINGP (object))
5722 buf = offset + SDATA (object); 5494 buf = offset + SSDATA (object);
5723
5724 rv = 0;
5725 } 5495 }
5726 else 5496 else
5727 /* This is a real error. */ 5497 /* This is a real error. */
5728 report_file_error ("writing to process", Fcons (proc, Qnil)); 5498 report_file_error ("writing to process", Fcons (proc, Qnil));
5729 } 5499 }
5730 buf += rv; 5500 buf += written;
5731 len -= rv; 5501 len -= written;
5732 this -= rv; 5502 this -= written;
5733 } 5503 }
5734 } 5504 }
5735 } 5505 }
@@ -5770,7 +5540,7 @@ Output from processes can arrive in between bunches. */)
5770 5540
5771 start1 = CHAR_TO_BYTE (XINT (start)); 5541 start1 = CHAR_TO_BYTE (XINT (start));
5772 end1 = CHAR_TO_BYTE (XINT (end)); 5542 end1 = CHAR_TO_BYTE (XINT (end));
5773 send_process (proc, BYTE_POS_ADDR (start1), end1 - start1, 5543 send_process (proc, (char *) BYTE_POS_ADDR (start1), end1 - start1,
5774 Fcurrent_buffer ()); 5544 Fcurrent_buffer ());
5775 5545
5776 return Qnil; 5546 return Qnil;
@@ -5789,7 +5559,7 @@ Output from processes can arrive in between bunches. */)
5789 Lisp_Object proc; 5559 Lisp_Object proc;
5790 CHECK_STRING (string); 5560 CHECK_STRING (string);
5791 proc = get_process (process); 5561 proc = get_process (process);
5792 send_process (proc, SDATA (string), 5562 send_process (proc, SSDATA (string),
5793 SBYTES (string), string); 5563 SBYTES (string), string);
5794 return Qnil; 5564 return Qnil;
5795} 5565}
@@ -5922,7 +5692,7 @@ process_send_signal (Lisp_Object process, int signo, Lisp_Object current_group,
5922 5692
5923 if (sig_char && *sig_char != CDISABLE) 5693 if (sig_char && *sig_char != CDISABLE)
5924 { 5694 {
5925 send_process (proc, sig_char, 1, Qnil); 5695 send_process (proc, (char *) sig_char, 1, Qnil);
5926 return; 5696 return;
5927 } 5697 }
5928 /* If we can't send the signal with a character, 5698 /* If we can't send the signal with a character,
@@ -6168,10 +5938,10 @@ SIGCODE may be an integer, or a symbol whose name is a signal name. */)
6168 ; 5938 ;
6169 else 5939 else
6170 { 5940 {
6171 unsigned char *name; 5941 char *name;
6172 5942
6173 CHECK_SYMBOL (sigcode); 5943 CHECK_SYMBOL (sigcode);
6174 name = SDATA (SYMBOL_NAME (sigcode)); 5944 name = SSDATA (SYMBOL_NAME (sigcode));
6175 5945
6176 if (!strncmp (name, "SIG", 3) || !strncmp (name, "sig", 3)) 5946 if (!strncmp (name, "SIG", 3) || !strncmp (name, "sig", 3))
6177 name += 3; 5947 name += 3;
@@ -6383,7 +6153,7 @@ process has been transmitted to the serial port. */)
6383 indirectly; if it does, that is a bug */ 6153 indirectly; if it does, that is a bug */
6384 6154
6385#ifdef SIGCHLD 6155#ifdef SIGCHLD
6386SIGTYPE 6156static void
6387sigchld_handler (int signo) 6157sigchld_handler (int signo)
6388{ 6158{
6389 int old_errno = errno; 6159 int old_errno = errno;
@@ -6531,9 +6301,9 @@ exec_sentinel_unwind (Lisp_Object data)
6531} 6301}
6532 6302
6533static Lisp_Object 6303static Lisp_Object
6534exec_sentinel_error_handler (Lisp_Object error) 6304exec_sentinel_error_handler (Lisp_Object error_val)
6535{ 6305{
6536 cmd_error_internal (error, "error in process sentinel: "); 6306 cmd_error_internal (error_val, "error in process sentinel: ");
6537 Vinhibit_quit = Qt; 6307 Vinhibit_quit = Qt;
6538 update_echo_area (); 6308 update_echo_area ();
6539 Fsleep_for (make_number (2), Qnil); 6309 Fsleep_for (make_number (2), Qnil);
@@ -6543,7 +6313,7 @@ exec_sentinel_error_handler (Lisp_Object error)
6543static void 6313static void
6544exec_sentinel (Lisp_Object proc, Lisp_Object reason) 6314exec_sentinel (Lisp_Object proc, Lisp_Object reason)
6545{ 6315{
6546 Lisp_Object sentinel, obuffer, odeactivate, okeymap; 6316 Lisp_Object sentinel, odeactivate;
6547 register struct Lisp_Process *p = XPROCESS (proc); 6317 register struct Lisp_Process *p = XPROCESS (proc);
6548 int count = SPECPDL_INDEX (); 6318 int count = SPECPDL_INDEX ();
6549 int outer_running_asynch_code = running_asynch_code; 6319 int outer_running_asynch_code = running_asynch_code;
@@ -6555,8 +6325,11 @@ exec_sentinel (Lisp_Object proc, Lisp_Object reason)
6555 /* No need to gcpro these, because all we do with them later 6325 /* No need to gcpro these, because all we do with them later
6556 is test them for EQness, and none of them should be a string. */ 6326 is test them for EQness, and none of them should be a string. */
6557 odeactivate = Vdeactivate_mark; 6327 odeactivate = Vdeactivate_mark;
6328#if 0
6329 Lisp_Object obuffer, okeymap;
6558 XSETBUFFER (obuffer, current_buffer); 6330 XSETBUFFER (obuffer, current_buffer);
6559 okeymap = current_buffer->keymap; 6331 okeymap = BVAR (current_buffer, keymap);
6332#endif
6560 6333
6561 /* There's no good reason to let sentinels change the current 6334 /* There's no good reason to let sentinels change the current
6562 buffer, and many callers of accept-process-output, sit-for, and 6335 buffer, and many callers of accept-process-output, sit-for, and
@@ -6706,7 +6479,7 @@ status_notify (struct Lisp_Process *deleting_process)
6706 6479
6707 /* Avoid error if buffer is deleted 6480 /* Avoid error if buffer is deleted
6708 (probably that's why the process is dead, too) */ 6481 (probably that's why the process is dead, too) */
6709 if (NILP (XBUFFER (buffer)->name)) 6482 if (NILP (BVAR (XBUFFER (buffer), name)))
6710 continue; 6483 continue;
6711 Fset_buffer (buffer); 6484 Fset_buffer (buffer);
6712 6485
@@ -6723,13 +6496,13 @@ status_notify (struct Lisp_Process *deleting_process)
6723 before = PT; 6496 before = PT;
6724 before_byte = PT_BYTE; 6497 before_byte = PT_BYTE;
6725 6498
6726 tem = current_buffer->read_only; 6499 tem = BVAR (current_buffer, read_only);
6727 current_buffer->read_only = Qnil; 6500 BVAR (current_buffer, read_only) = Qnil;
6728 insert_string ("\nProcess "); 6501 insert_string ("\nProcess ");
6729 Finsert (1, &p->name); 6502 Finsert (1, &p->name);
6730 insert_string (" "); 6503 insert_string (" ");
6731 Finsert (1, &msg); 6504 Finsert (1, &msg);
6732 current_buffer->read_only = tem; 6505 BVAR (current_buffer, read_only) = tem;
6733 set_marker_both (p->mark, p->buffer, PT, PT_BYTE); 6506 set_marker_both (p->mark, p->buffer, PT, PT_BYTE);
6734 6507
6735 if (opoint >= before) 6508 if (opoint >= before)
@@ -6820,6 +6593,8 @@ DEFUN ("process-filter-multibyte-p", Fprocess_filter_multibyte_p,
6820 6593
6821 6594
6822 6595
6596# ifdef HAVE_GPM
6597
6823void 6598void
6824add_gpm_wait_descriptor (int desc) 6599add_gpm_wait_descriptor (int desc)
6825{ 6600{
@@ -6832,6 +6607,10 @@ delete_gpm_wait_descriptor (int desc)
6832 delete_keyboard_wait_descriptor (desc); 6607 delete_keyboard_wait_descriptor (desc);
6833} 6608}
6834 6609
6610# endif
6611
6612# ifdef SIGIO
6613
6835/* Return nonzero if *MASK has a bit set 6614/* Return nonzero if *MASK has a bit set
6836 that corresponds to one of the keyboard input descriptors. */ 6615 that corresponds to one of the keyboard input descriptors. */
6837 6616
@@ -6847,6 +6626,7 @@ keyboard_bit_set (fd_set *mask)
6847 6626
6848 return 0; 6627 return 0;
6849} 6628}
6629# endif
6850 6630
6851#else /* not subprocesses */ 6631#else /* not subprocesses */
6852 6632
@@ -6950,7 +6730,7 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
6950 do 6730 do
6951 { 6731 {
6952 int old_timers_run = timers_run; 6732 int old_timers_run = timers_run;
6953 timer_delay = timer_check (1); 6733 timer_delay = timer_check ();
6954 if (timers_run != old_timers_run && do_display) 6734 if (timers_run != old_timers_run && do_display)
6955 /* We must retry, since a timer may have requeued itself 6735 /* We must retry, since a timer may have requeued itself
6956 and that could alter the time delay. */ 6736 and that could alter the time delay. */
@@ -7128,7 +6908,7 @@ setup_process_coding_systems (Lisp_Object process)
7128 ; 6908 ;
7129 else if (BUFFERP (p->buffer)) 6909 else if (BUFFERP (p->buffer))
7130 { 6910 {
7131 if (NILP (XBUFFER (p->buffer)->enable_multibyte_characters)) 6911 if (NILP (BVAR (XBUFFER (p->buffer), enable_multibyte_characters)))
7132 coding_system = raw_text_coding_system (coding_system); 6912 coding_system = raw_text_coding_system (coding_system);
7133 } 6913 }
7134 setup_coding_system (coding_system, proc_decode_coding_system[inch]); 6914 setup_coding_system (coding_system, proc_decode_coding_system[inch]);
@@ -7234,8 +7014,8 @@ kill_buffer_processes (Lisp_Object buffer)
7234#endif /* subprocesses */ 7014#endif /* subprocesses */
7235} 7015}
7236 7016
7237DEFUN ("waiting-for-user-input-p", Fwaiting_for_user_input_p, Swaiting_for_user_input_p, 7017DEFUN ("waiting-for-user-input-p", Fwaiting_for_user_input_p,
7238 0, 0, 0, 7018 Swaiting_for_user_input_p, 0, 0, 0,
7239 doc: /* Returns non-nil if Emacs is waiting for input from the user. 7019 doc: /* Returns non-nil if Emacs is waiting for input from the user.
7240This is intended for use by asynchronous process output filters and sentinels. */) 7020This is intended for use by asynchronous process output filters and sentinels. */)
7241 (void) 7021 (void)
@@ -7437,7 +7217,9 @@ init_process (void)
7437 processes. As such, we only change the default value. */ 7217 processes. As such, we only change the default value. */
7438 if (initialized) 7218 if (initialized)
7439 { 7219 {
7440 const char *release = get_operating_system_release (); 7220 char const *release = (STRINGP (Voperating_system_release)
7221 ? SSDATA (Voperating_system_release)
7222 : 0);
7441 if (!release || !release[0] || (release[0] < MIN_PTY_KERNEL_VERSION 7223 if (!release || !release[0] || (release[0] < MIN_PTY_KERNEL_VERSION
7442 && release[1] == '.')) { 7224 && release[1] == '.')) {
7443 Vprocess_connection_type = Qnil; 7225 Vprocess_connection_type = Qnil;
@@ -7682,7 +7464,6 @@ The variable takes effect when `start-process' is called. */);
7682 defsubr (&Sprocess_contact); 7464 defsubr (&Sprocess_contact);
7683 defsubr (&Sprocess_plist); 7465 defsubr (&Sprocess_plist);
7684 defsubr (&Sset_process_plist); 7466 defsubr (&Sset_process_plist);
7685 defsubr (&Slist_processes);
7686 defsubr (&Sprocess_list); 7467 defsubr (&Sprocess_list);
7687 defsubr (&Sstart_process); 7468 defsubr (&Sstart_process);
7688 defsubr (&Sserial_process_configure); 7469 defsubr (&Sserial_process_configure);