libpurple/protocols/zephyr/zephyr.c

branch
vv
changeset 26178
2081d31d5466
parent 26171
85b43bce42f1
parent 25105
fe13c190ca13
child 26337
ec2fc1bc9024
equal deleted inserted replaced
26177:35f25555116f 26178:2081d31d5466
62 62
63 typedef enum { 63 typedef enum {
64 PURPLE_ZEPHYR_NONE, /* Non-kerberized ZEPH0.2 */ 64 PURPLE_ZEPHYR_NONE, /* Non-kerberized ZEPH0.2 */
65 PURPLE_ZEPHYR_KRB4, /* ZEPH0.2 w/ KRB4 support */ 65 PURPLE_ZEPHYR_KRB4, /* ZEPH0.2 w/ KRB4 support */
66 PURPLE_ZEPHYR_TZC, /* tzc executable proxy */ 66 PURPLE_ZEPHYR_TZC, /* tzc executable proxy */
67 PURPLE_ZEPHYR_INTERGALACTIC_KRB4, /* Kerberized ZEPH0.3 */ 67 PURPLE_ZEPHYR_INTERGALACTIC_KRB4 /* Kerberized ZEPH0.3 */
68 } zephyr_connection_type; 68 } zephyr_connection_type;
69 69
70 struct _zephyr_account { 70 struct _zephyr_account {
71 PurpleAccount* account; 71 PurpleAccount* account;
72 char *username; 72 char *username;
1605 if (pid == 0) { 1605 if (pid == 0) {
1606 unsigned int i=0; 1606 unsigned int i=0;
1607 gboolean found_ps = FALSE; 1607 gboolean found_ps = FALSE;
1608 gchar ** tzc_cmd_array = g_strsplit(purple_account_get_string(gc->account,"tzc_command","/usr/bin/tzc -e %s")," ",0); 1608 gchar ** tzc_cmd_array = g_strsplit(purple_account_get_string(gc->account,"tzc_command","/usr/bin/tzc -e %s")," ",0);
1609 if (close(1) == -1) { 1609 if (close(1) == -1) {
1610 purple_debug_error("zephyr", "stdout couldn't be closed. dying\n");
1611 exit(-1); 1610 exit(-1);
1612 } 1611 }
1613 if (dup2(zephyr->fromtzc[1], 1) == -1) { 1612 if (dup2(zephyr->fromtzc[1], 1) == -1) {
1614 purple_debug_error("zephyr", "dup2 of stdout failed \n");
1615 exit(-1); 1613 exit(-1);
1616 } 1614 }
1617 if (close(zephyr->fromtzc[1]) == -1) { 1615 if (close(zephyr->fromtzc[1]) == -1) {
1618 purple_debug_error("zephyr", "closing of piped stdout failed\n");
1619 exit(-1); 1616 exit(-1);
1620 } 1617 }
1621 if (close(0) == -1) { 1618 if (close(0) == -1) {
1622 purple_debug_error("zephyr", "stdin couldn't be closed. dying\n");
1623 exit(-1); 1619 exit(-1);
1624 } 1620 }
1625 if (dup2(zephyr->totzc[0], 0) == -1) { 1621 if (dup2(zephyr->totzc[0], 0) == -1) {
1626 purple_debug_error("zephyr", "dup2 of stdin failed \n");
1627 exit(-1); 1622 exit(-1);
1628 } 1623 }
1629 if (close(zephyr->totzc[0]) == -1) { 1624 if (close(zephyr->totzc[0]) == -1) {
1630 purple_debug_error("zephyr", "closing of piped stdin failed\n");
1631 exit(-1); 1625 exit(-1);
1632 } 1626 }
1633 /* tzc_command should really be of the form 1627 /* tzc_command should really be of the form
1634 path/to/tzc -e %s 1628 path/to/tzc -e %s
1635 or 1629 or
1649 } 1643 }
1650 i++; 1644 i++;
1651 } 1645 }
1652 1646
1653 if (!found_ps) { 1647 if (!found_ps) {
1654 purple_connection_error(gc,"Tzc command needs %s to set the exposure\n"); 1648 exit(-1);
1655 return;
1656 } 1649 }
1657 1650
1658 execvp(tzc_cmd_array[0], tzc_cmd_array); 1651 execvp(tzc_cmd_array[0], tzc_cmd_array);
1652 exit(-1);
1659 } 1653 }
1660 else { 1654 else {
1661 fd_set rfds; 1655 fd_set rfds;
1662 int bufsize = 2048; 1656 int bufsize = 2048;
1663 char *buf = (char *)calloc(bufsize, 1); 1657 char *buf = (char *)calloc(bufsize, 1);
1665 struct timeval tv; 1659 struct timeval tv;
1666 char *ptr; 1660 char *ptr;
1667 int parenlevel=0; 1661 int parenlevel=0;
1668 char* tempstr; 1662 char* tempstr;
1669 int tempstridx; 1663 int tempstridx;
1664 int select_status;
1670 1665
1671 zephyr->tzc_pid = pid; 1666 zephyr->tzc_pid = pid;
1672 /* wait till we have data to read from ssh */ 1667 /* wait till we have data to read from ssh */
1673 FD_ZERO(&rfds); 1668 FD_ZERO(&rfds);
1674 FD_SET(zephyr->fromtzc[ZEPHYR_FD_READ], &rfds); 1669 FD_SET(zephyr->fromtzc[ZEPHYR_FD_READ], &rfds);
1676 tv.tv_sec = 10; 1671 tv.tv_sec = 10;
1677 tv.tv_usec = 0; 1672 tv.tv_usec = 0;
1678 1673
1679 purple_debug_info("zephyr", "about to read from tzc\n"); 1674 purple_debug_info("zephyr", "about to read from tzc\n");
1680 1675
1681 select(zephyr->fromtzc[ZEPHYR_FD_READ] + 1, &rfds, NULL, NULL, NULL); 1676 if (waitpid(pid, NULL, WNOHANG) == 0) { /* Only select if tzc is still running */
1677 purple_debug_info("zephyr", "about to read from tzc\n");
1678 select_status = select(zephyr->fromtzc[ZEPHYR_FD_READ] + 1, &rfds, NULL, NULL, NULL);
1679 }
1680 else {
1681 purple_debug_info("zephyr", "tzc exited early\n");
1682 select_status = -1;
1683 }
1682 1684
1683 FD_ZERO(&rfds); 1685 FD_ZERO(&rfds);
1684 FD_SET(zephyr->fromtzc[ZEPHYR_FD_READ], &rfds); 1686 FD_SET(zephyr->fromtzc[ZEPHYR_FD_READ], &rfds);
1685 while (select(zephyr->fromtzc[ZEPHYR_FD_READ] + 1, &rfds, NULL, NULL, &tv)) { 1687 while (select_status > 0 &&
1688 select(zephyr->fromtzc[ZEPHYR_FD_READ] + 1, &rfds, NULL, NULL, &tv) > 0) {
1686 read(zephyr->fromtzc[ZEPHYR_FD_READ], bufcur, 1); 1689 read(zephyr->fromtzc[ZEPHYR_FD_READ], bufcur, 1);
1687 bufcur++; 1690 bufcur++;
1688 if ((bufcur - buf) > (bufsize - 1)) { 1691 if ((bufcur - buf) > (bufsize - 1)) {
1689 if ((buf = realloc(buf, bufsize * 2)) == NULL) { 1692 if ((buf = realloc(buf, bufsize * 2)) == NULL) {
1690 exit(-1); 1693 exit(-1);

mercurial