summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcarlosg <carlosg>2005-10-05 14:29:01 +0000
committercarlosg <carlosg>2005-10-05 14:29:01 +0000
commite2981d438733e2783cc1bf054a78875a8aea314a (patch)
treee51ad437697619c5c50c09089577c62e00a26ac5
parent8d88f4ffc1579d4ddc641e1b99e9a41a20641051 (diff)
2005-10-04 Carlos Garnacho Parro <carlosg@gnome.org>
* Network/Hosts.pm: added * HostsConfig.pm: ditto * ServicesConfig.pm: ditto * Init/ServicesList.pm: ditto * Init/Services.pm: added code, need to review to see if it works on non system V distros * Loader.pl.in: added new services
-rw-r--r--ChangeLog10
-rw-r--r--HostsConfig.pm66
-rw-r--r--Init/Services.pm1582
-rw-r--r--Init/ServicesList.pm335
-rwxr-xr-xLoader.pl.in18
-rw-r--r--Network/Hosts.pm58
-rw-r--r--ServicesConfig.pm65
7 files changed, 712 insertions, 1422 deletions
diff --git a/ChangeLog b/ChangeLog
index 945c690..a625d2b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2005-10-04 Carlos Garnacho Parro <carlosg@gnome.org>
+
+ * Network/Hosts.pm: added
+ * HostsConfig.pm: ditto
+ * ServicesConfig.pm: ditto
+ * Init/ServicesList.pm: ditto
+ * Init/Services.pm: added code, need to review to see if it works on
+ non system V distros
+ * Loader.pl.in: added new services
+
2005-09-17 Carlos Garnacho Parro <carlosg@gnome.org>
* Loader.pl.in: add some code to check whether the backends are
diff --git a/HostsConfig.pm b/HostsConfig.pm
new file mode 100644
index 0000000..bd02417
--- /dev/null
+++ b/HostsConfig.pm
@@ -0,0 +1,66 @@
+#-*- Mode: perl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+# DBus object for the Hosts location config
+#
+# Copyright (C) 2005 Carlos Garnacho
+#
+# Authors: Carlos Garnacho Parro <carlosg@gnome.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Library General Public License as published
+# by the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+
+package HostsConfig;
+
+use base qw(Net::DBus::Object);
+use Network::Hosts;
+
+my $OBJECT_NAME = "HostsConfig";
+my $SHARES_PATH = $Utils::Backend::DBUS_PATH . "/" . $OBJECT_NAME;
+
+sub new
+{
+ my $class = shift;
+ my $self = $class->SUPER::new ($SHARES_PATH,
+ {
+ $OBJECT_NAME => {
+ methods => {
+ "get" => {
+ params => [],
+ returns => [[ "array", [ "struct", "string", [ "array", "string" ]]],
+ ["array", "string" ],
+ ["array", "string" ]],
+ },
+ },
+ signals => {
+ "changed" => [],
+ },
+ },
+ },
+ @_);
+ bless $self, $class;
+# Utils::Monitor::monitor_files (&Shares::Exports::get_files (),
+# $self, $OBJECT_NAME, "changed");
+ return $self;
+}
+
+sub get
+{
+ my ($self) = @_;
+
+ return (Network::Hosts::get (),
+ Network::Hosts::get_dns (),
+ Network::Hosts::get_search_domains ());
+}
+
+1;
diff --git a/Init/Services.pm b/Init/Services.pm
index e0ab5cf..043a618 100644
--- a/Init/Services.pm
+++ b/Init/Services.pm
@@ -1,4 +1,3 @@
-#!/usr/bin/env perl
#-*- Mode: perl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
# Functions for manipulating system services, like daemons and network.
@@ -25,141 +24,63 @@
package Init::Services;
-use Utils::Report;
-use Utils::File;
+use Init::ServicesList;
-$rcd_path;
-$initd_path;
-$relative_path;
-
-$SCRIPTSDIR = "@scriptsdir@";
-$FILESDIR = "@filesdir@";
-if ($SCRIPTSDIR =~ /^@scriptsdir[@]/)
+sub get_sysv_paths
{
- $FILESDIR = "files";
- $SCRIPTSDIR = ".";
- $DOTIN = ".in";
-}
+ my %dist_map =
+ (
+ # gst_dist => [rc.X dirs location, init.d scripts location, relative path location]
+ "redhat-5.2" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+ "redhat-6.0" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+ "redhat-6.1" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+ "redhat-6.2" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+ "redhat-7.0" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+ "redhat-7.1" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+ "redhat-7.2" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+ "redhat-7.3" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+ "redhat-8.0" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+ "redhat-9" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+ "openna-1.0" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+
+ "mandrake-7.1" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+ "mandrake-7.2" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+ "mandrake-9.0" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+ "mandrake-9.1" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+ "mandrake-9.2" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+ "mandrake-10.0" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+ "mandrake-10.1" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+
+ "blackpanther-4.0" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+
+ "conectiva-9" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+ "conectiva-10" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+
+ "debian-2.2" => ["$gst_prefix/etc", "$gst_prefix/etc/init.d", "../init.d"],
+ "debian-3.0" => ["$gst_prefix/etc", "$gst_prefix/etc/init.d", "../init.d"],
+ "debian-sarge" => ["$gst_prefix/etc", "$gst_prefix/etc/init.d", "../init.d"],
+
+ "ubuntu-5.04" => ["$gst_prefix/etc", "$gst_prefix/etc/init.d", "../init.d"],
+
+ "suse-7.0" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d", "../"],
+ "suse-9.0" => ["$gst_prefix/etc/init.d", "$gst_prefix/etc/init.d", "../"],
+ "suse-9.1" => ["$gst_prefix/etc/init.d", "$gst_prefix/etc/init.d", "../"],
-use File::Copy;
+ "turbolinux-7.0" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
-require "$SCRIPTSDIR/service-list.pl$DOTIN";
+ "pld-1.0" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+ "pld-1.1" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+ "pld-1.99" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
-# Where is the SysV subsystem installed?
-sub gst_service_sysv_get_paths
-{
- my %dist_map =
- (
- # dist => [rc.X dirs location, init.d scripts location, relative path location]
- "redhat-5.2" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
- "redhat-6.0" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
- "redhat-6.1" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
- "redhat-6.2" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
- "redhat-7.0" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
- "redhat-7.1" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
- "redhat-7.2" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
- "redhat-7.3" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
- "redhat-8.0" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
- "redhat-9" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
- "openna-1.0" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
-
- "mandrake-7.1" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
- "mandrake-7.2" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
- "mandrake-9.0" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
- "mandrake-9.1" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
- "mandrake-9.2" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
- "mandrake-10.0" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
- "mandrake-10.1" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
-
- "blackpanther-4.0" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
-
- "conectiva-9" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
- "conectiva-10" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
-
- "debian-2.2" => ["$gst_prefix/etc", "$gst_prefix/etc/init.d", "../init.d"],
- "debian-3.0" => ["$gst_prefix/etc", "$gst_prefix/etc/init.d", "../init.d"],
- "debian-sarge" => ["$gst_prefix/etc", "$gst_prefix/etc/init.d", "../init.d"],
-
- "suse-7.0" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d", "../"],
- "suse-9.0" => ["$gst_prefix/etc/init.d", "$gst_prefix/etc/init.d", "../"],
- "suse-9.1" => ["$gst_prefix/etc/init.d", "$gst_prefix/etc/init.d", "../"],
-
- "turbolinux-7.0" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
-
- "pld-1.0" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
- "pld-1.1" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
- "pld-1.99" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
-
- "fedora-1" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
- "fedora-2" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
- "fedora-3" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
-
- "specifix" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
-
- "vine-3.0" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
- "vine-3.1" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
- );
- my $res;
+ "fedora-1" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+ "fedora-2" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+ "fedora-3" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
- $res = $dist_map{$Utils::Backend::tool{"platform"}};
- &Utils::Report::do_report ("service_sysv_unsupported", $Utils::Backend::tool{"platform"}) if ($res eq undef);
- return @$res;
-}
+ "specifix" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
-# Those runlevels that are usually used. Maybe we should add
-# the current running runlevel, using the "runlevel" command.
-sub gst_service_sysv_get_runlevels
-{
- my %dist_map =
- (
- "redhat-5.2" => [3, 5],
- "redhat-6.0" => [3, 5],
- "redhat-6.1" => [3, 5],
- "redhat-6.2" => [3, 5],
- "redhat-7.0" => [3, 5],
- "redhat-7.1" => [3, 5],
- "redhat-7.2" => [3, 5],
- "redhat-7.3" => [3, 5],
- "redhat-8.0" => [3, 5],
- "redhat-9" => [3, 5],
- "openna-1.0" => [3, 5],
-
- "mandrake-7.1" => [3, 5],
- "mandrake-7.2" => [3, 5],
- "mandrake-9.0" => [3, 5],
- "mandrake-9.1" => [3, 5],
- "mandrake-9.2" => [3, 5],
- "mandrake-10.0" => [3, 5],
- "mandrake-10.1" => [3, 5],
-
- "blackpanther-4.0" => [3, 5],
-
- "conectiva-9" => [3, 5],
- "conectiva-10" => [3, 5],
-
- "debian-2.2" => [2, 3],
- "debian-3.0" => [2, 3],
- "debian-sarge" => [2, 3],
-
- "suse-7.0" => [3, 5],
- "suse-9.0" => [3, 5],
- "suse-9.1" => [3, 5],
-
- "turbolinux-7.0" => [3, 5],
-
- "pld-1.0" => [3, 5],
- "pld-1.1" => [3, 5],
- "pld-1.99" => [3, 5],
-
- "fedora-1" => [3, 5],
- "fedora-2" => [3, 5],
- "fedora-3" => [3, 5],
-
- "specifix" => [3, 5],
-
- "vine-3.0" => [3, 5],
- "vine-3.1" => [3, 5],
- );
+ "vine-3.0" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+ "vine-3.1" => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d/init.d", "../init.d"],
+ );
my $res;
$res = $dist_map{$Utils::Backend::tool{"platform"}};
@@ -167,331 +88,8 @@ sub gst_service_sysv_get_runlevels
return @$res;
}
-sub gst_service_get_verbose_runlevels
-{
- my (%dist_map, %runlevels, $desc, $distro);
- %dist_map =
- (
- "redhat-5.2" => "redhat-5.2",
- "redhat-6.0" => "redhat-5.2",
- "redhat-6.1" => "redhat-5.2",
- "redhat-6.2" => "redhat-5.2",
- "redhat-7.0" => "redhat-5.2",
- "redhat-7.1" => "redhat-5.2",
- "redhat-7.2" => "redhat-5.2",
- "redhat-7.3" => "redhat-5.2",
- "redhat-8.0" => "redhat-5.2",
- "redhat-9" => "redhat-5.2",
- "openna-1.0" => "redhat-5.2",
-
- "mandrake-7.1" => "redhat-5.2",
- "mandrake-7.2" => "redhat-5.2",
- "mandrake-9.0" => "redhat-5.2",
- "mandrake-9.1" => "redhat-5.2",
- "mandrake-9.2" => "redhat-5.2",
- "mandrake-10.0" => "redhat-5.2",
- "mandrake-10.1" => "redhat-5.2",
-
- "blackpanther-4.0" => "redhat-5.2",
-
- "conectiva-9" => "redhat-5.2",
- "conectiva-10" => "redhat-5.2",
-
- "debian-2.2" => "debian-2.2",
- "debian-3.0" => "debian-2.2",
- "debian-sarge" => "debian-2.2",
-
- "suse-7.0" => "redhat-5.2",
- "suse-9.0" => "redhat-5.2",
- "suse-9.1" => "redhat-5.2",
-
- "turbolinux-7.0" => "redhat-5.2",
- "pld-1.0" => "redhat-5.2",
- "pld-1.1" => "redhat-5.2",
- "pld-1.99" => "redhat-5.2",
- "fedora-1" => "redhat-5.2",
- "fedora-2" => "redhat-5.2",
- "fedora-3" => "redhat-5.2",
-
- "specifix" => "redhat-5.2",
-
- "vine-3.0" => "redhat-5.2",
- "vine-3.1" => "redhat-5.2",
-
- "slackware-9.1.0" => "slackware-9.1.0",
- "slackware-10.0.0" => "slackware-9.1.0",
- "slackware-10.1.0" => "slackware-9.1.0",
-
- "gentoo" => "gentoo",
-
- "freebsd-5" => "freebsd-5",
- "freebsd-6" => "freebsd-5",
- );
-
- %runlevels=
- (
- "redhat-5.2" => {"0" => _("Halting the system"),
- "3" => _("Text mode"),
- "5" => _("Graphical mode"),
- "6" => _("Rebooting the system")
- },
- "debian-2.2" => {"0" => _("Halting the system"),
- "2" => _("Graphical mode"),
- "3" => _("Text mode"),
- "6" => _("Rebooting the system")
- },
- "gentoo" => {"boot" => _("Starts all system neccesary services"),
- "default" => _("Default runlevel"),
- "nonetwork" => _("Networkless runlevel")
- },
- "freebsd-5" => {"rc" => "dude, FreeBSD has no runlevels" },
- "slackware-9.1.0" => {"4" => _("Graphical mode") }
- );
-
- $distro = $dist_map{$Utils::Backend::tool{"platform"}};
- $desc = $runlevels{$distro};
-
- return $runlevels{$distro};
-}
-
-# --- Plain process utilities --- #
-
-# Get owners list (login) of named process.
-sub gst_service_proc_get_owners
-{
- my ($service) = @_;
- my ($user, $pid, $command);
- my ($fd);
- my (@arr);
-
- &Utils::Report::enter ();
-
- $fd = Utils::File::run_pipe_read ("ps acx -o user,pid,command");
-
- while (<$fd>)
- {
- /(.*)[ \t]+(.*)[ \t]+(.*)/;
- $user = $1;
- $pid = $2;
- $command = $3;
-
- push @arr, $user if ($command eq $service);
- }
-
- &Utils::Report::leave ();
- return \@arr;
-}
-
-# Stops all instances of a process
-sub gst_service_proc_stop_all
-{
- my ($service) = @_;
-
- return &Utils::File::run ("killall $service");
-}
-
-# Starts instances of a process for a given list of users
-sub gst_service_proc_start_all
-{
- my ($cmd, $users) = @_;
- my ($fqcmd, $fqsu);
-
- $fqcmd = &Utils::File::get_cmd_path ($cmd);
- $fqsu = &Utils::File::locate_tool ("su");
-
- foreach $user (@$users)
- {
- # Can't use gst_file_run_bg here, since it clobbers the quotes.
- system ("$fqsu $user -c \"$fqcmd &\" >/dev/null 2>/dev/null");
- }
-}
-
-sub gst_service_sysv_list_dir
-{
- my ($path) = @_;
- my ($service, @services);
-
- foreach $service (<$path/*>)
- {
- if (-x $service)
- {
- $service =~ s/.*\///;
- push @services, $service;
- }
- }
-
- return \@services;
-}
-
-sub gst_service_sysv_list_available
-{
- my ($rcd_path, $initd_path);
-
- ($rcd_path, $initd_path) = &gst_service_sysv_get_paths ();
-
- return &gst_service_sysv_list_dir ($initd_path);
-}
-
-# Return 1 or 0: is the service running?
-# Depends on the rc script to support the "status" arg.
-# Maybe we should do something more portable.
-sub gst_service_sysv_get_status
-{
- my ($service) = @_;
- my ($rc_path, $initd_path, $res);
- my ($pid);
-
- &Utils::Report::enter ();
-
- # Stolen from RedHat's /etc/rc.d/init.d/functions:status
- # FIXME: portable to other UNIXES?
- $pid = &Utils::File::run_backtick ("pidof -o %PPID -x $service");
- chomp $pid;
-
- if ($pid)
- {
- $res = 1;
- &Utils::Report::do_report ("service_status_running", $service);
- }
- else
- {
- $res = 0;
- &Utils::Report::do_report ("service_status_stopped", $service);
- }
-
-# ($rcd_path, $initd_path) = &gst_service_sysv_get_paths ();
-# $res = 0;
-#
-# if (-f "$initd_path/$service")
-# {
-# $res = &Utils::File::run ("$initd_path/$service status")? 0 : 1;
-# &Utils::Report::do_report ("service_status_running", $service) if $res;
-# &Utils::Report::do_report ("service_status_stopped", $service) if !$res;
-# }
-
- &Utils::Report::leave ();
- return $res;
-}
-
-# If any of the passed services is running, return true.
-sub gst_service_sysv_get_status_any
-{
- my (@services) = @_;
- my $i;
-
- foreach $i (@services)
- {
- return 1 if &gst_service_sysv_get_status ($i);
- }
-
- return 0;
-}
-
-# Set start links and remove stop links at the usual runlevels.
-# Old start link is removed, in case the priority is different from $pri.
-sub gst_service_sysv_set_links_active
-{
- my ($pri, $service) = @_;
-
- foreach $runlevel (&gst_service_sysv_get_runlevels ())
- {
- &gst_service_sysv_remove_link ($runlevel, $service);
- &gst_service_sysv_add_link ($runlevel, "S", $pri, $service);
- }
-}
-
-# Set stop links and remove start links at the usual runlevels.
-sub gst_service_sysv_set_links_inactive
-{
- my ($pri, $service) = @_;
-
- foreach $runlevel (&gst_service_sysv_get_runlevels ())
- {
- &gst_service_sysv_remove_link ($runlevel, "$service");
- &gst_service_sysv_add_link ($runlevel, "K", $pri, $service);
- }
-}
-
-# Set links for active/inactive service at the given priority.
-sub gst_service_sysv_set_links
-{
- my ($pri, $service, $active) = @_;
-
- if ($active)
- {
- &gst_service_sysv_set_links_active ($pri, $service);
- }
- else
- {
- &gst_service_sysv_set_links_inactive (100 - $pri, $service);
- }
-}
-
-
-
-# Start or stop the service, depending on $active. Set
-# links accordingly. $force makes this function use
-# start/stop only, without considerations for restart.
-# Not to be called from parse/replace tables, due to last $force
-# param: use the following two functions instead.
-sub gst_service_sysv_set_status_do
-{
- my ($priority, $service, $active, $force) = @_;
- my ($arg, $status);
-
- &gst_service_sysv_set_links ($priority, $service, $active);
-
- $status = &gst_service_sysv_get_status ($service);
- if ($status && !$force)
- {
- # if it's already active and you want it active, restart.
- $arg = $active? "restart" : "stop";
- }
- else
- {
- # normal operation.
- $arg = $active? "start" : "stop";
- }
-
- return &gst_service_sysv_run_initd_script ($service, $arg);
-}
-
-sub gst_service_sysv_set_status
-{
- my ($priority, $service, $active) = @_;
-
- return &gst_service_sysv_set_status_do ($priority, $service, $active, 0);
-}
-
-sub gst_service_sysv_force_status
-{
- my ($priority, $service, $active) = @_;
-
- return &gst_service_sysv_set_status_do ($priority, $service, $active, 1);
-}
-
-sub gst_service_sysv_install_script
-{
- my ($service, $file) = @_;
- my ($res, $rcd_path, $initd_path);
-
- ($rcd_path, $initd_path) = &gst_service_sysv_get_paths ();
-
- if (!copy ("$FILESDIR/$file", "$initd_path/$service"))
- {
- &Utils::Report::do_report ("file_copy_failed", "$FILESDIR/$file", "$initd_path/$service");
- return -1;
- }
-
- chmod (0755, "$initd_path/$service");
-
- return 0;
-}
-
-# THESE ARE THE FUNCTIONS WHICH EXTRACT THE CONFIGURATION FROM THE COMPUTER
-
# we are going to extract the name of the script
-sub gst_service_sysv_get_service_name
+sub get_sysv_service_name
{
my ($service) = @_;
@@ -502,98 +100,81 @@ sub gst_service_sysv_get_service_name
# This function gets the state of the service along the runlevels,
# it also returns the average priority
-sub gst_service_sysv_get_runlevels_status
+sub get_sysv_runlevels_status
{
my ($service) = @_;
my ($link);
my ($runlevel, $action, $priority);
my (@arr, @ret);
- my ($sum, $count);
-
- $sum = $count = 0;
foreach $link (<$rcd_path/rc[0-6].d/[SK][0-9][0-9]$service>)
{
$link =~ s/$rcd_path\///;
$link =~ /rc([0-6])\.d\/([SK])([0-9][0-9]).*/;
($runlevel,$action,$priority)=($1,$2,$3);
- if ($action eq "S")
+
+ if ($action eq "S")
{
- push @arr, { "number" => $runlevel,
- "action" => "start" };
- $sum += $priority;
- }
+ push @arr, [ $runlevel, "start", $priority ];
+ }
elsif ($action eq "K")
{
- push @arr, { "number" => $runlevel,
- "action" => "stop" };
- $sum += (100 -$priority);
+ push @arr, [ $runlevel, "stop", $priority ];
}
- $count++;
}
- return (undef,99) if (scalar(@arr) eq 0);
- push @ret, { "runlevel" => \@arr };
- return (\@ret, int ($sum / $count));
+ return \@arr;
}
# We are going to extract the information of the service
-sub gst_service_sysv_get_service_info
+sub get_sysv_service_info
{
my ($service) = @_;
- my ($script, $name, $description, @actions, @runlevels);
- my %hash;
+ my ($script, @actions, @runlevels, $role);
# Return if it's a directory
- return undef if (-d $service);
+ return if (-d $service);
# We have to check if the service is executable
- return undef unless (-x $service);
+ return unless (-x $service);
- $script = &gst_service_sysv_get_service_name ($service);
+ $script = &get_sysv_service_name ($service);
# We have to check out if the service is in the "forbidden" list
- return undef if (&gst_service_list_service_is_forbidden ($script));
+ return if (&Init::ServicesList::is_forbidden ($script));
- ($name, $description) = &gst_service_list_get_info ($script);
- ($runlevels, $priority) = &gst_service_sysv_get_runlevels_status($script);
+ $runlevels = &get_sysv_runlevels_status($script);
+ $role = &Init::ServicesList::get_role ($script);
- $hash{"script"} = $script;
- $hash{"name"} = $name unless ($name eq undef);
- $hash{"description"} = $description unless ($description eq undef);
-# $hash{"runlevels"} = $runlevels unless ($runlevels eq undef);
- $hash{"priority"} = $priority;
-
- return \%hash;
+ return ($script, $role, $runlevels);
}
# This function gets an ordered array of the available services from a SysV system
-sub gst_service_sysv_get_services
+sub get_sysv_services
{
my ($service);
- my (@arr, %ret);
-
- ($rcd_path, $initd_path) = &gst_service_sysv_get_paths ();
+ my (@arr);
+
+ ($rcd_path, $initd_path) = &get_sysv_paths ();
+
+ return undef unless ($rcd_path && $initd_path);
foreach $service (<$initd_path/*>)
{
- my (%hash);
- $hash = &gst_service_sysv_get_service_info ($service);
+ my (@info);
- if ($hash ne undef)
- {
- $ret{$service} = $hash;
- }
+ @info = &get_sysv_service_info ($service);
+ push @arr, \@info if (scalar (@info));
}
- return \%ret;
+ return \@arr;
}
# This functions get an ordered array of the available services from a file-rc system
-sub gst_service_filerc_get_runlevels_status
+sub get_filerc_runlevels_status
{
- my ($start_service, $stop_service, @arr) = @_;
- my (@ret);
+ my ($start_service, $stop_service, $priority) = @_;
+ my (@arr, @ret);
# we start with the runlevels in which the service starts
if ($start_service !~ /-/) {
@@ -603,8 +184,9 @@ sub gst_service_filerc_get_runlevels_status
foreach $runlevel (@runlevels)
{
- push @arr, { "number" => $runlevel,
- "action" => "start" };
+ push @arr, { "name" => $runlevel,
+ "action" => "start",
+ "priority" => $priority};
}
}
@@ -616,8 +198,9 @@ sub gst_service_filerc_get_runlevels_status
foreach $runlevel (@runlevels)
{
- push @arr, { "number" => $runlevel,
- "action" => "stop" };
+ push @arr, { "name" => $runlevel,
+ "action" => "stop",
+ "priority" => $priority};
}
}
@@ -625,7 +208,7 @@ sub gst_service_filerc_get_runlevels_status
return \@ret;
}
-sub gst_service_filerc_get_service_info
+sub get_filerc_service_info
{
my ($line, %ret) = @_;
my %hash;
@@ -638,21 +221,12 @@ sub gst_service_filerc_get_service_info
$start_service = $3;
$script = $4;
- return undef if (&gst_service_list_service_is_forbidden ($script));
+ return undef if (&Init::ServicesList::is_forbidden ($script));
$hash{"script"} = $script;
- $hash{"runlevels"} = &gst_service_filerc_get_runlevels_status ($start_service, $stop_service);
-
- if ($start_service eq "-")
- {
- $hash{"priority"} = 100 - $priority;
- $priority = 100 - $priority;
- }
- else
- {
- $hash{"priority"} = $priority;
- }
+ $hash{"runlevels"} = &get_filerc_runlevels_status ($start_service, $stop_service, $priority);
+ $hash{"role"} = &Init::ServicesList::get_role ($script);
return (\%hash);
}
@@ -663,7 +237,7 @@ sub gst_service_filerc_get_service_info
sub gst_service_filerc_get_services
{
my ($script);
- my %ret;
+ my (%ret);
open FILE, "$gst_prefix/etc/runlevel.conf" or return undef;
while ($line = <FILE>)
@@ -672,7 +246,7 @@ sub gst_service_filerc_get_services
{
my (%hash);
my ($start_service, $stop_service);
- $hash = &gst_service_filerc_get_service_info ($line);
+ $hash = &get_filerc_service_info ($line);
if ($hash ne undef)
{
@@ -680,47 +254,31 @@ sub gst_service_filerc_get_services
if ($ret{$script} eq undef)
{
- ($name, $description) = &gst_service_list_get_info ($script);
- $$hash{"name"} = $name unless ($name eq undef);
- $$hash{"description"} = $description unless ($description eq undef);
- $$hash{"count"} = 1;
-
$ret{$script} = $hash;
}
else
{
- my (@runlevels);
-
- # We need to mix the runlevels
- @runlevels = $$hash{"runlevels"}[0]{"runlevel"};
- foreach $runlevel (@runlevels)
- {
- push @{$ret{$script}{"runlevels"}[0]{"runlevel"}}, $runlevel;
- }
-
- $ret{$script}{"priority"} += $$hash{"priority"};
-
- $ret{$script}{"count"}++;
+ my (@runlevels);
+
+ # We need to mix the runlevels
+ @runlevels = $$hash{"runlevels"}[0]{"runlevel"};
+ foreach $runlevel (@runlevels)
+ {
+ push @{$ret{$script}{"runlevels"}[0]{"runlevel"}}, $runlevel;
+ }
}
}
}
}
- # we have to return the average priority
- foreach $i (sort keys %ret)
- {
- $ret{$i}{"priority"} = int ($ret{$i}{"priority"} / $ret{$i}{"count"});
- delete $ret{$i}{"count"};
- }
-
return \%ret;
}
# this functions get a list of the services that run on a bsd init
-sub gst_service_bsd_get_service_info
+sub get_bsd_service_info
{
my ($service) = @_;
- my ($script, $name, $description);
+ my ($script);
my (%hash);
my (@arr, @rl);
@@ -728,36 +286,33 @@ sub gst_service_bsd_get_service_info
$script =~ s/^.*\///;
$script =~ s/^rc\.//;
- return undef if (! Utils::File::exists ($service));
-
- return undef if (&gst_service_list_service_is_forbidden ($script));
+ return undef if (! gst_file_exists ($service));
- ($name, $description) = &gst_service_list_get_info ($script);
+ return undef if (&Init::ServicesList::is_forbidden ($script));
$hash {"script"} = $service;
- $hash{"name"} = $name unless ($name eq undef);
- $hash{"description"} = $description unless ($description eq undef);
# we hardcode the fourth runlevel, it's the graphical one
if ( -x $service)
{
- push @arr, { "number" => 4,
+ push @arr, { "name" => 4,
"action" => "start" };
}
else
{
- push @arr, { "number" => 4,
- "action" => "stop" };
+ push @arr, { "name" => 4,
+ "action" => "stop" };
}
push @rl, { "runlevel" => \@arr };
$hash{"runlevels"} = \@rl;
+ $hash{"role"} = &Init::ServicesList::get_role ($script);
return \%hash;
}
-sub gst_service_bsd_get_services
+sub get_bsd_services
{
my (%ret);
my ($files) = [ "rc.M", "rc.inet2", "rc.4" ];
@@ -766,10 +321,10 @@ sub gst_service_bsd_get_services
foreach $i (@$files)
{
$file = "/etc/rc.d/" . $i;
- $fd = &Utils::File::open_read_from_names ($file);
+ $fd = &gst_file_open_read_from_names ($file);
if (!$fd) {
- &Utils::Report::do_report ("rc_file_read_failed", $file);
+ &gst_report ("rc_file_read_failed", $file);
return undef;
}
@@ -782,7 +337,7 @@ sub gst_service_bsd_get_services
my (%hash);
$service = $1;
- $hash = &gst_service_bsd_get_service_info ($service);
+ $hash = &get_bsd_service_info ($service);
if ($hash ne undef)
{
@@ -791,17 +346,17 @@ sub gst_service_bsd_get_services
}
}
- Utils::File::close_file ($fd);
+ gst_file_close ($fd);
}
return \%ret;
}
# these functions get a list of the services that run on a gentoo init
-sub gst_service_gentoo_get_service_status
+sub get_gentoo_service_status
{
my ($script, $runlevel) = @_;
- my ($services) = &gst_service_gentoo_get_services_by_runlevel ($runlevel);
+ my ($services) = &get_gentoo_services_by_runlevel ($runlevel);
foreach $i (@$services)
{
@@ -811,18 +366,18 @@ sub gst_service_gentoo_get_service_status
return 0;
}
-sub gst_service_gentoo_get_runlevels
+sub get_gentoo_runlevels
{
- my($raw_output) = Utils::File::run_backtick("rc-status -l");
+ my($raw_output) = gst_file_run_backtick("rc-status -l");
my(@runlevels) = split(/\n/,$raw_output);
return @runlevels;
}
-sub gst_service_gentoo_get_services_by_runlevel
+sub get_gentoo_services_by_runlevel
{
my($runlevel) = @_;
- my($raw_output) = Utils::File::run_backtick("rc-status $runlevel");
+ my($raw_output) = gst_file_run_backtick("rc-status $runlevel");
my(@raw_lines) = split(/\n/,$raw_output);
my(@services);
my($line);
@@ -839,15 +394,15 @@ sub gst_service_gentoo_get_services_by_runlevel
return \@services
}
-sub gst_service_gentoo_get_services_list
+sub get_gentoo_services_list
{
return &gst_service_sysv_list_dir ("/etc/init.d/");
}
-sub gst_service_gentoo_service_exist
+sub gentoo_service_exists
{
my($service) = @_;
- my($services) = &gst_service_gentoo_get_services_list();
+ my($services) = &get_gentoo_services_list();
foreach $i (@$services)
{
@@ -857,7 +412,7 @@ sub gst_service_gentoo_service_exist
return 0;
}
-sub gst_service_gentoo_get_runlevels_by_service
+sub get_gentoo_runlevels_by_service
{
my ($service) = @_;
my(@runlevels,@services_in_runlevel,@contain_runlevels, $runlevel);
@@ -866,15 +421,15 @@ sub gst_service_gentoo_get_runlevels_by_service
# let's do some caching to improve performance
if ($gentoo_services_hash eq undef)
{
- @runlevels = &gst_service_gentoo_get_runlevels ();
+ @runlevels = &get_gentoo_runlevels ();
foreach $runlevel (@runlevels)
{
- $$gentoo_services_hash{$runlevel} = &gst_service_gentoo_get_services_by_runlevel ($runlevel);
+ $$gentoo_services_hash{$runlevel} = &get_gentoo_services_by_runlevel ($runlevel);
}
}
- if (&gst_service_gentoo_service_exist($service))
+ if (&gentoo_service_exists($service))
{
foreach $runlevel (keys %$gentoo_services_hash)
{
@@ -890,24 +445,24 @@ sub gst_service_gentoo_get_runlevels_by_service
return @contain_runlevels;
}
-sub gst_service_gentoo_runlevel_status_by_service
+sub get_gentoo_runlevel_status_by_service
{
my ($service) = @_;
my (@arr, @ret);
- my (@runlevels) = &gst_service_gentoo_get_runlevels();
- my (@started) = &gst_service_gentoo_get_runlevels_by_service($service);
+ my (@runlevels) = &get_gentoo_runlevels();
+ my (@started) = &get_gentoo_runlevels_by_service($service);
my (%start_runlevels) = map { $started[$_], 1 } 0 .. $#started;
foreach $runlevel (@runlevels)
{
if (defined $start_runlevels{$runlevel})
{
- push @arr, { "number" => $runlevel,
+ push @arr, { "name" => $runlevel,
"action" => "start" };
}
else
{
- push @arr, { "number" => $runlevel,
+ push @arr, { "name" => $runlevel,
"action" => "stop" };
}
}
@@ -916,38 +471,35 @@ sub gst_service_gentoo_runlevel_status_by_service
return @ret;
}
-sub gst_service_gentoo_get_service_info
+sub get_gentoo_service_info
{
my ($service) = @_;
- my ($script, $name, $description, @actions, @runlevels);
+ my ($script, @actions, @runlevels);
my %hash;
# We have to check out if the service is in the "forbidden" list
- return undef if (&gst_service_list_service_is_forbidden ($service));
+ return undef if (&Init::ServicesList::is_forbidden ($service));
- ($name, $description) = &gst_service_list_get_info ($service);
-
- my($runlevels) = &gst_service_gentoo_runlevel_status_by_service ($service);
+ my($runlevels) = &get_gentoo_runlevel_status_by_service ($service);
$hash{"script"} = $service;
- $hash{"name"} = $name unless ($name eq undef);
- $hash{"description"} = $description unless ($description eq undef);
$hash{"runlevels"} = $runlevels unless ($runlevels eq undef);
+ $hash{"role"} = &Init::ServicesList::get_role ($service);
return \%hash;
}
-sub gst_service_gentoo_get_services
+sub get_gentoo_services
{
my ($service);
my (%ret);
- my ($service_list) = &gst_service_gentoo_get_services_list ();
+ my ($service_list) = &get_gentoo_services_list ();
foreach $service (@$service_list)
{
my (%hash);
- $hash = &gst_service_gentoo_get_service_info ($service);
+ $hash = &get_gentoo_service_info ($service);
$ret{$service} = $hash if ($hash ne undef);
}
@@ -956,12 +508,12 @@ sub gst_service_gentoo_get_services
# rcNG functions, mostly for FreeBSD
-sub gst_service_rcng_status_by_service
+sub get_rcng_status_by_service
{
my ($service) = @_;
my ($fd, $line, $active);
- $fd = &Utils::File::run_pipe_read ("/etc/rc.d/$service rcvar");
+ $fd = &gst_file_run_pipe_read ("/etc/rc.d/$service rcvar");
while (<$fd>)
{
@@ -974,44 +526,41 @@ sub gst_service_rcng_status_by_service
}
}
- Utils::File::close_file ($fd);
+ gst_file_close ($fd);
return $active;
}
-sub gst_service_rcng_get_service_info
+sub get_rcng_service_info
{
my ($service) = @_;
- my ($script, $name, $description, @actions, @runlevels);
+ my ($script, @actions, @runlevels);
my (%hash, @arr, @rl);
# We have to check if the service is in the "forbidden" list
- return undef if (&gst_service_list_service_is_forbidden ($service));
-
- ($name, $description) = &gst_service_list_get_info ($service);
+ return undef if (&Init::ServicesList::is_forbidden ($service));
$hash{"script"} = $service;
- $hash{"name"} = $name unless ($name eq undef);
- $hash{"description"} = $description unless ($description eq undef);
if (gst_service_rcng_status_by_service ($service))
{
- push @arr, { "number" => "rc",
+ push @arr, { "name" => "rc",
"action" => "start" };
}
else
{
- push @arr, { "number" => "rc",
+ push @arr, { "name" => "rc",
"action" => "stop" };
}
push @rl, { "runlevel", \@arr };
$hash {"runlevels"} = \@rl;
+ $hash {"role"} = &Init::ServicesList::get_role ($service);
return \%hash;
}
-sub gst_service_rcng_get_services
+sub get_rcng_services
{
my ($service);
my (%ret);
@@ -1021,7 +570,7 @@ sub gst_service_rcng_get_services
my (%hash);
$service =~ s/.*\///;
- $hash = &gst_service_rcng_get_service_info ($service);
+ $hash = &get_rcng_service_info ($service);
$ret{$service} = $hash if ($hash ne undef);
}
@@ -1030,20 +579,15 @@ sub gst_service_rcng_get_services
}
# SuSE functions, quite similar to SysV, but not equal...
-sub gst_service_suse_get_service_info ($service)
+sub get_suse_service_info ($service)
{
my ($service) = @_;
- my ($name, $description);
my (%hash, @arr, @ret);
# We have to check if the service is in the "forbidden" list
- return undef if (&gst_service_list_service_is_forbidden ($service));
-
- ($name, $description) = &gst_service_list_get_info ($service);
+ return undef if (&Init::ServicesList::is_forbidden ($service));
$hash{"script"} = $service;
- $hash{"name"} = $name unless ($name eq undef);
- $hash{"description"} = $description unless ($description eq undef);
foreach $link (<$rcd_path/rc[0-9S].d/S[0-9][0-9]$service>)
{
@@ -1051,13 +595,13 @@ sub gst_service_suse_get_service_info ($service)
$link =~ /rc([0-6])\.d\/S[0-9][0-9].*/;
$runlevel = $1;
- push @arr, { "number" => $runlevel,
+ push @arr, { "name" => $runlevel,
"action" => "start" };
}
foreach $link (<$rcd_path/boot.d/S[0-9][0-9]$service>)
{
- push @arr, {"number" => "B",
+ push @arr, {"name" => "B",
"action" => "start" };
}
@@ -1065,12 +609,13 @@ sub gst_service_suse_get_service_info ($service)
{
push @ret, { "runlevel" => \@arr };
$hash{"runlevels"} = \@ret;
+ $hash{"role"} = &Init::ServicesList::get_role ($service);
}
return \%hash;
}
-sub gst_service_suse_get_services
+sub get_suse_services
{
my ($service, %ret);
@@ -1083,7 +628,7 @@ sub gst_service_suse_get_services
next if (-d $service || ! -x $service);
$service =~ s/.*\///;
- $hash = &gst_service_suse_get_service_info ($service);
+ $hash = &get_suse_service_info ($service);
$ret{$service} = $hash if ($hash ne undef);
}
@@ -1092,27 +637,25 @@ sub gst_service_suse_get_services
}
# generic functions to get the available services
-sub gst_get_init_type
+sub get_init_type
{
- my $dist = $Utils::Backend::tool{"platform"};
-
- if (($dist =~ /debian/) && (stat ("$gst_prefix/etc/runlevel.conf")))
+ if (($gst_dist =~ /debian/) && (Utils::File::exists ("/etc/runlevel.conf")))
{
return "file-rc";
}
- elsif ($dist =~ /slackware/)
+ elsif ($gst_dist =~ /slackware/)
{
return "bsd";
}
- elsif ($dist =~ /freebsd/)
+ elsif ($gst_dist =~ /freebsd/)
{
return "rcng";
}
- elsif ($dist =~ /gentoo/)
+ elsif (($gst_dist =~ /gentoo/) || ($gst_dist =~ /^vlos/))
{
return "gentoo";
}
- elsif ($dist =~ /suse/)
+ elsif ($gst_dist =~ /suse/)
{
return "suse";
}
@@ -1122,11 +665,11 @@ sub gst_get_init_type
}
}
-sub gst_service_get_services
+sub get
{
- $type = &gst_get_init_type ();
+ $type = &get_init_type ();
- return &gst_service_sysv_get_services () if ($type eq "sysv");
+ return &get_sysv_services () if ($type eq "sysv");
return &gst_service_filerc_get_services () if ($type eq "file-rc");
return &gst_service_bsd_get_services () if ($type eq "bsd");
return &gst_service_gentoo_get_services () if ($type eq "gentoo");
@@ -1136,795 +679,4 @@ sub gst_service_get_services
return undef;
}
-
-# This function gets the runlevel that is in use
-sub gst_service_sysv_get_default_runlevel
-{
- my (@arr);
-
- @arr = split / /, `/sbin/runlevel` ;
- $arr[1] =~ s/\n//;
-
- return $arr[1];
-}
-
-sub gst_service_get_default_runlevel
-{
- my ($type) = &gst_get_init_type ();
-
- return "default" if ($type eq "gentoo");
- return "rc" if ($type eq "rcng");
- return &gst_service_sysv_get_default_runlevel ();
-}
-
-
-# THESE ARE THE FUNCTIONS WHICH APPLY THE CHANGES MADE TO THE CONFIGURATION OF THE COMPUTER
-
-sub gst_service_sysv_add_link
-{
- my ($runlevel, $action, $priority, $service) = @_;
- my ($prio) = sprintf ("%0.2d",$priority);
-
- symlink ("$relative_path/$service", "$rcd_path/rc$runlevel.d/$action$prio$service");
-
- &Utils::Report::enter ();
- &Utils::Report::do_report ("service_sysv_add_link", "$rcd_path/rc$runlevel.d/$action$prio$service");
- &Utils::Report::leave ();
-}
-
-sub gst_service_sysv_remove_link
-{
- my ($runlevel, $script) = @_;
-
- foreach $link (<$rcd_path/rc$runlevel.d/[SK][0-9][0-9]$script>)
- {
- &Utils::Report::do_report ("service_sysv_remove_link", "$link");
- unlink ("$link");
- &Utils::Report::leave ();
- }
-}
-
-
-# These are the functions for storing the service settings from XML in SysV
-sub gst_service_sysv_set_service
-{
- my ($service) = @_;
- my ($script, $priority, $runlevels);
- my ($action);
-
- ($rcd_path, $initd_path, $relative_path) = &gst_service_sysv_get_paths ();
-
- $script = $$service{"script"};
- $priority = $$service{"priority"};
- $runlevels = $$service{"runlevels"}[0]{"runlevel"};
-
- # pass though all the runlevels checking if the service must be started, stopped or removed
- for ($i = 0; $i <= 6; $i++)
- {
- &gst_service_sysv_remove_link ($i, $script);
-
- $action = undef;
- foreach $j (@$runlevels)
- {
- if ($i == $$j{"number"})
- {
- $found = 1;
- $action = $$j{"action"};
- }
- }
- if ($action ne undef)
- {
- if ($action eq "start")
- {
- &gst_service_sysv_add_link ($i, "S", $priority, $script);
- }
- else
- {
- &gst_service_sysv_add_link ($i, "K", 100 - $priority, $script);
- }
- }
- }
-}
-
-sub gst_service_sysv_set_services
-{
- my ($services, $runlevel) = @_;
-
- foreach $i (@$services)
- {
- &gst_service_sysv_set_service($i);
- }
-}
-
-# This is the function for storing the service settings from XML in file-rc
-sub gst_service_filerc_set_services
-{
- my ($services, $runlevel) = @_;
- my ($buff, $lineno, $line, $file);
- my ($rcd_path, $initd_path, $relative_path) = &gst_service_sysv_get_paths ();
-
- $file = "$gst_prefix/etc/runlevel.conf";
-
- $buff = &Utils::File::load_buffer ($file);
- &Utils::File::join_buffer_lines ($buff);
-
- $lineno = 0;
-
- # We prepare the file for storing the configuration, save the initial comments
- # and delete the rest
- do {
- $lineno++;
- } while ($$buff[$lineno] =~ /^#.*/);
-
- for ($i = $lineno; $i < scalar (@$buff); $i++)
- {
- $$buff[$i] =~ /.*\/etc\/init\.d\/(.*)/;
-
- # we need to keep the forbidden services and the services that only start in rcS.d
- if (!gst_service_list_service_is_forbidden ($1))
- {
- delete $$buff[$i];
- }
- }
-
- # Now we append the services
- foreach $service (@$services)
- {
- my (@start, @stop, @arr);
-
- $arr = $$service{"runlevels"}[0]{"runlevel"};
-
- # split the runlevels in two arrays
- foreach $i (@$arr)
- {
- if ($$i{"action"} eq "start")
- {
- push @start, $$i{"number"};
- }
- else
- {
- push @stop, $$i{"number"};
- }
- }
-
- if ((scalar (@start) eq 0) && (scalar (@stop) eq 0))
- {
- #print a empty line
- $line = sprintf ("%0.2d",$$service{"priority"}) . "\t";
- $line .= "-\t-";
- $line .= "\t\t". "/etc/init.d/" . $$service{"script"} . "\n";
- push @$buff, $line;
- }
- else
- {
- if (scalar (@start) ne 0)
- {
- # print the line with the runlevels in which the service starts with priority = $priority
- $line = sprintf ("%0.2d",$$service{"priority"}) . "\t";
- $line .= "-" . "\t";
- $line .= join ",", sort @start;
- $line .= "\t\t". "/etc/init.d/" . $$service{"script"} . "\n";
- push @$buff, $line;
- }
-
- if (scalar (@stop) ne 0)
- {
- # print the line with the runlevels in which the service stops with priority = 100 - $priority
- $line = sprintf ("%0.2d", 100 - $$service{"priority"}) . "\t";
- $line .= join ",", sort @stop;
- $line .= "\t" . "-";
- $line .= "\t\t". "/etc/init.d/" . $$service{"script"} . "\n";
- push @$buff, $line;
- }
- }
- }
-
- @$buff = sort @$buff;
-
- push @$buff, "\n";
- &Utils::File::clean_buffer ($buff);
- &Utils::File::save_buffer ($buff, $file);
-}
-
-sub gst_service_bsd_set_services
-{
- my ($services, $runlevel) = @_;
- my ($script, $runlevels);
-
- foreach $service (@$services)
- {
- $script = $$service{"script"};
- $runlevels = $$service{"runlevels"}[0]{"runlevel"}[0];
-
- $action = $$runlevels {"action"};
-
- if ($action eq "start")
- {
- &Utils::File::run ("chmod ugo+x $script");
- }
- else
- {
- &Utils::File::run ("chmod ugo-x $script");
- }
- }
-}
-
-sub gst_service_gentoo_set_services
-{
- my ($services, $runlevel) = @_;
- my ($action);
-
- foreach $service (@$services)
- {
- $script = $$service{"script"};
- $arr = $$service{"runlevels"}[0]{"runlevel"};
-
- foreach $i (@$arr)
- {
- $action = $$i{"action"};
- $rl = $$i{"number"};
-
- if ( $action eq "start")
- {
- &Utils::File::run ("rc-update add $script $rl");
- }
- elsif ($action eq "stop")
- {
- &Utils::File::run ("rc-update del $script $rl");
- }
- }
- }
-}
-
-sub gst_service_rcng_set_status
-{
- my ($service, $action) = @_;
- my ($fd, $key, $res);
- my ($default_rcconf) = "/etc/defaults/rc.conf";
- my ($rcconf) = "/etc/rc.conf";
-
- if (&Utils::File::exists ("/etc/rc.d/$service"))
- {
- $fd = &Utils::File::run_pipe_read ("/etc/rc.d/$service rcvar");
-
- while (<$fd>)
- {
- if (/^\$(.*)=.*$/)
- {
- # to avoid cluttering rc.conf with duplicated data,
- # we first look in the defaults/rc.conf for the key
- $key = $1;
- $res = &Utils::Parse::get_sh_bool ($default_rcconf, $key);
-
- if ($res == $action)
- {
- &Utils::Replace::set_sh ($rcconf, $key);
- }
- else
- {
- &Utils::Replace::set_sh_bool ($rcconf, $key, "YES", "NO", $action);
- }
- }
- }
-
- &Utils::File::close_file ($fd);
- }
- elsif (&Utils::File::exists ("/usr/local/etc/rc.d/$service.sh"))
- {
- if ($action)
- {
- Utils::File::copy_file ("/usr/local/etc/rc.d/$service.sh.sample",
- "/usr/local/etc/rc.d/$service.sh");
- }
- else
- {
- Utils::File::remove ("/usr/local/etc/rc.d/$service.sh");
- }
- }
-}
-
-sub gst_service_rcng_set_services
-{
- my ($services, $runlevel) = @_;
- my ($action, $runlevels, $script);
-
- foreach $service (@$services)
- {
- $script = $$service {"script"};
- $runlevels = $$service{"runlevels"}[0]{"runlevel"}[0];
- $action = ($$runlevels {"action"} eq "start")? 1 : 0;
-
- &gst_service_rcng_set_status ($script, $action);
- }
-}
-
-sub gst_service_suse_set_services
-{
- my ($services, $runlevel) = @_;
- my ($action, $runlevels, $script, $rllist);
-
- foreach $service (@$services)
- {
- $script = $$service{"script"};
- $runlevels = $$service{"runlevels"}[0]{"runlevel"};
- $rllist = "";
-
- &Utils::File::run ("insserv -r $script");
-
- foreach $rl (@$runlevels)
- {
- if ($$rl{"action"} eq "start")
- {
- $rllist .= $$rl{"number"} . ",";
- }
- }
-
- if ($rllist ne "")
- {
- $rllist =~ s/,$//;
-
- &Utils::File::run ("insserv $script,start=$rllist");
- }
- }
-}
-
-sub gst_service_set_services
-{
- my ($services, $runlevel) = @_;
-
- $type = &gst_get_init_type ();
-
- &gst_service_sysv_set_services ($services, $runlevel) if ($type eq "sysv");
- &gst_service_filerc_set_services ($services, $runlevel) if ($type eq "file-rc");
- &gst_service_bsd_set_services ($services, $runlevel) if ($type eq "bsd");
- &gst_service_gentoo_set_services ($services, $runlevel) if ($type eq "gentoo");
- &gst_service_rcng_set_services ($services, $runlevel) if ($type eq "rcng");
- &gst_service_suse_set_services ($services, $runlevel) if ($type eq "suse");
-}
-
-sub gst_service_set_conf
-{
- my ($hash) = @_;
- my ($services, $runlevel);
-
- return unless $hash;
- $services = $$hash{"services"}[0]{"service"};
- return unless $services;
- $runlevel = $$hash{"runlevel"};
- return unless $runlevel;
-
- &gst_service_set_services($services, $runlevel);
-}
-
-# stuff for checking whether service is running
-sub gst_service_debian_get_status
-{
- my ($service) = @_;
- my ($rcd_path, $initd_path) = &gst_service_sysv_get_paths ();
- my ($output, $pidfile);
-
- $output = `grep "\/var\/run\/.*\.pid" $initd_path\/$service`;
-
- if ($output =~ /.*(\/var\/run\/.*\.pid).*/ )
- {
- $pidfile = $1;
- $pidval = `cat $pidfile`;
-
- return 0 if $pidval eq "";
-
- $pid = `ps h $pidval`;
-
- if ($pid eq "")
- {
- return 0;
- }
- else
- {
- return 1;
- }
- }
-
- return undef;
-}
-
-sub gst_service_redhat_get_status
-{
- my ($service) = @_;
- my ($rcd_path, $initd_path) = &gst_service_sysv_get_paths ();
-
- if (-f "/var/lock/subsys/$service")
- {
- return 1;
- }
-
- return 0;
-}
-
-sub gst_service_gentoo_get_status
-{
- my ($service) = @_;
-
- $line = `/etc/init.d/$service status`;
-
- return 1 if ($line =~ /started/);
- return 0;
-}
-
-sub gst_service_rcng_get_status
-{
- my ($service) = @_;
-
- $line = Utils::File::run_backtick ("/etc/rc.d/$service forcestatus");
- return 1 if ($line =~ /pid [0-9]*/);
-
- # hacky as hell, we need to check services in /usr/local/etc/rc.d
- # and there's no standard way to check they're running
- return 1 if (-f "/var/run/$service.pid");
-
- # we give up, the service isn't running
- return 0;
-}
-
-sub gst_service_suse_get_status
-{
- my ($service) = @_;
-
- $line = Utils::File::run_backtick ("/etc/init.d/$service status");
- return 1 if ($line =~ /running/);
- return 0;
-}
-
-# returns true if the service is already running
-sub gst_service_get_status
-{
- my ($service) = @_;
- my %dist_map =
- (
- "debian-2.2" => \&gst_service_debian_get_status,
- "debian-3.0" => \&gst_service_debian_get_status,
- "debian-sarge" => \&gst_service_debian_get_status,
-
- "redhat-5.2" => \&gst_service_redhat_get_status,
- "redhat-6.0" => \&gst_service_redhat_get_status,
- "redhat-6.1" => \&gst_service_redhat_get_status,
- "redhat-6.2" => \&gst_service_redhat_get_status,
- "redhat-7.0" => \&gst_service_redhat_get_status,
- "redhat-7.1" => \&gst_service_redhat_get_status,
- "redhat-7.2" => \&gst_service_redhat_get_status,
- "redhat-7.3" => \&gst_service_redhat_get_status,
- "redhat-8.0" => \&gst_service_redhat_get_status,
- "redhat-9" => \&gst_service_redhat_get_status,
- "mandrake-7.2" => \&gst_service_redhat_get_status,
- "fedora-1" => \&gst_service_redhat_get_status,
- "fedora-2" => \&gst_service_redhat_get_status,
- "fedora-3" => \&gst_service_redhat_get_status,
- "specifix" => \&gst_service_redhat_get_status,
-
- "suse-9.0" => \&gst_service_suse_get_status,
- "suse-9.1" => \&gst_service_suse_get_status,
-
- "gentoo" => \&gst_service_gentoo_get_status,
-
- "freebsd-5" => \&gst_service_rcng_get_status,
- "freebsd-6" => \&gst_service_rcng_get_status,
- );
- my $proc;
-
- $proc = $dist_map {$Utils::Backend::tool{"platform"}};
-
- return undef if ($proc eq undef);
-
- return &$proc ($service);
-}
-
-# Functions to run a service
-sub gst_service_sysv_run_initd_script
-{
- my ($service, $arg) = @_;
- my ($rc_path, $initd_path);
- my $str;
- my %map =
- ("restart" => "restarted",
- "stop" => "stopped",
- "start" => "started");
-
- &Utils::Report::enter ();
-
- if (!exists $map{$arg})
- {
- &Utils::Report::do_report ("service_sysv_op_unk", $arg);
- &Utils::Report::leave ();
- return -1;
- }
-
- $str = $map{$arg};
-
- ($rcd_path, $initd_path) = &gst_service_sysv_get_paths ();
-
- if (-f "$initd_path/$service")
- {
- if (!&Utils::File::run ("$initd_path/$service $arg"))
- {
- &Utils::Report::do_report ("service_sysv_op_success", $service, $str);
- &Utils::Report::leave ();
- return 0;
- }
- }
-
- &Utils::Report::do_report ("service_sysv_op_failed", $service, $str);
- &Utils::Report::leave ();
- return -1;
-}
-
-sub gst_service_bsd_run_script
-{
- my ($service, $arg) = @_;
- my ($chmod) = 0;
-
- return if (!&Utils::File::exists ($service));
-
- # if it's not executable then chmod it
- if (!((stat ($service))[2] & (S_IXUSR || S_IXGRP || S_IXOTH)))
- {
- $chmod = 1;
- &Utils::File::run ("chmod ugo+x $service");
- }
-
- &Utils::File::run ("$service $arg");
-
- # return it to it's normal state
- if ($chmod)
- {
- &Utils::File::run ("chmod ugo-x $service");
- }
-}
-
-sub gst_service_gentoo_run_script
-{
- my ($service, $arg) = @_;
- my ($option);
-
- my %map =
- ("stop" => "stopped",
- "start" => "started"
- );
-
- &Utils::Report::enter ();
-
- if (!exists $map{$arg})
- {
- &Utils::Report::do_report ("service_sysv_op_unk", $arg);
- &Utils::Report::leave ();
- return -1;
- }
-
- if (&gst_service_gentoo_service_exist ($service))
- {
- if (!&Utils::File::run ("/etc/init.d/$service $arg"))
- {
- &Utils::Report::do_report ("service_sysv_op_success", $service, $str);
- &Utils::Report::leave ();
- return 0;
- }
- }
-
- &Utils::Report::do_report ("service_sysv_op_failed", $service, $str);
- &Utils::Report::leave ();
- return -1;
-}
-
-sub gst_service_rcng_run_script
-{
- my ($service, $arg) = @_;
- my ($farg);
-
- my %map =
- ("stop" => "forcestop",
- "start" => "forcestart"
- );
-
- &Utils::Report::enter ();
-
- if (!exists $map{$arg})
- {
- &Utils::Report::do_report ("service_sysv_op_unk", $arg);
- &Utils::Report::leave ();
- return -1;
- }
-
- $farg = $map {$arg};
-
- if (!&Utils::File::run ("/etc/rc.d/$service $farg"))
- {
- &Utils::Report::do_report ("service_sysv_op_success", $service, $str);
- &Utils::Report::leave ();
- return 0;
- }
-
- &Utils::Report::do_report ("service_sysv_op_failed", $service, $str);
- &Utils::Report::leave ();
- return -1;
-}
-
-sub gst_service_run_script
-{
- my ($service, $arg) = @_;
- my ($proc, $type);
- my %map =
- (
- "sysv" => \&gst_service_sysv_run_initd_script,
- "bsd" => \&gst_service_bsd_run_script,
- "gentoo" => \&gst_service_gentoo_run_script,
- "rcng" => \&gst_service_rcng_run_script,
- "suse" => \&gst_service_sysv_run_initd_script,
- );
-
- $type = &gst_get_init_type ();
-
- $proc = $map {$type};
-
- &$proc ($service, $arg);
-}
-
-# functions to know if a service will be installed
-sub gst_service_sysv_installed
-{
- my ($service) = @_;
- my ($res, $rcd_path, $initd_path);
-
- &Utils::Report::enter ();
-
- ($rcd_path, $initd_path) = &gst_service_sysv_get_paths ();
-
- $res = 1;
- if (! -f "$initd_path/$service")
- {
- $res = 0;
- &Utils::Report::do_report ("service_sysv_not_found", $service);
- }
-
- &Utils::Report::leave ();
- return $res;
-}
-
-sub gst_service_bsd_installed
-{
- my ($service) = @_;
-
- return 1 if ( -f "$service");
- return 0;
-}
-
-sub gst_service_gentoo_installed
-{
- my ($service) = @_;
-
- return 1 if ( -f "/etc/init.d/$service");
- return 0;
-}
-
-sub gst_service_rcng_installed
-{
- my ($service) = @_;
-
- return 1 if ( -f "/etc/rc.d/$service");
- return 1 if ( -f "/usr/local/etc/rc.d/$service.sh.sample");
- return 0;
-}
-
-sub gst_service_installed
-{
- my ($service) = @_;
- my ($type);
- $type = &gst_get_init_type ();
-
- return &gst_service_sysv_installed ($service) if (($type eq "sysv") || ($type eq "file-rc") || ($type eq "suse"));
- return &gst_service_bsd_installed ($service) if ($type eq "bsd");
- return &gst_service_gentoo_installed ($service) if ($type eq "gentoo");
- return &gst_service_rcng_installed ($service) if ($type eq "rcng");
-
- return 0;
-}
-
-sub gst_service_list_any_installed
-{
- my @service = @_;
- my $res;
-
- $res = 0;
-
- foreach $serv (@service)
- {
- if (gst_service_installed ($serv))
- {
- $res = 1;
- }
- }
-
- return $res;
-}
-
-sub gst_service_bsd_set_status
-{
- my ($script, $active) = @_;
- my (@arr);
-
- if ($active)
- {
- &Utils::File::run ("chmod ugo+x $script");
- &gst_service_run_script ($script, "start");
- }
- else
- {
- &gst_service_run_script ($script, "stop");
- &Utils::File::run ("chmod ugo-x $script");
- }
-}
-
-sub gst_service_gentoo_set_status
-{
- my ($script, $force_now, $active) = @_;
- my (@arr);
-
- if ($active)
- {
- &Utils::File::run ("rc-update add $script default");
- &Utils::File::run ("/etc/init.d/$script start") if ($force_now == 1);
- }
- else
- {
- &Utils::File::run ("rc-update del $script default");
- &Utils::File::run ("/etc/init.d/$script stop") if ($force_now == 1);
- }
-}
-
-sub gst_service_suse_set_status
-{
- my ($script, $active) = @_;
- my (@runlevels, $rllist);
- my ($rcd_path, $initd_path);
- my ($rl);
-
- ($rcd_path, $initd_path) = &gst_service_sysv_get_paths ();
- @runlevels = &gst_service_sysv_get_runlevels ();
-
- if ($active)
- {
- $rllist = join ",", @runlevels;
- &Utils::File::run ("insserv $script,start=$rllist");
- &gst_service_run_script ($script, "start");
- }
- else
- {
- # to remove a service from a few runlevels we need to run
- # insserv -r and then insserv blah,start=x,y,z
- foreach $link (<$rcd_path/rc[0-9S].d/S[0-9][0-9]$script>)
- {
- $link =~ s/$rcd_path\///;
- $link =~ /rc([0-9S])\.d\/S[0-9][0-9].*/;
- $rllist .= "$1,";
- }
-
- foreach $link (<$rcd_path/boot.d/S[0-9][0-9]$service>)
- {
- $rllist .= "B,";
- }
-
- # remove the default runlevels from the list
- foreach $runlevel (@runlevels)
- {
- $rllist =~ s/$runlevel,//;
- }
-
- $rllist =~ s/,$//;
-
- &Utils::File::run ("insserv -r $script");
-
- if ($rllist ne "")
- {
- &Utils::File::run ("insserv $script,start=$rllist");
- }
-
- &gst_service_run_script ($script, "stop");
- }
-}
+1;
diff --git a/Init/ServicesList.pm b/Init/ServicesList.pm
new file mode 100644
index 0000000..bc1aab9
--- /dev/null
+++ b/Init/ServicesList.pm
@@ -0,0 +1,335 @@
+#-*- Mode: perl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+# Copyright (C) 2005 Carlos Garnacho
+#
+# Authors: Carlos Garnacho Parro <carlosg@gnome.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Library General Public License as published
+# by the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+
+package Init::ServicesList;
+
+
+# This function determines if a service is "forbidden" or not (if runlevel-admin must show it or not)
+sub is_forbidden
+{
+ my ($service) = @_;
+ my ($ret);
+
+ my ($service_forbidden_list) =
+ [
+ # These are the forbidden services I found in Red Hat
+ "halt",
+ "functions",
+ "killall",
+ # These are the forbidden services I found in Debian Woody
+ "single",
+ "sendsigs",
+ "reboot",
+ "rcS",
+ "modutils",
+ "hostname\.sh",
+ "devpts\.sh",
+ "console-screen\.sh",
+ "checkroot\.sh",
+ "checkfs\.sh",
+ "bootmisc\.sh",
+ "bootclean\.sh",
+ "checkfs\.sh",
+ "keymap\.sh",
+ "hwclockfirst\.sh",
+ "etc-setserial",
+ "procps\.sh",
+ "mountall\.sh",
+ "dns-clean",
+ "ifupdown",
+ "networking",
+ "mountnfs\.sh",
+ "mountkernfs",
+ "mountvirtfs",
+ "setserial",
+ "hwclock\.sh",
+ "urandom",
+ "nviboot",
+ "pppd-dns",
+ "skeleton",
+ "xfree86-common",
+ "rc",
+ ".*\.dpkg-old",
+ ".*~",
+ # this shouldn't be shown in slackware
+ "inet2",
+ # those were found in gentoo
+ "bootmisc",
+ "checkfs",
+ "checkroot",
+ "clock",
+ "consolefont",
+ "crypto-loop",
+ "domainname",
+ "hostname",
+ "keymaps",
+ "localmount",
+ "net\..*",
+ "numlock",
+ "depscan\.sh",
+ "functions\.sh",
+ "halt\.sh",
+ "reboot\.sh",
+ "rmnologin",
+ "runscript\.sh",
+ "serial",
+ "shutdown\.sh",
+ "switch",
+ # those were found in FreeBSD
+ "DAEMON",
+ "LOGIN",
+ "NETWORKING",
+ "SERVERS",
+ "addswap",
+ "adjkerntz",
+ "archdep",
+ "atm2\.sh",
+ "atm3\.sh",
+ "ccd",
+ "cleanvar",
+ "devdb",
+ "devfs",
+ "dhclient",
+ "diskless",
+ "dumpon",
+ "fsck",
+ "hostname",
+ "initdiskless",
+ "initrandom",
+ "ldconfig",
+ "local",
+ "localdaemons",
+ "mountcritlocal",
+ "mountcritremote",
+ "msgs",
+ "netif",
+ "network1",
+ "network2",
+ "network3",
+ "nisdomain",
+ "othermta",
+ "pccard",
+ "pcvt",
+ "pwcheck",
+ "random",
+ "rcconf\.sh",
+ "root",
+ "savecore",
+ "securelevel",
+ "serial",
+ "sppp",
+ "swap1",
+ "syscons",
+ "sysctl",
+ "ttys",
+ "virecover",
+ # These are the services found in SuSE
+ "rc[sS0-9]\.d",
+ "boot",
+ "boot\..*",
+ ];
+
+ foreach $i (@$service_forbidden_list)
+ {
+ return 1 if ($service =~ "^$i\$");
+ }
+
+ return 0;
+}
+
+
+# Ok, maybe we should define this roles stuff a bit:
+#
+# SYSTEM: all system related services that only powerusers care of
+# SOUND: any service related to sound
+# WEB_SERVER: any web server
+# COMMAND_SCHEDULER: any service which runs scheduled commands
+# NETWORK: network related services that only powerusers care of
+# PRINTER_SERVICE: printing daemons in general
+# DYNAMIC_DNS: Dinamic DNS services
+# DICT:
+# MTA: Mail transport agents
+# MAIL_FETCHER: services that fetch the mail from other accounts
+# DISPLAY_MANAGER: Display managers
+# SYSTEM_LOGGER: system log services
+# DATABASE_SERVER: database servers
+# FILE_SERVER: file servers
+# NTP_SERVER: Network time protocol servers
+# SECURE_SHELL_SERVER: Secure shell servers
+# AUTOMOUNTER: automounter daemons and so
+# ANTIVIRUS:
+# FILE_SHARING: for emule-like services
+# FTP_SERVER:
+#
+#
+# If you feel that there are more important/necessary roles,
+# mail me at carlosg@gnome.org
+
+sub get_role
+{
+ my ($script) = @_;
+
+ my %service_roles = (
+ "acpid" => "SYSTEM",
+ "alsa" => "SOUND",
+ "am-utils" => "AUTOMOUNTER",
+ "amavis" => "ANTIVIRUS",
+ "amavis-ng" => "ANTIVIRUS",
+ "apache" => "WEB_SERVER",
+ "apache-perl" => "WEB_SERVER",
+ "apache-ssl" => "WEB_SERVER",
+ "apache2" => "WEB_SERVER",
+ "anacron" => "COMMAND_SCHEDULER",
+ "apmd" => "SYSTEM",
+ "atd" => "COMMAND_SCHEDULER", #FIXME
+ "atftpd" => "FTP_SERVER",
+ "aumix" => "SOUND",
+ "autofs" => "AUTOMOUNTER",
+ "bind" => "NETWORK",
+ "binfmt-support" => "SYSTEM",
+ "bootlogd" => "SYSTEM",
+ "chargen" => "NETWORK",
+ "chargen-udp" => "NETWORK",
+ "cherokee" => "WEB_SERVER",
+ "clamav-daemon" => "ANTIVIRUS",
+ "courier" => "MTA",
+ "courier-mta" => "MTA",
+ "cpufreqd" => "SYSTEM",
+ "cron" => "COMMAND_SCHEDULER",
+ "crond" => "COMMAND_SCHEDULER",
+ "cupsd" => "PRINTER_SERVICE",
+ "cupsys" => "PRINTER_SERVICE",
+ "daytime" => "NETWORK",
+ "daytime-udp" => "NETWORK",
+ "dbus-1" => "SYSTEM",
+ "ddclient" => "DYNAMIC_DNS",
+ "dhis-client" => "DYNAMIC_DNS",
+ "dictd" => "DICT",
+ "echo" => "NETWORK",
+ "echo-udp" => "NETWORK",
+ "esound" => "SOUND",
+ "exim" => "MTA",
+ "fam" => "SYSTEM",
+ "fcron" => "COMMAND_SCHEDULER",
+ "firstboot" => "SYSTEM",
+ "festival" => "SOUND", #FIXME
+ "fetchmail" => "MAIL_FETCHER",
+ "freenet6" => "NETWORK",
+ "ftpd" => "FTP_SERVER",
+ "gdm" => "DISPLAY_MANAGER",
+ "gpm" => "SYSTEM", #FIXME
+ "hdparm" => "SYSTEM",
+ "hotplug" => "SYSTEM",
+ "httpd" => "WEB_SERVER",
+ "inetd" => "NETWORK",
+ "iptables" => "NETWORK",
+ "irda" => "SYSTEM",
+ "isakmpd" => "NETWORK",
+ "isdn" => "NETWORK",
+ "joystick" => "SYSTEM",
+ "kdm" => "DISPLAY_MANAGER",
+ "keytable" => "SYSTEM",
+ "klogd" => "SYSTEM_LOGGER",
+ "kudzu" => "SYSTEM",
+ "lircd" => "SYSTEM",
+ "lircmd" => "SYSTEM",
+ "local" => "SYSTEM",
+ "lpd" => "PRINTER_SERVICE",
+ "lpdng" => "PRINTER_SERVICE",
+ "mailscanner" => "ANTIVIRUS",
+ "makedev" => "SYSTEM",
+ "metalog" => "SYSTEM_LOGGER",
+ "mldonkey-server" => "FILE_SHARING",
+ "modules" => "SYSTEM",
+ "module-init-tools" => "SYSTEM",
+ "mysql" => "DATABASE_SERVER",
+ "muddleftpd" => "FTP_SERVER",
+ "named" => "NETWORK",
+ "netfs" => "SYSTEM",
+ "network" => "SYSTEM",
+ "nfs" => "FILE_SERVER",
+ "nfs-user-server" => "FILE_SERVER",
+ "nfs-kernel-server" => "FILE_SERVER",
+ "nfslock" => "SYSTEM",
+ "nscd" => "NETWORK",
+ "ntpd" => "NTP_SERVER",
+ "ntpdate" => "NTP_SERVER",
+ "ntp-client" => "NTP_CLIENT",
+ "ntp-simple" => "NTP_SERVER",
+ "oftpd" => "FTP_SERVER",
+ "oops" => "NETWORK",
+ "pcmcia" => "SYSTEM",
+ "pdnsd" => "NETWORK",
+ "pipsecd" => "NETWORK",
+ "portmap" => "NETWORK",
+ "postfix" => "MTA",
+ "postgresql" => "DATABASE_SERVER",
+ "postgresql-7.4" => "DATABASE_SERVER",
+ "postgresql-8.0" => "DATABASE_SERVER",
+ "ppp" => "NETWORK",
+ "proftpd" => "FTP_SERVER",
+ "privoxy" => "NETWORK",
+ "pure-ftpd" => "FTP_SERVER",
+ "qmail" => "MTA",
+ "random" => "SYSTEM",
+ "rawdevices" => "SYSTEM",
+ "rhnsd" => "SYSTEM",
+ "rsync" => "NETWORK",
+ "rsyncd" => "NETWORK",
+ "samba" => "FILE_SERVER",
+ "saslauthd" => "SYSTEM", # FIXME: maybe a SECURITY role makes sense?
+ "sendmail" => "MTA",
+ "servers" => "NETWORK",
+ "services" => "NETWORK",
+ "setserial" => "SYSTEM",
+ "sgi_fam" => "SYSTEM",
+ "smartmontools" => "SYSTEM",
+ "spamassassin" => "SYSTEM",
+ "snmpd" => "NETWORK",
+ "ssh" => "SECURE_SHELL_SERVER",
+ "sshd" => "SECURE_SHELL_SERVER",
+ "sysklogd" => "SYSTEM_LOGGER",
+ "syslog" => "SYSTEM_LOGGER",
+ "tftpd-hpa" => "FTP_SERVER",
+ "time" => "NETWORK",
+ "time-udp" => "NETWORK",
+ "urandom" => "SYSTEM",
+ "vcron" => "COMMAND_SCHEDULER",
+ "vmware" => "SYSTEM", # FIXME
+ "vsftpd" => "FTP_SERVER",
+ "wdm" => "DISPLAY_MANAGER",
+ "webmin" => "SYSTEM", # FIXME as well
+ "winbind" => "NETWORK",
+ "wine" => "SYSTEM", # FIXME like vmware
+ "wu-ftpd" => "FTP_SERVER",
+ "wzdftpd" => "FTP_SERVER",
+ "xdm" => "DISPLAY_MANAGER",
+ "xfs" => "SYSTEM",
+ "xinetd" => "NETWORK",
+ "zmailer" => "MTA",
+ );
+
+ my ($role) = $service_roles{$script};
+
+ return $role if ($role);
+ return "UNKNOWN";
+}
+
+1;
diff --git a/Loader.pl.in b/Loader.pl.in
index c60ef51..4973525 100755
--- a/Loader.pl.in
+++ b/Loader.pl.in
@@ -42,6 +42,8 @@ use UsersConfig;
use GroupsConfig;
use TimeConfig;
use NTPConfig;
+use HostsConfig;
+use ServicesConfig;
# Initialize tool
&Utils::Backend::init ($name, $version, $description, $directives, @ARGV);
@@ -52,13 +54,15 @@ my $service = Net::DBus::Service->new($Utils::Backend::DBUS_PREFIX, $bus);
my $reactor = Net::DBus::Reactor->new();
#Initialize all objects
-my $smb_config = SMBConfig->new ($service);
-my $nfs_config = NFSConfig->new ($service);
-my $shells_config = ShellsConfig->new ($service);
-my $users_config = UsersConfig->new ($service);
-my $groups_config = GroupsConfig->new ($service);
-my $time_config = TimeConfig->new ($service);
-my $ntp_config = NTPConfig->new ($service);
+my $smb_config = SMBConfig->new ($service);
+my $nfs_config = NFSConfig->new ($service);
+my $shells_config = ShellsConfig->new ($service);
+my $users_config = UsersConfig->new ($service);
+my $groups_config = GroupsConfig->new ($service);
+my $time_config = TimeConfig->new ($service);
+my $ntp_config = NTPConfig->new ($service);
+my $hosts_config = HostsConfig->new ($service);
+my $services_config = ServicesConfig->new ($service);
$reactor->manage($bus->{connection});
$reactor->add_timeout (50, Net::DBus::Callback->new(method => \&Utils::Monitor::do_monitor_files));
diff --git a/Network/Hosts.pm b/Network/Hosts.pm
new file mode 100644
index 0000000..41babc9
--- /dev/null
+++ b/Network/Hosts.pm
@@ -0,0 +1,58 @@
+#-*- Mode: perl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+# Hosts Configuration handling
+#
+# Copyright (C) 2000-2001 Ximian, Inc.
+#
+# Authors: Hans Petter Jansson <hpj@ximian.com>
+# Carlos Garnacho <carlosg@gnome.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Library General Public License as published
+# by the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+
+package Network::Hosts;
+
+sub get
+{
+ my ($statichosts, @arr);
+
+ $statichosts = &Utils::Parse::split_hash ("/etc/hosts", "[ \t]+", "[ \t]+");
+
+ foreach $i (sort keys %$statichosts)
+ {
+ push @arr, [$i, $$statichosts{$i}];
+ }
+
+ return \@arr;
+}
+
+sub get_dns
+{
+ my (@dns);
+
+ @dns = &Utils::Parse::split_all_unique_hash_comment ("/etc/resolv.conf", "nameserver", "[ \t]+");
+
+ return @dns;
+}
+
+sub get_search_domains
+{
+ my (@search_domains);
+
+ @search_domains = &Utils::Parse::split_first_array_unique ("/etc/resolv.conf", "search", "[ \t]+", "[ \t]+");
+
+ return @search_domains;
+}
+
+1;
diff --git a/ServicesConfig.pm b/ServicesConfig.pm
new file mode 100644
index 0000000..2e41d98
--- /dev/null
+++ b/ServicesConfig.pm
@@ -0,0 +1,65 @@
+#-*- Mode: perl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+# DBus object for the Services config
+#
+# Copyright (C) 2005 Carlos Garnacho
+#
+# Authors: Carlos Garnacho Parro <carlosg@gnome.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Library General Public License as published
+# by the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+
+package ServicesConfig;
+
+use base qw(Net::DBus::Object);
+use Init::Services;
+
+my $OBJECT_NAME = "ServicesConfig";
+my $SHARES_PATH = $Utils::Backend::DBUS_PATH . "/" . $OBJECT_NAME;
+
+sub new
+{
+ my $class = shift;
+ my $self = $class->SUPER::new ($SHARES_PATH,
+ {
+ $OBJECT_NAME => {
+ methods => {
+ "get" => {
+ params => [],
+ returns => [[ "array", [ "struct", "string", "string", [ "array", [ "struct", "string", "string", "int32" ]]]]],
+ },
+ },
+ signals => {
+ "changed" => [],
+ },
+ },
+ },
+ @_);
+ bless $self, $class;
+# Utils::Monitor::monitor_files (&Shares::Exports::get_files (),
+# $self, $OBJECT_NAME, "changed");
+ return $self;
+}
+
+sub get
+{
+ my ($self) = @_;
+ my ($config);
+
+ $config = &Init::Services::get ();
+
+ return $config;
+}
+
+1;