Subject: chgrp, Illegal seek

From: Axel Rose <[email-masked]>
Date: Tue, 1 May 2001 17:41:29 +0200

Hello,

I'm just wondering whether the following problem is netatalk
related. I doubt but hope that other users came across this before ...

A have a lpd input filter written in Perl.
The input filter is run by "lp" who is a member of the "nobody"
group.

I log the error "Illegal seek" from this line
system( "chgrp", "nobody", $out ) && &my_error_log( "$!" );

On the shell I can verify
sh-2.04$ id
uid=4(lp) gid=7(lp) groups=7(lp),99(nobody)
sh-2.04$ chgrp nobody <lp-created-ps-file>
sh-2.04$ echo $?
0

Only when run from lpd this peculiar error comes up.

Has anybody come across this?

Any hints very much welcome

Axel

(my current workaround is a simple "chmod 777 $out")
System is a RH7.0 with netatalk1.5-pre6

---

From: Chad Cunningham <[email-masked]>
Date: Tue, 1 May 2001 13:48:43 -0400 (EDT)

> related. I doubt but hope that other users came across this before ...

No, it has nothing to do with netatlk.

> 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.

-- 

Chad Cunningham
[email-masked]

"Well, once again my friend, we find that science is a two-headed beast. One
head is nice, it gives us aspirin and other modern conveniences,...but the
other head of science is bad! Oh beware the other head of science, Arthur, it
bites!"

---

From: Axel Rose <[email-masked]>
Date: Tue, 1 May 2001 23:29:46 +0200

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.

>status, or if you really need the output, redirect it to a file and read

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

---

From: Axel Rose <[email-masked]>
Date: Wed, 2 May 2001 00:03:16 +0200

I found a workaround. If permissions are set this way

# ls -ld /tmp/pdf
drwxrwsr-x    2 lp       nobody ...

for the directory where I temporarily create PS and PDF file
there will be no error for chgrp() and also no need to use chgrp().

Concerning netatalk now I only wish to see refreshed folder contents
on the Mac. I'm not sure whether Macs do poll or the server sends
a signal. Why does it work under Helios or NT then?

And another off-topic but real problem is that GhostScript doesn't
work on certain files. I still need to investigate this. I create
a one line BBEdit text file, save as "123", print, everything is fine.
Now I save to a file named "ab cd xy", print and get a gs error!??

Thank you for having an opportunity to discuss this here

Sincerely

Axel

-- 
----------------------------------------------------------------------
Axel Rose, Springer & Jacoby Digital GmbH & Co. KG, mailto:[email-masked]
  pub PGP key 1024/A21CB825 E0E4 BC69 E001 96E9  2EFD 86CA 9CA1 AAC5
  "... denn alles, was entsteht, ist wert, daß es zugrunde geht ..."