From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 872BA385800F for ; Sat, 27 Mar 2021 12:56:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 872BA385800F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id AA5F4AE05; Sat, 27 Mar 2021 12:56:06 +0000 (UTC) Date: Sat, 27 Mar 2021 13:56:04 +0100 From: Tom de Vries To: dwz@sourceware.org, jakub@redhat.com, mark@klomp.org Subject: [committed] Factor out wait_child_exit Message-ID: <20210327125603.GA18266@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: dwz@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Dwz mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Mar 2021 12:56:08 -0000 Hi, Factor out new function wait_child_exit out of dwz_files_1. Committed to trunk. Thanks, - Tom Factor out wait_child_exit 2021-03-27 Tom de Vries * dwz.c (wait_child_exit): New function, factored out of ... (dwz_files_1): ... here. --- dwz.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/dwz.c b/dwz.c index 1be4f2a..bd40e90 100644 --- a/dwz.c +++ b/dwz.c @@ -16437,6 +16437,26 @@ decode_child_exit_status (int state, struct file_result *res) return ret; } +/* Wait on child exit with PID, update PIDS and RES. */ +static int +wait_child_exit (pid_t pid, pid_t *pids, int nr_pids, + struct file_result *res) +{ + int state; + pid_t got_pid = waitpid (pid, &state, 0); + + int i; + for (i = 0; i < nr_pids; ++i) + if (pids[i] == got_pid) + { + pids[i] = 0; + break; + } + assert (i < nr_pids); + + return decode_child_exit_status (state, res); +} + /* Dwarf-compress FILES. If HARDLINK, detect if some files are hardlinks and if so, dwarf-compress just one, and relink the others. */ static int @@ -16487,21 +16507,10 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink, if (nr_forks == max_forks) { - int state; - pid_t got_pid = waitpid (-1, &state, 0); - int thisret - = decode_child_exit_status (state, res); + int thisret = wait_child_exit (-1, pids, i, res); if (thisret == 1) ret = 1; nr_forks--; - int j; - for (j = 0; j < i; ++j) - if (pids[j] == got_pid) - { - pids[j] = 0; - break; - } - assert (j < i); } pid_t fork_res = fork (); @@ -16527,10 +16536,7 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink, continue; if (pids[i] == 0) continue; - int state; - pid_t got_pid = waitpid (pids[i], &state, 0); - assert (got_pid == pids[i]); - thisret = decode_child_exit_status (state, res); + thisret = wait_child_exit (pids[i], &pids[i], 1, res); if (thisret == 1) ret = 1; }