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;
 
  37   my $login = $lx_office_conf{task_server}->{login};
 
  41   $::lxdebug = LXDebug->new;
 
  42   $::locale  = Locale->new($::lx_office_conf{system}->{language});
 
  44   $::auth    = SL::Auth->new;
 
  45   $::request = { cgi => CGI->new({}) };
 
  47   die 'cannot reach auth db'               unless $::auth->session_tables_present;
 
  49   $::auth->restore_session;
 
  51   require "bin/mozilla/common.pl";
 
  53   die "cannot find user $login"            unless %::myconfig = $::auth->read_user(login => $login);
 
  54   die "cannot find locale for user $login" unless $::locale   = Locale->new('de');
 
  58   my $user = $lx_office_conf{task_server}->{run_as};
 
  62   while (my @details = getpwent()) {
 
  63     next unless $details[0] eq $user;
 
  64     ($uid, $gid) = @details[2, 3];
 
  70     print "Error: Cannot drop privileges to ${user}: user does not exist\n";
 
  75     print "Error: Cannot drop group privileges to ${user} (group ID $gid): $!\n";
 
  80     print "Error: Cannot drop user privileges to ${user} (user ID $uid): $!\n";
 
  88   SL::LxOfficeConf->read($self->{configfile});
 
  90   die "Missing section [task_server] in config file"                unless $lx_office_conf{task_server};
 
  91   die "Missing key 'login' in section [task_server] in config file" unless $lx_office_conf{task_server}->{login};
 
 102       $::lxdebug->message(0, "Retrieving jobs") if $lx_office_conf{task_server}->{debug};
 
 104       my $jobs = SL::DB::Manager::BackgroundJob->get_all_need_to_run;
 
 106       $::lxdebug->message(0, "  Found: " . join(' ', map { $_->package_name } @{ $jobs })) if $lx_office_conf{task_server}->{debug} && @{ $jobs };
 
 108       foreach my $job (@{ $jobs }) {
 
 109         # Provide fresh global variables in case legacy code modifies
 
 111         $::locale = Locale->new($::lx_office_conf{system}->{language});
 
 120     if ($lx_office_conf{task_server}->{debug}) {
 
 121       $::lxdebug->message(0, "Exception during execution: ${EVAL_ERROR}") if !$ok;
 
 122       $::lxdebug->message(0, "Sleeping");
 
 125     my $seconds = 60 - (localtime)[0];
 
 126     sleep($seconds < 30 ? $seconds + 60 : $seconds);
 
 131 my $pidbase = "${cwd}/users/pid";
 
 133 mkdir($pidbase) if !-d $pidbase;
 
 135 my $file = -f "${cwd}/config/lx_office.conf" ? "${cwd}/config/lx_office.conf" : "${cwd}/config/lx_office.conf.default";
 
 136 newdaemon(configfile => $file,
 
 137           progname   => 'lx-office-task-server',
 
 138           pidbase    => "${pidbase}/",