From 894839df424f877a63b65272dcdaf94bdefb3653 Mon Sep 17 00:00:00 2001 From: opensides Date: Sun, 28 Mar 2010 00:21:19 +0000 Subject: [PATCH] - More open fixes, add missing my in front of filehandle variable git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@17331 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/client/events/corefunctions.pm | 34 +++++++++++++------------- gosa-si/client/events/dak.pm | 2 +- gosa-si/client/events/gosaTriggered.pm | 8 +++--- gosa-si/client/events/installation.pm | 4 +-- gosa-si/client/events/load_reporter.pm | 10 ++++---- gosa-si/gosa-si-client | 16 ++++++------ gosa-si/gosa-si-server | 18 +++++++------- gosa-si/modules/ArpHandler.pm | 2 -- gosa-si/modules/ClientPackages.pm | 4 +-- gosa-si/modules/GosaSupportDaemon.pm | 8 +++--- gosa-si/modules/ServerPackages.pm | 7 ++++-- 11 files changed, 57 insertions(+), 56 deletions(-) diff --git a/gosa-si/client/events/corefunctions.pm b/gosa-si/client/events/corefunctions.pm index 016e6b888..a25aa98cb 100644 --- a/gosa-si/client/events/corefunctions.pm +++ b/gosa-si/client/events/corefunctions.pm @@ -11,7 +11,7 @@ use File::Basename; my @events = ( "get_events", "registered", - 'new_syslog_config', + "new_syslog_config", "new_ntp_config", "new_ldap_config", "new_key", @@ -71,12 +71,12 @@ sub write_to_file { chomp($string); if( not -f $file ) { - open (FILE, "$file"); - close(FILE); + open (my $FD_FILE, "$file"); + close($FD_FILE); } - open(FILE, ">>", "$file") or &main::daemon_log("ERROR in corefunctions.pm: can not open '$file' to write '$string'", 1);; - print FILE $string."\n"; - close(FILE); + open(my $FD_FILE, ">>", "$file") or &main::daemon_log("ERROR in corefunctions.pm: can not open '$file' to write '$string'", 1);; + print $FD_FILE $string."\n"; + close($FD_FILE); } return; @@ -182,7 +182,7 @@ sub new_syslog_config { } # Substitute existing server with new syslog server - open ($FILE, "<","$syslog_file"); + open (my $FILE, "<","$syslog_file"); my @file = <$FILE>; close($FILE); my $syslog_server_line = "*.*\t@".$syslog_server."\n"; @@ -200,7 +200,7 @@ sub new_syslog_config { } # Write changes to file and close it - open ($FILE, "+>","$syslog_file"); + open (my $FILE, "+>","$syslog_file"); print $FILE join("", @file); close($FILE); &main::daemon_log("INFO: Wrote new configuration file: $syslog_file", 5); @@ -239,7 +239,7 @@ sub new_ntp_config { } # Substitute existing server with new ntp server - open ($FILE, "<","$chrony_file"); + open (my $FILE, "<","$chrony_file"); my @file = <$FILE>; close($FILE); my @new_file; @@ -262,7 +262,7 @@ sub new_ntp_config { } # Write changes to file and close it - open ($FILE, ">","$chrony_file"); + open (my $FILE, ">","$chrony_file"); print $FILE join("", @new_file); close($FILE); &main::daemon_log("INFO: Wrote new configuration file: $chrony_file", 5); @@ -359,7 +359,7 @@ sub new_ldap_config { # Setup ldap.conf my $file1; my $file2; - open($file1, ">","$ldap_config"); + open(my $file1, ">","$ldap_config"); print $file1 "# This file was automatically generated by gosa-si-client. Do not change.\n"; print $file1 "URI"; foreach $element (@ldap_uris) { @@ -373,8 +373,8 @@ sub new_ldap_config { daemon_log("INFO: Wrote $ldap_config", 5); # Setup pam_ldap.conf / libnss-ldap.conf - open($file1, ">","$pam_config"); - open($file2, ">","$nss_config"); + open(my $file1, ">","$pam_config"); + open(my $file2, ">","$nss_config"); print $file1 "# This file was automatically generated by gosa-si-client. Do not change.\n"; print $file2 "# This file was automatically generated by gosa-si-client. Do not change.\n"; print $file1 "uri"; @@ -398,11 +398,11 @@ sub new_ldap_config { # Create goto.secrets if told so - for compatibility reasons if (defined $goto_admin){ - open($file1, ">","/etc/goto/secret"); + open(my $file1, ">","/etc/goto/secret"); close($file1); chown(0,0, "/etc/goto/secret"); chmod(0600, "/etc/goto/secret"); - open($file1, ">","/etc/goto/secret"); + open(my $file1, ">","/etc/goto/secret"); print $file1 "GOTOADMIN=\"$goto_admin\"\nGOTOSECRET=\"$goto_secret\"\n"; close($file1); daemon_log("INFO: Wrote /etc/goto/secret", 5); @@ -415,7 +415,7 @@ sub new_ldap_config { my $ldap_server= $ldap_uris[0]; $ldap_server=~ s/^ldap:\/\/([^:]+).*$/$1/; - open($file1, ">","$cfg_name"); + open(my $file1, ">","$cfg_name"); print $file1 "LDAP_BASE=\"$ldap_base\"\n"; print $file1 "LDAP_SERVER=\"$ldap_server\"\n"; print $file1 "LDAP_URIS=\"@ldap_uris\"\n"; @@ -432,7 +432,7 @@ sub new_ldap_config { $cfg_name= "/etc/ldap/ldap-offline.conf"; # Get first LDAP server - open($file1, ">","$cfg_name"); + open(my $file1, ">","$cfg_name"); print $file1 "LDAP_BASE=\"$ldap_base\"\n"; print $file1 "LDAP_SERVER=\"127.0.0.1\"\n"; print $file1 "LDAP_URIS=\"ldap://127.0.0.1\"\n"; diff --git a/gosa-si/client/events/dak.pm b/gosa-si/client/events/dak.pm index 57c2f8533..b6a0a6883 100644 --- a/gosa-si/client/events/dak.pm +++ b/gosa-si/client/events/dak.pm @@ -130,7 +130,7 @@ sub import_dak_key { &add_content2xml_hash($out_hash, "error", "DAK Keyring is not writable"); } else { my $keyfile; - open($keyfile, ">","/tmp/gosa_si_tmp_dak_key"); + open(my $keyfile, ">","/tmp/gosa_si_tmp_dak_key"); print $keyfile $key; close($keyfile); my $command = "$gpg --import /tmp/gosa_si_tmp_dak_key"; diff --git a/gosa-si/client/events/gosaTriggered.pm b/gosa-si/client/events/gosaTriggered.pm index 3b6f9678a..fb7c8f892 100644 --- a/gosa-si/client/events/gosaTriggered.pm +++ b/gosa-si/client/events/gosaTriggered.pm @@ -193,7 +193,7 @@ sub trigger_action_localboot { # Check logged in user my @user_list = &get_logged_in_users; if( @user_list >= 1 ) { - open($FILE, ">", "/etc/gosa-si/event"); + open(my $FILE, ">", "/etc/gosa-si/event"); print $FILE "trigger_action_localboot\n"; close($FILE); } @@ -293,7 +293,7 @@ sub trigger_action_reboot { my @user_list = &get_logged_in_users; if( @user_list >= 1 ) { system( "/usr/bin/goto-notify reboot" ); - open($FILE, ">", "/etc/gosa-si/event"); + open(my $FILE, ">", "/etc/gosa-si/event"); print $FILE "reboot\n"; close($FILE); } @@ -355,7 +355,7 @@ sub trigger_action_halt { my @user_list = &get_logged_in_users; if( @user_list >= 1 ) { system( "/usr/bin/goto-notify halt" ); - open($FILE, ">", "/etc/gosa-si/event"); + open(my $FILE, ">", "/etc/gosa-si/event"); print $FILE "halt\n"; close($FILE); } @@ -407,7 +407,7 @@ sub trigger_action_reinstall { my @user_list = &get_logged_in_users; if( @user_list >= 1 ) { system( "/usr/bin/goto-notify install" ); - open($FILE, ">", "/etc/gosa-si/event"); + open(my $FILE, ">", "/etc/gosa-si/event"); print $FILE "install\n"; close($FILE); } diff --git a/gosa-si/client/events/installation.pm b/gosa-si/client/events/installation.pm index 700adc5a1..ecd9204fd 100644 --- a/gosa-si/client/events/installation.pm +++ b/gosa-si/client/events/installation.pm @@ -28,9 +28,9 @@ sub set_activated_for_installation { my $source = @{$msg_hash->{'source'}}[0]; my $Datei = "/var/run/gosa-si-client.activated"; - open($FILE, ">", "$Datei"); + open(my $FILE, ">", "$Datei"); print $FILE "$msg\n"; - close $FILE; + close($FILE); return; } diff --git a/gosa-si/client/events/load_reporter.pm b/gosa-si/client/events/load_reporter.pm index 9227b729c..b9cb41e7b 100644 --- a/gosa-si/client/events/load_reporter.pm +++ b/gosa-si/client/events/load_reporter.pm @@ -14,9 +14,9 @@ END {} my @events = ( "get_events", "get_terminal_server", - "get_load", - "report_load", - "set_terminal_server", + "get_load", + "report_load", + "set_terminal_server", ); @EXPORT = @events; @@ -58,7 +58,7 @@ sub get_load my $file = "/proc/loadavg"; if ((not -f $file) || (not -r $file)) { return } - open($FHD, "<", "$file"); + open(my $FHD, "<", "$file"); my $line = <$FHD>; close($FHD); chomp($line); @@ -86,7 +86,7 @@ sub set_terminal_server { $file_content .= "$ts $load\n"; } - open($FHD, ">", "$ts_load_file.part"); + open(my $FHD, ">", "$ts_load_file.part"); printf $FHD $file_content; close($FHD); diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client index 49756c38a..0ffe6e158 100755 --- a/gosa-si/gosa-si-client +++ b/gosa-si/gosa-si-client @@ -175,14 +175,14 @@ sub check_cmdline_param () { sub check_pid { $pid = -1; # Check, if we are already running - if( open($LOCK_FILE, "<","$pid_file") ) { + if( open(my $LOCK_FILE, "<","$pid_file") ) { $pid = <$LOCK_FILE>; if( defined $pid ) { chomp( $pid ); if( -f "/proc/$pid/stat" ) { my($stat) = `cat /proc/$pid/stat` =~ m/$pid \((.+)\).*/; if( $0 eq $stat ) { - close( $LOCK_FILE ); + close($LOCK_FILE); exit -1; } } @@ -194,7 +194,7 @@ sub check_pid { # create a syslog msg if it is not to possible to open PID file if (not sysopen(LOCK_FILE, $pid_file, O_WRONLY|O_CREAT|O_EXCL, 0644)) { my($msg) = "Couldn't obtain lockfile '$pid_file' "; - if (open($LOCK_FILE, '<', $pid_file) + if (open(my $LOCK_FILE, '<', $pid_file) && ($pid = <$LOCK_FILE>)) { chomp($pid); @@ -334,7 +334,7 @@ sub get_local_mac_for_remote_ip { if($server_ip =~ /^(\d\d?\d?\.){3}\d\d?\d?$/) { my $PROC_NET_ROUTE= ('/proc/net/route'); - open($PROC_NET_ROUTE, "<","$PROC_NET_ROUTE") + open(my $PROC_NET_ROUTE, "<","$PROC_NET_ROUTE") or die "Could not open $PROC_NET_ROUTE"; my @ifs = <$PROC_NET_ROUTE>; @@ -505,7 +505,7 @@ sub write_to_file { chomp($string); - if (open($FILE, ">>", "$file")){ + if (open(my $FILE, ">>", "$file")){ print $FILE $string."\n"; close($FILE); } @@ -828,7 +828,7 @@ sub trigger_seen_messages { # Check if file has 'seen' tag foreach my $goto_file (@goto_files) { - open($FILE, "$goto_dir/$goto_file"); + open(my $FILE, "$goto_dir/$goto_file"); my @lines = <$FILE>; close($FILE); @@ -994,7 +994,7 @@ sub save_fai_log { next; } - open($FILE, "<","$log_file"); + open(my $FILE, "<","$log_file"); my @lines = <$FILE> ; close ($FILE); my $log_string = join("", @lines); @@ -1161,7 +1161,7 @@ if( ! $foreground ) { # Do something useful - put our PID into the pid_file if( 0 != $pid ) { - open( $LOCK_FILE, ">","$pid_file" ); + open( my $LOCK_FILE, ">", "$pid_file" ); print $LOCK_FILE "$pid\n"; close( $LOCK_FILE ); if( !$foreground ) { diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index e820b2494..255fa3391 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -454,7 +454,7 @@ sub check_cmdline_param () { sub check_pid { $pid = -1; # Check, if we are already running - if( open($LOCK_FILE, "<","$pid_file") ) { + if( open( my $LOCK_FILE, "<", "$pid_file" ) ) { $pid = <$LOCK_FILE>; if( defined $pid ) { chomp( $pid ); @@ -474,7 +474,7 @@ sub check_pid { # create a syslog msg if it is not to possible to open PID file if (not sysopen(LOCK_FILE, $pid_file, O_WRONLY|O_CREAT|O_EXCL, 0644)) { my($msg) = "Couldn't obtain lockfile '$pid_file' "; - if (open($LOCK_FILE, '<', $pid_file) + if (open(my $LOCK_FILE, '<', $pid_file) && ($pid = <$LOCK_FILE>)) { chomp($pid); @@ -2880,7 +2880,7 @@ sub create_sources_list { } my $fh; - open($fh, ">","$result"); + open(my $fh, ">", "$result"); if (not defined $fh) { &main::daemon_log("$session_id DEBUG: cannot open '$result' for writing", 7); return undef; @@ -2963,7 +2963,7 @@ sub create_packages_list_db { my $line; - open($CONFIG, "<","$sources_file") or do { + open(my $CONFIG, "<", "$sources_file") or do { daemon_log( "$session_id ERROR: create_packages_list_db: Failed to open '$sources_file'", 1); unlink($packages_list_under_construction); return; @@ -3193,7 +3193,7 @@ sub parse_package { return; } - open($PACKAGES, "<","$path.in"); + open(my $PACKAGES, "<", "$path.in"); if(not defined($PACKAGES)) { daemon_log("$session_id ERROR: create_packages_list_db: parse_package: cannot open '$path.in'",1); return; @@ -3284,8 +3284,8 @@ sub cleanup_and_extract { my $tmpl= ""; { local $/=undef; - open($FILE, "$dir/DEBIAN/templates"); - $tmpl = &encode_base64(); + open(my $FILE, "$dir/DEBIAN/templates"); + $tmpl = &encode_base64(<$FILE>); close($FILE); } rmtree("$dir/DEBIAN/templates"); @@ -3496,7 +3496,7 @@ if( ! $foreground ) { # Do something useful - put our PID into the pid_file if( 0 != $pid ) { - open( $LOCK_FILE, ">","$pid_file" ); + open( my $LOCK_FILE, ">", "$pid_file" ); print $LOCK_FILE "$pid\n"; close( $LOCK_FILE ); if( !$foreground ) { @@ -3518,7 +3518,7 @@ if ($server_headURL =~ /\/tag\// || # Prepare log file and set permissions $root_uid = getpwnam('root'); $adm_gid = getgrnam('adm'); -open($FH, ">>","$log_file"); +open(my $FH, ">>", "$log_file"); close($FH); chmod(0440, $log_file); chown($root_uid, $adm_gid, $log_file); diff --git a/gosa-si/modules/ArpHandler.pm b/gosa-si/modules/ArpHandler.pm index bed05ab3b..c19fc4b8d 100644 --- a/gosa-si/modules/ArpHandler.pm +++ b/gosa-si/modules/ArpHandler.pm @@ -1,7 +1,5 @@ package ArpHandler; - - use strict; use warnings; diff --git a/gosa-si/modules/ClientPackages.pm b/gosa-si/modules/ClientPackages.pm index 8fc6318bc..b9d4ff8a9 100644 --- a/gosa-si/modules/ClientPackages.pm +++ b/gosa-si/modules/ClientPackages.pm @@ -452,7 +452,7 @@ sub here_i_am { if ( defined($msg_hash->{'force-hostname'}[0]) && length($msg_hash->{'force-hostname'}[0]) > 0){ # $heap->{force-hostname}->{$mac_address}= $msg_hash->{'force-hostname'}[0]; - open ($TFILE, ">", "/var/tmp/$mac_address"); + open (my $TFILE, ">", "/var/tmp/$mac_address"); print $TFILE $msg_hash->{'force-hostname'}[0]; close ($TFILE); } else { @@ -1082,7 +1082,7 @@ sub server_matches { } else { my $PROC_NET_ROUTE= ('/proc/net/route'); - open($FD_PROC_NET_ROUTE, "<", "$PROC_NET_ROUTE") + open(my $FD_PROC_NET_ROUTE, "<", "$PROC_NET_ROUTE") or die "Could not open $PROC_NET_ROUTE"; my @ifs = <$FD_PROC_NET_ROUTE>; diff --git a/gosa-si/modules/GosaSupportDaemon.pm b/gosa-si/modules/GosaSupportDaemon.pm index 14e755aea..1e6429b9d 100644 --- a/gosa-si/modules/GosaSupportDaemon.pm +++ b/gosa-si/modules/GosaSupportDaemon.pm @@ -513,7 +513,7 @@ sub get_orderby_statement { sub get_dns_domains() { my $line; my @searches; - open($RESOLV, "<", "/etc/resolv.conf") or return @searches; + open(my $RESOLV, "<", "/etc/resolv.conf") or return @searches; while(<$RESOLV>){ $line= $_; chomp $line; @@ -726,7 +726,7 @@ sub get_interfaces { my @result; my $PROC_NET_DEV= ('/proc/net/dev'); - open($FD_PROC_NET_DEV, "<", "$PROC_NET_DEV") + open(my $FD_PROC_NET_DEV, "<", "$PROC_NET_DEV") or die "Could not open $PROC_NET_DEV"; my @ifs = <$FD_PROC_NET_DEV>; @@ -754,7 +754,7 @@ sub get_local_ip_for_remote_ip { if($remote_ip =~ /^(\d\d?\d?\.){3}\d\d?\d?$/) { my $PROC_NET_ROUTE= ('/proc/net/route'); - open($FD_PROC_NET_ROUTE, "<", "$PROC_NET_ROUTE") + open(my $FD_PROC_NET_ROUTE, "<", "$PROC_NET_ROUTE") or die "Could not open $PROC_NET_ROUTE"; my @ifs = <$FD_PROC_NET_ROUTE>; @@ -858,7 +858,7 @@ sub run_as { &main::daemon_log("ERROR: The sudo utility is not available! Please fix this!"); } my $cmd_line= "$sudo_cmd su - $uid -c '$command'"; - open($PIPE, "$cmd_line |"); + open(my $PIPE, "$cmd_line |"); my $result = {'command' => $cmd_line}; push @{$result->{'output'}}, <$PIPE>; close($PIPE); diff --git a/gosa-si/modules/ServerPackages.pm b/gosa-si/modules/ServerPackages.pm index b008d01a9..4a1d1a140 100644 --- a/gosa-si/modules/ServerPackages.pm +++ b/gosa-si/modules/ServerPackages.pm @@ -1,15 +1,18 @@ package ServerPackages; -use Exporter; -@ISA = ("Exporter"); + # Each module has to have a function 'process_incoming_msg'. This function works as a interface to gosa-sd and receives the msg hash from gosa-sd. 'process_incoming_function checks, wether it has a function to process the incoming msg and forward the msg to it. use strict; use warnings; + +use Exporter; use GOSA::GosaSupportDaemon; use Data::Dumper; +@ISA = ("Exporter"); + my $event_dir = "/usr/lib/gosa-si/server/ServerPackages"; use lib "/usr/lib/gosa-si/server/ServerPackages"; -- 2.30.2