Commit Diff
Diff:
d3d07147e45c1d13f2879130149ab354574e0f32
270695a375c6af6579a26ccc62cef0be2b98a3e0
Commit:
270695a375c6af6579a26ccc62cef0be2b98a3e0
Tree:
3c2ed83effdecf75bf60bb5f1480d440b802cd7c
Author:
Omar Polo <op@omarpolo.com>
Date:
Tue Aug 30 10:25:46 2022 UTC
Message:
use File::Temp for the index pages; specify why it's not using tmppath

we can't use the tmppath pledge promise as File::Temp checks whether
/tmp exists. We could unveil("/tmp", "r") and use `tmppath', but it
seem misleading.

(noticed after semarie@ reminded me of `tmppath')
commit - d3d07147e45c1d13f2879130149ab354574e0f32
commit + 270695a375c6af6579a26ccc62cef0be2b98a3e0
blob - c4a737f62a074b753ace5130fde82a16f29cffaf
blob + 1cdf9604017edb0e7c5ffaae40eac7402c2975d6
--- mkindex
+++ mkindex
@@ -9,6 +9,7 @@ use v5.32;
use strict;
use warnings;
use v5.32;
+use File::Temp qw(tempfile);
use OpenBSD::Pledge;
use OpenBSD::Unveil;
@@ -23,6 +24,7 @@ my $from_day;
my $pfh; # page file handle
my $page = 0;
my @pages;
+my @files;
my $from_day;
my $to_day;
my $threads_seen = 0;
@@ -56,11 +58,10 @@ sub nextfile {
sub nextfile {
endfile if defined $pfh;
$page += 1;
- my $path = pagename($page);
- # XXX: mkstemp would be better...
- open($pfh, '>', "/tmp/$path")
- or die "can't open $path: $!";
+ my $path;
+ ($pfh, $path) = tempfile "/tmp/gotmarc.index.XXXXXXXXXX";
+ push @files, $path;
say $pfh "<div class='thread'><ul>";
}
@@ -91,7 +92,7 @@ sub renderpages {
for (my $i = 1; $i <= $page; $i++) {
my $name = pagename($i);
- my $path = "/tmp/$name";
+ my $path = shift @files;
my $dest = "$outdir/$name";
open(my $pfh, '>', $dest)
@@ -160,9 +161,12 @@ unveil("/tmp", "rwc") or die "unveil /tmp: $!";
unveil($outdir, "rwc") or die "unveil $outdir: $!";
unveil(".", "r") or die "unveil .: $!";
+
+# can't use tmppath because File::Temp checks wether /tmp exists.
unveil("/tmp", "rwc") or die "unveil /tmp: $!";
-pledge("stdio rpath wpath cpath") or die "pledge: $!";
+# fattr for File::Temp
+pledge("stdio rpath wpath cpath fattr") or die "pledge: $!";
nextfile;
Omar Polo