diff --git a/core/socket.c b/core/socket.c index 79268747..c856e1c2 100644 --- a/core/socket.c +++ b/core/socket.c @@ -1958,3 +1958,21 @@ void uwsgi_tcp_nodelay(int fd) { #endif } +int uwsgi_accept(int server_fd) { + struct sockaddr_un client_src; + memset(&client_src, 0, sizeof(struct sockaddr_un)); + socklen_t client_src_len = 0; +#if defined(__linux__) && defined(SOCK_NONBLOCK) && !defined(OBSOLETE_LINUX_KERNEL) + return accept4(server_fd, (struct sockaddr *) &client_src, &client_src_len, SOCK_NONBLOCK); +#elif defined(__linux__) + int client_fd = accept(server_fd, (struct sockaddr *) &client_src, &client_src_len); + if (client_fd >= 0) { + uwsgi_socket_nb(client_fd); + } + return client_fd; +#else + return accept(server_fd, (struct sockaddr *) &client_src, &client_src_len); +#endif + + +} diff --git a/core/utils.c b/core/utils.c index e8001575..a250542d 100644 --- a/core/utils.c +++ b/core/utils.c @@ -543,6 +543,13 @@ void uwsgi_as_root() { } } + + int i; + for (i = 0; i < uwsgi.gp_cnt; i++) { + if (uwsgi.gp[i]->post_jail) { + uwsgi.gp[i]->post_jail(); + } + } } if (uwsgi.chroot && !uwsgi.reloads) { diff --git a/core/uwsgi.c b/core/uwsgi.c index 20c483ec..84f9ff6e 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -2374,7 +2374,7 @@ int uwsgi_start(void *v_argv) { uwsgi_foreach(usl, uwsgi.call_in_jail) { if (uwsgi_call_symbol(usl->value)) { - uwsgi_log("unaable to call function \"%s\"\n", usl->value); + uwsgi_log("unable to call function \"%s\"\n", usl->value); exit(1); } } diff --git a/plugins/pty/pty.c b/plugins/pty/pty.c index 0d732764..62edd7cb 100644 --- a/plugins/pty/pty.c +++ b/plugins/pty/pty.c @@ -118,6 +118,14 @@ static void *uwsgi_pty_loop(void *arg) { if client is ready we have something to write to the master pty */ + // block signals on this thread + sigset_t smask; + sigfillset(&smask); +#ifndef UWSGI_DEBUG + sigdelset(&smask, SIGSEGV); +#endif + pthread_sigmask(SIG_BLOCK, &smask, NULL); + for(;;) { char buf[8192]; int interesting_fd = -1; diff --git a/uwsgi.h b/uwsgi.h index 62d2af25..2c23a661 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -1003,6 +1003,7 @@ struct uwsgi_plugin { uint16_t(*rpc) (void *, uint8_t, char **, uint16_t *, char *); void (*jail) (int (*)(void *), char **); + void (*post_jail) (void); void (*before_privileges_drop) (void); int (*mule) (char *); @@ -4293,6 +4294,8 @@ void uwsgi_log_encoders_register_embedded(void); void uwsgi_register_log_encoder(char *, char *(*)(struct uwsgi_log_encoder *, char *, size_t, size_t *)); +int uwsgi_accept(int); + #ifdef __cplusplus } #endif