| 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 |
| 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); |