Copyright © https://mongoose-os.com

Mongoose OS Forum

frame
ATTENTION! This forum has moved to:

https://community.mongoose-os.com

Do not post any new messages.

segfault with broken pipe

AmirulAmirul Bangladesh

Hi,

I have a very very simple code that I setup to allow a program to provide builtin web server support. There is nothing much to it, it receives request and passes along to php-cli interface, which takes care of some interface stuff.

Now two things I have noticed is that, after the php-cli work is done, the worker process is not destroyed so it becomes zombie.

secondly, if the connection is closed before library writes the result to connection then then it crashes with SIGPIPE.

0x00000030836e97f2 in send () from /lib64/libc.so.6

Is there something I am doing wrong? I am sure I must be doing something really silly. Can you guide me maybe? Here is the simple code that I am using. It is actually an example from your release

#include "mongoose.h"

static const char *s_http_port = "8000";
static struct mg_serve_http_opts s_http_server_opts;

static void http_request_handler(struct mg_connection *nc, int ev, void *ev_data)
{
        struct http_message *hm = (struct http_message *) ev_data;

        switch (ev)
        {
                case MG_EV_HTTP_REQUEST:

                        if (mg_vcmp(&hm->uri, "/api/v1/sum") == 0) {

                        } else {

                                mg_serve_http(nc, hm, s_http_server_opts);
                        }
                        break;

                default:
                        break;
        }
}

nt main(int argc, char *argv[])
{
        struct mg_mgr mgr;
        struct mg_connection *nc;
        char docroot[PATH_MAX], cgipath[PATH_MAX];

        mg_mgr_init(&mgr, NULL);

        strcpy(docroot, "/path/to/doc/root/");
        strcpy(cgipath, "/path/to/cgi/php-cli");

        s_http_server_opts.document_root = docroot;
        s_http_server_opts.cgi_interpreter = cgipath;

        nc = mg_bind(&mgr, s_http_port, http_request_handler);
        if (nc == NULL) {
                fprintf(stderr, "Error starting server on port %s\n", s_http_port);
                exit(1);
        }

    mg_set_protocol_http_websocket(nc);
        s_http_server_opts.enable_directory_listing = "yes";

        printf("Starting server on port %s, serving %s\n", s_http_port, s_http_server_opts.document_root);

        for (;;) {
                mg_mgr_poll(&mgr, 1000);
        }
    mg_mgr_free(&mgr);

        return 0;
}

Thanks in advance :)

Comments

  • SergeySergey Dublin, Ireland

    call signal() for SIGPIPE and SIGCHLD, pass SIG_IGN.

Sign In or Register to comment.