comparison src/process.c @ 16:0293115a14e9 r19-15b91

Import from CVS: tag r19-15b91
author cvs
date Mon, 13 Aug 2007 08:49:20 +0200
parents 376386a54a3c
children 859a2309aef8
comparison
equal deleted inserted replaced
15:ad457d5f7d04 16:0293115a14e9
215 { 215 {
216 struct Lisp_Process *proc = XPROCESS (obj); 216 struct Lisp_Process *proc = XPROCESS (obj);
217 217
218 if (print_readably) 218 if (print_readably)
219 error ("printing unreadable object #<process %s>", 219 error ("printing unreadable object #<process %s>",
220 string_data (XSTRING (proc->name))); 220 XSTRING_DATA (proc->name));
221 221
222 if (!escapeflag) 222 if (!escapeflag)
223 { 223 {
224 print_internal (proc->name, printcharfun, 0); 224 print_internal (proc->name, printcharfun, 0);
225 } 225 }
468 return proc; 468 return proc;
469 469
470 if (GC_NILP (name)) 470 if (GC_NILP (name))
471 error ("Current buffer has no process"); 471 error ("Current buffer has no process");
472 else 472 else
473 error ("Process %s does not exist", string_data (XSTRING (name))); 473 error ("Process %s does not exist", XSTRING_DATA (name));
474 /* NOTREACHED */ 474 /* NOTREACHED */
475 return Qnil; /* warning suppression */ 475 return Qnil; /* warning suppression */
476 } 476 }
477 477
478 DEFUN ("process-id", Fprocess_id, Sprocess_id, 1, 1, 0 /* 478 DEFUN ("process-id", Fprocess_id, Sprocess_id, 1, 1, 0 /*
706 { 706 {
707 /* Figure out the eof character for the outfd of the given process. 707 /* Figure out the eof character for the outfd of the given process.
708 * The following code is similar to that in process_send_signal, and 708 * The following code is similar to that in process_send_signal, and
709 * should probably be merged with that code somehow. */ 709 * should probably be merged with that code somehow. */
710 710
711 CONST Bufbyte ctrl_d = (Bufbyte) '\004';
712
713 if (!isatty (p->outfd))
714 return ctrl_d;
711 #ifdef HAVE_TERMIOS 715 #ifdef HAVE_TERMIOS
712 struct termios t; 716 {
713 tcgetattr (p->outfd, &t); 717 struct termios t;
714 if (strlen ((CONST char *) t.c_cc) < (unsigned int) (VEOF + 1)) 718 tcgetattr (p->outfd, &t);
715 return (Bufbyte) '\004'; 719 #if 0
716 else 720 /* What is the following line designed to do??? -mrb */
717 return (Bufbyte) t.c_cc[VEOF]; 721 if (strlen ((CONST char *) t.c_cc) < (unsigned int) (VEOF + 1))
722 return ctrl_d;
723 else
724 return (Bufbyte) t.c_cc[VEOF];
725 #endif
726 return t.c_cc[VEOF] == CDISABLE ? ctrl_d : (Bufbyte) t.c_cc[VEOF];
727 }
718 #else /* ! HAVE_TERMIOS */ 728 #else /* ! HAVE_TERMIOS */
719 /* On Berkeley descendants, the following IOCTL's retrieve the 729 /* On Berkeley descendants, the following IOCTL's retrieve the
720 current control characters. */ 730 current control characters. */
721 #if defined (TIOCGETC) 731 #if defined (TIOCGETC)
722 struct tchars c; 732 {
723 ioctl (p->outfd, TIOCGETC, &c); 733 struct tchars c;
724 return (Bufbyte) c.t_eofc; 734 ioctl (p->outfd, TIOCGETC, &c);
735 return (Bufbyte) c.t_eofc;
736 }
725 #else /* ! defined (TIOCGLTC) && defined (TIOCGETC) */ 737 #else /* ! defined (TIOCGLTC) && defined (TIOCGETC) */
726 /* On SYSV descendants, the TCGETA ioctl retrieves the current control 738 /* On SYSV descendants, the TCGETA ioctl retrieves the current control
727 characters. */ 739 characters. */
728 #ifdef TCGETA 740 #ifdef TCGETA
729 struct termio t; 741 {
730 ioctl (p->outfd, TCGETA, &t); 742 struct termio t;
731 if (strlen ((CONST char *) t.c_cc) < (unsigned int) (VINTR + 1)) 743 ioctl (p->outfd, TCGETA, &t);
732 return (Bufbyte) '\004'; 744 if (strlen ((CONST char *) t.c_cc) < (unsigned int) (VINTR + 1))
733 else 745 return ctrl_d;
734 return (Bufbyte) t.c_cc[VINTR]; 746 else
747 return (Bufbyte) t.c_cc[VINTR];
748 }
735 #else /* ! defined (TCGETA) */ 749 #else /* ! defined (TCGETA) */
736 /* Rather than complain, we'll just guess ^D, which is what 750 /* Rather than complain, we'll just guess ^D, which is what
737 * earlier emacsen always used. */ 751 * earlier emacsen always used. */
738 return (Bufbyte) '\004'; 752 return ctrl_d;
739 #endif /* ! defined (TCGETA) */ 753 #endif /* ! defined (TCGETA) */
740 #endif /* ! defined (TIOCGETC) */ 754 #endif /* ! defined (TIOCGETC) */
741 #endif /* ! defined (HAVE_TERMIOS) */ 755 #endif /* ! defined (HAVE_TERMIOS) */
742 } 756 }
743 757
1141 program = args[2]; 1155 program = args[2];
1142 1156
1143 #ifdef VMS 1157 #ifdef VMS
1144 /* Make a one member argv with all args concatenated 1158 /* Make a one member argv with all args concatenated
1145 together separated by a blank. */ 1159 together separated by a blank. */
1146 len = string_length (XSTRING (program)) + 2; 1160 len = XSTRING_LENGTH (program) + 2;
1147 for (i = 3; i < nargs; i++) 1161 for (i = 3; i < nargs; i++)
1148 { 1162 {
1149 tem = args[i]; 1163 tem = args[i];
1150 CHECK_STRING (tem); 1164 CHECK_STRING (tem);
1151 len += string_length (XSTRING (tem)) + 1; /* count the blank */ 1165 len += XSTRING_LENGTH (tem) + 1; /* count the blank */
1152 } 1166 }
1153 new_argv = (char *) alloca (len); 1167 new_argv = (char *) alloca (len);
1154 strcpy (new_argv, string_data (XSTRING (program))); 1168 strcpy (new_argv, XSTRING_DATA (program));
1155 for (i = 3; i < nargs; i++) 1169 for (i = 3; i < nargs; i++)
1156 { 1170 {
1157 tem = args[i]; 1171 tem = args[i];
1158 CHECK_STRING (tem); 1172 CHECK_STRING (tem);
1159 strcat (new_argv, " "); 1173 strcat (new_argv, " ");
1160 strcat (new_argv, string_data (XSTRING (tem))); 1174 strcat (new_argv, XSTRING_DATA (tem));
1161 } 1175 }
1162 /* Need to add code here to check for program existence on VMS */ 1176 /* Need to add code here to check for program existence on VMS */
1163 1177
1164 #else /* not VMS */ 1178 #else /* not VMS */
1165 new_argv = (char **) 1179 new_argv = (char **)
1166 alloca ((nargs - 1) * sizeof (char *)); 1180 alloca ((nargs - 1) * sizeof (char *));
1167 1181
1168 new_argv[0] = (char *) string_data (XSTRING (program)); 1182 new_argv[0] = (char *) XSTRING_DATA (program);
1169 1183
1170 /* If program file name is not absolute, search our path for it */ 1184 /* If program file name is not absolute, search our path for it */
1171 if (!IS_DIRECTORY_SEP (string_byte (XSTRING (program), 0)) 1185 if (!IS_DIRECTORY_SEP (XSTRING_BYTE (program, 0))
1172 && !(string_length (XSTRING (program)) > 1 1186 && !(XSTRING_LENGTH (program) > 1
1173 && IS_DEVICE_SEP (string_byte (XSTRING (program), 1)))) 1187 && IS_DEVICE_SEP (XSTRING_BYTE (program, 1))))
1174 { 1188 {
1175 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; /* Caller protects args[] */ 1189 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; /* Caller protects args[] */
1176 GCPRO4 (buffer, current_dir, name, program); 1190 GCPRO4 (buffer, current_dir, name, program);
1177 1191
1178 tem = Qnil; 1192 tem = Qnil;
1180 X_OK); 1194 X_OK);
1181 UNGCPRO; 1195 UNGCPRO;
1182 if (NILP (tem)) 1196 if (NILP (tem))
1183 report_file_error ("Searching for program", list1 (program)); 1197 report_file_error ("Searching for program", list1 (program));
1184 tem = Fexpand_file_name (tem, Qnil); 1198 tem = Fexpand_file_name (tem, Qnil);
1185 new_argv[0] = (char *) string_data (XSTRING (tem)); 1199 new_argv[0] = (char *) XSTRING_DATA (tem);
1186 } 1200 }
1187 else 1201 else
1188 { 1202 {
1189 if (!NILP (Ffile_directory_p (program))) 1203 if (!NILP (Ffile_directory_p (program)))
1190 error ("Specified program for new process is a directory"); 1204 error ("Specified program for new process is a directory");
1192 1206
1193 for (i = 3; i < nargs; i++) 1207 for (i = 3; i < nargs; i++)
1194 { 1208 {
1195 tem = args[i]; 1209 tem = args[i];
1196 CHECK_STRING (tem); 1210 CHECK_STRING (tem);
1197 new_argv[i - 2] = 1211 new_argv[i - 2] = (char *) XSTRING_DATA (tem);
1198 (char *) string_data (XSTRING (tem));
1199 } 1212 }
1200 new_argv[i - 2] = 0; 1213 new_argv[i - 2] = 0;
1201 1214
1202 #endif /* not VMS */ 1215 #endif /* not VMS */
1203 1216
1216 remove it from the process list. This means that each error 1229 remove it from the process list. This means that each error
1217 check in create_process doesn't need to call remove_process 1230 check in create_process doesn't need to call remove_process
1218 itself; it's all taken care of here. */ 1231 itself; it's all taken care of here. */
1219 record_unwind_protect (start_process_unwind, proc); 1232 record_unwind_protect (start_process_unwind, proc);
1220 1233
1221 create_process (proc, new_argv, 1234 create_process (proc, new_argv, (char *) XSTRING_DATA (current_dir));
1222 (char *) string_data (XSTRING (current_dir)));
1223 1235
1224 return unbind_to (speccount, proc); 1236 return unbind_to (speccount, proc);
1225 } 1237 }
1226 1238
1227 1239
1295 #ifdef TRY_AGAIN 1307 #ifdef TRY_AGAIN
1296 h_errno = 0; 1308 h_errno = 0;
1297 #endif 1309 #endif
1298 /* Some systems can't handle SIGIO/SIGALARM in gethostbyname. */ 1310 /* Some systems can't handle SIGIO/SIGALARM in gethostbyname. */
1299 slow_down_interrupts (); 1311 slow_down_interrupts ();
1300 host_info_ptr = gethostbyname ((char *) string_data (XSTRING (host))); 1312 host_info_ptr = gethostbyname ((char *) XSTRING_DATA (host));
1301 speed_up_interrupts (); 1313 speed_up_interrupts ();
1302 #ifdef TRY_AGAIN 1314 #ifdef TRY_AGAIN
1303 if (! (host_info_ptr == 0 && h_errno == TRY_AGAIN)) 1315 if (! (host_info_ptr == 0 && h_errno == TRY_AGAIN))
1304 #endif 1316 #endif
1305 break; 1317 break;
1312 } 1324 }
1313 else 1325 else
1314 { 1326 {
1315 IN_ADDR numeric_addr; 1327 IN_ADDR numeric_addr;
1316 /* Attempt to interpret host as numeric inet address */ 1328 /* Attempt to interpret host as numeric inet address */
1317 numeric_addr = inet_addr ((char *) string_data (XSTRING (host))); 1329 numeric_addr = inet_addr ((char *) XSTRING_DATA (host));
1318 if (NUMERIC_ADDR_ERROR) 1330 if (NUMERIC_ADDR_ERROR)
1319 { 1331 {
1320 maybe_error (Qprocess, errb, 1332 maybe_error (Qprocess, errb,
1321 "Unknown host \"%s\"", string_data (XSTRING (host))); 1333 "Unknown host \"%s\"", XSTRING_DATA (host));
1322 return 0; 1334 return 0;
1323 } 1335 }
1324 1336
1325 /* There was some broken code here that called strlen() here 1337 /* There was some broken code here that called strlen() here
1326 on (char *) &numeric_addr and even sometimes accessed 1338 on (char *) &numeric_addr and even sometimes accessed
1363 Lisp_Object proc; 1375 Lisp_Object proc;
1364 struct sockaddr_in address; 1376 struct sockaddr_in address;
1365 int s, outch, inch; 1377 int s, outch, inch;
1366 int port; 1378 int port;
1367 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 1379 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
1368 int retry = 0; 1380 volatile int retry = 0;
1369 int retval; 1381 int retval;
1370 1382
1371 GCPRO4 (name, buffer, host, service); 1383 GCPRO4 (name, buffer, host, service);
1372 CHECK_STRING (name); 1384 CHECK_STRING (name);
1373 CHECK_STRING (host); 1385 CHECK_STRING (host);
1375 port = htons ((unsigned short) XINT (service)); 1387 port = htons ((unsigned short) XINT (service));
1376 else 1388 else
1377 { 1389 {
1378 struct servent *svc_info; 1390 struct servent *svc_info;
1379 CHECK_STRING (service); 1391 CHECK_STRING (service);
1380 svc_info = getservbyname ((char *) string_data (XSTRING (service)), 1392 svc_info = getservbyname ((char *) XSTRING_DATA (service), "tcp");
1381 "tcp");
1382 if (svc_info == 0) 1393 if (svc_info == 0)
1383 #ifdef WIN32 1394 #ifdef WIN32
1384 error ("Unknown service \"%s\" (%d)", 1395 error ("Unknown service \"%s\" (%d)",
1385 string_data (XSTRING (service)), WSAGetLastError ()); 1396 XSTRING_DATA (service), WSAGetLastError ());
1386 #else 1397 #else
1387 error ("Unknown service \"%s\"", string_data (XSTRING (service))); 1398 error ("Unknown service \"%s\"", XSTRING_DATA (service));
1388 #endif 1399 #endif
1389 port = svc_info->s_port; 1400 port = svc_info->s_port;
1390 } 1401 }
1391 1402
1392 get_internet_address (host, &address, ERROR_ME); 1403 get_internet_address (host, &address, ERROR_ME);
1461 1472
1462 #else /* HAVE_TERM */ 1473 #else /* HAVE_TERM */
1463 s = connect_server (0); 1474 s = connect_server (0);
1464 if (s < 0) 1475 if (s < 0)
1465 report_file_error ("error creating socket", Fcons (name, Qnil)); 1476 report_file_error ("error creating socket", Fcons (name, Qnil));
1466 send_command (s, C_PORT, 0, "%s:%d", string_data (XSTRING (host)), ntohs (port)); 1477 send_command (s, C_PORT, 0, "%s:%d", XSTRING_DATA (host), ntohs (port));
1467 send_command (s, C_DUMB, 1, 0); 1478 send_command (s, C_DUMB, 1, 0);
1468 #endif /* HAVE_TERM */ 1479 #endif /* HAVE_TERM */
1469 1480
1470 inch = s; 1481 inch = s;
1471 outch = dup (s); 1482 outch = dup (s);
1764 int start, int len) 1775 int start, int len)
1765 { 1776 {
1766 /* This function can GC */ 1777 /* This function can GC */
1767 /* Use volatile to protect variables from being clobbered by longjmp. */ 1778 /* Use volatile to protect variables from being clobbered by longjmp. */
1768 struct gcpro gcpro1, gcpro2; 1779 struct gcpro gcpro1, gcpro2;
1769 SIGTYPE (*old_sigpipe) (int) = 0; 1780 SIGTYPE (*volatile old_sigpipe) (int) = 0;
1770 Lisp_Object lstream = Qnil; 1781 Lisp_Object lstream = Qnil;
1771 volatile struct Lisp_Process *p = XPROCESS (proc); 1782 volatile struct Lisp_Process *p = XPROCESS (proc);
1772 #if defined (NO_UNION_TYPE) /* || !defined (__GNUC__) GCC bug only??? */ 1783 #if defined (NO_UNION_TYPE) /* || !defined (__GNUC__) GCC bug only??? */
1773 /* #### ugh! There must be a better solution. */ 1784 /* #### ugh! There must be a better solution. */
1774 Lisp_Object defeat_volatile_kludge = (Lisp_Object) proc; 1785 Lisp_Object defeat_volatile_kludge = (Lisp_Object) proc;
1855 p->tick++; 1866 p->tick++;
1856 process_tick++; 1867 process_tick++;
1857 deactivate_process (proc); 1868 deactivate_process (proc);
1858 #ifdef VMS 1869 #ifdef VMS
1859 error ("Error writing to process %s; closed it", 1870 error ("Error writing to process %s; closed it",
1860 string_data (XSTRING (p->name))); 1871 XSTRING_DATA (p->name));
1861 #else 1872 #else
1862 error ("SIGPIPE raised on process %s; closed it", 1873 error ("SIGPIPE raised on process %s; closed it",
1863 string_data (XSTRING (p->name))); 1874 XSTRING_DATA (p->name));
1864 #endif 1875 #endif
1865 } 1876 }
1866 Lstream_flush (XLSTREAM (p->outstream)); 1877 Lstream_flush (XLSTREAM (p->outstream));
1867 UNGCPRO; 1878 UNGCPRO;
1868 } 1879 }
2682 int gid; 2693 int gid;
2683 int no_pgrp = 0; 2694 int no_pgrp = 0;
2684 2695
2685 if (network_connection_p (proc)) 2696 if (network_connection_p (proc))
2686 error ("Network connection %s is not a subprocess", 2697 error ("Network connection %s is not a subprocess",
2687 string_data (XSTRING (p->name))); 2698 XSTRING_DATA (p->name));
2688 if (p->infd < 0) 2699 if (p->infd < 0)
2689 error ("Process %s is not active", 2700 error ("Process %s is not active",
2690 string_data (XSTRING (p->name))); 2701 XSTRING_DATA (p->name));
2691 2702
2692 if (!p->pty_flag) 2703 if (!p->pty_flag)
2693 current_group = 0; 2704 current_group = 0;
2694 2705
2695 /* If we are using pgrps, get a pgrp number and make it negative. */ 2706 /* If we are using pgrps, get a pgrp number and make it negative. */
3017 3028
3018 proc = get_process (process); 3029 proc = get_process (process);
3019 3030
3020 /* Make sure the process is really alive. */ 3031 /* Make sure the process is really alive. */
3021 if (! EQ (XPROCESS (proc)->status_symbol, Qrun)) 3032 if (! EQ (XPROCESS (proc)->status_symbol, Qrun))
3022 error ("Process %s not running", 3033 error ("Process %s not running", XSTRING_DATA (XPROCESS (proc)->name));
3023 string_data (XSTRING (XPROCESS (proc)->name)));
3024 3034
3025 #ifdef VMS 3035 #ifdef VMS
3026 send_process (proc, Qnil, (Bufbyte *) "\032", 0, 1); /* ^Z */ 3036 send_process (proc, Qnil, (Bufbyte *) "\032", 0, 1); /* ^Z */
3027 #else 3037 #else
3028 if (XPROCESS (proc)->pty_flag) 3038 if (XPROCESS (proc)->pty_flag)