annotate tests/sigpipe.c @ 2640:a4040d921acc

[xemacs-hg @ 2005-03-09 05:36:28 by stephent] internals and lispref <871xapfkkq.fsf@tleepslib.sk.tsukuba.ac.jp>
author stephent
date Wed, 09 Mar 2005 05:36:50 +0000
parents 3f6adebda25c
children 679041362cd4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1231
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
1 /* code is all from loser.c and loser.el by Mly
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
2
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
3 Copyright (C) 2002 Richard Mlynarik <mly@pobox.com>
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
4
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
5 This is part of XEmacs
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
6
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
7 Compile this file. Run it in the background giving it a command line
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
8 argument PORT which is a positive integer 1024 < PORT < 32768 (avoid the
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
9 numbers assigned in /etc/services).
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
10
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
11 Then start up a fresh (you're going to crash) XEmacs. Execute the following
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
12
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
13 (defun lose (port)
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
14 (interactive "nUrk: ")
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
15 (require 'comint)
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
16 (while t
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
17 (condition-case e
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
18 (let* ((name "*lose*")
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
19 (b (get-buffer-create name)))
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
20 (switch-to-buffer b)
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
21 (comint-mode)
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
22 (comint-exec b name (cons "127.0.0.1" port) nil '())
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
23 (process-send-string (get-buffer-process b) "\377\373\001")
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
24 (process-send-string (get-buffer-process b) "\377\373\001"))
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
25 (error (message "URK: %s" e)) (sit-for 1))))
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
26
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
27 Then M-x lose RET PORT RET and you lose big (in XEmacs 21.1, anyway).
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
28 Note: the error messages are proper functioning. What should eventually
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
29 happen after a number of SIGPIPEs is that you get a SIGSEGV and life is
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
30 bad and XEmacs is dead.
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
31 */
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
32
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
33 #include <arpa/inet.h>
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
34
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
35 int
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
36 main (int argc, char **argv)
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
37 {
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
38 struct sockaddr_in junk;
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
39 int s;
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
40
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
41 memset (&junk, 0, sizeof (junk));
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
42
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
43 junk.sin_family = AF_INET;
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
44 junk.sin_addr.s_addr = htonl (INADDR_ANY); /* un*x sucks */
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
45 junk.sin_port = htons (atoi (argv[1])); /* un*x blows */
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
46
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
47 s = socket (PF_INET, SOCK_STREAM, 0);
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
48
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
49 bind (s, (struct sockaddr *)&junk, sizeof (junk));
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
50
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
51 listen (s, 1);
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
52
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
53 for (;;)
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
54 {
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
55 int loser = accept (s, NULL, 0);
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
56 close (loser);
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
57 }
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
58 }
3f6adebda25c [xemacs-hg @ 2003-01-23 11:24:08 by stephent]
stephent
parents:
diff changeset
59