Project

General

Profile

« Previous | Next » 

Revision 4c3d9312

Added by Ermal LUÇI over 14 years ago

Ticket #1017. Put a @ before each fwrite to silence errors. Also setup the log file in the beginning rather than on each individual function.

View differences:

etc/inc/pkg-utils.inc
49 49
require_once("pfsense-utils.inc");
50 50
require_once("globals.inc");
51 51

  
52

  
53
/* set up logging if needed */
54
if (!$fd_log) {
55
	if (!$fd_log = fopen("{$g['tmp_path']}/pkg_mgr_{$package}.log", "w"))
56
		update_output_window("Warning, could not open log for writing.");
57
}
58

  
52 59
if(!function_exists("update_status")) {
53 60
	function update_status($status) {
54 61
		echo $status . "\n";
......
465 472

  
466 473
	if($pkg_interface == "console") 	
467 474
		echo "\n";
468
	/* open logfiles and begin installation */
469
	if (!$fd_log) {
470
		if (!$fd_log = fopen("{$g['tmp_path']}/pkg_mgr_{$package}.log", "w"))
471
			update_output_window("Warning, could not open log for writing.");
472
	}
473 475
	/* fetch package information if needed */
474 476
	if(empty($pkg_info) or !is_array($pkg_info[$package])) {
475 477
		$pkg_info = get_pkg_info(array($package));
......
582 584
	} else
583 585
		$pkg_info = $config['installedpackages']['package'][$pkgid];
584 586

  
585
	/* set up logging if needed */
586
	if(!$fd_log) {
587
		if(!$fd_log = fopen("{$g['tmp_path']}/pkg_mgr_{$pkg}.log", "w")) {
588
			update_output_window("Warning, could not open log for writing.");
589
		}
590
	}
591

  
592 587
	/* pkg_add the package and its dependencies */
593 588
	if($pkg_info['depends_on_package_base_url'] != "") {
594 589
		if($pkg_interface == "console") 
......
614 609
			if($pkg_installed == true) {
615 610
				$static_output .= "done.\n";
616 611
				update_output_window($static_output);
617
				fwrite($fd_log, "pkg_add successfully completed.\n");
612
				@fwrite($fd_log, "pkg_add successfully completed.\n");
618 613
			} else {
619 614
				$static_output .= "of {$pkg_name} failed!\n\nInstallation aborted.";
620 615
				update_output_window($static_output);
621
				fwrite($fd_log, "Package WAS NOT installed properly.\n");
622
				fclose($fd_log);
616
				@fwrite($fd_log, "Package WAS NOT installed properly.\n");
623 617
				if($pkg_interface <> "console") {
624 618
					echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';</script>";
625 619
					echo "\n<script language=\"JavaScript\">document.progholder.style.visibility='hidden';</script>";
......
679 673
					return false;
680 674
				}
681 675
				if(stristr($filename, ".tgz") <> "") {
682
					fwrite($fd_log, "Extracting tarball to -C for " . $filename . "...\n");
676
					@fwrite($fd_log, "Extracting tarball to -C for " . $filename . "...\n");
683 677
					$tarout = "";
684 678
					exec("/usr/bin/tar xvzf " . $prefix . $filename . " -C / 2>&1", $tarout);
685
					fwrite($fd_log, print_r($tarout, true) . "\n");
679
					@fwrite($fd_log, print_r($tarout, true) . "\n");
686 680
				}
687 681
				if($pkg_chmod <> "") {
688
					fwrite($fd_log, "Changing file mode to {$pkg_chmod} for {$prefix}{$filename}\n");
682
					@fwrite($fd_log, "Changing file mode to {$pkg_chmod} for {$prefix}{$filename}\n");
689 683
					@chmod($prefix . $filename, $pkg_chmod);
690 684
					system("/bin/chmod {$pkg_chmod} {$prefix}{$filename}");
691 685
				}
......
703 697
		if($pkg_config['include_file'] <> "") {
704 698
			$static_output .= "Loading package instructions...\n";
705 699
			update_output_window($static_output);
706
			fwrite($fd_log, "require_once('{$pkg_config['include_file']}')\n");
700
			@fwrite($fd_log, "require_once('{$pkg_config['include_file']}')\n");
707 701
			if (file_exists($pkg_config['include_file']))
708 702
				require_once($pkg_config['include_file']);
709 703
			else {
......
785 779
	} else {
786 780
		$static_output .= "Loading package configuration... failed!\n\nInstallation aborted.";
787 781
		update_output_window($static_output);
788
		fwrite($fd_log, "Unable to load package configuration. Installation aborted.\n");
789
		fclose($fd_log);
782
		@fwrite($fd_log, "Unable to load package configuration. Installation aborted.\n");
790 783
		if($pkg_interface <> "console") {
791 784
			echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';</script>";
792 785
			echo "\n<script language=\"JavaScript\">document.progholder.style.visibility='hidden';</script>";
......
853 846
		conf_mount_ro();
854 847
		return;
855 848
	}
856
	/* set up logging if needed */
857
	if(!$fd_log) {
858
		if(!$fd_log = fopen("{$g['tmp_path']}/pkg_mgr_{$pkg}.log", "w")) {
859
			update_output_window("Warning, could not open log for writing.");
860
		}
861
	}
862
	fwrite($fd_log, "Removing {$pkg} package... ");
849
	@fwrite($fd_log, "Removing {$pkg} package... ");
863 850
	$static_output .= "Removing {$pkg} components...\n";
864 851
	update_output_window($static_output);
865 852
	/* parse package configuration */
......
935 922
		if($pkg_config['include_file'] <> "") {
936 923
			$static_output .= "Loading package instructions...\n";
937 924
			update_output_window($static_output);
938
			fwrite($fd_log, "require_once(\"{$pkg_config['include_file']}\")\n");
925
			@fwrite($fd_log, "require_once(\"{$pkg_config['include_file']}\")\n");
939 926
			if (file_exists($pkg_config['include_file']))
940 927
				require_once($pkg_config['include_file']);
941 928
			else {
......
987 974
		if($pkg_config['include_file'] <> "") {
988 975
                        $static_output .= "\tRemoving package instructions...";
989 976
                        update_output_window($static_output);
990
                        fwrite($fd_log, "Remove '{$pkg_config['include_file']}'\n");
977
                        @fwrite($fd_log, "Remove '{$pkg_config['include_file']}'\n");
991 978
                        unlink_if_exists("/usr/local/pkg/" . $pkg_config['include_file']);
992 979
			$static_output .= "done.\n";
993 980
                        update_output_window($static_output);
......
1024 1011
	$static_output .= "done.\n";
1025 1012
	update_output_window($static_output);
1026 1013
	write_config("Removed {$pkg} package.\n");
1027
	/* file cleanup */
1028
	$ctag = file("/etc/crontab");
1029
	foreach($ctag as $line)
1030
		if(trim($line) != "")
1031
			$towrite[] = $line;
1032

  
1033
	$tmptab = fopen("{$g['tmp_path']}/crontab", "w");
1034
	foreach($towrite as $line)
1035
		fwrite($tmptab, $line);
1036
	fclose($tmptab);
1037

  
1038
	// Go RW again since the write_config above will put it back to RO
1039
	conf_mount_rw();
1040
	rename("{$g['tmp_path']}/crontab", "/etc/crontab");
1041
	conf_mount_ro();
1042 1014
}
1043 1015

  
1044 1016
function expand_to_bytes($size) {

Also available in: Unified diff