1 /* Serial interface for a pipe to a separate program
2 Copyright 1999 Free Software Foundation, Inc.
4 Contributed by Cygnus Solutions.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
27 #include <sys/types.h>
29 #include <sys/socket.h>
36 static int pipe_open (serial_t scb
, const char *name
);
37 static void pipe_close (serial_t scb
);
39 extern void _initialize_ser_pipe (void);
46 /* Open up a raw pipe */
49 pipe_open (serial_t scb
, const char *name
)
54 struct pipe_state
*state
;
56 /* Copyright (c) 1988, 1993
57 * The Regents of the University of California. All rights reserved.
59 * This code is derived from software written by Ken Arnold and
60 * published in UNIX Review, Vol. 6, No. 8.
64 if (socketpair (AF_UNIX
, SOCK_STREAM
, 0, pdes
) < 0)
80 /* re-wire pdes[1] to stdin/stdout */
82 if (pdes
[1] != STDOUT_FILENO
)
84 dup2 (pdes
[1], STDOUT_FILENO
);
87 dup2 (STDOUT_FILENO
, STDIN_FILENO
);
89 /* close any stray FD's - FIXME - how? */
90 /* POSIX.2 B.3.2.2 "popen() shall ensure that any streams
91 from previous popen() calls that remain open in the
92 parent process are closed in the new child process. */
93 for (old
= pidlist
; old
; old
= old
->next
)
94 close (fileno (old
->fp
)); /* don't allow a flush */
96 execl ("/bin/sh", "sh", "-c", name
, NULL
);
103 state
= XMALLOC (struct pipe_state
);
108 /* If we don't do this, GDB simply exits when the remote side dies. */
109 signal (SIGPIPE
, SIG_IGN
);
115 pipe_close (serial_t scb
)
117 struct pipe_state
*state
= scb
->state
;
120 int pid
= state
->pid
;
126 /* Might be useful to check that the child does die. */
130 static struct serial_ops pipe_ops
;
133 _initialize_ser_pipe (void)
135 struct serial_ops
*ops
= XMALLOC (struct serial_ops
);
136 memset (ops
, sizeof (struct serial_ops
), 0);
139 ops
->open
= pipe_open
;
140 ops
->close
= pipe_close
;
141 ops
->readchar
= ser_unix_readchar
;
142 ops
->write
= ser_unix_write
;
143 ops
->flush_output
= ser_unix_nop_flush_output
;
144 ops
->flush_input
= ser_unix_flush_input
;
145 ops
->send_break
= ser_unix_nop_send_break
;
146 ops
->go_raw
= ser_unix_nop_raw
;
147 ops
->get_tty_state
= ser_unix_nop_get_tty_state
;
148 ops
->set_tty_state
= ser_unix_nop_set_tty_state
;
149 ops
->print_tty_state
= ser_unix_nop_print_tty_state
;
150 ops
->noflush_set_tty_state
= ser_unix_nop_noflush_set_tty_state
;
151 ops
->setbaudrate
= ser_unix_nop_setbaudrate
;
152 ops
->setstopbits
= ser_unix_nop_setstopbits
;
153 ops
->drain_output
= ser_unix_nop_drain_output
;
154 ops
->async
= ser_unix_async
;
155 serial_add_interface (ops
);