diff options
author | carlosg <carlosg> | 2006-08-11 16:25:56 +0000 |
---|---|---|
committer | carlosg <carlosg> | 2006-08-11 16:25:56 +0000 |
commit | 78bba5b089f04bd61f4fb0a6bd2df90bfe49eec5 (patch) | |
tree | 7264adff6f02eb4f266783aaac6baf794891518b /Utils | |
parent | 8ed7927e834be83087c40fb69dcd65c9c9885ec1 (diff) |
2006-08-11 Carlos Garnacho <carlosg@gnome.org>
* Init/ServicesList.pm: add postgresql-8.1 to the list. Ubuntu patch
* Network/Ifaces.pm (check_capi): modified Ubuntu patch. More reliable
ISDN detection on Linux.
(get_interface_replace_table) (set): hardcode serial speed to 115200.
Modified Ubuntu patch
* Utils/Backend.pm (daemonize) (set_no_daemon) (init): run daemonized
by default, add --no-daemon. Modified Ubuntu patch. Also, remove lots
of unused code
* Utils/File.pm (get_data_path): removed, no longer necessary
* Utils/Platform.pm: slight code fixes
* Utils/Replace.pm (set_ppp_options_connect): use chatscript path.
Ubuntu patch.
Thanks to the Ubuntu Folks!! (mvo and dholbach surely)
Diffstat (limited to 'Utils')
-rw-r--r-- | Utils/Backend.pm | 335 | ||||
-rw-r--r-- | Utils/File.pm | 9 | ||||
-rw-r--r-- | Utils/Platform.pm | 9 | ||||
-rw-r--r-- | Utils/Replace.pm | 2 |
4 files changed, 30 insertions, 325 deletions
diff --git a/Utils/Backend.pm b/Utils/Backend.pm index f43a135..2a6d28c 100644 --- a/Utils/Backend.pm +++ b/Utils/Backend.pm @@ -68,6 +68,7 @@ else # We should get rid of all these globals. +our $no_daemon = 0; our $prefix = ""; our $do_verbose = 0; our $do_report = 0; @@ -105,33 +106,18 @@ sub print_usage_generic end_of_usage_generic; my $usage_generic_tail =<< "end_of_usage_generic;"; - -i --interface Shows the available backend directives for interactive mode, - in XML format. + -h --help Prints this page to standard error. - Interactive mode is set when no -g, -s or -f arguments are - given. - - -d --directive <directive> Takes a \'name::arg1::arg2...::argN\' directive - value as comming from standard input in interactive mode. - - -h --help Prints this page to standard error. - - --version Prints version information to standard output. + --version Prints version information to standard output. Modifiers (specify any combination of these): + -no-daemon Does not daemonize the backend + --platform <name-ver> Overrides the detection of your platform\'s name and version, e.g. redhat-6.2. Use with care. See the documentation for a full list of supported platforms. - --disable-immediate With --set, prevents the configurator from - running any commands that make immediate changes to - the system configuration. Use with --prefix to make a - dry run that won\'t affect your configuration. - - With --get, suppresses running of non-vital external - programs that might take a long time to finish. - -p --prefix <location> Specifies a directory prefix where the configuration is looked for or stored. When storing (with --set), directories and files may be created. @@ -198,20 +184,6 @@ sub print_version # --- Initialization and finalization --- # -sub set_operation -{ - my ($tool, $operation) = @_; - - if ($tool{"operation"} ne "") - { - print STDERR "Error: You may specify only one major operation.\n\n"; - &print_usage ($tool, 1); - exit (1); - } - - $$tool{"operation"} = $operation; -} - sub set_with_param { my ($tool, $arg_name, $value) = @_; @@ -231,12 +203,12 @@ sub set_with_param $$tool{$arg_name} = $value; } -sub set_op_directive +sub set_no_daemon { - my ($tool, $directive) = @_; + my ($tool) = @_; - &set_with_param ($tool, "directive", $directive); - &set_operation ($tool, "directive"); + &set_with_param ($tool, "no-daemon", 1); + $no_daemon = 1; } sub set_prefix @@ -262,27 +234,6 @@ sub set_session_bus $session_bus = 1; } -sub merge_std_directives -{ - my ($tool) = @_; - my ($directives, $i); - my %std_directives = - ( -# platforms directive to do later. - "interface" => [ \&print_interface_directive, [], - "Print XML showing backend capabilities." ], - "end" => [ \&end_directive, [], - "Finish gracefuly and exit with success." ] - ); - - $directives = $$tool{"directives"}; - # Standard directives may be overriden. - foreach $i (keys %std_directives) - { - $$directives{$i} = $std_directives{$i} if !exists $$directives{$i}; - } -} - sub is_backend { my ($tool) = @_; @@ -314,19 +265,12 @@ sub init $tool{"version"} = $version; $tool{"description"} = $description; $tool{"directives"} = $directives; - - &merge_std_directives (\%tool); # Parse arguments. - while ($arg = shift (@args)) { - if ($arg eq "--get" || $arg eq "-g") { &set_operation (\%tool, "get"); } - elsif ($arg eq "--set" || $arg eq "-s") { &set_operation (\%tool, "set"); } - elsif ($arg eq "--filter" || $arg eq "-f") { &set_operation (\%tool, "filter"); } - elsif ($arg eq "--directive" || $arg eq "-d") { &set_op_directive (\%tool, shift @args); } - elsif ($arg eq "--interface" || $arg eq "-i") { &print_interface (\%tool, 0); } - elsif ($arg eq "--help" || $arg eq "-h") { &print_usage (\%tool, 0); } + if ($arg eq "--help" || $arg eq "-h") { &print_usage (\%tool, 0); } + elsif ($arg eq "--no-daemon" || $arg eq "-n") { &set_no_daemon (\%tool); } elsif ($arg eq "--version") { &print_version (\%tool, 0); } elsif ($arg eq "--prefix" || $arg eq "-p") { &set_prefix (\%tool, shift @args); } elsif ($arg eq "--platform") { &set_dist (\%tool, shift @args); } @@ -347,258 +291,35 @@ sub init &print_usage (\%tool, 1); } } - - # Set up subsystems. - &Utils::Report::begin (); - - return \%tool; -} -sub terminate -{ - &Utils::Report::set_threshold (-1); - exit (0); -} - -sub end_directive -{ - my ($tool) = @_; - - &Utils::Report::end (); - &Utils::XML::print_request_end (); - &terminate (); -} - - -sub print_interface_comment -{ - my ($name, $directive) = @_; - my %std_comments = - ("get" => - "Prints the current configuration to standard output, as " . - "a standalone XML document. The configuration is read from " . - "the host\'s system config files.", - - "set" => - "Updates the current configuration from a standalone XML " . - "document read from standard input. The format is the same " . - "as for the document generated with --get.", - - "filter" => - "Reads XML configuration from standard input, parses it, " . - "and writes the configurator\'s impression of it back to " . - "standard output. Good for debugging and parsing tests." - ); - - $comment = $$directive[2]; - $comment = $std_comments{$name} if (exists $std_comments{$name}); - - if ($comment) - { - &Utils::XML::print_line ("<comment>"); - &Utils::XML::print_line ($comment); - &Utils::XML::print_line ("</comment>"); - } -} - -# if $exit_code is provided (ne undef), exit with that code at the end. -sub print_interface -{ - my ($tool, $exit_code) = @_; - my ($directives, $key); - - $directives = $$tool{"directives"}; - - &Utils::XML::print_begin ("interface"); - foreach $key (sort keys %$directives) + if (!$no_daemon) { - my $comment = $ {$$directives{$key}}[2]; - my @args = @{ $ {$$directives{$key}}[1]}; - my $arg; - - &Utils::XML::container_enter ("directive"); - &Utils::XML::print_line ("<name>$key</name>"); - &print_interface_comment ($key, $$directives{$key}); - - while ($arg = shift (@args)) - { - if ($arg =~ /\*$/) - { - my $tmp = $arg; - - &Utils::Report::do_report ("directive_invalid", $key) if ($#args != -1); - chop $tmp; - &Utils::XML::print_line ("<var-arguments>$tmp</var-arguments>"); - } - else - { - &Utils::XML::print_line ("<argument>$arg</argument>"); - } - } - - &Utils::XML::container_leave (); + &daemonize (); } - &Utils::XML::print_end ("interface"); - - exit $exit_code if $exit_code ne undef; -} - - -sub print_interface_directive -{ - my ($tool) = @_; - - &Utils::Report::end (); - &print_interface ($tool); -} - - -sub directive_fail -{ - my (@report_args) = @_; - - &Utils::Report::do_report (@report_args); - &Utils::Report::end (); - &Utils::XML::print_request_end (); -} - -# This sepparates a line in args by the directive line format, -# doing the necessary escape sequence manipulations. -sub directive_parse_line -{ - my ($line) = @_; - my ($arg, @args); - - chomp $line; - $line =~ s/\\\\/___escape\\___/g; - $line =~ s/\\::/___escape2:___/g; - @args = split ("::", $line); - - foreach $arg (@args) - { - $arg =~ s/___escape2:___/::/g; - $arg =~ s/___escape\\___/\\/g; - } - - return @args; -} - -# Normal use for the direcives hash in the backends is: -# -# "name" => [ \&sub, [ "arg1", "arg2", "arg3",... "argN" ], "comment" ] -# -# name name of the directive that will be used in interactive mode. -# sub is the function that runs the directive. -# arg1...argN show the number of arguments that the function may use. The -# name of the argument is used for documentation purposes for -# the interfaces XML (dumped by the "interfaces" directive). -# An argument ending with * means that 0 or more arguments -# may be given. -# comment documents the directive in a brief way, for the interface XML. -# -# Example: -# -# "install_font" => [ \&gst_font_install, [ "directory", "file", "morefiles*" ], "Installs fonts." ] -# -# This means that when an interactive mode directive is given, such as: -# -# install_font::/usr/share/fonts::/tmp/myfile::/tmp/myfile2 -# -# the function gst_font_install will be called, with the tool structure, /usr/share/fonts, -# /tmp/myfile and /tmp/myfile2 as arguments. Directives with 1 or 0 arguments -# would be rejected, as we are requiring 2, and optionaly allowing more. -# Check enable_iface in network-conf.in for an example of a directive handler. -# -# The generated interface XML piece for this entry would be: -# -# <directive> -# <name>gst_font_install</name> -# <comment> -# Installs fonts. -# </comment> -# <argument>directory</argument> -# <argument>file</argument> -# <var-arguments>morefiles</var-arguments> -# </directive> - - -sub directive_run -{ - my ($tool, $line) = @_; - my ($key, @args, $directives, $proc, $reqargs, $i); - - ($key, @args) = &directive_parse_line ($line); - $directives = $$tool{"directives"}; + # Set up subsystems. &Utils::Report::begin (); - if (!exists $$directives{$key}) - { - &directive_fail ("directive_unsup", $key); - return; - } - - $reqargs = []; - foreach $i (@{$ {$$directives{$key}}[1]}) - { - push @$reqargs, $i if not ($i =~ /\*$/); - } - - if (scalar @args < scalar @$reqargs) - { - &directive_fail ("directive_lowargs", $key, scalar (@$reqargs), join (',', $key, @args)); - return; - } - - $reqargs = $ {$$directives{$key}}[1]; - if ((scalar @args != scalar @$reqargs) && - !($$reqargs[$#$reqargs] =~ /\*$/)) - { - &directive_fail ("directive_badargs", $key, scalar (@$reqargs), join (',', $key, @args)); - return; - } - - &Utils::Report::do_report ("directive_run", $key, join (',', @args)); - - $proc = $ {$$directives{$key}}[0]; - &$proc ($tool, @args); - - &Utils::XML::print_request_end (); + return \%tool; } - -sub run +sub daemonize { - my ($tool) = @_; - my ($line); - - if ($$tool{"operation"} ne "directive") - { - my @stdops = qw (get set filter); - my ($op); - - foreach $op (@stdops) - { - if ($$tool{"operation"} eq $op) - { - $$tool{"operation"} = "directive"; - $$tool{"directive"} = $op; - } - } - } + chdir '/' or die "Can't chdir to /: $!"; + umask 0; + open STDIN, '/dev/null' or die "Can't read /dev/null: $!"; + open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!"; + open STDERR, '>/dev/null' or die "Can't write to /dev/null: $!"; - &Utils::Report::end (); + defined (my $pid = fork) or die "Can't fork: $!"; + exit (0) if $pid; - if ($$tool{"directive"}) - { - &directive_run ($tool, $$tool{"directive"}); - &terminate (); - } + setsid or die "Can't start a new session: $!"; - while ($line = <STDIN>) - { - &directive_run ($tool, $line); - } + # write pid file + open (PIDFILE, ">/var/run/system-tools-backends.pid") or die "Can't open pidfile"; + print PIDFILE $$; + close (PIDFILE); } sub get_bus diff --git a/Utils/File.pm b/Utils/File.pm index 77f5b2e..35c05d1 100644 --- a/Utils/File.pm +++ b/Utils/File.pm @@ -56,15 +56,6 @@ sub get_backup_path return (&get_base_path () . "/backup"); } - -sub get_data_path -{ - my $path = &get_base_path (). "/data"; - chmod (0755, $path); - return $path; -} - - # Give a command, and it will put in C locale, some sane PATH values and find # the program to run in the path. Redirects stderr to null. sub do_get_cmd_path diff --git a/Utils/Platform.pm b/Utils/Platform.pm index 9cc50da..dd97eb1 100644 --- a/Utils/Platform.pm +++ b/Utils/Platform.pm @@ -46,7 +46,7 @@ my $PLATFORM_INFO = { "debian-3.1" => [ "Debian GNU/Linux", "3.1", "Sarge" ], "ubuntu-5.04" => [ "Ubuntu Linux", "5.04", "Hoary" ], "ubuntu-5.10" => [ "Ubuntu Linux", "5.10", "Breezy" ], - "ubuntu-6.04" => [ "Ubuntu Linux", "6.04", "Dapper" ], + "ubuntu-6.06" => [ "Ubuntu Linux", "6.06", "Dapper" ], "ubuntu-6.10" => [ "Ubuntu Linux", "6.10", "Edgy" ], "redhat-5.2" => [ "Red Hat Linux", "5.2", "Apollo" ], "redhat-6.0" => [ "Red Hat Linux", "6.0", "Hedwig" ], @@ -151,17 +151,10 @@ sub ensure_distro_map sub check_lsb { my ($ver, $dist); - my %distmap = - ("Debian" => "debian"), - ("Mandrake" => "mandrake"), - ("Conectiva" => "conectiva"), - ("Blackpanther" => "blackpanther"); $dist = lc (&Utils::Parse::get_sh ("/etc/lsb-release", "DISTRIB_ID")); $ver = lc (&Utils::Parse::get_sh ("/etc/lsb-release", "DISTRIB_RELEASE")); - $dist = $distmap{$dist} if exists $dirmap{$dir}; - return -1 if ($dist eq "") || ($ver eq ""); return "$dist-$ver"; } diff --git a/Utils/Replace.pm b/Utils/Replace.pm index 7c9cd66..055967c 100644 --- a/Utils/Replace.pm +++ b/Utils/Replace.pm @@ -1348,7 +1348,7 @@ sub set_ppp_options_connect &Utils::Report::enter (); &Utils::Report::do_report ("network_set_ppp_connect", $file); - $ret = &set_ppp_options_re ($file, "^connect", "connect \"/usr/sbin/chat -v -f $value\""); + $ret = &set_ppp_options_re ($file, "^connect", "connect \"/usr/sbin/chat -v -f /etc/chatscripts/$value\""); &Utils::Report::leave (); return $ret; } |