+ struct pollfd pollfd;
+ int num_rdy;
+ int num_hup = 0;
+
+
+ /* Read the output from the child terminal before the prompt. If no data in
+ * 200 ms, we stop reading to give the password */
+ g_info("Reading from child console...");
+ while(1) {
+ pollfd.fd = fdpty;
+ pollfd.events = POLLIN|POLLPRI;
+
+ num_rdy = poll(&pollfd, 1, 200);
+#if 0
+ if(num_rdy == -1) {
+ perror("Poll error");
+ goto wait_child;
+ }
+#endif //0
+
+ /* Timeout : stop waiting for chars */
+ if(num_rdy == 0) break;
+
+ switch(pollfd.revents) {
+ case POLLERR:
+ g_warning("Error returned in polling fd\n");
+ num_hup++;
+ break;
+ case POLLHUP:
+ g_info("Polling FD : hung up.");
+ num_hup++;
+ break;
+ case POLLNVAL:
+ g_warning("Polling fd tells it is not open");
+ num_hup++;
+ break;
+ case POLLPRI:
+ case POLLIN:
+ count = read (fdpty, buf, 256);
+ if(count > 0) {
+ buf[count] = '\0';
+ printf("%s", buf);
+ } else if(count == -1) {
+ perror("Error in read");
+ goto wait_child;
+ }
+ break;
+ }
+ if(num_hup > 0) {
+ g_warning("Child hung up too fast");
+ goto wait_child;
+ }
+ }
+
+ /* Write the password */