trim(8): add another safety net
It is quite easy make a mistake and run something like this: trim -f /dev/da0 -r rfile This would trim the whole device then emit an error on non-existing file -r. Add another check to prevent this while allowing this form still for real object names beginning from dash: trim -f -- /dev/da0 -r rfile MFC after: 1 week
This commit is contained in:
parent
582141f69d
commit
7f65491576
@ -40,6 +40,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sysexits.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@ -104,6 +105,23 @@ main(int argc, char **argv)
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
/*
|
||||
* Safety net: do not allow mistakes like
|
||||
*
|
||||
* trim -f /dev/da0 -r rfile
|
||||
*
|
||||
* This would trim whole device then error on non-existing file -r.
|
||||
* Following check prevents this while allowing this form still:
|
||||
*
|
||||
* trim -f -- /dev/da0 -r rfile
|
||||
*/
|
||||
|
||||
if (strcmp(argv[optind-1], "--") != 0) {
|
||||
for (ch = optind; ch < argc; ch++)
|
||||
if (argv[ch][0] == '-')
|
||||
usage(name);
|
||||
}
|
||||
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user