From patchwork Thu May 31 22:23:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephan Holljes X-Patchwork-Id: 9189 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:11c:0:0:0:0:0 with SMTP id c28-v6csp161330jad; Thu, 31 May 2018 15:24:49 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKFaoWpfaek1W5ZEhEYEtNH+hGCmW4B7T2iWzasYNPbIr44uqtjeEdsRWw5C7kqWqXNaQII X-Received: by 2002:a1c:eacd:: with SMTP id g74-v6mr904700wmi.103.1527805489417; Thu, 31 May 2018 15:24:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527805489; cv=none; d=google.com; s=arc-20160816; b=bR+qPTfHn+0WrucDE63gOYaiuU47dsa+NnIXxR+BlD0MyyreWvdJbCpweQEIIbi4PG iLedmZjf1qmbmRHVnImgQW7f0TwrIPWcOP+K+xAEYSSZyDWo6ucrRfdqpp9XIgjkg9UY BI5Ro+zhsa7h7UNxvPiycCHFeIljwErfUKx1mdehkkRNOU036w5oSH9ybx6bVVTAT2n2 CJv7bMpmmeXdATyvmbY+oyra0ba9yeJmJzNrMSJahptrKiPOEhsH/Tpy50W7gV6ywNxo 2GwwPvvRjk2J1ztOVorzFm8fGxio5sWNn49oees5U6GmiXbHSyRmu4JPNWqhttEL/ub1 R/AQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=+xSejd7H0aMjec/0nMMQMnt7MFyOzvf6OjMAGJJVkKE=; b=DekV0RbbRvZOJH5xXrKKYr7W5UIuObKCMKjEr9l9hdteEY84ocNGo1ULHyNVak9KJH tzTcZsYWbg2hdNqTIBjjbzXyOce2aABf0yu7ZP2rlLnabEl4FvVYJzsVs6+GN8kknCbX 5kWUArWdCCs7TMpEMvdVPvHXmfw0/B6pnvCNaf/O9yoGu1qoGWqWs5MSwVVolUnJcGo3 RbJ5XX886wxle3eo1Ow04/IHMNhge5GqY5Sa7A9qTZEkOIIObljyhaQ30Bw7SGE2/mLr 5pfWg9G3KknPjybYY46aUjMYRs7hytnLcsxURF5AxufQ8/wVkaYzo3reMiERaGDjtyi9 O86Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@googlemail.com header.s=20161025 header.b=bEJEH+Rv; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id d17-v6si2505179wrp.303.2018.05.31.15.24.49; Thu, 31 May 2018 15:24:49 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@googlemail.com header.s=20161025 header.b=bEJEH+Rv; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 59B0A68A473; Fri, 1 Jun 2018 01:23:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f43.google.com (mail-wm0-f43.google.com [74.125.82.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7CBCF68A42A for ; Fri, 1 Jun 2018 01:23:42 +0300 (EEST) Received: by mail-wm0-f43.google.com with SMTP id l1-v6so56668642wmb.2 for ; Thu, 31 May 2018 15:24:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pozGGQzA8eWsBhFOYNOalJEeqvTHnA2ES4W+wRAJHHE=; b=bEJEH+Rvj47edRrQOddGBOOrP9e577CITyb+7FafVu7NR3qlD6iQ64p+IwmVLq8Ifi iWxDxdhuIaFrKTkYN6XpmzxBkyhQEilukljkv+nyo3eGwqTVwpEDgrDM9XMqE6u3W17Y nxJOfS1DPImKDrqPe+JMgyQOipe00IC9Ip+54x0VeJMukpSAsJIt55ilAvJMYRpnQvQm GAu+mEJpSzl42FKf6veIU39qdW870hooUF/AsUpPe9o7s4iRGG3WaH1dNErgpmQAREwG C7H+8lU0SriuWIgQ33ZAg5joGeFddsUXqWDv1Zie7WroHe4UdTbkqLSv/3TimqUkyK9z Eh0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pozGGQzA8eWsBhFOYNOalJEeqvTHnA2ES4W+wRAJHHE=; b=ZhLhWjvQ9G2ByEQToFgEgPvZ6p16n4Jjq5TSqjp6vHsYroxFwhifBYEzS8cUvzlBt+ /WOF/uDYHZW8Ah1g/fOusgcUXBaBKgTsXdPkAmzme5BtcNeMZ39epQy30EfEhntgJLD2 /p5Zw+4t5N9FeuZSWqOnqYME7z9GLB2b+P9OLb0iS1L9/7u9XIxBcswgALNaooPDFXNj VongjUi5loI2Mrppx4T7mAzvp7tPQ18G4GXHacwpaLOJ8UWq8D8ock2y6tMaoc4aUSag KHTk/S70iDPFfrVQudR08qV0Ed48iqcWQapgZ4GsBb1EjhkmrxN6IoD9B7jo4tAdyjoo 8NXA== X-Gm-Message-State: ALKqPwes+z0QBBQJDL6KaF91B/hcNV+DIU7CqRtlTDoNaObTGfU9Y4yf UHTK3Da9pB6DgUy7zxWDgRL7VQ== X-Received: by 2002:a1c:dcd4:: with SMTP id t203-v6mr597445wmg.156.1527805466925; Thu, 31 May 2018 15:24:26 -0700 (PDT) Received: from localhost.localdomain ([46.5.2.0]) by smtp.gmail.com with ESMTPSA id b72-v6sm705017wmf.11.2018.05.31.15.24.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 May 2018 15:24:26 -0700 (PDT) From: Stephan Holljes To: ffmpeg-devel@ffmpeg.org Date: Fri, 1 Jun 2018 00:23:55 +0200 Message-Id: <20180531222415.24966-3-klaxa1337@googlemail.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180531222415.24966-1-klaxa1337@googlemail.com> References: <20180528182711.3221-1-klaxa1337@googlemail.com> <20180531222415.24966-1-klaxa1337@googlemail.com> Subject: [FFmpeg-devel] [PATCH 02/22] ffserver.c: Check pthread_create for thread creation failure X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Stephan Holljes MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Stephan Holljes --- ffserver.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/ffserver.c b/ffserver.c index 116c399..9b28fdc 100644 --- a/ffserver.c +++ b/ffserver.c @@ -554,21 +554,35 @@ void *run_server(void *arg) { for (i = 0; i < pub->nb_threads; i++) { winfos[i].pub = pub; winfos[i].thread_id = i; - pthread_create(&w_threads[i], NULL, write_thread, &winfos_p[stream_index][i]); + ret = pthread_create(&w_threads[i], NULL, write_thread, &winfos_p[stream_index][i]); + if (ret != 0) { + pub->shutdown = 1; + goto end; + } } w_threads_p[stream_index] = w_threads; - pthread_create(&r_thread, NULL, read_thread, &rinfos[stream_index]); + ret = pthread_create(&r_thread, NULL, read_thread, &rinfos[stream_index]); + if (ret != 0) { + pub->shutdown = 1; + goto end; + } r_threads[stream_index] = r_thread; } //pthread_create(&a_thread, NULL, accept_thread, &ainfo); accept_thread(&ainfo); + +end: for (stream_index = 0; stream_index < config->nb_streams; stream_index++) { - pthread_join(r_threads[stream_index], NULL); + // in case of thread creation failure this might NULL + if (r_threads[stream_index]) + pthread_join(r_threads[stream_index], NULL); if (pubs[stream_index]) { for (i = 0; i < pubs[stream_index]->nb_threads; i++) { - pthread_join(w_threads_p[stream_index][i], NULL); + // might also be NULL because of thread creation failure + if (w_threads_p[stream_index][i]) + pthread_join(w_threads_p[stream_index][i], NULL); } } av_free(winfos_p[stream_index]); @@ -592,7 +606,7 @@ int main(int argc, char *argv[]) struct HTTPDConfig *configs; int nb_configs; pthread_t *server_threads; - int i; + int i, ret; if (argc < 2) { printf("Usage: %s config.lua\n", argv[0]); @@ -606,12 +620,16 @@ int main(int argc, char *argv[]) } server_threads = av_mallocz_array(nb_configs, sizeof(pthread_t)); for (i = 0; i < nb_configs; i++) { - config_dump(configs + i); - pthread_create(&server_threads[i], NULL, run_server, configs + i); + config_dump(configs + i, stderr); + ret = pthread_create(&server_threads[i], NULL, run_server, configs + i); + if (ret != 0) { + server_threads[i] = 0; + } } for (i = 0; i < nb_configs; i++) { - pthread_join(server_threads[i], NULL); + if (server_threads[i]) + pthread_join(server_threads[i], NULL); config_free(configs + i); } av_free(configs);