annotate lib/pty.c @ 855:30eaf54a63f7

2006-11-16 Brian Masney <masneyb@gftp.org> * lib/protocols.c (gftp_get_all_subdirs) - don't return if there was a problem running gftp_stat_filename(). Only return if there was a fatal error. (closes #314929)
author masneyb
date Fri, 17 Nov 2006 03:04:57 +0000
parents 1e07981f7511
children 1808cebed602
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
1 /*****************************************************************************/
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
2 /* pty.c - general purpose routines */
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
3 /* Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org> */
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
4 /* */
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
5 /* This program is free software; you can redistribute it and/or modify */
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
6 /* it under the terms of the GNU General Public License as published by */
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
7 /* the Free Software Foundation; either version 2 of the License, or */
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
8 /* (at your option) any later version. */
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
9 /* */
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
10 /* This program is distributed in the hope that it will be useful, */
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
13 /* GNU General Public License for more details. */
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
14 /* */
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
15 /* You should have received a copy of the GNU General Public License */
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
16 /* along with this program; if not, write to the Free Software */
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
18 /*****************************************************************************/
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
19
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 515
diff changeset
20 #include "gftp.h"
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
21 static const char cvsid[] = "$Id$";
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
22
179
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 178
diff changeset
23 #ifdef __sgi
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
24
179
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 178
diff changeset
25 char *
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
26 gftp_get_pty_impl (void)
179
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 178
diff changeset
27 {
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 178
diff changeset
28 return ("sgi");
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 178
diff changeset
29 }
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 178
diff changeset
30
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
31
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
32 static int
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
33 _gftp_ptym_open (char *pts_name, size_t len, int *fds)
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
34 {
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
35 char *new_pts_name;
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
36 int fdm;
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
37
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
38 if ((new_pts_name = _getpty (&fdm, O_RDWR, 0600, 0)) == NULL)
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
39 return (GFTP_ERETRYABLE);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
40
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
41 strncpy (pts_name, new_pts_name, len);
249
094e83b55cb1 2003-8-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 235
diff changeset
42 pts_name[len - 1] = '\0';
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
43
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
44 return (fdm);
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
45 }
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
46
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
47
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
48 static int
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
49 _gftp_ptys_open (int fdm, int fds, char *pts_name)
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
50 {
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
51 int new_fds;
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
52
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
53 if ((new_fds = open (pts_name, O_RDWR)) < 0)
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
54 {
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
55 close (fdm);
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
56 return (-1);
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
57 }
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
58
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
59 return (new_fds);
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
60 }
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
61
178
8beb7bfca92b 2003-6-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 146
diff changeset
62 #elif HAVE_GRANTPT
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
63
738
4029ab7f13e4 2006-5-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 629
diff changeset
64 #if !(defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__))
235
1638e32e6a35 2003-7-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 232
diff changeset
65 #include <stropts.h>
629
1504cfdd5d55 2004-11-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 541
diff changeset
66 #endif
235
1638e32e6a35 2003-7-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 232
diff changeset
67
179
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 178
diff changeset
68 char *
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
69 gftp_get_pty_impl (void)
179
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 178
diff changeset
70 {
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 178
diff changeset
71 return ("unix98");
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 178
diff changeset
72 }
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 178
diff changeset
73
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 178
diff changeset
74
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
75 static int
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
76 _gftp_ptym_open (char *pts_name, size_t len, int *fds)
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
77 {
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
78 char *new_pts_name;
740
6968041e4b82 2006-5-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 738
diff changeset
79 void (*savesig)();
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
80 int fdm;
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
81
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
82 if ((fdm = open ("/dev/ptmx", O_RDWR)) < 0)
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
83 return (GFTP_ERETRYABLE);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
84
740
6968041e4b82 2006-5-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 738
diff changeset
85 savesig = signal (SIGCHLD, SIG_DFL);
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
86 if (grantpt (fdm) < 0)
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
87 {
740
6968041e4b82 2006-5-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 738
diff changeset
88 signal(SIGCHLD, savesig);
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
89 close (fdm);
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
90 return (GFTP_ERETRYABLE);
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
91 }
740
6968041e4b82 2006-5-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 738
diff changeset
92 signal (SIGCHLD, savesig);
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
93
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
94 if (unlockpt (fdm) < 0)
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
95 {
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
96 close (fdm);
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
97 return (GFTP_ERETRYABLE);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
98 }
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
99
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
100 if ((new_pts_name = ptsname (fdm)) == NULL)
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
101 {
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
102 close (fdm);
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
103 return (GFTP_ERETRYABLE);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
104 }
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
105
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
106 strncpy (pts_name, new_pts_name, len);
249
094e83b55cb1 2003-8-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 235
diff changeset
107 pts_name[len - 1] = '\0';
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
108
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
109 return (fdm);
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
110 }
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
111
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
112
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
113 static int
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
114 _gftp_ptys_open (int fdm, int fds, char *pts_name)
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
115 {
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
116 int new_fds;
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
117
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
118 if ((new_fds = open (pts_name, O_RDWR)) < 0)
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
119 {
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
120 close (fdm);
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
121 return (-1);
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
122 }
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
123
756
1e07981f7511 2006-6-22 Brian Masney <masneyb@gftp.org>
masneyb
parents: 740
diff changeset
124 #if defined(SYSV) || defined (hpux)
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
125 /* I intentionally ignore these errors */
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
126 ioctl (new_fds, I_PUSH, "ptem");
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
127 ioctl (new_fds, I_PUSH, "ldterm");
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
128 ioctl (new_fds, I_PUSH, "ttcompat");
179
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 178
diff changeset
129 #endif
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
130
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
131 return (new_fds);
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
132 }
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
133
515
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
134 #elif HAVE_OPENPTY
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
135
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
136 #ifdef HAVE_PTY_H
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
137 #include <pty.h>
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
138 #include <utmp.h> /* for login_tty */
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
139 #elif HAVE_LIBUTIL_H
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
140 #include <libutil.h>
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
141 #include <utmp.h> /* for login_tty */
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
142 #else
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
143 extern int openpty(int *amaster, int *aslave, char *name, struct termios *termp, struct winsize * winp);
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
144 extern int login_tty(int fd);
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
145 #endif
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
146
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
147 char *
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
148 gftp_get_pty_impl (void)
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
149 {
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
150 return ("openpty");
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
151 }
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
152
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
153
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
154 static int
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
155 _gftp_ptym_open (char *pts_name, size_t len, int *fds)
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
156 {
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
157 int fdm;
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
158
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
159 if (openpty (&fdm, fds, pts_name, NULL, NULL) < 0)
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
160 return (GFTP_ERETRYABLE);
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
161
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
162 ioctl (*fds, TIOCSCTTY, NULL);
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
163
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
164 return (fdm);
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
165 }
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
166
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
167
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
168 static int
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
169 _gftp_ptys_open (int fdm, int fds, char *pts_name)
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
170 {
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
171 if (login_tty (fds) < 0)
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
172 return (GFTP_EFATAL);
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
173
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
174 return (fds);
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
175 }
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
176
cb78cf311d23 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
177 #else
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
178
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
179 /* Fall back to *BSD... */
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
180
179
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 178
diff changeset
181 char *
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
182 gftp_get_pty_impl (void)
179
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 178
diff changeset
183 {
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 178
diff changeset
184 return ("bsd");
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 178
diff changeset
185 }
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 178
diff changeset
186
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 178
diff changeset
187
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
188 static int
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
189 _gftp_ptym_open (char *pts_name, size_t len, int *fds)
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
190 {
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
191 char *pos1, *pos2;
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
192 int fdm;
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
193
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
194 g_return_val_if_fail (len >= 10, GFTP_EFATAL);
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
195
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
196 strncpy (pts_name, "/dev/ptyXY", len);
249
094e83b55cb1 2003-8-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 235
diff changeset
197 pts_name[len - 1] = '\0';
094e83b55cb1 2003-8-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 235
diff changeset
198
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
199 for (pos1 = "pqrstuvwxyzPQRST"; *pos1 != '\0'; pos1++)
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
200 {
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
201 pts_name[8] = *pos1;
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
202 for (pos2 = "0123456789abcdef"; *pos2 != '\0'; pos2++)
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
203 {
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
204 pts_name[9] = *pos2;
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
205 if ((fdm = open (pts_name, O_RDWR)) < 0)
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
206 continue;
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
207
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
208 pts_name[5] = 't';
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
209 chmod (pts_name, S_IRUSR | S_IWUSR);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
210 chown (pts_name, getuid (), -1);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
211
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
212 return (fdm);
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
213 }
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
214 }
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
215
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
216 return (GFTP_ERETRYABLE);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
217 }
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
218
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
219
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
220 static int
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
221 _gftp_ptys_open (int fdm, int fds, char *pts_name)
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
222 {
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
223 int new_fds;
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
224
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
225 if ((new_fds = open (pts_name, O_RDWR)) < 0)
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
226 {
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
227 close (fdm);
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
228 return (-1);
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
229 }
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
230
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
231 #if defined(TIOCSCTTY) && !defined(CIBAUD)
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
232 ioctl (new_fds, TIOCSCTTY, NULL);
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
233 #endif
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
234
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
235 return (new_fds);
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
236 }
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
237
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
238 #endif /* __sgi */
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
239
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
240
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
241 static int
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
242 _gftp_tty_raw (int fd)
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
243 {
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
244 struct termios buf;
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
245
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
246 if (tcgetattr (fd, &buf) < 0)
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
247 return (-1);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
248
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
249 buf.c_iflag |= IGNPAR;
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
250 buf.c_iflag &= ~(ICRNL | ISTRIP | IXON | IGNCR | IXANY | IXOFF | INLCR);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
251 buf.c_lflag &= ~(ECHO | ICANON | ISIG | ECHOE | ECHOK | ECHONL);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
252 #ifdef IEXTEN
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
253 buf.c_lflag &= ~(IEXTEN);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
254 #endif
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
255
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
256 buf.c_oflag &= ~(OPOST);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
257 buf.c_cc[VMIN] = 1;
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
258 buf.c_cc[VTIME] = 0;
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
259
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
260 if (tcsetattr (fd, TCSADRAIN, &buf) < 0)
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
261 return (-1);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
262 return (0);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
263 }
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
264
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
265
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
266 static void
458
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
267 _gftp_close_all_fds (int ptysfd)
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
268 {
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
269 int i, maxfds;
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
270
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
271 #ifdef HAVE_GETDTABLESIZE
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
272 maxfds = getdtablesize () - 1;
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
273 #elif defined (OPEN_MAX)
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
274 maxfds = OPEN_MAX;
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
275 #else
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
276 maxfds = -1;
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
277 #endif
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
278
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
279 for (i=3; i<maxfds; i++)
458
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
280 {
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
281 if (i == ptysfd)
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
282 continue;
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
283
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
284 close (i);
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
285 }
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
286 }
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
287
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
288
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
289 pid_t
458
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
290 gftp_exec (gftp_request * request, int *fdm, int *ptymfd, char **args)
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
291 {
458
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
292 char pts_name[64];
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
293 pid_t child;
458
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
294 int ptysfd;
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
295 int s[2];
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
296
458
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
297 *pts_name = '\0';
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
298 if ((*ptymfd = _gftp_ptym_open (pts_name, sizeof (pts_name), &ptysfd)) < 0)
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
299 {
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
300 request->logging_function (gftp_logging_error, request->user_data,
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
301 _("Cannot open master pty %s: %s\n"), pts_name,
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
302 g_strerror (errno));
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
303 return (-1);
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
304 }
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
305
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
306 if (socketpair (AF_LOCAL, SOCK_STREAM, 0, s) < 0)
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
307 {
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
308 request->logging_function (gftp_logging_error, request,
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
309 _("Cannot create a socket pair: %s\n"),
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
310 g_strerror (errno));
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
311 return (-1);
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
312 }
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
313
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
314 if ((child = fork ()) == 0)
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
315 {
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
316 setsid ();
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
317
458
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
318 if ((ptysfd = _gftp_ptys_open (*ptymfd, ptysfd, pts_name)) < 0)
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
319 {
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
320 printf ("Cannot open slave pts %s: %s\n", pts_name,
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
321 g_strerror (errno));
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
322 return (-1);
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
323 }
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
324
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
325 close (s[0]);
458
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
326 close (*ptymfd);
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
327
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
328 _gftp_tty_raw (s[1]);
458
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
329 _gftp_tty_raw (ptysfd);
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
330
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
331 dup2 (s[1], 0);
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
332 dup2 (s[1], 1);
541
e46278e7ef1d 2004-8-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 526
diff changeset
333 dup2 (ptysfd, 2);
458
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
334 _gftp_close_all_fds (ptysfd);
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
335
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
336 execvp (args[0], args);
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
337
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
338 printf (_("Error: Cannot execute ssh: %s\n"), g_strerror (errno));
458
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
339 _exit (1);
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
340 }
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
341 else if (child > 0)
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
342 {
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
343 close (s[1]);
458
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
344
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
345 *fdm = s[0];
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
346 _gftp_tty_raw (s[0]);
458
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
347 _gftp_tty_raw (*ptymfd);
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
348
210
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
349 return (child);
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
350 }
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
351 else
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
352 {
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
353 request->logging_function (gftp_logging_error, request->user_data,
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
354 _("Cannot fork another process: %s\n"),
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
355 g_strerror (errno));
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
356 return (-1);
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
357 }
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
358 }
82ebd1b05345 2003-7-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
359