Comments (14)
Huh. Well, apparently it was a file called ag.txt or agtest.txt. I removed them, and it worked fine.
from the_silver_searcher.
Interestingly, this actually seems to be a problem with outputting to a file. Those two files were generated by
ag "test" > ag.txt
and
ag "test" > agtest.txt
Both of those throw segfaults.
This series of commands may help pin it down:
$ ack "test" > blah
$ ag "test" > blah2
$ ag "test" > agtest
Segmentation fault
$ ack "test" > agtest2
from the_silver_searcher.
Nice catch. I bet this is because buf is actually agtest.txt mmap()ed. If agtest.txt matches the search, then ag will try to print out results. The problem is that the redirected IO overwrites agtest.txt. That means the contents of buf change during printing. Also, buf_len doesn't change and we risk accessing invalid memory like you encountered.
from the_silver_searcher.
What operating system are you on? I can't reproduce this on OS X 10.7 or Ubuntu 11.10.
Also, can you try to reproduce this with the map_private branch?
from the_silver_searcher.
That was on the latest version of Snow Leopard. I ran into it at work, so I won't be able to get to it until Monday unfortunately.
from the_silver_searcher.
I was having trouble reproducing this as well, but I remembered that I compiled with GCC 4.7 at work rather than Apple's default. I just recompiled with 4.7 and had the segfault show up on OSX 10.8
from the_silver_searcher.
map_private doesn't fix it.
from the_silver_searcher.
The output from the two compilers is a bit different.
4.2:
src/search.c: In function ‘search_dir’:
src/search.c:187: warning: passing argument 3 of ‘scandir’ from incompatible pointer type
src/search.c:210: warning: passing argument 3 of ‘scandir’ from incompatible pointer type
4.7
src/search.c: In function ‘search_dir’:
src/search.c:187:5: warning: passing argument 3 of ‘scandir’ from incompatible pointer type [enabled by default]
In file included from src/search.h:4:0,
from src/search.c:1:
/usr/include/dirent.h:143:5: note: expected ‘int (*)(const struct dirent *)’ but argument is of type ‘int (*)(struct dirent *)’
src/search.c:210:5: warning: passing argument 3 of ‘scandir’ from incompatible pointer type [enabled by default]
In file included from src/search.h:4:0,
from src/search.c:1:
/usr/include/dirent.h:143:5: note: expected ‘int (*)(const struct dirent *)’ but argument is of type ‘int (*)(struct dirent *)’
from the_silver_searcher.
Aww, well it was worth a shot. Thanks for trying the branch.
I thought I had some #ifdefs to get rid of those warnings on OS X. I signed up for the Mac developer program yesterday, but I don't have access to 10.8 yet. Maybe the signature for scandir changed in Mountain Lion. Or it could be that you have glibc installed.
from the_silver_searcher.
OSX has always had functions that want a const struct dirent*
instead of a struct dirent*
(like Linux does). In previous projects I've done some OSX detection and used a #define:
#ifdef __APPLE__
#define DIRENT const dirent*
#else
#define DIRENT dirent*
#endif
from the_silver_searcher.
From man scandir on OS X 10.7:
int
scandir(const char *dirname, struct dirent ***namelist, int (*select)(struct dirent *), int (*compar)(const void *, const void *));
From man scandir on Ubuntu 11.10:
int scandir(const char *dirp, struct dirent ***namelist,
int (*filter)(const struct dirent *),
int (*compar)(const struct dirent **, const struct dirent **));
I think you have it backwards. You definitely made me double-check my work, though. :)
from the_silver_searcher.
Yeah, I don't get those warnings on 10.6, so it must be something weird about 10.8 or my laptop.
from the_silver_searcher.
Resurrecting this thread.
This is a fundamental issue with modifying mmapped files while they're being read. If you can think of any solutions, I'd love to hear them. I wrote a few of my own, but I don't want to influence yours. Please take a couple minutes to think of solutions before reading any farther.
...
...
...
My ideas:
- Locking every file. This seems inefficient. Every file has to be locked while it's searched, and every file with a match has to be locked until the matches are printed out. This also might require write permissions on the files being searched, or cause searching to hang while waiting for a file lock. I'm pretty sure most filesystems and OSes require write permissions to exclusively lock a file.
- Adding a --no-mmap option. I'm not sure how useful this would be. I think most people who see a segfault would say, "This program sucks." and stop using it.
- Default to reading files into buffers and add a --mmap option. This increases memory usage and hurts performance.
That's what I've thought of after a couple minutes. I'm split between option 2 and doing nothing. I welcome other ideas.
from the_silver_searcher.
I think the solution is to do nothing.
from the_silver_searcher.
Related Issues (20)
- Running any search within a specific directory opens a file in that directory in Visual Studio
- Anyone want to help with a friendly fork of this project? HOT 6
- --make file type...
- Travis CI badge is broken
- Compilation stoped on qualifier from pointer target type [-Wcast-qual] HOT 1
- "bus error" on Mac OS with specific test file and regex HOT 1
- ag not finding accent letters in case insensitive search explicitly with -i option
- If the file doesn't exist, skip search instead of throwing errors
- wrong output on osx default terminal
- Confused about flag `--print-long-lines`: long lines seem to be printed by default? But can't turn that behavior *off* or modify it? (like `--print-long-lines=false` or `--print-long-lines=200` or something?)
- 2.2.0: test suite uses cram which is no longer maintained
- Add per-directory .gitignore support
- ignore patterns should not directory below their source file
- ag incorrectly parses [.][^.]*$
- feat: include OSC8 escape codes in output
- memory leak in function 'parse_options' HOT 1
- ag does not work on tmpfs/cgroup filesystem
- Entries in .gitignore are applied to the wrong base directory
- Bash completion script is broken with bash-completion v2.12.0 HOT 1
- Missing `S_ISSOCK` for stdin check HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from the_silver_searcher.