浏览代码

Force the -relative-to-installdir pattern for chrootings

George Baugh 5 月之前
父节点
当前提交
f32d989c19
共有 2 个文件被更改,包括 10 次插入 和 8 次删除
  1. 4 3
      bin/tpsgi
  2. 6 5
      lib/TPSGI.pm

+ 4 - 3
bin/tpsgi

@@ -23,16 +23,17 @@ tpsgi obeys a config file, ~/.tpsgi.ini which is in Config::Simple (key=value) f
 
     verbose     # Whether to print all log messages or not
     custom_log  # Custom location for default (rotated) log
-    routers     # Router module(s), separate with comma
+    routers     # Router module(s), separate with comma.  Relative to TPSGI install dir.
     indices     # Dirindex files.  In addition to index.html, index.htm, index.cgi
     loggers     # Logger module(s), separate with comma
     auth        # Authentication module
     domain      # Domain name of the application, used by things like service files
-    basedir     # Directory you want to chdir into on startup (defaults to HOME).
+    basedir     # Directory you want to chdir into on startup. Relative to TPSGI install dir.  Default '.'
     user        # Who to run as
     http_user   # Who's proxying this application (used for statics)
 
 The idea is that this application is going to be run in a chroot with the user's homedir being the application dir.
+This is why the various paths asked for are relative to the tPSGI install dir.
 
 =cut
 
@@ -52,7 +53,7 @@ our $app = sub {
     umask 0022;
 
     # Change your dir into whatever basedir you need to be in
-    chdir($options{'basedir'}) or die "Can't chdir into $options{'basedir'}: $!";
+    chdir("$options{tpsgi_dir}/$options{basedir}") or die "Can't chdir into $options{tpsgi_dir}/$options{'basedir'}: $!";
 
     # If we have manually set the NYTPROF var, use it and don't try to control
     # When to stop or start it.

+ 6 - 5
lib/TPSGI.pm

@@ -228,19 +228,20 @@ sub new {
     no strict 'refs';
     foreach my $route ( @{ $self->{routers} } ) {
 
-        die "No such routing module $route" unless -f $route;
+        die "No such routing module $route" unless -f "$options{tpsgi_dir}/$route";
 
         # The router needs to exist and have nonzero numbers of routes.
         my ($package) = basename($route) =~ m/(\S+)\.pm$/;
         my $r         = "$package\:\:routes";
         my $a         = "$package\:\:aliases";
 
-        my $libdir = dirname($route);
+		# It also should be a top-level namespace, not somewhere deep down. KISS.
+        my $libdir = dirname("$options{tpsgi_dir}/$route");
         push( @INC, $libdir );
 
         local $@;
-        $self->DEBUG("require $route");
-        my $success = eval { require $route; 1; };
+        $self->DEBUG("require $options{tpsgi_dir}/$route");
+        my $success = eval { require "$options{tpsgi_dir}/$route"; 1; };
         if ($success) {
             my $pkg_routes = *$r{ARRAY};
             for ( my $i = 0; $i < @$pkg_routes; $i += 2 ) {
@@ -1086,7 +1087,7 @@ sub get_config {
         domain     => '',
         user       => '',
         binds      => [],
-        basedir    => $ENV{'HOME'},
+        basedir    => '.',
         http_user  => '',
 		tpsgi_dir  => Cwd::getcwd(),
     );