From patchwork Tue Aug 1 15:48:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 7050 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 (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4RFffp6vJhz3wpN for ; Tue, 1 Aug 2023 15:49:06 +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 (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4RFffk4ldZz16n; Tue, 1 Aug 2023 15:49:02 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4RFffk2zlqz309x; Tue, 1 Aug 2023 15:49:02 +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 4RFffj3598z2y12 for ; Tue, 1 Aug 2023 15:49:01 +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 (secp384r1) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4RFffj0llrzW2; Tue, 1 Aug 2023 15:49:01 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1690904941; 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=2VEePwmX5qWbhyOFOKqyG2aUurmvUEfH2PBh//cDilM=; b=Xva5VLO5RNAM4SYWtzGqa99Yio0gD8pu/P7n4RIgvaDsSEu5ZhKBZEUIPqyt6xEsfZ4NMp z/rX+dIZ2FKmiABg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1690904941; 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=2VEePwmX5qWbhyOFOKqyG2aUurmvUEfH2PBh//cDilM=; b=MmljHMKo59KAbagc2CwKV6qAjbfin28mtGdQcj8M+udhHY4VprAizw1+rFcFqFvNEdOhDP oLL5iNZILyQ/JMcqvFKqq6Wljou/fWg0IlEclngMF/olv9rEXU/WhUBS1R0I6T5a0DEQzx Oq+eEMMerLv/5Q+thVls+RzlaHWAvTc7IbjVmkYqb9xOHDF+vCcipQ/szGl3tPN3jDJG56 Yfj+AYmuENixlHPzAQhJvtPj6PRe2ptLnxSz/DHZpawPO3Sd5VNiQmv4LGyrjmjshD2hKN WG+G+QzQ3l/UOQReOHWxsXRy2Z3DQ5+t3r5Bu/N+rO5SMKNlcjPSCe5iw0tVIQ== From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCHv2 03/12] extrahd.cgi: Abort if a device could not be umounted. Date: Tue, 1 Aug 2023 17:48:30 +0200 Message-Id: <20230801154839.2373-3-stefan.schantl@ipfire.org> In-Reply-To: <20230801154839.2373-1-stefan.schantl@ipfire.org> References: <20230801154839.2373-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 Reviewed-by: Bernhard Bitsch --- 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 bafdb9fc9..f31bc2c44 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) {