PAR-Packer fetching environment variables set in /etc/environment

[email protected] (Robin Twiggs) Fri, 6 May 2022 16:55:07 +1000
Newsgroups perl.par
Message-ID <CAAoMnnjT+FkPiUqCiLFDUWe7eW+5adSUsv0B2uKtWtDug4FrOQ@mail.gmail.com>
--000000000000612c2605de5257bd
Content-Type: text/plain; charset="UTF-8"

Hello,

Thanks for a very useful module.

I prefer to set PAR_GLOBAL_TEMP in /etc/environment file on linux.

I've come up with the following code I would like to contribute to achieve
this.
I suspect this code is probably best placed quite early in sub
_par_init_env:

BEGIN{
  my $envfile="/etc/environment";
  if (-r $envfile)
  {
    open(my $fh,"<",$envfile)or die $!;
    while(<$fh>)
    {
      my $line=$_;
      $line=~s/^\s+|\s+$//g;      my @ea=split("=",$line);
      if((scalar @ea == 2)and($ea[1]=~m/^[\S]+$/))
      {
        $ENV{$ea[0]}=$ea[1];
      }
    }
  }
}


I find cron jobs, systemd services and other executables
that call PAR EXEs' don't always have the correct environment set.
This causes PAR to then attempt to unpack in /tmp/ when they should
unpack elsewhere as set in PAR_GLOBAL_TEMP in /etc/environment.

The attempt to unpack fails if /tmp/ is mounted noexec, which I'm finding
is being used more often these days.


Thanks,
Robin Twiggs

--000000000000612c2605de5257bd
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hello,<br><br>Thanks for a very useful module.<br><br>I pr=
efer to set=C2=A0PAR_GLOBAL_TEMP in /etc/environment file on linux.<br><br>=
I&#39;ve come up with the following code I would like to contribute to achi=
eve this.<br>I suspect this code is probably best placed quite early in=C2=
=A0sub _par_init_env:<div><br></div><div><pre class=3D"gmail-code-java" sty=
le=3D"margin-top:0px;margin-bottom:0px;padding:0px;max-height:30em;overflow=
:auto;white-space:pre-wrap;color:rgb(23,43,77);font-size:12px;background-co=
lor:rgb(244,245,247)">BEGIN{
  my $envfile=3D<span class=3D"gmail-code-quote" style=3D"color:rgb(0,145,0=
)">&quot;/etc/environment&quot;</span>;
  <span class=3D"gmail-code-keyword" style=3D"color:rgb(145,0,145)">if</spa=
n> (-r $envfile)
  {
    open(my $fh,<span class=3D"gmail-code-quote" style=3D"color:rgb(0,145,0=
)">&quot;&lt;&quot;</span>,$envfile)or die $!;
    <span class=3D"gmail-code-keyword" style=3D"color:rgb(145,0,145)">while=
</span>(&lt;$fh&gt;)
    {
      my $line=3D$_;
      $line=3D~s/^\s+|\s+$<span class=3D"gmail-code-comment" style=3D"color=
:rgb(128,128,128)">//g;
</span>      my @ea=3Dsplit(<span class=3D"gmail-code-quote" style=3D"color=
:rgb(0,145,0)">&quot;=3D&quot;</span>,$line);
      <span class=3D"gmail-code-keyword" style=3D"color:rgb(145,0,145)">if<=
/span>((scalar @ea =3D=3D 2)and($ea[1]=3D~m/^[\S]+$/))
      {
        $ENV{$ea[0]}=3D$ea[1];
      }
    }
  }
}</pre></div><div><br></div><div>I find cron jobs, systemd services and oth=
er executables<br>that call PAR EXEs&#39; don&#39;t always have the correct=
 environment set.<br>This causes PAR to then attempt to unpack in /tmp/ whe=
n they should<br>unpack elsewhere as set in PAR_GLOBAL_TEMP in /etc/environ=
ment.<br><br></div><div>The attempt to unpack fails if /tmp/ is mounted noe=
xec, which I&#39;m finding is being used more often these days.</div><div>=
=C2=A0</div><div><br></div><div>Thanks,<br>Robin Twiggs</div></div>

--000000000000612c2605de5257bd--