diff options
| author | jdennis <jdennis@c9f7a03b-bd48-0410-a16d-cbbf54688b0b> | 2010-11-19 20:37:51 +0000 |
|---|---|---|
| committer | jdennis <jdennis@c9f7a03b-bd48-0410-a16d-cbbf54688b0b> | 2010-11-19 20:37:51 +0000 |
| commit | 6f05385c5d658a107cc5ff787436bffd9727f865 (patch) | |
| tree | 21ca58366afbf1efd1bb5b35e75007eb4a2d9f11 | |
| parent | 8a52e6243118380c747a6bea76431a21cb4ece6a (diff) | |
| download | pki-6f05385c5d658a107cc5ff787436bffd9727f865.tar.gz pki-6f05385c5d658a107cc5ff787436bffd9727f865.tar.xz pki-6f05385c5d658a107cc5ff787436bffd9727f865.zip | |
Remove pointless no-op string interpolations
Constructs such as
"$variable"
when $variable is already a string are no-op waste of processor cycles
and confusing to read. Just use the variable.
Explanation:
Perl performs variable substitutions on all double quoted strings,
this is called string interpolation. To do this Perl scans the string
looking for anything that looks like a variable and substitutes it's
current value. But when the string consists of nothing other than a
variable (e.g. "$variable") the result is the same as the variable,
effectively it's just a no-op. I'm not sure if the interpreter is
smart enough to recognize this as a no-op and skip the interpolation,
irregardless there is no point in coding it this way.
It eludes me as to what the programmer thought they were accomplishing
when they wrote "$variable".
git-svn-id: svn+ssh://svn.fedorahosted.org/svn/pki/trunk@1542 c9f7a03b-bd48-0410-a16d-cbbf54688b0b
| -rwxr-xr-x | pki/base/setup/pkicommon | 98 | ||||
| -rwxr-xr-x | pki/base/setup/pkicreate | 58 | ||||
| -rwxr-xr-x | pki/base/setup/pkiremove | 16 |
3 files changed, 86 insertions, 86 deletions
diff --git a/pki/base/setup/pkicommon b/pki/base/setup/pkicommon index bb0df492..bdff5e25 100755 --- a/pki/base/setup/pkicommon +++ b/pki/base/setup/pkicommon @@ -36,7 +36,7 @@ my $perl_version_error_message = "ERROR: Using Perl version $] ...\n" . "$MINIMUM_PERL_VERSION or later to " . "run this script!\n"; -die "$perl_version_error_message" if $] < $MINIMUM_PERL_VERSION; +die $perl_version_error_message if $] < $MINIMUM_PERL_VERSION; ############################################################## @@ -47,7 +47,7 @@ die "$perl_version_error_message" if $] < $MINIMUM_PERL_VERSION; # invocation directory has not been deleted! my $cwd = `/bin/pwd`; chomp $cwd; -if ("$cwd" eq "") { +if ($cwd eq "") { print(STDERR "Cannot invoke '$0' from non-existent directory!\n"); print(STDOUT "\n"); exit 255; @@ -880,7 +880,7 @@ sub create_user . "-c 'Certificate System' " . "-u $PKI_UID " . "-r " - . "$username"; + . $username; } elsif ($^O eq "solaris") { $command = "/usr/sbin/useradd " . "-g $groupname " @@ -888,7 +888,7 @@ sub create_user . "-s /bin/false " . "-c 'Certificate System' " . "-u $PKI_UID " - . "$username"; + . $username; } else { $command = "/usr/sbin/useradd " . "-g $groupname " @@ -896,7 +896,7 @@ sub create_user . "-s '' " . "-c 'Certificate System' " . "-u $PKI_UID " - . "$username"; + . $username; } } else { # Attempt to create $username with random UID @@ -908,27 +908,27 @@ sub create_user . "-d /usr/share/pki " . "-s /sbin/nologin " . "-c 'Certificate System' " - . "$username"; + . $username; } elsif ($^O eq "solaris") { $command = "/usr/sbin/useradd " . "-g $groupname " . "-d /usr/share/pki " . "-s /bin/false " . "-c 'Certificate System' " - . "$username"; + . $username; } else { $command = "/usr/sbin/useradd " . "-g $groupname " . "-d /usr/share/pki " . "-s '' " . "-c 'Certificate System' " - . "$username"; + . $username; } } $report = `$command`; if ($report ne "") { - emit("$report", "error"); + emit($report, "error"); } $result = user_exists($username); @@ -973,15 +973,15 @@ sub create_group $command = "/usr/sbin/groupadd " . "-g $PKI_GID " . "-r " - . "$groupname"; + . $groupname; } elsif ($^O eq "solaris") { $command = "/usr/sbin/groupadd " . "-g $PKI_GID " - . "$groupname"; + . $groupname; } else { $command = "/usr/sbin/groupadd " . "-g $PKI_GID " - . "$groupname"; + . $groupname; } } else { # Attempt to create $groupname with random GID @@ -989,19 +989,19 @@ sub create_group . "(gid=random) to '/etc/group'.\n", "debug"); if ($^O eq "linux") { $command = "/usr/sbin/groupadd " - . "$groupname"; + . $groupname; } elsif ($^O eq "solaris") { $command = "/usr/sbin/groupadd " - . "$groupname"; + . $groupname; } else { $command = "/usr/sbin/groupadd " - . "$groupname"; + . $groupname; } } $report = `$command`; if ($report ne "") { - emit("$report", "error"); + emit($report, "error"); } $result = group_exists($groupname); @@ -1114,20 +1114,20 @@ sub add_user_as_a_member_of_group if ($^O eq "linux") { $command = "/usr/sbin/usermod " . "-G $groupname " - . "$username"; + . $username; } elsif ($^O eq "solaris") { $command = "/usr/sbin/usermod " . "-G $groupname " - . "$username"; + . $username; } else { $command = "/usr/sbin/usermod " . "-G $groupname " - . "$username"; + . $username; } $report = `$command`; if ($report ne "") { - emit("$report", "error"); + emit($report, "error"); } else { # successfully added user to be a member of group $result = 1; @@ -1195,12 +1195,12 @@ sub check_for_valid_url_prefix { my ($url_prefix) = @_; - if (("$url_prefix" eq $FILE_PREFIX) || - ("$url_prefix" eq $FTP_PREFIX) || - ("$url_prefix" eq $HTTP_PREFIX) || - ("$url_prefix" eq $HTTPS_PREFIX) || - ("$url_prefix" eq $LDAP_PREFIX) || - ("$url_prefix" eq $LDAPS_PREFIX)) { + if (($url_prefix eq $FILE_PREFIX) || + ($url_prefix eq $FTP_PREFIX) || + ($url_prefix eq $HTTP_PREFIX) || + ($url_prefix eq $HTTPS_PREFIX) || + ($url_prefix eq $LDAP_PREFIX) || + ($url_prefix eq $LDAPS_PREFIX)) { return 1; } @@ -1384,7 +1384,7 @@ sub IsServerReachable } # create a URL from the passed-in parameters - my $url = $prefix . "$host" . ":" . "$port"; + my $url = $prefix . $host . ":" . $port; # initialize the state of the Server referred to by this URL my $rv = 0; @@ -1580,7 +1580,7 @@ sub LDAP_add . "-a " . "-f '$file'"; - system("$command"); + system($command); set_library_path($original_library_path); @@ -1613,7 +1613,7 @@ sub LDAP_modify . "-w '$tokendb_password' " . "-f '$file'"; - system("$command"); + system($command); set_library_path($original_library_path); @@ -1641,7 +1641,7 @@ sub certutil_create_databases . $default_system_libraries . $path_sep . $original_library_path); - if ("$pwdfile" eq "") { + if ($pwdfile eq "") { $command = "$default_certutil_command " . "-N " . "-d $instance_path"; @@ -1652,7 +1652,7 @@ sub certutil_create_databases . "-f $pwdfile"; } - system("$command"); + system($command); set_library_path($original_library_path); @@ -1684,7 +1684,7 @@ sub certutil_delete_cert . "-h '$token' " . "-n '$nickname'"; - system("$command"); + system($command); set_library_path($original_library_path); @@ -1710,7 +1710,7 @@ sub certutil_generate_CSR . $default_system_libraries . $path_sep . $original_library_path); - if ("$pwdfile" eq "") { + if ($pwdfile eq "") { $command = "$default_certutil_command " . "-R " . "-d $instance_path " @@ -1727,7 +1727,7 @@ sub certutil_generate_CSR . "-f $pwdfile"; } - system("$command"); + system($command); set_library_path($original_library_path); @@ -1771,7 +1771,7 @@ sub certutil_generate_self_signed_cert . $default_system_libraries . $path_sep . $original_library_path); - if ("$pwdfile" eq "") { + if ($pwdfile eq "") { $command = "$default_certutil_command " . "-S " . "-d $instance_path " @@ -1804,7 +1804,7 @@ sub certutil_generate_self_signed_cert . "2>&1"; } - system("$command"); + system($command); set_library_path($original_library_path); @@ -1890,7 +1890,7 @@ sub certutil_print_cert . "-n '$nickname'"; } - system("$command"); + system($command); set_library_path($original_library_path); @@ -1920,7 +1920,7 @@ sub certutil_list_certs . "-d $instance_path " . "-h '$token'"; - system("$command"); + system($command); set_library_path($original_library_path); @@ -1982,8 +1982,8 @@ sub print_to_logfile { my ($logfile_name, $message) = @_; - if ("$logfile_name" ne "") { - $logfd->print("$message"); + if ($logfile_name ne "") { + $logfd->print($message); } return; @@ -1995,7 +1995,7 @@ sub close_logfile { my ($logfile_name) = @_; - if ("$logfile_name" ne "") { + if ($logfile_name ne "") { $logfd->close(); } @@ -2079,7 +2079,7 @@ sub emit # ("debug", "error", "info", or "log") # to this specified log file $log_entry = "[$stamp] [$type] $string"; - print_to_logfile("$logfile", "$log_entry"); + print_to_logfile($logfile, $log_entry); return; } @@ -2253,18 +2253,18 @@ sub create_file $command = ""; if (is_Windows()) { - if ("$message" eq "") { + if ($message eq "") { open(FILE, "> $file"); close(FILE); } else { open(FILE, "> $file"); - print(FILE "$message"); + print(FILE $message); close(FILE); } } else { my $rv = 0; - if ("$message" eq "") { + if ($message eq "") { $rv = `touch $file`; if (!$rv) { emit("create_file(): unable to create empty file called " @@ -2274,7 +2274,7 @@ sub create_file } else { $command = "echo '$message' > $file"; - system("$command"); + system($command); } } @@ -3141,7 +3141,7 @@ if ($^O eq "linux") { @chkconfig_fields = split(' ', $line); # determine instance runlevel - if (("$chkconfig_fields[2]" ne "$DEFAULT_RUNLEVEL") && + if (("$chkconfig_fields[2]" ne $DEFAULT_RUNLEVEL) && (substr("$chkconfig_fields[2]", 0) != "0") && (substr("$chkconfig_fields[2]", 0) != "1") && (substr("$chkconfig_fields[2]", 0) != "2") && @@ -3183,7 +3183,7 @@ if ($^O eq "linux") { . "--add" . " " . $pki_instance_name; - system("$command"); + system($command); emit("Registered '$pki_instance_name' with '/sbin/chkconfig'.\n"); } @@ -3200,7 +3200,7 @@ if ($^O eq "linux") { . "--del" . " " . $pki_instance_name; - system("$command"); + system($command); } } diff --git a/pki/base/setup/pkicreate b/pki/base/setup/pkicreate index cfbdb1eb..dbd7a2f6 100755 --- a/pki/base/setup/pkicreate +++ b/pki/base/setup/pkicreate @@ -54,7 +54,7 @@ my $perl_version_error_message = "ERROR: Using Perl version $] ...\n" . "$MINIMUM_PERL_VERSION or later to " . "run this script!\n"; -die "$perl_version_error_message" if $] < $MINIMUM_PERL_VERSION; +die $perl_version_error_message if $] < $MINIMUM_PERL_VERSION; ############################################################## @@ -68,7 +68,7 @@ umask 00002; # invocation directory has not been deleted! my $cwd = `/bin/pwd`; chomp $cwd; -if ("$cwd" eq "") { +if ($cwd eq "") { print(STDERR "Cannot invoke '$0' from non-existent directory!\n"); print(STDOUT "\n"); exit 255; @@ -137,7 +137,7 @@ $pki_flavor =~ s/\s+$//g; my $pki_subsystem_common_area = "/usr/share/$pki_flavor"; my $common_path = "/usr/share/$pki_flavor/scripts"; -if (! -d "$common_path") { +if (! -d $common_path) { print(STDERR "ERROR: The path '$common_path' does not exist!\n" . " Unable to load shared Common Perl Data " @@ -1124,7 +1124,7 @@ sub parse_arguments() $pki_subsystem_path = $pki_subsystem_common_area . "/" . $subsystem_type; - if (!(-d "$pki_subsystem_path")) { + if (!(-d $pki_subsystem_path)) { usage(); emit("$pki_subsystem_path not present. " . "Please install the corresponding subsystem RPM first!\n", @@ -1353,7 +1353,7 @@ sub parse_arguments() } - # At this point in time, ALWAYS check that "$pki_group" exists! + # At this point in time, ALWAYS check that $pki_group exists! if (!group_exists($pki_group)) { if (!create_group($pki_group)) { usage(); @@ -1387,7 +1387,7 @@ sub parse_arguments() } - # At this point in time, ALWAYS check that "$pki_user" exists! + # At this point in time, ALWAYS check that $pki_user exists! if (!user_exists($pki_user)) { if (!create_user($pki_user, $pki_group)) { usage(); @@ -1398,7 +1398,7 @@ sub parse_arguments() } - # At this point in time, ALWAYS check that shell access for "$pki_user" is + # At this point in time, ALWAYS check that shell access for $pki_user is # disallowed; for now, simply notify the user performing the installation # and continue if (!user_disallows_shell($pki_user)) { @@ -1407,8 +1407,8 @@ sub parse_arguments() } - # At this point in time, ALWAYS check that "$pki_user" - # is a valid member of "$pki_group" + # At this point in time, ALWAYS check that $pki_user + # is a valid member of $pki_group # # NOTE: Uncomment the following code to enforce a strict policy of # requiring $pki_user to be a member of $pki_group . . . @@ -1421,8 +1421,8 @@ sub parse_arguments() # } - # At this point in time, ALWAYS attempt to add "$pki_user" as a - # valid member of "$default_nfast_group" (presuming one exists) + # At this point in time, ALWAYS attempt to add $pki_user as a + # valid member of $default_nfast_group (presuming one exists) if (group_exists($default_nfast_group)) { # Ignore failures as this should be considered a 'benign' error if (add_user_as_a_member_of_group($pki_user, @@ -1938,15 +1938,15 @@ sub process_pki_directories() . "/" . $pki_cfg_base_name; if ($subsystem_type eq $RA || $subsystem_type eq $TPS) { - $httpd_conf_instance_file_path = "$conf_instance_path" + $httpd_conf_instance_file_path = $conf_instance_path . "/" . $httpd_conf_base_name; - $magic_instance_file_path = "$conf_instance_path" + $magic_instance_file_path = $conf_instance_path . "/" . $magic_base_name; $mime_types_instance_file_path = $conf_instance_path . "/" . $mime_types_base_name; - $nss_conf_instance_file_path = "$conf_instance_path" + $nss_conf_instance_file_path = $conf_instance_path . "/" . $nss_conf_base_name; - $perl_conf_instance_file_path = "$conf_instance_path" + $perl_conf_instance_file_path = $conf_instance_path . "/" . $perl_conf_base_name; $pwcache_conf_instance_file_path = $conf_instance_path . "/" . $pwcache_conf_base_name; @@ -2008,15 +2008,15 @@ sub process_pki_directories() # Populate optionally redirected instance directory path # and setup a symlink in the standard area if ($subsystem_type eq $RA || $subsystem_type eq $TPS) { - $httpd_conf_instance_file_path = "$redirected_conf_path" + $httpd_conf_instance_file_path = $redirected_conf_path . "/" . $httpd_conf_base_name; - $magic_instance_file_path = "$redirected_conf_path" + $magic_instance_file_path = $redirected_conf_path . "/" . $magic_base_name; $mime_types_instance_file_path = $redirected_conf_path . "/" . $mime_types_base_name; - $nss_conf_instance_file_path = "$redirected_conf_path" + $nss_conf_instance_file_path = $redirected_conf_path . "/" . $nss_conf_base_name; - $perl_conf_instance_file_path = "$redirected_conf_path" + $perl_conf_instance_file_path = $redirected_conf_path . "/" . $perl_conf_base_name; $pwcache_conf_instance_file_path = $redirected_conf_path . "/" . $pwcache_conf_base_name; @@ -2392,7 +2392,7 @@ sub process_file_template # used for initialization, for consistency, as with ALL # other password/pin values (with one notable EXCEPTION), # the word "(sensitive)" is printed out rather than the - # contents of "$value". + # contents of $value. emit(" replacing: $key with: (sensitive)\n"); } else { emit(" replacing: $key with: $value\n"); @@ -3364,9 +3364,9 @@ sub build_pki_registry_subsystem_path() $pki_registry_subsystem_path = $pki_registry_path . "/" . $subsystem_type; - if (!directory_exists("$pki_registry_subsystem_path")) { + if (!directory_exists($pki_registry_subsystem_path)) { # create pki registry for this subsystem - $result = create_directory("$pki_registry_subsystem_path"); + $result = create_directory($pki_registry_subsystem_path); if (!$result) { emit("Failed to create directory " . "$pki_registry_subsystem_path ...\n"); @@ -3827,7 +3827,7 @@ sub process_pki_selinux_setup() my $pidfile = "/var/run/${pki_instance_name}.pid"; if ($pki_instance_name ne $default_inst_name) { &add_selinux_file_context($setype . "_var_run_t", - "$pidfile", "f"); + $pidfile, "f"); } if (-e $pidfile) { emit("Restorecon file context for $pidfile\n"); @@ -3919,11 +3919,11 @@ sub install_pki_instance() emit("Installing PKI instance ...\n"); - if (!directory_exists("$pki_instance_path")) { - $result = create_directory("$pki_instance_path"); + if (!directory_exists($pki_instance_path)) { + $result = create_directory($pki_instance_path); push(@installed_stray_directories, - "$pki_instance_path"); + $pki_instance_path); if (!$result) { return 0; } @@ -4036,7 +4036,7 @@ sub cleanup() "\n\nPKI instance creation Cleanup Utility " . "cleaning up on error ...\n\n"); - $result = remove_directory("$pki_instance_path"); + $result = remove_directory($pki_instance_path); my $size = @installed_files; @@ -4176,9 +4176,9 @@ ASK_AGAIN: . " " . $pki_instance_name; } - $command = "$pki_init_script_command"; + $command = $pki_init_script_command; - system("$command"); + system($command); # Notify user to check firewall settings . . . print(STDOUT diff --git a/pki/base/setup/pkiremove b/pki/base/setup/pkiremove index 498f197f..88873ff2 100755 --- a/pki/base/setup/pkiremove +++ b/pki/base/setup/pkiremove @@ -48,7 +48,7 @@ my $perl_version_error_message = "ERROR: Using Perl version $] ...\n" . "$MINIMUM_PERL_VERSION or later to " . "run this script!\n"; -die "$perl_version_error_message" if $] < $MINIMUM_PERL_VERSION; +die $perl_version_error_message if $] < $MINIMUM_PERL_VERSION; ############################################################## @@ -59,7 +59,7 @@ die "$perl_version_error_message" if $] < $MINIMUM_PERL_VERSION; # invocation directory has not been deleted! my $cwd = `/bin/pwd`; chomp $cwd; -if ("$cwd" eq "") { +if ($cwd eq "") { print(STDERR "Cannot invoke '$0' from non-existent directory!\n"); print(STDOUT "\n"); exit 255; @@ -107,7 +107,7 @@ $pki_flavor =~ s/\s+$//g; # Establish path to scripts my $common_path = "/usr/share/pki/scripts"; -if (! -d "$common_path") { +if (! -d $common_path) { print(STDERR "ERROR: The path '$common_path' does not exist!\n" . " Unable to load shared Common Perl Data " @@ -257,7 +257,7 @@ sub update_domain() } close(DAT); - # NOTE: Don't check for the existence of "$httpport", as this will + # NOTE: Don't check for the existence of $httpport, as this will # be undefined for a Security Domain that has been migrated! if ((!defined($sechost)) || (!defined($seceeport)) || @@ -547,7 +547,7 @@ ASK_AGAIN: goto ASK_AGAIN; } - if (!file_exists("$source_file_path")) { + if (!file_exists($source_file_path)) { print(STDERR "ERROR: Can't remove instance, " . "cleanup file does not exist!\n"); @@ -675,9 +675,9 @@ ASK_AGAIN: } } - $command = "$pki_init_script_command"; + $command = $pki_init_script_command; - system("$command"); + system($command); my $size = @directories; @@ -778,7 +778,7 @@ sub main() $pki_instance_path = "${pki_instance_root}/${pki_instance_name}"; - if (!directory_exists("$pki_instance_path")) { + if (!directory_exists($pki_instance_path)) { print(STDERR "$0: Target directory $pki_instance_path " . "is not a legal directory.\n\n"); |
