Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4a679454 authored by Tom Cherry's avatar Tom Cherry
Browse files

init: cleanup exit() uses

Primarily, this fixes a bug where a forked child of property service
uses exit() instead of _exit, which has the unintended consequences of
running the global destructors of init proper, which leads to
unintended cleanup.

Secondly, this replaces the remaining calls of exit() that really
should be LOG(FATAL).

Test: boot sailfish
Change-Id: I779228e7d44a73186bc7685bb723c4b9278a0a2d
parent f5dba110
Loading
Loading
Loading
Loading
+1 −2
Original line number Original line Diff line number Diff line
@@ -569,8 +569,7 @@ int main(int argc, char** argv) {


    epoll_fd = epoll_create1(EPOLL_CLOEXEC);
    epoll_fd = epoll_create1(EPOLL_CLOEXEC);
    if (epoll_fd == -1) {
    if (epoll_fd == -1) {
        PLOG(ERROR) << "epoll_create1 failed";
        PLOG(FATAL) << "epoll_create1 failed";
        exit(1);
    }
    }


    sigchld_handler_init();
    sigchld_handler_init();
+3 −5
Original line number Original line Diff line number Diff line
@@ -73,8 +73,7 @@ static struct selabel_handle* sehandle_prop;


void property_init() {
void property_init() {
    if (__system_property_area_init()) {
    if (__system_property_area_init()) {
        LOG(ERROR) << "Failed to initialize property area";
        LOG(FATAL) << "Failed to initialize property area";
        exit(1);
    }
    }
}
}


@@ -216,7 +215,7 @@ static void PropertyChildLaunch() {
            LOG(ERROR) << "property_set_async(\"" << info.name << "\", \"" << info.value
            LOG(ERROR) << "property_set_async(\"" << info.name << "\", \"" << info.value
                       << "\") failed";
                       << "\") failed";
        }
        }
        exit(0);
        _exit(0);
    }
    }
}
}


@@ -712,8 +711,7 @@ void start_property_service() {
    property_set_fd = CreateSocket(PROP_SERVICE_NAME, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK,
    property_set_fd = CreateSocket(PROP_SERVICE_NAME, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK,
                                   false, 0666, 0, 0, nullptr);
                                   false, 0666, 0, 0, nullptr);
    if (property_set_fd == -1) {
    if (property_set_fd == -1) {
        PLOG(ERROR) << "start_property_service socket creation failed";
        PLOG(FATAL) << "start_property_service socket creation failed";
        exit(1);
    }
    }


    listen(property_set_fd, 8);
    listen(property_set_fd, 8);
+1 −2
Original line number Original line Diff line number Diff line
@@ -119,8 +119,7 @@ void sigchld_handler_init() {
    // Create a signalling mechanism for SIGCHLD.
    // Create a signalling mechanism for SIGCHLD.
    int s[2];
    int s[2];
    if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0, s) == -1) {
    if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0, s) == -1) {
        PLOG(ERROR) << "socketpair failed";
        PLOG(FATAL) << "socketpair failed in sigchld_handler_init";
        exit(1);
    }
    }


    signal_write_fd = s[0];
    signal_write_fd = s[0];