Re: chgrp, Illegal seek


Subject: Re: chgrp, Illegal seek
From: Axel Rose (rose@sj.com)
Date: Tue May 01 2001 - 17:29:46 EDT


Sorry for readers if this is getting a bit Perl specific. (and way long)
If the whole thing is working I'd like to make the solution available
for others who are in need of a server based PDF generator in their
Mac network.

> > system( "chgrp", "nobody", $out ) && &my_error_log( "$!" );
>
>Unless system fails, $! is undefined. Use $? if you want to check the exit
>status, or if you really need the output, redirect it to a file and read
>that in.

The full code logs the problem to a file.

open( L, ">>if.log" ) || die "can't open if.log for appending\n$!";
my $out = "$TMP/psout$$.ps";
open( O, ">$out" ) || ( &logit( "fatal - can't create '$out'\n$!" ) && exit 1);
print O while(<STDIN>);
close O;
&logit( "created PS file - '$out'" );

system( "chmod", 660, $out ) &&
        ( &logit( "error - 'chmod 660 $out' failed\n$!" ) && &sys_logit( $? ) );
system( "chgrp", nobody, $out ) &&
      ( &logit( "error - 'chgrp nobody $out' failed\n$!" ) && &sys_logit( $? ) );

sub logit
{
        print L scalar localtime( time ), " : $_[0]\n";
        return 1;
}

sub sys_logit
{
        my $return = $_[0];

        my $ret = $return >> 8;
        my $signal = $return & 127;
        my $coredumped = $return & 128;
        &logit( "error - returned with '$ret'" ) if ( $ret );
        &logit( "error - stopped by signal '$signal'" ) if ( $signal );
        &logit( "error - core dumped" ) if ( $coredumped );
        &logit( "no error - called by accident??" ) unless( $return );
        return 1;
}

...

within /etc/printcap I put
lp:\
        :sd=/var/spool/lpd/lp:\
        :mx#0:\
        :if=/etc/atalk/ifpdf.pl:\
        :send_try=1:\
        :sh:\
        :lp=/dev/null:

and in papd.conf
pdf-terminator:\
        :pr=|/usr/bin/lpr -Plp:op=root:\
        :pd=/usr/share/ppd/acro4.ppd:

system() failes, returns 1, the logit() and sys_logit subs are executed and
the logfile shows (showed)

Tue May 1 17:42:53 2001 : error - 'chgrp nobody /tmp/pdf/psout2070.pdf' failed
Illegal seek

The code is equivalent to
  system( "..." ) == 0 or ( logit($!) && sys_logit($?) )

So $! should contain the system error string. At least I think so.
But some quirk must be there. I can't reproduce the string "Illegal seek"
now (perhaps because of code cleanup). Now $! reads
Operation not permitted.

And that is the real question. The lp daemon can't do the "chgrp" whereas
the "lp" user can do it in a login shell. I'm really not sure but would
love to find a better solution than world writable files.

Thanks for the patience and the great help so far

Axel



This archive was generated by hypermail 2b28 : Sun Oct 14 2001 - 03:04:39 EDT