ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/init.C
(Generate patch)

Comparing rxvt-unicode/src/init.C (file contents):
Revision 1.143 by root, Mon Jan 16 15:00:20 2006 UTC vs.
Revision 1.146 by root, Tue Jan 17 15:17:39 2006 UTC

1370rxvt_term::run_command (const char *const *argv) 1370rxvt_term::run_command (const char *const *argv)
1371{ 1371{
1372#if ENABLE_FRILLS 1372#if ENABLE_FRILLS
1373 if (rs[Rs_pty_fd]) 1373 if (rs[Rs_pty_fd])
1374 { 1374 {
1375 pty.pty = atoi (rs[Rs_pty_fd]); 1375 pty->pty = atoi (rs[Rs_pty_fd]);
1376 1376
1377 if (pty.pty >= 0) 1377 if (pty->pty >= 0)
1378 { 1378 {
1379 if (getfd_hook) 1379 if (getfd_hook)
1380 pty.pty = (*getfd_hook) (pty.pty); 1380 pty->pty = (*getfd_hook) (pty->pty);
1381 1381
1382 if (pty.pty < 0 || fcntl (pty.pty, F_SETFL, O_NONBLOCK)) 1382 if (pty->pty < 0 || fcntl (pty->pty, F_SETFL, O_NONBLOCK))
1383 rxvt_fatal ("unusable pty-fd filehandle, aborting.\n"); 1383 rxvt_fatal ("unusable pty-fd filehandle, aborting.\n");
1384 } 1384 }
1385 } 1385 }
1386 else 1386 else
1387#endif 1387#endif
1388 if (!pty.get ()) 1388 if (!pty->get ())
1389 rxvt_fatal ("can't initialize pseudo-tty, aborting.\n"); 1389 rxvt_fatal ("can't initialize pseudo-tty, aborting.\n");
1390 1390
1391 pty.set_utf8_mode (enc_utf8); 1391 pty->set_utf8_mode (enc_utf8);
1392 1392
1393 /* set initial window size */ 1393 /* set initial window size */
1394 tt_winch (); 1394 tt_winch ();
1395 1395
1396 int er; 1396 int er;
1409#if ENABLE_FRILLS 1409#if ENABLE_FRILLS
1410 if (rs[Rs_pty_fd]) 1410 if (rs[Rs_pty_fd])
1411 return; 1411 return;
1412#endif 1412#endif
1413 1413
1414#ifndef __QNX__
1415 /* spin off the command interpreter */ 1414 /* spin off the command interpreter */
1416 switch (cmd_pid = fork ()) 1415 switch (cmd_pid = fork ())
1417 { 1416 {
1418 case -1: 1417 case -1:
1419 { 1418 {
1421 rxvt_fatal ("can't fork, aborting.\n"); 1420 rxvt_fatal ("can't fork, aborting.\n");
1422 } 1421 }
1423 case 0: 1422 case 0:
1424 init_env (); 1423 init_env ();
1425 1424
1426 if (!pty.make_controlling_tty ()) 1425 if (!pty->make_controlling_tty ())
1427 fprintf (stderr, "%s: could not obtain control of tty.", RESNAME); 1426 fprintf (stderr, "%s: could not obtain control of tty.", RESNAME);
1428 else 1427 else
1429 { 1428 {
1430 /* Reopen stdin, stdout and stderr over the tty file descriptor */ 1429 /* Reopen stdin, stdout and stderr over the tty file descriptor */
1431 dup2 (pty.tty, STDIN_FILENO); 1430 dup2 (pty->tty, STDIN_FILENO);
1432 dup2 (pty.tty, STDOUT_FILENO); 1431 dup2 (pty->tty, STDOUT_FILENO);
1433 dup2 (pty.tty, STDERR_FILENO); 1432 dup2 (pty->tty, STDERR_FILENO);
1434 1433
1435 // close all our file handles that we do no longer need 1434 // close all our file handles that we do no longer need
1436 for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) 1435 for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++)
1437 { 1436 {
1438 if ((*t)->pty.pty > 2) close ((*t)->pty.pty); 1437 if ((*t)->pty->pty > 2) close ((*t)->pty->pty);
1439 if ((*t)->pty.tty > 2) close ((*t)->pty.tty); 1438 if ((*t)->pty->tty > 2) close ((*t)->pty->tty);
1440 } 1439 }
1441 1440
1442 run_child (argv); 1441 run_child (argv);
1443 fprintf (stderr, "%s: unable to exec child.", RESNAME); 1442 fprintf (stderr, "%s: unable to exec child.", RESNAME);
1444 } 1443 }
1445 1444
1446 _exit (EXIT_FAILURE); 1445 _exit (EXIT_FAILURE);
1447 1446
1448 default: 1447 default:
1449 { 1448 if (!OPTION (Opt_utmpInhibit))
1450#if defined(HAVE_STRUCT_UTMP) && defined(HAVE_TTYSLOT) 1449 pty->login (cmd_pid, OPTION (Opt_loginShell), rs[Rs_display_name]);
1451 int fdstdin;
1452 1450
1453 fdstdin = dup (STDIN_FILENO); 1451 pty->close_tty ();
1454 dup2 (pty.tty, STDIN_FILENO);
1455#endif
1456
1457#ifdef UTMP_SUPPORT
1458 privileged_utmp (SAVE);
1459#endif
1460
1461#if defined(HAVE_STRUCT_UTMP) && defined(HAVE_TTYSLOT)
1462
1463 dup2 (fdstdin, STDIN_FILENO);
1464 close (fdstdin);
1465#endif
1466 }
1467
1468 pty.close_tty (); /* keep STDERR_FILENO, pty.pty, display->fd () open */
1469 break; 1452 break;
1470 } 1453 }
1471#else /* __QNX__ uses qnxspawn () */
1472 fchmod (pty.tty, 0622);
1473 fcntl (pty.tty, F_SETFD, FD_CLOEXEC);
1474 fcntl (pty.pty, F_SETFD, FD_CLOEXEC);
1475
1476 if (run_child (argv) == -1)
1477 exit (EXIT_FAILURE);
1478#endif
1479} 1454}
1480 1455
1481/* ------------------------------------------------------------------------- * 1456/* ------------------------------------------------------------------------- *
1482 * CHILD PROCESS OPERATIONS * 1457 * CHILD PROCESS OPERATIONS *
1483 * ------------------------------------------------------------------------- */ 1458 * ------------------------------------------------------------------------- */
1527 // unblock signals (signals are blocked by iom.C 1502 // unblock signals (signals are blocked by iom.C
1528 sigset_t ss; 1503 sigset_t ss;
1529 sigemptyset (&ss); 1504 sigemptyset (&ss);
1530 sigprocmask (SIG_SETMASK, &ss, 0); 1505 sigprocmask (SIG_SETMASK, &ss, 0);
1531 1506
1532#ifndef __QNX__
1533 /* command interpreter path */ 1507 /* command interpreter path */
1534 if (argv != NULL) 1508 if (argv != NULL)
1535 { 1509 {
1536# ifdef DEBUG_CMD 1510# ifdef DEBUG_CMD
1537 int i; 1511 int i;
1563 1537
1564 execlp (shell, argv0, NULL); 1538 execlp (shell, argv0, NULL);
1565 /* no error message: STDERR is closed! */ 1539 /* no error message: STDERR is closed! */
1566 } 1540 }
1567 1541
1568#else /* __QNX__ uses qnxspawn () */
1569
1570 char iov_a[10] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
1571 char *command = NULL, fullcommand[_MAX_PATH];
1572 char **arg_v, *arg_a[2] = { NULL, NULL };
1573
1574 if (argv != NULL)
1575 {
1576 if (access (argv[0], X_OK) == -1)
1577 {
1578 if (strchr (argv[0], '/') == NULL)
1579 {
1580 searchenv (argv[0], "PATH", fullcommand);
1581
1582 if (fullcommand[0] != '\0')
1583 command = fullcommand;
1584 }
1585
1586 if (access (command, X_OK) == -1)
1587 return -1;
1588 }
1589 else
1590 command = argv[0];
1591
1592 arg_v = argv;
1593 }
1594 else
1595 {
1596 if ((command = getenv ("SHELL")) == NULL || *command == '\0')
1597 command = "/bin/sh";
1598
1599 arg_a[0] = my_basename (command);
1600
1601 if (OPTION (Opt_loginShell))
1602 {
1603 login = rxvt_malloc ((strlen (arg_a[0]) + 2) * sizeof (char));
1604
1605 login[0] = '-';
1606 strcpy (&login[1], arg_a[0]);
1607 arg_a[0] = login;
1608 }
1609
1610 arg_v = arg_a;
1611 }
1612
1613 iov_a[0] = iov_a[1] = iov_a[2] = pty.tty;
1614 cmd_pid = qnx_spawn (0, 0, 0, -1, -1,
1615 _SPAWN_SETSID | _SPAWN_TCSETPGRP,
1616 command, arg_v, environ, iov_a, 0);
1617 if (login)
1618 free (login);
1619
1620 pty.close_tty ();
1621 return pty.pty;
1622#endif
1623
1624 return -1; 1542 return -1;
1625} 1543}
1626 1544
1627/*----------------------- end-of-file (C source) -----------------------*/ 1545/*----------------------- end-of-file (C source) -----------------------*/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines