Bug 107676 - [patch] file(1): file -p does not work
Summary: [patch] file(1): file -p does not work
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 7.0-CURRENT
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-01-08 13:50 UTC by Dr. Markus Waldeck
Modified: 2008-02-29 03:04 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dr. Markus Waldeck 2007-01-08 13:50:11 UTC
The option "-p" does not work because the utimes system call fails.

ktrace:
28598 file     CALL  utimes(0xbfbfed78,0xbfbfe6d0)
28598 file     RET   utimes -1 errno 22 Invalid argument

truss:
utimes("FILENAME",{1168184675.-1077942524, 1166372455.000001}) ERR#22 'Invalid argument'

How-To-Repeat: Use a system call tracer (ktrace, truss, strace, ...)
Comment 1 Ricardo Nabinger Sanchez 2007-01-08 15:53:35 UTC
Also happens on 6.1-RELEASE i386:

% truss file - p main.c
...
lstat("main.c",0xbfbee200)                       = 0 (0x0)
open("main.c",0x0,027757561000)                  = 3 (0x3)
read(0x3,0xbfbee260,0x10000)                     = 6455 (0x1937)
break(0x8051000)                                 = 0 (0x0)
lseek(3,0x0,SEEK_SET)                            = 0 (0x0)
close(3)                                         = 0 (0x0)
utimes("main.c",{1168271467 -1077943672})        ERR#22 'Invalid argument'
...

-- 
Ricardo Nabinger Sanchez     <rnsanchez@{gmail.com,wait4.org}>
Powered by FreeBSD

  "Left to themselves, things tend to go from bad to worse."
Comment 2 Maxim Konovalov 2007-01-08 16:51:35 UTC
Quick and mostly untested patch:

Index: magic.c
===================================================================
RCS file: /home/ncvs/src/contrib/file/magic.c,v
retrieving revision 1.1.1.3
diff -u -p -r1.1.1.3 magic.c
--- magic.c	19 Jun 2006 07:52:12 -0000	1.1.1.3
+++ magic.c	8 Jan 2007 16:46:12 -0000
@@ -195,6 +195,7 @@ close_and_restore(const struct magic_set
 		 */
 #ifdef HAVE_UTIMES
 		struct timeval  utsbuf[2];
+		memset(utsbuf, 0, sizeof(struct timeval) * 2);
 		utsbuf[0].tv_sec = sb->st_atime;
 		utsbuf[1].tv_sec = sb->st_mtime;

@@ -202,6 +203,7 @@ close_and_restore(const struct magic_set
 #elif defined(HAVE_UTIME_H) || defined(HAVE_SYS_UTIME_H)
 		struct utimbuf  utbuf;

+		memset(&utbuf, 0, sizeof(struct utimbuf));
 		utbuf.actime = sb->st_atime;
 		utbuf.modtime = sb->st_mtime;
 		(void) utime(name, &utbuf); /* don't care if loses */
%%%

-- 
Maxim Konovalov
Comment 3 Soeren Straarup 2007-03-15 06:23:55 UTC
Did

http://www.freebsd.org/cgi/query-pr.cgi?pr=107676&getpatch=1

Solve the problem?

/Soeren

-- 
Soeren Straarup   | aka OZ2DAK aka Xride
FreeBSD committer | FreeBSD since 2.2.6-R
  If a program is not working right, then send a patch
Comment 4 Matteo Riondato freebsd_committer 2007-03-23 11:02:42 UTC
State Changed
From-To: open->feedback

We asked for feedback
Comment 5 Gavin Atkinson freebsd_committer freebsd_triage 2008-01-29 13:49:01 UTC
State Changed
From-To: feedback->analyzed

I can confirm that the patch in the PR fixes the problem.  The issue is 
that tv_usec in the timeval struct contains random junk, and if that 
junk falls outside of the 0 - 999999 range, utimes() fails. 

Note that on FreeBSD, we use utimes(), so I haven't verified that the 
second half of the PR (that deals with systems missing utimes()) is 
correct.
Comment 6 Gavin Atkinson freebsd_committer freebsd_triage 2008-01-30 18:54:55 UTC
Email sent to Christos Zoulas (file(1) maintainer) about this issue with
link to this PR.  Hopefully this or a similar patch will be incorporated
upstream, which will then come into FreeBSD on a future import.
Comment 7 Gavin Atkinson freebsd_committer freebsd_triage 2008-01-30 21:24:06 UTC
State Changed
From-To: analyzed->suspended

Patch has been incorporated upstream.  Mark as suspended until a new 
version of file(1) is released and imported into the FreeBSD tree.
Comment 8 dfilter service freebsd_committer 2008-02-02 07:19:19 UTC
obrien      2008-02-02 07:19:11 UTC

  FreeBSD src repository

  src/contrib/file - Imported sources
  Update of /home/ncvs/src/contrib/file
  In directory repoman.freebsd.org:/tmp/cvs-serv75049
  
  Log Message:
  Fix nit in version 4.23 in which -p does not work (thus updating access
  times when it shouldn't).  The PR's patch has been incorporated upstream
  as magic.c rev 1.46.
  
  PR:		107676
  Submitted by:	Dr. Markus Waldeck <waldeck@gmx.de>
  
  Status:
  
  Vendor Tag:	ZOULAS
  Release Tags:	file_4_23__r1_46
  		
  U src/contrib/file/README
  U src/contrib/file/acinclude.m4
  U src/contrib/file/configure.in
  U src/contrib/file/aclocal.m4
  U src/contrib/file/Makefile.am
  U src/contrib/file/Makefile.in
  U src/contrib/file/config.h.in
  U src/contrib/file/configure
  U src/contrib/file/ChangeLog
  U src/contrib/file/magic.c
  U src/contrib/file/install-sh
  U src/contrib/file/mkinstalldirs
  U src/contrib/file/LEGAL.NOTICE
  U src/contrib/file/MAINT
  U src/contrib/file/PORTING
  U src/contrib/file/file.c
  U src/contrib/file/Header
  U src/contrib/file/Localstuff
  U src/contrib/file/magic.mime
  U src/contrib/file/magic2mime
  U src/contrib/file/apprentice.c
  U src/contrib/file/apptype.c
  U src/contrib/file/ascmagic.c
  U src/contrib/file/compress.c
  U src/contrib/file/file.h
  U src/contrib/file/file_opts.h
  U src/contrib/file/fsmagic.c
  U src/contrib/file/funcs.c
  U src/contrib/file/is_tar.c
  U src/contrib/file/magic.h
  U src/contrib/file/names.h
  U src/contrib/file/patchlevel.h
  U src/contrib/file/print.c
  U src/contrib/file/readelf.c
  U src/contrib/file/readelf.h
  U src/contrib/file/softmagic.c
  U src/contrib/file/tar.h
  U src/contrib/file/test.c
  U src/contrib/file/file.man
  U src/contrib/file/libmagic.man
  U src/contrib/file/magic.man
  U src/contrib/file/Magdir/acorn
  U src/contrib/file/Magdir/adi
  U src/contrib/file/Magdir/adventure
  U src/contrib/file/Magdir/allegro
  U src/contrib/file/Magdir/alliant
  U src/contrib/file/Magdir/alpha
  U src/contrib/file/Magdir/amanda
  U src/contrib/file/Magdir/amigaos
  U src/contrib/file/Magdir/animation
  U src/contrib/file/Magdir/apl
  U src/contrib/file/Magdir/apple
  U src/contrib/file/Magdir/applix
  U src/contrib/file/Magdir/archive
  U src/contrib/file/Magdir/asterix
  U src/contrib/file/Magdir/att3b
  U src/contrib/file/Magdir/audio
  U src/contrib/file/Magdir/basis
  U src/contrib/file/Magdir/bflt
  U src/contrib/file/Magdir/blender
  U src/contrib/file/Magdir/blit
  U src/contrib/file/Magdir/bout
  U src/contrib/file/Magdir/bsdi
  U src/contrib/file/Magdir/btsnoop
  U src/contrib/file/Magdir/cad
  U src/contrib/file/Magdir/cafebabe
  U src/contrib/file/Magdir/c-lang
  U src/contrib/file/Magdir/c64
  U src/contrib/file/Magdir/cddb
  U src/contrib/file/Magdir/chord
  U src/contrib/file/Magdir/cisco
  U src/contrib/file/Magdir/efi
  U src/contrib/file/Magdir/citrus
  U src/contrib/file/Magdir/claris
  U src/contrib/file/Magdir/clipper
  U src/contrib/file/Magdir/cracklib
  U src/contrib/file/Magdir/spec
  U src/contrib/file/Magdir/commands
  U src/contrib/file/Magdir/communications
  U src/contrib/file/Magdir/compress
  U src/contrib/file/Magdir/console
  U src/contrib/file/Magdir/convex
  U src/contrib/file/Magdir/ctags
  U src/contrib/file/Magdir/dact
  U src/contrib/file/Magdir/database
  U src/contrib/file/Magdir/diamond
  U src/contrib/file/Magdir/diff
  U src/contrib/file/Magdir/digital
  U src/contrib/file/Magdir/dolby
  U src/contrib/file/Magdir/dump
  U src/contrib/file/Magdir/editors
  U src/contrib/file/Magdir/elf
  U src/contrib/file/Magdir/encore
  U src/contrib/file/Magdir/epoc
  U src/contrib/file/Magdir/esri
  U src/contrib/file/Magdir/fcs
  U src/contrib/file/Magdir/filesystems
  U src/contrib/file/Magdir/flash
  U src/contrib/file/Magdir/fonts
  U src/contrib/file/Magdir/fortran
  U src/contrib/file/Magdir/frame
  U src/contrib/file/Magdir/freebsd
  U src/contrib/file/Magdir/gcc
  U src/contrib/file/Magdir/fsav
  U src/contrib/file/Magdir/games
  U src/contrib/file/Magdir/geos
  U src/contrib/file/Magdir/gimp
  U src/contrib/file/Magdir/gnu
  U src/contrib/file/Magdir/grace
  U src/contrib/file/Magdir/gringotts
  U src/contrib/file/Magdir/hitachi-sh
  U src/contrib/file/Magdir/hp
  U src/contrib/file/Magdir/human68k
  U src/contrib/file/Magdir/ibm370
  U src/contrib/file/Magdir/ibm6000
  U src/contrib/file/Magdir/iff
  U src/contrib/file/Magdir/images
  U src/contrib/file/Magdir/intel
  U src/contrib/file/Magdir/interleaf
  U src/contrib/file/Magdir/island
  U src/contrib/file/Magdir/ispell
  U src/contrib/file/Magdir/java
  U src/contrib/file/Magdir/jpeg
  U src/contrib/file/Magdir/karma
  U src/contrib/file/Magdir/lecter
  U src/contrib/file/Magdir/lex
  U src/contrib/file/Magdir/lif
  U src/contrib/file/Magdir/linux
  U src/contrib/file/Magdir/lisp
  U src/contrib/file/Magdir/mach
  U src/contrib/file/Magdir/macintosh
  U src/contrib/file/Magdir/magic
  U src/contrib/file/Magdir/mail.news
  U src/contrib/file/Magdir/maple
  U src/contrib/file/Magdir/mup
  U src/contrib/file/Magdir/mathematica
  U src/contrib/file/Magdir/matroska
  U src/contrib/file/Magdir/mcrypt
  U src/contrib/file/Magdir/mime
  U src/contrib/file/Magdir/mips
  U src/contrib/file/Magdir/mirage
  U src/contrib/file/Magdir/misctools
  U src/contrib/file/Magdir/mkid
  U src/contrib/file/Magdir/mlssa
  U src/contrib/file/Magdir/mmdf
  U src/contrib/file/Magdir/modem
  U src/contrib/file/Magdir/motorola
  U src/contrib/file/Magdir/msdos
  U src/contrib/file/Magdir/msvc
  U src/contrib/file/Magdir/natinst
  U src/contrib/file/Magdir/ncr
  U src/contrib/file/Magdir/netbsd
  U src/contrib/file/Magdir/netscape
  U src/contrib/file/Magdir/news
  U src/contrib/file/Magdir/nitpicker
  U src/contrib/file/Magdir/ocaml
  U src/contrib/file/Magdir/octave
  U src/contrib/file/Magdir/olf
  U src/contrib/file/Magdir/os2
  U src/contrib/file/Magdir/os400
  U src/contrib/file/Magdir/os9
  U src/contrib/file/Magdir/osf1
  U src/contrib/file/Magdir/palm
  U src/contrib/file/Magdir/parix
  U src/contrib/file/Magdir/pbm
  U src/contrib/file/Magdir/pdf
  U src/contrib/file/Magdir/pdp
  U src/contrib/file/Magdir/perl
  U src/contrib/file/Magdir/pgp
  U src/contrib/file/Magdir/pkgadd
  U src/contrib/file/Magdir/plan9
  U src/contrib/file/Magdir/plus5
  U src/contrib/file/Magdir/printer
  U src/contrib/file/Magdir/project
  U src/contrib/file/Magdir/psdbms
  U src/contrib/file/Magdir/psion
  U src/contrib/file/Magdir/pulsar
  U src/contrib/file/Magdir/pyramid
  U src/contrib/file/Magdir/python
  U src/contrib/file/Magdir/revision
  U src/contrib/file/Magdir/riff
  U src/contrib/file/Magdir/rpm
  U src/contrib/file/Magdir/rtf
  U src/contrib/file/Magdir/sc
  U src/contrib/file/Magdir/sccs
  U src/contrib/file/Magdir/sendmail
  U src/contrib/file/Magdir/sequent
  U src/contrib/file/Magdir/sgi
  U src/contrib/file/Magdir/sgml
  U src/contrib/file/Magdir/sharc
  U src/contrib/file/Magdir/sinclair
  U src/contrib/file/Magdir/sketch
  U src/contrib/file/Magdir/smalltalk
  U src/contrib/file/Magdir/sniffer
  U src/contrib/file/Magdir/dyadic
  U src/contrib/file/Magdir/scientific
  U src/contrib/file/Magdir/softquad
  U src/contrib/file/Magdir/sql
  U src/contrib/file/Magdir/spectrum
  U src/contrib/file/Magdir/sun
  U src/contrib/file/Magdir/sysex
  U src/contrib/file/Magdir/teapot
  U src/contrib/file/Magdir/terminfo
  U src/contrib/file/Magdir/tex
  U src/contrib/file/Magdir/tgif
  U src/contrib/file/Magdir/ti-8x
  U src/contrib/file/Magdir/timezone
  U src/contrib/file/Magdir/troff
  U src/contrib/file/Magdir/tuxedo
  U src/contrib/file/Magdir/typeset
  U src/contrib/file/Magdir/unknown
  U src/contrib/file/Magdir/unicode
  U src/contrib/file/Magdir/uuencode
  U src/contrib/file/Magdir/varied.out
  U src/contrib/file/Magdir/varied.script
  U src/contrib/file/Magdir/vax
  U src/contrib/file/Magdir/vicar
  U src/contrib/file/Magdir/virtutech
  U src/contrib/file/Magdir/visx
  U src/contrib/file/Magdir/vms
  U src/contrib/file/Magdir/vmware
  U src/contrib/file/Magdir/vorbis
  U src/contrib/file/Magdir/vxl
  U src/contrib/file/Magdir/wordprocessors
  U src/contrib/file/Magdir/xdelta
  U src/contrib/file/Magdir/xenix
  U src/contrib/file/Magdir/xo65
  U src/contrib/file/Magdir/xwindows
  U src/contrib/file/Magdir/zilog
  U src/contrib/file/Magdir/zyxel
  
  No conflicts created by this import
  
_______________________________________________
cvs-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/cvs-all
To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
Comment 9 Mark Linimon freebsd_committer freebsd_triage 2008-02-29 03:03:48 UTC
State Changed
From-To: suspended->closed

Committed by obrien 2008-02-02.