9   $dir    =  Cwd::getcwd() . '/' . $dir unless $dir =~ m|^/|;
 
  12   chdir($dir) || die "Cannot change directory to ${dir}\n";
 
  14   unshift @INC, "modules/override"; # Use our own versions of various modules (e.g. YAML).
 
  15   push    @INC, "modules/fallback"; # Only use our own versions of modules if there's no system version.
 
  18 use CGI qw( -no_xhtml);
 
  23 use English qw(-no_match_vars);
 
  24 use POSIX qw(setuid setgid);
 
  26 use SL::DB::BackgroundJob;
 
  27 use SL::BackgroundJob::ALL;
 
  29 use SL::Helper::DateTime;
 
  36 # this is a cleaned up version of am.pl
 
  37 # it lacks redirection, some html setup and most of the authentication process.
 
  38 # it is assumed that anyone with physical access and execution rights on this script
 
  39 # won't be hindered by authentication anyway.
 
  41   my $login = $lx_office_conf{task_server}->{login};
 
  45   $::lxdebug = LXDebug->new;
 
  46   $::locale  = Locale->new($::lx_office_conf{system}->{language});
 
  47   $::cgi     = CGI->new qw();
 
  49   $::auth    = SL::Auth->new;
 
  51   die 'cannot reach auth db'               unless $::auth->session_tables_present;
 
  53   $::auth->restore_session;
 
  55   require "bin/mozilla/common.pl";
 
  57   die "cannot find user $login"            unless %::myconfig = $::auth->read_user($login);
 
  58   die "cannot find locale for user $login" unless $::locale   = Locale->new('de');
 
  62   my $user = $lx_office_conf{task_server}->{run_as};
 
  66   while (my @details = getpwent()) {
 
  67     next unless $details[0] eq $user;
 
  68     ($uid, $gid) = @details[2, 3];
 
  74     print "Error: Cannot drop privileges to ${user}: user does not exist\n";
 
  79     print "Error: Cannot drop group privileges to ${user} (group ID $gid): $!\n";
 
  84     print "Error: Cannot drop user privileges to ${user} (user ID $uid): $!\n";
 
  92   SL::LxOfficeConf->read;
 
  94   die "Missing section [task_server] in config file"                unless $lx_office_conf{task_server};
 
  95   die "Missing key 'login' in section [task_server] in config file" unless $lx_office_conf{task_server}->{login};
 
 106       $::lxdebug->message(0, "Retrieving jobs") if $lx_office_conf{task_server}->{debug};
 
 108       my $jobs = SL::DB::Manager::BackgroundJob->get_all_need_to_run;
 
 110       $::lxdebug->message(0, "  Found: " . join(' ', map { $_->package_name } @{ $jobs })) if $lx_office_conf{task_server}->{debug} && @{ $jobs };
 
 112       foreach my $job (@{ $jobs }) {
 
 113         # Provide fresh global variables in case legacy code modifies
 
 115         $::locale = Locale->new($::lx_office_conf{system}->{language});
 
 124     if ($lx_office_conf{task_server}->{debug}) {
 
 125       $::lxdebug->message(0, "Exception during execution: ${EVAL_ERROR}") if !$ok;
 
 126       $::lxdebug->message(0, "Sleeping");
 
 129     my $seconds = 60 - (localtime)[0];
 
 130     sleep($seconds < 30 ? $seconds + 60 : $seconds);
 
 135 my $pidbase = "${cwd}/users/pid";
 
 137 mkdir($pidbase) if !-d $pidbase;
 
 139 my $file = -f "${cwd}/config/lx_office.conf" ? "${cwd}/config/lx_office.conf" : "${cwd}/config/lx_office.conf.default";
 
 140 newdaemon(configfile => $file,
 
 141           progname   => 'lx-office-task-server',
 
 142           pidbase    => "${pidbase}/",