Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
"less" won't display properly on certain filenames
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
gkmac
Guru
Guru


Joined: 19 Jan 2003
Posts: 333
Location: West Sussex, UK

PostPosted: Thu Oct 09, 2003 5:54 pm    Post subject: "less" won't display properly on certain filenames Reply with quote

I've setup logrotate on my server and the logs are rotating fine, but attempting to view them has revealed that "less" the text file viewer has a strange oddity.

Taking the file /var/log/messages as an example, logrotate keeps the old rotated logs as messages.1 messages.2 and so on. If I type "less messages" then everything is normal, like below...
Code:
Oct  5 04:00:05 esgone syslog-ng[27771]: new configuration initialized
Oct  5 04:15:00 esgone CRON[18668]: (root) CMD (test -x /usr/sbin/run-crons && /usr/sbin/run-crons )
Oct  5 04:30:00 esgone CRON[18679]: (root) CMD (test -x /usr/sbin/run-crons && /usr/sbin/run-crons )
Oct  5 04:45:00 esgone CRON[18691]: (root) CMD (test -x /usr/sbin/run-crons && /usr/sbin/run-crons )
Oct  5 05:00:00 esgone CRON[18703]: (root) CMD (rm -f /var/spool/cron/lastrun/cron.hourly)
Oct  5 05:00:00 esgone CRON[18704]: (root) CMD (test -x /usr/sbin/run-crons && /usr/sbin/run-crons )
But if I try to view messages.1 or messages.2 or any archived log file then it is not displayed properly. It seems to totally ignore newlines, like this...
Code:
Sep  28  04:00:05 esgone syslog-ng[10604]: new configuration ini-
tialized Sep 28 04:15:00 esgone CRON[7973]: (root) CMD  (test  -x
/usr/sbin/run-crons  && /usr/sbin/run-crons ) Sep 28 04:30:00 es-
gone CRON[7984]:  (root)  CMD  (test  -x  /usr/sbin/run-crons  &&
/usr/sbin/run-crons  )  Sep 28 04:45:00 esgone CRON[7995]: (root)
CMD (test -x /usr/sbin/run-crons && /usr/sbin/run-crons ) Sep  28
05:00:00     esgone     CRON[8007]:    (root)    CMD    (rm    -f
/var/spool/cron/lastrun/cron.hourly)  Sep  28   05:00:00   esgone

The log files themselves are not corrupted, since viewing them by another method (e.g. cat) works fine. If I rename one of them to a filename that does not having a dot and a number on the end of the filename, less displays them normally!

So it seems less is switching to this broken behaviour just by asking it to view a file with a period and a number on the end. I've searched the man and info pages and found nothing as to why less would behave this way.

So does anyone know why less is doing this, and more importantly do they know how to stop it doing so?
Back to top
View user's profile Send private message
ozonator
Guru
Guru


Joined: 11 Jun 2003
Posts: 591
Location: Ontario, Canada

PostPosted: Thu Oct 09, 2003 6:48 pm    Post subject: Reply with quote

I've noticed this, too... very strange. Started seeing it last week on a machine after I upgraded to Gentoo 1.4, i.e., after I re-emerged everything with gcc 3.2.3 (I originally installed more than a year ago, with 1.2, using gcc 2.95.3). I've not noticed this on another machine running Gentoo, also using gcc 3.2.x, but which has a different architecture (ppc) and thus different CFLAGS. Do you think the compiler options/optimizations might have led to this? (I'd post my CFLAGS, but my Gentoo machines are across the city and powered off right now.) Have you tried re-emerging 'less'?
Back to top
View user's profile Send private message
cram
Guru
Guru


Joined: 17 Nov 2002
Posts: 312
Location: Saskatoon, Canada

PostPosted: Thu Oct 09, 2003 6:54 pm    Post subject: Reply with quote

check the manpage again, and look for info on the input preprocessor,

basically this is a script (pointed to by $LESSOPEN) which can modify files prior to their being passed off to less.
_________________
aaarggghhhh.
Good point Chewie.
Back to top
View user's profile Send private message
gkmac
Guru
Guru


Joined: 19 Jan 2003
Posts: 333
Location: West Sussex, UK

PostPosted: Thu Oct 09, 2003 6:57 pm    Post subject: Reply with quote

ozonator wrote:
Do you think the compiler options/optimizations might have led to this?

Have you tried re-emerging 'less'?
Yes I have tried re-emerging "less" with no luck. I used to use -O3 in the CFLAGS but recently switched to -O2. When I first noticed this oddity my "less" was compiled with -O3. My newly re-emerged "less" is now -O2 optimised but it still shows this oddity.
Back to top
View user's profile Send private message
gkmac
Guru
Guru


Joined: 19 Jan 2003
Posts: 333
Location: West Sussex, UK

PostPosted: Thu Oct 09, 2003 7:06 pm    Post subject: Reply with quote

cram wrote:
check the manpage again, and look for info on the input preprocessor, basically this is a script (pointed to by $LESSOPEN) which can modify files prior to their being passed off to less.

Thanks a lot cram! Now I know what's causing this. $LESSOPEN is set to a script which can be found at /usr/bin/lesspipe.sh which contained amongst other things, this...
Code:
  *.[1-9] | *.n | *.man)
    [ "$(file -L $1 | cut -d ' ' -f 2)" = "troff" -o \
    "$(file -L $1 | cut -d ' ' -f 2)" = "ASCII" ] &&
    groff -S -s -p -t -e -Tascii -mandoc "$1" 2>/dev/null ;;
...which meant nothing to me, but I knew that the *.[1-9] would match my logrotated files. I simply removed the *.[1-9] at the start, and now I can view my old logs properly!

The question is why that *.[1-9] is there in the first place. Would it be something to do with man pages I wonder?
Back to top
View user's profile Send private message
cram
Guru
Guru


Joined: 17 Nov 2002
Posts: 312
Location: Saskatoon, Canada

PostPosted: Thu Oct 09, 2003 7:11 pm    Post subject: Reply with quote

Quote:
The question is why that *.[1-9] is there in the first place. Would it be something to do with man pages I wonder?


Yeah, I think so. Manpages are formatted with groff, so I think it passes these files through groff before giving to less.

I suppose the correct thing to do would be to change the script so that it only groff'ed *.[1-9] files if they existed in a $MANPATH directory
_________________
aaarggghhhh.
Good point Chewie.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum