Code

- More open fixes, add missing my in front of filehandle variable
authoropensides <opensides@594d385d-05f5-0310-b6e9-bd551577e9d8>
Sun, 28 Mar 2010 00:21:19 +0000 (00:21 +0000)
committeropensides <opensides@594d385d-05f5-0310-b6e9-bd551577e9d8>
Sun, 28 Mar 2010 00:21:19 +0000 (00:21 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@17331 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-si/client/events/corefunctions.pm
gosa-si/client/events/dak.pm
gosa-si/client/events/gosaTriggered.pm
gosa-si/client/events/installation.pm
gosa-si/client/events/load_reporter.pm
gosa-si/gosa-si-client
gosa-si/gosa-si-server
gosa-si/modules/ArpHandler.pm
gosa-si/modules/ClientPackages.pm
gosa-si/modules/GosaSupportDaemon.pm
gosa-si/modules/ServerPackages.pm

index 016e6b888ee0d91d2c9b5db40be6d84c885fdbb8..a25aa98cb89f3ed1fbffa3cf949979c768ab1ad1 100644 (file)
@@ -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";
index 57c2f85337f769dfd0f322f4ebe3e62310f26f09..b6a0a6883c3e7e0797743fbbb543a38ea4a25396 100644 (file)
@@ -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";
index 3b6f9678a23f141028684689f622d4b3d828451c..fb7c8f8926bc296fcc97805b7ceec1de00f8fb77 100644 (file)
@@ -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);
                }
index 700adc5a193870f0eaf93fa0ff17b122f0503931..ecd9204fdf945a3452d5eae0b0cb66cfc58a71f9 100644 (file)
@@ -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;
 }
index 9227b729c1c123c454837dbb4c5e735f3d27f5ed..b9cb41e7b52483e1d22d127d64bcdbda574d2bf6 100644 (file)
@@ -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);
 
index 49756c38aedf229af59aead2afeac0d026a629c9..0ffe6e15867442010667644fdf8e93e45a22a9ba 100755 (executable)
@@ -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 ) { 
index e820b24940a2ad25dddadef16ac358b9433da52b..255fa3391de4ed93aac794f748b6d230a4378c53 100755 (executable)
@@ -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(<FILE>);
+                               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);
index bed05ab3baee2c54c6683b43e4d154202e37cd50..c19fc4b8d94d2240d8b86bd74ba6b705284d66b3 100644 (file)
@@ -1,7 +1,5 @@
 package ArpHandler;
 
-
-
 use strict;
 use warnings;
 
index 8fc6318bcf69b87dfd021adf2558e858c0eed3e4..b9d4ff8a9c09baee90cdcf40088243e65de6b2e8 100644 (file)
@@ -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>;
index 14e755aea245aefbb33d4f8df7d8f3dd6ca2c6a2..1e6429b9d156502a6f52c3fd0788334e15ab7e01 100644 (file)
@@ -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);
index b008d01a9fc5b8549cf70f7113da2fc13eb42779..4a1d1a1400af047eb2680fb95d72793c4b0f6b41 100644 (file)
@@ -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";