From bc098fdb0c24e8535ee79390e66d3ec1fb6ed56e Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Mon, 10 Sep 2012 14:36:26 -0700 Subject: [PATCH] Complete saving of config options --- iscsi-server/atboot.cgi | 8 ++++---- iscsi-server/iscsi-server-lib.pl | 32 ++++++++++++++++++++++---------- iscsi-server/save_opts.cgi | 6 ++++-- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/iscsi-server/atboot.cgi b/iscsi-server/atboot.cgi index f14071caf..5240df62b 100644 --- a/iscsi-server/atboot.cgi +++ b/iscsi-server/atboot.cgi @@ -12,10 +12,10 @@ our (%text, %config, %in); my $old = &init::action_status($config{'init_name'}); if ($old != 2 && $in{'boot'}) { # Enable at boot - if (!-r $config{'opts_file'}) { - my $fh = "OPTS"; - &open_tempfile($fh, ">$config{'opts_file'}"); - &close_tempfile($fh); + my $str = &get_iscsi_options_string(); + if (!$str) { + # Force creation of environment variable file + &save_iscsi_options_string(""); } &init::enable_at_boot($config{'init_name'}, "Start or stop the iSCSI server", diff --git a/iscsi-server/iscsi-server-lib.pl b/iscsi-server/iscsi-server-lib.pl index 62a85e6c2..1ee202719 100644 --- a/iscsi-server/iscsi-server-lib.pl +++ b/iscsi-server/iscsi-server-lib.pl @@ -375,6 +375,13 @@ foreach my $n (@names) { return @rv; } +# get_iscsi_options_file() +# Returns the file containing command-line options, for use when locking +sub get_iscsi_options_file +{ +return $config{'opts_file'}; +} + # get_iscsi_options_string() # Returns all flags as a string sub get_iscsi_options_string @@ -408,8 +415,21 @@ while($str =~ /\S/) { return \%opts; } +# save_iscsi_options_string(str) +# Update the options file with command line options from a string +sub save_iscsi_options_string +{ +my ($str) = @_; +my %env; +&lock_file($config{'opts_file'}); +&read_env_file($config{'opts_file'}, \%env); +$env{'NETBSD_ISCSI_OPTS'} = $str; +&write_env_file($config{'opts_file'}, \%env); +&unlock_file($config{'opts_file'}); +} + # save_iscsi_options(&opts) -# Update the options file or init script and built-in config +# Update the options file with command line options from a hash sub save_iscsi_options { my ($opts) = @_; @@ -422,15 +442,7 @@ foreach my $o (keys %$opts) { push(@str, "-".$o." ".$opts->{$o}); } } -my $str = join(" ", @str); - -# Save in an environment file -my %env; -&lock_file($config{'opts_file'}); -&read_env_file($config{'opts_file'}, \%env); -$env{'NETBSD_ISCSI_OPTS'} = $str; -&write_env_file($config{'opts_file'}, \%env); -&unlock_file($config{'opts_file'}); +&save_iscsi_options_string(join(" ", @str)); } 1; diff --git a/iscsi-server/save_opts.cgi b/iscsi-server/save_opts.cgi index afb1f70de..d474fc3ae 100644 --- a/iscsi-server/save_opts.cgi +++ b/iscsi-server/save_opts.cgi @@ -4,9 +4,11 @@ use strict; use warnings; require './iscsi-server-lib.pl'; -our (%text, %config); +our (%text, %config, %in); +&ReadParse(); &error_setup($text{'opts_err'}); +&lock_file(&get_iscsi_options_file()); my $opts = &get_iscsi_options(); # IPv4 enabled? @@ -55,8 +57,8 @@ else { $opts->{'s'} = $in{'sess'}; } -# XXX locking? &save_iscsi_options($opts); +&unlock_file(&get_iscsi_options_file()); &webmin_log("opts"); &redirect("");