aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c96
1 files changed, 50 insertions, 46 deletions
diff --git a/src/process.c b/src/process.c
index 66cb227bb0a..08c515d34e0 100644
--- a/src/process.c
+++ b/src/process.c
@@ -414,10 +414,10 @@ update_status (p)
414 struct Lisp_Process *p; 414 struct Lisp_Process *p;
415{ 415{
416 union { int i; WAITTYPE wt; } u; 416 union { int i; WAITTYPE wt; } u;
417 u.i = XFASTINT (p->raw_status_low) + (XFASTINT (p->raw_status_high) << 16); 417 eassert (p->raw_status_new);
418 u.i = p->raw_status;
418 p->status = status_convert (u.wt); 419 p->status = status_convert (u.wt);
419 p->raw_status_low = Qnil; 420 p->raw_status_new = 0;
420 p->raw_status_high = Qnil;
421} 421}
422 422
423/* Convert a process status word in Unix format to 423/* Convert a process status word in Unix format to
@@ -619,11 +619,10 @@ make_process (name)
619 619
620 XSETINT (p->infd, -1); 620 XSETINT (p->infd, -1);
621 XSETINT (p->outfd, -1); 621 XSETINT (p->outfd, -1);
622 XSETFASTINT (p->pid, 0);
623 XSETFASTINT (p->tick, 0); 622 XSETFASTINT (p->tick, 0);
624 XSETFASTINT (p->update_tick, 0); 623 XSETFASTINT (p->update_tick, 0);
625 p->raw_status_low = Qnil; 624 p->pid = 0;
626 p->raw_status_high = Qnil; 625 p->raw_status_new = 0;
627 p->status = Qrun; 626 p->status = Qrun;
628 p->mark = Fmake_marker (); 627 p->mark = Fmake_marker ();
629 628
@@ -789,8 +788,7 @@ nil, indicating the current buffer's process. */)
789 process = get_process (process); 788 process = get_process (process);
790 p = XPROCESS (process); 789 p = XPROCESS (process);
791 790
792 p->raw_status_low = Qnil; 791 p->raw_status_new = 0;
793 p->raw_status_high = Qnil;
794 if (NETCONN1_P (p)) 792 if (NETCONN1_P (p))
795 { 793 {
796 p->status = Fcons (Qexit, Fcons (make_number (0), Qnil)); 794 p->status = Fcons (Qexit, Fcons (make_number (0), Qnil));
@@ -840,7 +838,7 @@ nil, indicating the current buffer's process. */)
840 return process; 838 return process;
841 839
842 p = XPROCESS (process); 840 p = XPROCESS (process);
843 if (!NILP (p->raw_status_low)) 841 if (p->raw_status_new)
844 update_status (p); 842 update_status (p);
845 status = p->status; 843 status = p->status;
846 if (CONSP (status)) 844 if (CONSP (status))
@@ -865,7 +863,7 @@ If PROCESS has not yet exited or died, return 0. */)
865 register Lisp_Object process; 863 register Lisp_Object process;
866{ 864{
867 CHECK_PROCESS (process); 865 CHECK_PROCESS (process);
868 if (!NILP (XPROCESS (process)->raw_status_low)) 866 if (XPROCESS (process)->raw_status_new)
869 update_status (XPROCESS (process)); 867 update_status (XPROCESS (process));
870 if (CONSP (XPROCESS (process)->status)) 868 if (CONSP (XPROCESS (process)->status))
871 return XCAR (XCDR (XPROCESS (process)->status)); 869 return XCAR (XCDR (XPROCESS (process)->status));
@@ -880,7 +878,9 @@ For a network connection, this value is nil. */)
880 register Lisp_Object process; 878 register Lisp_Object process;
881{ 879{
882 CHECK_PROCESS (process); 880 CHECK_PROCESS (process);
883 return XPROCESS (process)->pid; 881 return (XPROCESS (process)->pid
882 ? make_fixnum_or_float (XPROCESS (process)->pid)
883 : Qnil);
884} 884}
885 885
886DEFUN ("process-name", Fprocess_name, Sprocess_name, 1, 1, 0, 886DEFUN ("process-name", Fprocess_name, Sprocess_name, 1, 1, 0,
@@ -1362,7 +1362,7 @@ list_processes_1 (query_only)
1362 Finsert (1, &p->name); 1362 Finsert (1, &p->name);
1363 Findent_to (i_status, minspace); 1363 Findent_to (i_status, minspace);
1364 1364
1365 if (!NILP (p->raw_status_low)) 1365 if (p->raw_status_new)
1366 update_status (p); 1366 update_status (p);
1367 symbol = p->status; 1367 symbol = p->status;
1368 if (CONSP (p->status)) 1368 if (CONSP (p->status))
@@ -1734,7 +1734,7 @@ start_process_unwind (proc)
1734 abort (); 1734 abort ();
1735 1735
1736 /* Was PROC started successfully? */ 1736 /* Was PROC started successfully? */
1737 if (XINT (XPROCESS (proc)->pid) <= 0) 1737 if (XPROCESS (proc)->pid <= 0)
1738 remove_process (proc); 1738 remove_process (proc);
1739 1739
1740 return Qnil; 1740 return Qnil;
@@ -1945,7 +1945,7 @@ create_process (process, new_argv, current_dir)
1945 in the table after this function has returned; if it does 1945 in the table after this function has returned; if it does
1946 it might cause call-process to hang and subsequent asynchronous 1946 it might cause call-process to hang and subsequent asynchronous
1947 processes to get their return values scrambled. */ 1947 processes to get their return values scrambled. */
1948 XSETINT (XPROCESS (process)->pid, -1); 1948 XPROCESS (process)->pid = -1;
1949 1949
1950 BLOCK_INPUT; 1950 BLOCK_INPUT;
1951 1951
@@ -2136,7 +2136,7 @@ create_process (process, new_argv, current_dir)
2136 else 2136 else
2137 { 2137 {
2138 /* vfork succeeded. */ 2138 /* vfork succeeded. */
2139 XSETFASTINT (XPROCESS (process)->pid, pid); 2139 XPROCESS (process)->pid = pid;
2140 2140
2141#ifdef WINDOWSNT 2141#ifdef WINDOWSNT
2142 register_child (pid, inchannel); 2142 register_child (pid, inchannel);
@@ -3349,7 +3349,7 @@ usage: (make-network-process &rest ARGS) */)
3349 p->kill_without_query = Qt; 3349 p->kill_without_query = Qt;
3350 if ((tem = Fplist_get (contact, QCstop), !NILP (tem))) 3350 if ((tem = Fplist_get (contact, QCstop), !NILP (tem)))
3351 p->command = Qt; 3351 p->command = Qt;
3352 p->pid = Qnil; 3352 p->pid = 0;
3353 XSETINT (p->infd, inch); 3353 XSETINT (p->infd, inch);
3354 XSETINT (p->outfd, outch); 3354 XSETINT (p->outfd, outch);
3355 if (is_server && socktype == SOCK_STREAM) 3355 if (is_server && socktype == SOCK_STREAM)
@@ -4065,7 +4065,7 @@ server_accept_connection (server, channel)
4065 p->sentinel = ps->sentinel; 4065 p->sentinel = ps->sentinel;
4066 p->filter = ps->filter; 4066 p->filter = ps->filter;
4067 p->command = Qnil; 4067 p->command = Qnil;
4068 p->pid = Qnil; 4068 p->pid = 0;
4069 XSETINT (p->infd, s); 4069 XSETINT (p->infd, s);
4070 XSETINT (p->outfd, s); 4070 XSETINT (p->outfd, s);
4071 p->status = Qrun; 4071 p->status = Qrun;
@@ -4365,9 +4365,9 @@ wait_reading_process_output (time_limit, microsecs, read_kbd, do_display,
4365 4365
4366 /* Don't wait for output from a non-running process. Just 4366 /* Don't wait for output from a non-running process. Just
4367 read whatever data has already been received. */ 4367 read whatever data has already been received. */
4368 if (wait_proc != 0 && !NILP (wait_proc->raw_status_low)) 4368 if (wait_proc && wait_proc->raw_status_new)
4369 update_status (wait_proc); 4369 update_status (wait_proc);
4370 if (wait_proc != 0 4370 if (wait_proc
4371 && ! EQ (wait_proc->status, Qrun) 4371 && ! EQ (wait_proc->status, Qrun)
4372 && ! EQ (wait_proc->status, Qconnect)) 4372 && ! EQ (wait_proc->status, Qconnect))
4373 { 4373 {
@@ -4751,7 +4751,7 @@ wait_reading_process_output (time_limit, microsecs, read_kbd, do_display,
4751 /* Preserve status of processes already terminated. */ 4751 /* Preserve status of processes already terminated. */
4752 XSETINT (XPROCESS (proc)->tick, ++process_tick); 4752 XSETINT (XPROCESS (proc)->tick, ++process_tick);
4753 deactivate_process (proc); 4753 deactivate_process (proc);
4754 if (!NILP (XPROCESS (proc)->raw_status_low)) 4754 if (XPROCESS (proc)->raw_status_new)
4755 update_status (XPROCESS (proc)); 4755 update_status (XPROCESS (proc));
4756 if (EQ (XPROCESS (proc)->status, Qrun)) 4756 if (EQ (XPROCESS (proc)->status, Qrun))
4757 XPROCESS (proc)->status 4757 XPROCESS (proc)->status
@@ -5288,7 +5288,7 @@ send_process (proc, buf, len, object)
5288 VMS_PROC_STUFF *vs, *get_vms_process_pointer(); 5288 VMS_PROC_STUFF *vs, *get_vms_process_pointer();
5289#endif /* VMS */ 5289#endif /* VMS */
5290 5290
5291 if (! NILP (p->raw_status_low)) 5291 if (p->raw_status_new)
5292 update_status (p); 5292 update_status (p);
5293 if (! EQ (p->status, Qrun)) 5293 if (! EQ (p->status, Qrun))
5294 error ("Process %s not running", SDATA (p->name)); 5294 error ("Process %s not running", SDATA (p->name));
@@ -5552,8 +5552,7 @@ send_process (proc, buf, len, object)
5552 proc = process_sent_to; 5552 proc = process_sent_to;
5553 p = XPROCESS (proc); 5553 p = XPROCESS (proc);
5554#endif 5554#endif
5555 p->raw_status_low = Qnil; 5555 p->raw_status_new = 0;
5556 p->raw_status_high = Qnil;
5557 p->status = Fcons (Qexit, Fcons (make_number (256), Qnil)); 5556 p->status = Fcons (Qexit, Fcons (make_number (256), Qnil));
5558 XSETINT (p->tick, ++process_tick); 5557 XSETINT (p->tick, ++process_tick);
5559 deactivate_process (proc); 5558 deactivate_process (proc);
@@ -5668,7 +5667,7 @@ return t unconditionally. */)
5668 5667
5669 gid = emacs_get_tty_pgrp (p); 5668 gid = emacs_get_tty_pgrp (p);
5670 5669
5671 if (gid == XFASTINT (p->pid)) 5670 if (gid == p->pid)
5672 return Qnil; 5671 return Qnil;
5673 return Qt; 5672 return Qt;
5674} 5673}
@@ -5715,7 +5714,7 @@ process_send_signal (process, signo, current_group, nomsg)
5715 /* If we are using pgrps, get a pgrp number and make it negative. */ 5714 /* If we are using pgrps, get a pgrp number and make it negative. */
5716 if (NILP (current_group)) 5715 if (NILP (current_group))
5717 /* Send the signal to the shell's process group. */ 5716 /* Send the signal to the shell's process group. */
5718 gid = XFASTINT (p->pid); 5717 gid = p->pid;
5719 else 5718 else
5720 { 5719 {
5721#ifdef SIGNALS_VIA_CHARACTERS 5720#ifdef SIGNALS_VIA_CHARACTERS
@@ -5834,7 +5833,7 @@ process_send_signal (process, signo, current_group, nomsg)
5834 if (gid == -1) 5833 if (gid == -1)
5835 /* If we can't get the information, assume 5834 /* If we can't get the information, assume
5836 the shell owns the tty. */ 5835 the shell owns the tty. */
5837 gid = XFASTINT (p->pid); 5836 gid = p->pid;
5838 5837
5839 /* It is not clear whether anything really can set GID to -1. 5838 /* It is not clear whether anything really can set GID to -1.
5840 Perhaps on some system one of those ioctls can or could do so. 5839 Perhaps on some system one of those ioctls can or could do so.
@@ -5844,12 +5843,12 @@ process_send_signal (process, signo, current_group, nomsg)
5844#else /* ! defined (TIOCGPGRP ) */ 5843#else /* ! defined (TIOCGPGRP ) */
5845 /* Can't select pgrps on this system, so we know that 5844 /* Can't select pgrps on this system, so we know that
5846 the child itself heads the pgrp. */ 5845 the child itself heads the pgrp. */
5847 gid = XFASTINT (p->pid); 5846 gid = p->pid;
5848#endif /* ! defined (TIOCGPGRP ) */ 5847#endif /* ! defined (TIOCGPGRP ) */
5849 5848
5850 /* If current_group is lambda, and the shell owns the terminal, 5849 /* If current_group is lambda, and the shell owns the terminal,
5851 don't send any signal. */ 5850 don't send any signal. */
5852 if (EQ (current_group, Qlambda) && gid == XFASTINT (p->pid)) 5851 if (EQ (current_group, Qlambda) && gid == p->pid)
5853 return; 5852 return;
5854 } 5853 }
5855 5854
@@ -5857,8 +5856,7 @@ process_send_signal (process, signo, current_group, nomsg)
5857 { 5856 {
5858#ifdef SIGCONT 5857#ifdef SIGCONT
5859 case SIGCONT: 5858 case SIGCONT:
5860 p->raw_status_low = Qnil; 5859 p->raw_status_new = 0;
5861 p->raw_status_high = Qnil;
5862 p->status = Qrun; 5860 p->status = Qrun;
5863 XSETINT (p->tick, ++process_tick); 5861 XSETINT (p->tick, ++process_tick);
5864 if (!nomsg) 5862 if (!nomsg)
@@ -5877,7 +5875,7 @@ process_send_signal (process, signo, current_group, nomsg)
5877#endif 5875#endif
5878 case SIGKILL: 5876 case SIGKILL:
5879#ifdef VMS 5877#ifdef VMS
5880 sys$forcex (&(XFASTINT (p->pid)), 0, 1); 5878 sys$forcex (&(p->pid), 0, 1);
5881 whoosh: 5879 whoosh:
5882#endif 5880#endif
5883 flush_pending_output (XINT (p->infd)); 5881 flush_pending_output (XINT (p->infd));
@@ -5889,7 +5887,7 @@ process_send_signal (process, signo, current_group, nomsg)
5889 obvious alternative. */ 5887 obvious alternative. */
5890 if (no_pgrp) 5888 if (no_pgrp)
5891 { 5889 {
5892 kill (XFASTINT (p->pid), signo); 5890 kill (p->pid, signo);
5893 return; 5891 return;
5894 } 5892 }
5895 5893
@@ -5902,7 +5900,7 @@ process_send_signal (process, signo, current_group, nomsg)
5902 } 5900 }
5903 else 5901 else
5904 { 5902 {
5905 gid = - XFASTINT (p->pid); 5903 gid = - p->pid;
5906 kill (gid, signo); 5904 kill (gid, signo);
5907 } 5905 }
5908#else /* ! defined (TIOCSIGSEND) */ 5906#else /* ! defined (TIOCSIGSEND) */
@@ -6022,11 +6020,17 @@ SIGCODE may be an integer, or a symbol whose name is a signal name. */)
6022 (process, sigcode) 6020 (process, sigcode)
6023 Lisp_Object process, sigcode; 6021 Lisp_Object process, sigcode;
6024{ 6022{
6025 Lisp_Object pid; 6023 pid_t pid;
6026 6024
6027 if (INTEGERP (process)) 6025 if (INTEGERP (process))
6028 { 6026 {
6029 pid = process; 6027 pid = XINT (process);
6028 goto got_it;
6029 }
6030
6031 if (FLOATP (process))
6032 {
6033 pid = (pid_t) XFLOAT (process);
6030 goto got_it; 6034 goto got_it;
6031 } 6035 }
6032 6036
@@ -6035,8 +6039,8 @@ SIGCODE may be an integer, or a symbol whose name is a signal name. */)
6035 Lisp_Object tem; 6039 Lisp_Object tem;
6036 if (tem = Fget_process (process), NILP (tem)) 6040 if (tem = Fget_process (process), NILP (tem))
6037 { 6041 {
6038 pid = Fstring_to_number (process, make_number (10)); 6042 pid = XINT (Fstring_to_number (process, make_number (10)));
6039 if (XINT (pid) != 0) 6043 if (pid > 0)
6040 goto got_it; 6044 goto got_it;
6041 } 6045 }
6042 process = tem; 6046 process = tem;
@@ -6049,7 +6053,7 @@ SIGCODE may be an integer, or a symbol whose name is a signal name. */)
6049 6053
6050 CHECK_PROCESS (process); 6054 CHECK_PROCESS (process);
6051 pid = XPROCESS (process)->pid; 6055 pid = XPROCESS (process)->pid;
6052 if (!INTEGERP (pid) || XINT (pid) <= 0) 6056 if (pid <= 0)
6053 error ("Cannot signal process %s", SDATA (XPROCESS (process)->name)); 6057 error ("Cannot signal process %s", SDATA (XPROCESS (process)->name));
6054 6058
6055 got_it: 6059 got_it:
@@ -6168,7 +6172,7 @@ SIGCODE may be an integer, or a symbol whose name is a signal name. */)
6168 6172
6169#undef handle_signal 6173#undef handle_signal
6170 6174
6171 return make_number (kill (XINT (pid), XINT (sigcode))); 6175 return make_number (kill (pid, XINT (sigcode)));
6172} 6176}
6173 6177
6174DEFUN ("process-send-eof", Fprocess_send_eof, Sprocess_send_eof, 0, 1, 0, 6178DEFUN ("process-send-eof", Fprocess_send_eof, Sprocess_send_eof, 0, 1, 0,
@@ -6192,7 +6196,7 @@ text to PROCESS after you call this function. */)
6192 coding = proc_encode_coding_system[XINT (XPROCESS (proc)->outfd)]; 6196 coding = proc_encode_coding_system[XINT (XPROCESS (proc)->outfd)];
6193 6197
6194 /* Make sure the process is really alive. */ 6198 /* Make sure the process is really alive. */
6195 if (! NILP (XPROCESS (proc)->raw_status_low)) 6199 if (XPROCESS (proc)->raw_status_new)
6196 update_status (XPROCESS (proc)); 6200 update_status (XPROCESS (proc));
6197 if (! EQ (XPROCESS (proc)->status, Qrun)) 6201 if (! EQ (XPROCESS (proc)->status, Qrun))
6198 error ("Process %s not running", SDATA (XPROCESS (proc)->name)); 6202 error ("Process %s not running", SDATA (XPROCESS (proc)->name));
@@ -6217,7 +6221,7 @@ text to PROCESS after you call this function. */)
6217 for communication with the subprocess, call shutdown to cause EOF. 6221 for communication with the subprocess, call shutdown to cause EOF.
6218 (In some old system, shutdown to socketpair doesn't work. 6222 (In some old system, shutdown to socketpair doesn't work.
6219 Then we just can't win.) */ 6223 Then we just can't win.) */
6220 if (NILP (XPROCESS (proc)->pid) 6224 if (XPROCESS (proc)->pid == 0
6221 || XINT (XPROCESS (proc)->outfd) == XINT (XPROCESS (proc)->infd)) 6225 || XINT (XPROCESS (proc)->outfd) == XINT (XPROCESS (proc)->infd))
6222 shutdown (XINT (XPROCESS (proc)->outfd), 1); 6226 shutdown (XINT (XPROCESS (proc)->outfd), 1);
6223 /* In case of socketpair, outfd == infd, so don't close it. */ 6227 /* In case of socketpair, outfd == infd, so don't close it. */
@@ -6354,7 +6358,7 @@ sigchld_handler (signo)
6354 { 6358 {
6355 proc = XCDR (XCAR (tail)); 6359 proc = XCDR (XCAR (tail));
6356 p = XPROCESS (proc); 6360 p = XPROCESS (proc);
6357 if (GC_EQ (p->childp, Qt) && XINT (p->pid) == pid) 6361 if (GC_EQ (p->childp, Qt) && p->pid == pid)
6358 break; 6362 break;
6359 p = 0; 6363 p = 0;
6360 } 6364 }
@@ -6366,7 +6370,7 @@ sigchld_handler (signo)
6366 { 6370 {
6367 proc = XCDR (XCAR (tail)); 6371 proc = XCDR (XCAR (tail));
6368 p = XPROCESS (proc); 6372 p = XPROCESS (proc);
6369 if (GC_INTEGERP (p->pid) && XINT (p->pid) == -1) 6373 if (p->pid == -1)
6370 break; 6374 break;
6371 p = 0; 6375 p = 0;
6372 } 6376 }
@@ -6379,8 +6383,8 @@ sigchld_handler (signo)
6379 6383
6380 XSETINT (p->tick, ++process_tick); 6384 XSETINT (p->tick, ++process_tick);
6381 u.wt = w; 6385 u.wt = w;
6382 XSETINT (p->raw_status_low, u.i & 0xffff); 6386 p->raw_status = u.i;
6383 XSETINT (p->raw_status_high, u.i >> 16); 6387 p->raw_status_new = 1;
6384 6388
6385 /* If process has terminated, stop waiting for its output. */ 6389 /* If process has terminated, stop waiting for its output. */
6386 if ((WIFSIGNALED (w) || WIFEXITED (w)) 6390 if ((WIFSIGNALED (w) || WIFEXITED (w))
@@ -6577,7 +6581,7 @@ status_notify (deleting_process)
6577 buffer = p->buffer; 6581 buffer = p->buffer;
6578 6582
6579 /* Get the text to use for the message. */ 6583 /* Get the text to use for the message. */
6580 if (!NILP (p->raw_status_low)) 6584 if (p->raw_status_new)
6581 update_status (p); 6585 update_status (p);
6582 msg = status_message (p); 6586 msg = status_message (p);
6583 6587