From patchwork Thu Mar 8 03:19:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Chaiken X-Patchwork-Id: 882954 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2607:f8b0:400c:c05::23e; helo=mail-vk0-x23e.google.com; envelope-from=swupdate+bncbd6llgxorqbrbr6xqlkqkgqe6otychy@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=peloton-tech.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="FrDKw0FB"; dkim-atps=neutral Received: from mail-vk0-x23e.google.com (mail-vk0-x23e.google.com [IPv6:2607:f8b0:400c:c05::23e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zxbND0Yf5z9sgm for ; Thu, 8 Mar 2018 14:19:38 +1100 (AEDT) Received: by mail-vk0-x23e.google.com with SMTP id w3sf2497803vkh.7 for ; Wed, 07 Mar 2018 19:19:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1520479176; cv=pass; d=google.com; s=arc-20160816; b=F7i0PGA/IzHN+sOWxkjqY1xpZ2dcpoYwlJOasz8twHFpzJ2RBfKajiN5tpTCXgSHh6 b9WCSkapD7xSiiVEDPvmrErj5v/auImG/52DzuXCAVxFb9uY+QNLcSeDE9xZfJaYvhNx AWKWCFDOeqtsNNYLCn5zS4egIuGB0Vl992Rk/ekl9PfydtQ261ipLswcCBGX/pu/FSnD NQzNfGSxPcv9QsGXlk0taIgUo380weSQjA+LrMUlzYJYiqc+MgusAy716/tNibygdVDL MhvUztfuQLeZ1z9ei4rmF/kNI47BzM5PtlX2mfo8jQwBPxvqIFHHdPS8iGgK+LPfKw/J 5U5Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:message-id:date:subject:cc:to:from :arc-authentication-results:arc-message-signature:mime-version :sender:dkim-signature:arc-authentication-results; bh=YKmQactpaSQfZhhbyXR+t2Fzw1l/W1ICjfzqVk7q9nc=; b=iAG7FAcXHkUwq1YnNXCs5HsLtcm+4iMigzm4AyouC9+GLs3P/2kI1KfTOyxtP5zWpW BiEHzt4PjiI7zXl4qwVQjLus08LjsnzgD124i604ldUqV48izvbwljdubekuabVRhFXM uy0+Or/W/+o4S02F2Dhw96MXSZXq5nzMFgh25ArqYk5loiIdfPkm9dQDCN7/Q7COYkQs DlqRUadkfz5WHAuybypmLKvaq0EVmxmm09X87uZCTUmjcQk4K8O7dZlpbXWEgaHo+W7H g5abTV96aEPqJMZWLhX9VqBfCjT8GTE6eM1E92nIxz4wSplq04iu1EJIHHy6q/nsajdS S3Dg== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 12.1.72.210 is neither permitted nor denied by best guess record for domain of alison@alison-debian.peloton-tech.com) smtp.mailfrom=alison@alison-debian.peloton-tech.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=YKmQactpaSQfZhhbyXR+t2Fzw1l/W1ICjfzqVk7q9nc=; b=FrDKw0FByArJSBMlnhPvg8kzRnUE1xeGjpoKsvuYn7KPgkI1aEB1ouHWKPAlsJqFZH a9HThJjdZhVESTLamJ/Y+GAFedR4xKx/aOMWzUI7NtazrOTgqjYyXkmfh24qXiIN04Tj eKXs7ZscdrFp8OnqHqFDTmHIX1yWwgmw0Hp/TFSP7yIgQpEwzhZ9w0bxX35RFFvSl+M8 D3ehC9ZxKPnKazj/huyu+TegONmvfnHrOFFK6yC8BLgAFv0xMX2XYULXQcbSD/kfkp2b Wdtz2lhYmrxjRHmRFLFc6RswcN0eD2tiwjd67tTfuEezWb3Deq3P3a8HXyvdtevH9qPE vfuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=YKmQactpaSQfZhhbyXR+t2Fzw1l/W1ICjfzqVk7q9nc=; b=OE6cPmevfJRg7G9VBazGJ6xxP/quCm7U6RPJ+cOwqcNbWqIzM06qBn4Fp7Yallabce Apet6RiSMqd+8Afx5sxK7l6LKlbQCzoO1BUqhHfr94Eps8GJZDt/AAvApHXGVRQVqK8c w+8S4KcXx/N8pgFtL0nh+SIS0o7tV/uFpmiFLIF/IzZC4OBEbjY0tyVj2SUJBj8sxmZP SVReS3H3PKb+k82xDIAUqn6Im7IKX1jP4KXXb3ciBUSM4sNy4wdad1g/cZC82ogGdr7Z Q7u13/cT+BEjV1R4t5rM7Xo0Spz/avdHqTqpWTkN5j4CFLmZXoZw+xaXjEXRWTASH0Zv uJTg== Sender: swupdate@googlegroups.com X-Gm-Message-State: APf1xPDG4AMXPvBZD2KarZ0fpYu+wviuF1VPyciWvkHo441dN+Jhu7nf n2pnFVJzMnuw/VuOtcCoutE= X-Google-Smtp-Source: AG47ELsra3ZKaRJKiN1jWJYzhrs27+WLFomFZemduXXINSoM9LRA2S1yZmckCNn6asY0xlNqVSvr/A== X-Received: by 10.31.173.2 with SMTP id w2mr2754128vke.10.1520479176231; Wed, 07 Mar 2018 19:19:36 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.129.123.67 with SMTP id w64ls195780ywc.8.gmail; Wed, 07 Mar 2018 19:19:35 -0800 (PST) X-Received: by 10.129.145.68 with SMTP id i65mr11435894ywg.75.1520479175729; Wed, 07 Mar 2018 19:19:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520479175; cv=none; d=google.com; s=arc-20160816; b=RHY2xjaN4JmxLjWPoqA/GkGD0E0B4qW5e2YHAiBcFhhKttgiGJC/vqwWV8W3x5Q7oi R5fVSyPhzuAhzrZTmYckcfAF43i2x00iTxaocXOw+HMFKvWF+VyLQBlh91lfYUZ2jy+H 1SWteFf5fiRQfmVMhSWaGbTfqIQxoAFZOIuYjWXry1rOnHHd4ktTDKptkQPFUvCOQnlq Q4C6oHqtsloxZOPqE0Nl/qqoWM6AF8dMOuAycSJ4jO3KSpIVFIWxKynetruBiMc339S5 wsXXM/HOINSAgKJiydY3dF9ahg5cmmAlmqVO0hO7kQP4cjMdsYb+UrIrFdBzcpMMSl4h s9JQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:arc-authentication-results; bh=uY4744sjlQkhqkSjf3O1QfsIA3q+GHn8qqcUs6zAQr4=; b=bRUoKDL9JjmpyMzYcEpKoC81gntngF9tP6g20EAfz2dJ6z6A10vg3CROom1+xLSR5L 5QpNztWsFbVWZ5TLnWcrBXNYX2yY3Vt1Xh+8NHaMg4o8Cx/x0o3eog31+/hJAQz/5gm+ GE3ycEVPL4uwk+bgTsMtFYYmB3gI40ZVZz75YHtvrgwEYKQ4Y/12RfOBNLYg9hUrIVyN 7kt4x0Ze4lnCxanIUwRPuwPWZ5XYS3o1zuFYuZip1daPS/s1yk/V/JU/4AarI9BnZHoB k1yDCxqAssV56bvLHVxy6UJYRT9zagSVjV4OPZjRWodCWVgid1BVWXwhJrnd9nNSiuH+ 9IRA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 12.1.72.210 is neither permitted nor denied by best guess record for domain of alison@alison-debian.peloton-tech.com) smtp.mailfrom=alison@alison-debian.peloton-tech.com Received: from alison-debian.peloton-tech.com ([12.1.72.210]) by gmr-mx.google.com with SMTP id l17-v6si597399ybm.0.2018.03.07.19.19.35 for ; Wed, 07 Mar 2018 19:19:35 -0800 (PST) Received-SPF: neutral (google.com: 12.1.72.210 is neither permitted nor denied by best guess record for domain of alison@alison-debian.peloton-tech.com) client-ip=12.1.72.210; Received: (qmail 32029 invoked by uid 1026); 8 Mar 2018 03:19:32 -0000 From: alison@peloton-tech.com To: swupdate@googlegroups.com Cc: sami.hartikainen@teleste.com, alison@she-devel.com, Alison Chaiken Subject: [swupdate] [PATCH] ipc: protect against pthread_cond_wait() spurious wakeups Date: Wed, 7 Mar 2018 19:19:30 -0800 Message-Id: <1520479170-31989-1-git-send-email-alison@peloton-tech.com> X-Mailer: git-send-email 2.1.4 X-Original-Sender: alison@peloton-tech.com X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 12.1.72.210 is neither permitted nor denied by best guess record for domain of alison@alison-debian.peloton-tech.com) smtp.mailfrom=alison@alison-debian.peloton-tech.com Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , From: Alison Chaiken pthread_cond_wait() is subject to spurious wakeups. Make certain that the network_initializer() thread is genuinely ready to run by checking that inst.fd has been set by network_thread(). Otherwise network_initializer() has no work to perform. Suggested-by: Brian Silverman Signed-off-by: Alison Chaiken --- corelib/stream_interface.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/corelib/stream_interface.c b/corelib/stream_interface.c index 91f523f..9e31b19 100644 --- a/corelib/stream_interface.c +++ b/corelib/stream_interface.c @@ -301,7 +301,11 @@ void *network_initializer(void *data) /* wait for someone to issue an install request */ pthread_mutex_lock(&stream_mutex); - pthread_cond_wait(&stream_wkup, &stream_mutex); + /* Guard against spurious wakeups of pthread_cond_wait() by checking that the + installer thread has a file descriptor to read. */ + while (inst.fd == -1) { + pthread_cond_wait(&stream_wkup, &stream_mutex); + } inst.status = RUN; pthread_mutex_unlock(&stream_mutex); notify(START, RECOVERY_NO_ERROR, INFOLEVEL, "Software Update started !");