~jamesodhunt/upstart/fix-for-bug-912558-slangasek

« back to all changes in this revision

Viewing changes to init/log.c

  • Committer: James Hunt
  • Date: 2012-01-20 17:28:02 UTC
  • Revision ID: james.hunt@ubuntu.com-20120120172802-507z8dh3vmqrsxtk
Code works if early_assert enabled or all my debug garbage is removed :)

Show diffs side-by-side

added added

removed removed

Lines of Context:
805
805
 
806
806
        nih_message ("XXX: hello from log_read_watch");
807
807
 
 
808
        {
 
809
                int flags;
 
810
 
 
811
                errno = 0;
 
812
                flags = fcntl (log->io->watch->fd, F_GETFL);
 
813
                nih_message ("fd=%d, flags=%d, errno=%d\n", log->io->watch->fd, flags, errno);
 
814
        }
 
815
 
808
816
        while (1) {
809
817
                nih_debug ("%s: line %d", __func__, __LINE__);
810
818
                /* Ensure we have some space to read data from the job */
832
840
                }
833
841
        nih_debug ("%s: line %d", __func__, __LINE__);
834
842
 
835
 
                if (len < 0) {
 
843
                if (len <= 0) {
 
844
 
 
845
                        if (! (saved == EIO || saved == EBADF))
 
846
                                continue;
 
847
 
 
848
                        /* Either the job process end of the pty has
 
849
                         * been closed (EIO / EBADF), or there really
 
850
                         * is no (more) data to be read.
 
851
                         */
 
852
                        close (log->fd);
 
853
 
836
854
                        nih_debug ("%s: log: line=%d, errno=%d",
837
855
                                        __func__, __LINE__, saved);
838
 
 
839
 
                        /* Expected error caused by attempting to
840
 
                         * read from the pty after the job at
841
 
                         * the remote end has exited.
842
 
                         */
843
 
                        if (saved == EIO || saved == EBADF) {
844
 
        nih_debug ("%s: line %d", __func__, __LINE__);
845
 
                                close (log->fd);
846
 
        nih_debug ("%s: line %d", __func__, __LINE__);
847
 
                                break;
848
 
                        }
849
 
        nih_debug ("%s: line %d", __func__, __LINE__);
850
 
 
851
 
                        /* Probably EINTR/EAGAIN. Since we're using
852
 
                         * non-blocking I/O, retry.
853
 
                         */
854
 
                        continue;
855
 
                } else {
856
 
        nih_debug ("%s: line %d", __func__, __LINE__);
857
 
                        /* Nothing more to read */
858
856
                        break;
859
857
                }
860
 
        nih_debug ("%s: line %d", __func__, __LINE__);
861
858
        }
862
 
        nih_debug ("%s: line %d", __func__, __LINE__);
863
859
}