On Sat, Oct 12, 2024 at 10:23:00PM -0400, Greg Wooledge wrote:
> On Sat, Oct 12, 2024 at 21:43:39 -0400, Karl Vogel wrote:
> > >> In previous messages:
> > >
> > > system('systemctl', '--quiet', [...] , @start_units) == 0
> > > or die("Could not execute systemctl: $!");
> > >
> > > Could not execute systemctl: at /usr/bin/deb-systemd-invoke line 148.
> >
> > See the ":" followed by two spaces? Unlike systemctl, well-behaved
> > programs set "errno" when they puke, and that setting is turned into
> > a more-or-less useful error message like "Permission denied".
> > "$!" would have held that message.
>
> I don't think this is correct. A *function* can set errno (a global
> variable in C), in addition to returning a value. A process can't,
> unless there has been some major change to the Unix process model that
> I've missed.
That's correct: in Perl, $! is the ERRNO of the last /failed/ system call
(think, e.g. open). What the OP (original prorammer? ;-) wanted to say
here is $?, which would be the "child exit status" -- i.e. what systemctl
wants to tell us, if anything.
The errno is fine (more precisely: wasn't touched, so it stayed at 0 if
it was before) since the fork() underlying system(...) actually succeeded.
See man perlvar(1) for the gory details (since it's big, search for ERRNO
or CHILD_ERROR there, respectively).
Cheers
--
t
Attachment:
signature.asc
Description: PGP signature