Hi

On Wed, Nov 27, 2013 at 11:39 PM, Lennart Poettering
<lenn...@poettering.net> wrote:
> On Wed, 27.11.13 19:48, David Herrmann (dh.herrm...@gmail.com) wrote:
>
>> +
>> +pid_t pty_new(unsigned short term_width, unsigned short term_height, 
>> Terminal *t, Pty **out) {
>> +        Pty *pty;
>> +        pid_t pid;
>> +        int fd, comm[2], slave, r;
>> +        char d;
>> +
>> +        pty = calloc(1, sizeof(*pty));
>> +        if (!pty)
>> +                return -ENOMEM;
>> +
>> +        fd = posix_openpt(O_RDWR | O_NOCTTY | O_CLOEXEC | O_NONBLOCK);
>> +        if (fd < 0) {
>> +                free(pty);
>> +                return -errno;
>> +        }
>> +
>> +        r = sd_event_add_io(t->m->event,
>> +                            fd,
>> +                            EPOLLHUP | EPOLLERR | EPOLLIN | EPOLLOUT | 
>> EPOLLET,
>> +                            pty_io_fn,
>> +                            pty,
>> +                            &pty->fd_source);
>> +        if (r < 0) {
>> +                close(fd);
>> +                free(pty);
>> +                return r;
>> +        }
>> +
>> +        r = sd_event_add_defer(t->m->event, pty_idle_fn, pty, 
>> &pty->idle_source);
>> +        if (r < 0) {
>> +                sd_event_source_set_enabled(pty->fd_source, SD_EVENT_OFF);
>> +                sd_event_source_unref(pty->fd_source);
>> +                close(fd);
>> +                free(pty);
>> +                return r;
>> +        }
>> +
>> +        r = pipe2(comm, O_CLOEXEC);
>> +        if (r < 0) {
>> +                r = -errno;
>> +                sd_event_source_set_enabled(pty->idle_source, SD_EVENT_OFF);
>> +                sd_event_source_unref(pty->idle_source);
>> +                sd_event_source_set_enabled(pty->fd_source, SD_EVENT_OFF);
>> +                sd_event_source_unref(pty->fd_source);
>> +                close(fd);
>> +                free(pty);
>> +                return r;
>> +        }
>> +
>> +        pid = fork();
>> +        if (pid < 0) {
>> +                /* error */
>> +                pid = -errno;
>> +                close(comm[0]);
>> +                close(comm[1]);
>> +                sd_event_source_set_enabled(pty->idle_source, SD_EVENT_OFF);
>> +                sd_event_source_unref(pty->idle_source);
>> +                sd_event_source_set_enabled(pty->fd_source, SD_EVENT_OFF);
>> +                sd_event_source_unref(pty->fd_source);
>> +                close(fd);
>> +                free(pty);
>> +                return pid;
>
> Grr. Just define a label to jump to to clean everything up that is
> initialized, and skip over the bits that isn't. Duplicating the
> destruction logic on every if block is just wrong...

Closed-source developers get paid by number of lines, why don't get
open-source developers honored by number of lines? I would excel in
that category!

Fixed.

Thanks
David
_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to