From patchwork Fri Jun 23 04:01:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 6948 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4QnNpX17y3z3wjw for ; Fri, 23 Jun 2023 04:01:40 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4QnNpV0LtGz1Np; Fri, 23 Jun 2023 04:01:38 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4QnNpT6Cq2z30GP; Fri, 23 Jun 2023 04:01:37 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4QnNpS1yPTz2xY5 for ; Fri, 23 Jun 2023 04:01:36 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4QnNpR5H7mzbW; Fri, 23 Jun 2023 04:01:35 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1687492896; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cMWuicTisBDtb9RhTHrB3XRRGDZFEukRHbqgS10ivfw=; b=t3jSo0360xuHTdXzbv2lnW2C7pYkaBb+hHVOheGA/8M1eMeF1grD+JSmmqzMeOYBvgKS+5 82Gl3n2iGEUHm/DQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1687492896; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cMWuicTisBDtb9RhTHrB3XRRGDZFEukRHbqgS10ivfw=; b=mglRHp3Qr8u0sMmTKRDc0k3CU8S4MX08U2eROSNe4BMzRlySUX4kd+Y4byZQXb83pGMLcA cEBbFmasqsK1jqa3stYmRI/+aQ9YThbWfhqnPPNGP1tgloGgGkW7gK5Hdnd0DFoJR67vbL he/xDIi2uDW0jMss3B2snJp+QCwibKjxRDayyJTpOd0ENXw2VTSII9L48EGGHuC/2K09c2 p2XrxkUIReZOPJy/3fssIc8vFY36cQlihpuRPalK6uL0HcFUS1xRQJF1l9ucyOemWN49vX Q0pgWaGqGmBswkVdgHwKT15bZ4ta3vXsyU511BPkc+taRu5pmsX9/bk7OdREbA== From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCH 3/8] extrahd.cgi: Abort if a device could not be umounted. Date: Fri, 23 Jun 2023 06:01:19 +0200 Message-Id: <20230623040124.3826-3-stefan.schantl@ipfire.org> In-Reply-To: <20230623040124.3826-1-stefan.schantl@ipfire.org> References: <20230623040124.3826-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" Signed-off-by: Stefan Schantl --- html/cgi-bin/extrahd.cgi | 42 +++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/html/cgi-bin/extrahd.cgi b/html/cgi-bin/extrahd.cgi index 117890f08..dde4e7356 100644 --- a/html/cgi-bin/extrahd.cgi +++ b/html/cgi-bin/extrahd.cgi @@ -146,33 +146,35 @@ if ($extrahdsettings{'ACTION'} eq $Lang::tr{'add'}) { # } elsif ($extrahdsettings{'ACTION'} eq $Lang::tr{'delete'}) { # Call helper binary to unmount the device. - &General::system("/usr/local/bin/extrahdctrl", "umount", "$extrahdsettings{'PATH'}"); + unless(&General::system("/usr/local/bin/extrahdctrl", "umount", "$extrahdsettings{'PATH'}")) { + # Open the device file for reading. + open(FILE, "< $devicefile" ) or die "Unable to read $devicefile"; - # Open the device file for reading. - open(FILE, "< $devicefile" ) or die "Unable to read $devicefile"; + # Read the file content into a temporary array. + my @tmp = ; - # Read the file content into a temporary array. - my @tmp = ; - - # Close file handle. - close(FILE); + # Close file handle. + close(FILE); - # Re-open device file for writing. - open(FILE, "> $devicefile" ) or die "Unable to write $devicefile"; + # Re-open device file for writing. + open(FILE, "> $devicefile" ) or die "Unable to write $devicefile"; - # Loop through the previous read file content. - foreach my $line (sort @tmp) { - # Split line content and assign nice variables. - my ($uuid, $fs, $path) = split( /\;/, $line ); + # Loop through the previous read file content. + foreach my $line (sort @tmp) { + # Split line content and assign nice variables. + my ($uuid, $fs, $path) = split( /\;/, $line ); - # Write the line in case it does not contain our element to delete. - if ($path ne $extrahdsettings{'PATH'}) { - print FILE "$line"; + # Write the line in case it does not contain our element to delete. + if ($path ne $extrahdsettings{'PATH'}) { + print FILE "$line"; + } } - } - # Close file handle. - close(FILE); + # Close file handle. + close(FILE); + } else { + $errormessage = "$Lang::tr{'extrahd cant umount'} $extrahdsettings{'PATH'}$Lang::tr{'extrahd maybe the device is in use'}?"; + } } if ($errormessage) {