26 |
#include <argp.h> |
#include <argp.h> |
27 |
#include <hurd/fsys.h> |
#include <hurd/fsys.h> |
28 |
#include <string.h> |
#include <string.h> |
29 |
|
#include <error.h> |
30 |
|
|
31 |
#include <version.h> |
#include <version.h> |
32 |
|
|
149 |
struct trivfs_control **ourcntl, **peercntl; |
struct trivfs_control **ourcntl, **peercntl; |
150 |
mach_port_t bootstrap, right; |
mach_port_t bootstrap, right; |
151 |
struct stat st; |
struct stat st; |
152 |
|
error_t err; |
153 |
|
|
154 |
term_bucket = ports_create_bucket (); |
term_bucket = ports_create_bucket (); |
155 |
|
|
208 |
|
|
209 |
default: |
default: |
210 |
/* Should not happen. */ |
/* Should not happen. */ |
211 |
fprintf (stderr, "Unknown terminal type\n"); |
error (1, 0, "Unknown terminal type"); |
|
exit (1); |
|
212 |
} |
} |
213 |
|
|
214 |
task_get_bootstrap_port (mach_task_self (), &bootstrap); |
task_get_bootstrap_port (mach_task_self (), &bootstrap); |
215 |
|
|
216 |
if (bootstrap == MACH_PORT_NULL) |
if (bootstrap == MACH_PORT_NULL) |
217 |
{ |
error (1, 0, "Must be started as a translator"); |
|
fprintf (stderr, "Must be started as a translator\n"); |
|
|
exit (1); |
|
|
} |
|
218 |
|
|
219 |
/* Set our node. */ |
/* Set our node. */ |
220 |
errno = trivfs_startup (bootstrap, 0, |
err = trivfs_startup (bootstrap, 0, |
221 |
ourcntlclass, term_bucket, ourclass, term_bucket, |
ourcntlclass, term_bucket, ourclass, term_bucket, |
222 |
ourcntl); |
ourcntl); |
223 |
if (errno) |
if (err) |
224 |
{ |
error (1, err, "Starting translator"); |
|
perror ("Starting translator"); |
|
|
exit (1); |
|
|
} |
|
225 |
|
|
226 |
/* For ptys, the nodename depends on which half is used. For now just use |
/* For ptys, the nodename depends on which half is used. For now just use |
227 |
the hook to store the nodename. */ |
the hook to store the nodename. */ |
233 |
char *peer_name = tty_arg; |
char *peer_name = tty_arg; |
234 |
file_t file = file_name_lookup (peer_name, O_CREAT|O_NOTRANS, 0666); |
file_t file = file_name_lookup (peer_name, O_CREAT|O_NOTRANS, 0666); |
235 |
|
|
236 |
if (file != MACH_PORT_NULL) |
if (file == MACH_PORT_NULL) |
237 |
errno = 0; |
err = errno; |
238 |
|
|
239 |
if (! errno) |
if (! err) |
240 |
errno = trivfs_create_control (file, peercntlclass, term_bucket, |
err = trivfs_create_control (file, peercntlclass, term_bucket, |
241 |
peerclass, term_bucket, peercntl); |
peerclass, term_bucket, peercntl); |
242 |
if (! errno) |
if (! err) |
243 |
{ |
{ |
244 |
right = ports_get_send_right (*peercntl); |
right = ports_get_send_right (*peercntl); |
245 |
errno = file_set_translator (file, 0, FS_TRANS_EXCL | FS_TRANS_SET, |
err = file_set_translator (file, 0, FS_TRANS_EXCL | FS_TRANS_SET, |
246 |
0, 0, 0, right, MACH_MSG_TYPE_COPY_SEND); |
0, 0, 0, right, MACH_MSG_TYPE_COPY_SEND); |
247 |
mach_port_deallocate (mach_task_self (), right); |
mach_port_deallocate (mach_task_self (), right); |
248 |
} |
} |
249 |
|
|
250 |
if (errno) |
if (err) |
251 |
{ |
error (1, err, peer_name); |
|
perror (peer_name); |
|
|
exit (1); |
|
|
} |
|
252 |
|
|
253 |
(*peercntl)->hook = peer_name; |
(*peercntl)->hook = peer_name; |
254 |
ports_port_deref (*peercntl); |
ports_port_deref (*peercntl); |
259 |
mutex_init (&global_lock); |
mutex_init (&global_lock); |
260 |
|
|
261 |
/* Initialize status from underlying node. */ |
/* Initialize status from underlying node. */ |
262 |
errno = io_stat ((*ourcntl)->underlying, &st); |
err = io_stat ((*ourcntl)->underlying, &st); |
263 |
if (errno) |
if (err) |
264 |
{ |
{ |
265 |
/* We cannot stat the underlying node. Fallback to the defaults. */ |
/* We cannot stat the underlying node. Fallback to the defaults. */ |
266 |
term_owner = term_group = 0; |
term_owner = term_group = 0; |
267 |
term_mode = (bottom == &ptyio_bottom ? DEFFILEMODE : S_IRUSR | S_IWUSR); |
term_mode = (bottom == &ptyio_bottom ? DEFFILEMODE : S_IRUSR | S_IWUSR); |
|
errno = 0; |
|
268 |
} |
} |
269 |
else |
else |
270 |
{ |
{ |
280 |
|
|
281 |
outputq = create_queue (256, QUEUE_LOWAT, QUEUE_HIWAT); |
outputq = create_queue (256, QUEUE_LOWAT, QUEUE_HIWAT); |
282 |
|
|
283 |
errno = (*bottom->init) (); |
err = (*bottom->init) (); |
284 |
if (errno) |
if (err) |
285 |
{ |
error (1, err, "Initializing bottom handler"); |
|
perror ("Initializing bottom handler"); |
|
|
exit (1); |
|
|
} |
|
286 |
|
|
287 |
condition_init (&carrier_alert); |
condition_init (&carrier_alert); |
288 |
condition_init (&select_alert); |
condition_init (&select_alert); |