X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=make%2Ftemplate%2Finspircd;h=d5e89040ddd6a240a0285732e23da77659023ac2;hb=937c562ce4bfda96386ec28db82b3b4ef5b7b21d;hp=05cbe0ea03df3a052219589cefd92d3255cbb40c;hpb=43ea75c0b3b64f1ebde2c7048a64d1f5bb3242fe;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/make/template/inspircd b/make/template/inspircd index 05cbe0ea0..d5e89040d 100644 --- a/make/template/inspircd +++ b/make/template/inspircd @@ -1,9 +1,9 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # +------------------------------------+ # | Inspire Internet Relay Chat Daemon | # +------------------------------------+ # -# InspIRCd: (C) 2002-2009 InspIRCd Development Team +# InspIRCd: (C) 2002-2010 InspIRCd Development Team # See: http://wiki.inspircd.org/Credits # # This program is free but copyrighted software; see @@ -22,6 +22,23 @@ my $runpath = "@BASE_DIR@"; my $valgrindlogpath = "$basepath/valgrindlogs"; my $executable = "@EXECUTABLE@"; my $version = "@VERSION@"; +my $uid = "@UID@"; + +if ($< == 0 || $> == 0) { + if ($uid !~ /^\d+$/) { + # Named UID, look it up + $uid = getpwnam $uid; + } + if (!$uid) { + die "Cannot find a valid UID to change to"; + } + # drop root if we were configured with an ircd UID + $< = $uid; + $> = $uid; + if ($< == 0 || $> == 0) { + die "Could not drop root: $!"; + } +} our($pid,$pidfile); # Lets see what they want to do.. Set the variable (Cause i'm a lazy coder) @@ -153,7 +170,7 @@ sub dev_debug(@) checkgdb(); # If we are still alive here.. Try starting the IRCd.. - exec 'gdb', "--command=$basepath/.gdbargs", '--args', "$binpath/$executable", qw(-nofork -debug), @_; + exec 'gdb', "--command=$basepath/.gdbargs", '--args', "$binpath/$executable", qw(--nofork --debug), @_; die "Failed to start GDB: $!\n"; } @@ -172,7 +189,7 @@ sub dev_screendebug(@) # If we are still alive here.. Try starting the IRCd.. print "Starting InspIRCd in `screen`, type `screen -r` when the ircd crashes to view the gdb output and get a backtrace.\n"; print "Once you're inside the screen session press ^C + d to re-detach from the session\n"; - exec qw(screen -m -d gdb), "--comand=$basepath/.gdbargs", '-args', "$binpath/$executable", qw(-nofork -debug -nolog), @_; + exec qw(screen -m -d gdb), "--command=$basepath/.gdbargs", '-args', "$binpath/$executable", qw(--nofork --debug --nolog), @_; die "Failed to start screen: $!\n"; } @@ -192,7 +209,7 @@ sub dev_valdebug(@) # If we are still alive here.. Try starting the IRCd.. # May want to do something with these args at some point: --suppressions=.inspircd.sup --gen-suppressions=yes # Could be useful when we want to stop it complaining about things we're sure aren't issues. - exec qw(valgrind -v --tool=memcheck --leak-check=yes --db-attach=yes --num-callers=10), "$binpath/$executable", qw(-nofork -debug -nolog), @_; + exec qw(valgrind -v --tool=memcheck --leak-check=yes --db-attach=yes --num-callers=10), "$binpath/$executable", qw(--nofork --debug --nolog), @_; die "Failed to start valgrind: $!\n"; } @@ -229,7 +246,7 @@ sub dev_valdebug_unattended(@) exec qw(valgrind -v --tool=memcheck --leak-check=full --show-reachable=yes --num-callers=15 --track-fds=yes), "--suppressions=$binpath/valgrind.sup", qw(--gen-suppressions=all), qw(--leak-resolution=med --time-stamp=yes --log-fd=2 --), - "$binpath/$executable", qw(-nofork -debug -nolog), @_; + "$binpath/$executable", qw(--nofork --debug --nolog), @_; die "Can't execute valgrind: $!\n"; } } @@ -251,7 +268,7 @@ sub dev_screenvaldebug(@) # If we are still alive here.. Try starting the IRCd.. print "Starting InspIRCd in `screen`, type `screen -r` when the ircd crashes to view the valgrind and gdb output and get a backtrace.\n"; print "Once you're inside the screen session press ^C + d to re-detach from the session\n"; - exec qw(screen -m -d valgrind -v --tool=memcheck --leak-check=yes --db-attach=yes --num-callers=10), "$binpath/$executable", qw(-nofork -debug -nolog), @_; + exec qw(screen -m -d valgrind -v --tool=memcheck --leak-check=yes --db-attach=yes --num-callers=10), "$binpath/$executable", qw(--nofork --debug --nolog), @_; die "Failed to start screen: $!\n"; } @@ -368,11 +385,11 @@ sub getstatus { sub getprocessid { - my $pid; - open PIDFILE, "< $pidfile" or return 0; + my $pid = 0; + open PIDFILE, '<', $pidfile or return 0; while() { - $pid = $_; + /^(\d+)$/ and $pid = $1; } close PIDFILE; return $pid; @@ -404,187 +421,3 @@ sub checkscreen exit; } } - -sub checkxmllint -{ - open(FH, "xmllint|") or die "Couldn't start xmllint: $!\n"; -} - -sub cmd_checkconf() -{ - checkxmllint(); - validateconf($conf); - print "Config check complete\n"; - exit 0; -} - -my %filechecked; - -sub validateconf -{ - my ($file) = @_; - - # Are We using a relative path? - if ($file !~ /^\//) { - # Convert it to a full path.. - $file = $runpath . $file; - } - - # Have we checked this file before? - return if $filechecked{$file}; - $filechecked{$file} = 1; - - # Open the File.. - open INFILE, "< $file" or die "Unable to open file $file\n"; - # Grab entire file contents.. - my(@lines) = ; - # Close the file - close INFILE; - - # remove trailing spaces - chomp(@lines); - - my @newlines = (); - my @blanks = (); - my $conline; - - push @newlines, ""; -# push @newlines, ""; - push @newlines, ""; - - for my $i (@lines) - { - # remove trailing newlines - chomp($i); - - # convert tabs to spaces - $i =~ s/\t/ /g; - - # remove leading spaces - $i =~ s/^ *//; - - # remove comments - $i =~ s/^#.*//; - - # remove trailing #s - $i =~ s/(.*)#$/\1/; - - # remove trailing comments - my $line = ""; - my $quote = 0; - for (my $j = 0; $j < length($i); $j++) - { - if (substr($i,$j, 1) eq '"') { $quote = ($quote) ? 0 : 1; } elsif (substr($i,$j, 1) eq "#" && !$quote) { last; } - $line .= substr($i,$j, 1); - } - $i = $line; - - # remove trailing spaces - $i =~ s/ *$//; - - # setup incf for include check and clean it up, since this breaks parsing use local var - my $incf = $i; - $incf =~ s/[^=]+=\s(.*)/\1/; - - # include file? - if (($incf =~ s/\//i) && ($incf !~ /^#/)) - { - # yes, process it - validateconf($1); - } - - if ($i =~ /^<.*/ && $conline =~ /^<.*/) - { - push @newlines, $conline; - push @newlines, @blanks; - $conline = $i; - } - - if ($i =~ /^<.*>$/) - { - $i =~ s/(.*)>$/\1 \/>/; - push @newlines, $i; - } - elsif ($i =~ /.*>$/) - { - $conline .= " $i"; - $conline =~ s/(.*)>$/\1 \/>/; - push @blanks, ""; - push @newlines, $conline; - push @newlines, @blanks; - $conline = ""; - undef @blanks; - } - elsif ($i =~ /^<.*/) - { - $conline = $i; - } - elsif ($conline =~ /^<.*/ && $i) - { - $conline .= " $i"; - push @blanks, ""; - } - else - { - if ($conline) - { - push @blanks, $i; - } - else - { - push @newlines, $i; - } - } - } - if ($conline) - { - push @newlines, $conline; - push @newlines, @blanks; - } - - push @newlines, ""; - - my $tmpfile; - do - { - $tmpfile = tmpnam(); - } until sysopen(TF, $tmpfile, O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW, 0700); - - for my $n (@newlines) - { - print TF "$n\n"; - } - close TF; - - my @result = `xmllint -noout $tmpfile 2>&1`; - chomp(@result); - - my $skip = 0; - for my $n (@result) - { - if ($skip) - { - $skip = 0; - next; - } - $n =~ s/$tmpfile\:\d*\: *//g; - if ($n =~ /.*config>.*/) - { - $n = ""; - $skip = 1; - } - - if ($n && !$skip) - { - if ($n =~ /line \d*/) - { - my $lineno = $n; - $lineno =~ s/.*line (\d*).*/\1/; - $lineno = $lineno-2; - $n =~ s/line (\d*)/line $lineno/; - } - print "$file : $n\n"; - } - } - unlink($tmpfile); -}