Add -W/--writable function to checkpath

Checkpath -W will use access(3p) to determine whether or not a path is
writable. This is more accurate than test(1p) because it also takes into
account whether or not the filesystem is mounted read-only.

Modified by William Hubbs to add the man page update.
This commit is contained in:
Christian Ruppert 2012-01-25 23:18:08 +01:00 committed by William Hubbs
parent 5d441dd376
commit 7ea5c614d9
2 changed files with 14 additions and 2 deletions

View File

@ -315,6 +315,11 @@ Mark the service as inactive.
.Xc .Xc
Checks to see if the path exists, is of the right type, owned by the right Checks to see if the path exists, is of the right type, owned by the right
people and has the correct access modes. If not, then it corrects the path. people and has the correct access modes. If not, then it corrects the path.
.It Ic checkpath
.Op Fl W , -writable
.Ar path
.Xc
checks to see if the path is writable.
.It Ic yesno Ar value .It Ic yesno Ar value
If If
.Ar value .Ar value

View File

@ -185,8 +185,8 @@ parse_owner(struct passwd **user, struct group **group, const char *owner)
} }
#include "_usage.h" #include "_usage.h"
#define extraopts "path1 path2 ..." #define extraopts "path1 [path2] [...]"
#define getoptstring "dDfFpm:o:" getoptstring_COMMON #define getoptstring "dDfFpm:o:W:" getoptstring_COMMON
static const struct option longopts[] = { static const struct option longopts[] = {
{ "directory", 0, NULL, 'd'}, { "directory", 0, NULL, 'd'},
{ "directory-truncate", 0, NULL, 'D'}, { "directory-truncate", 0, NULL, 'D'},
@ -195,6 +195,7 @@ static const struct option longopts[] = {
{ "pipe", 0, NULL, 'p'}, { "pipe", 0, NULL, 'p'},
{ "mode", 1, NULL, 'm'}, { "mode", 1, NULL, 'm'},
{ "owner", 1, NULL, 'o'}, { "owner", 1, NULL, 'o'},
{ "writable", 1, NULL, 'W'},
longopts_COMMON longopts_COMMON
}; };
static const char * const longopts_help[] = { static const char * const longopts_help[] = {
@ -205,6 +206,7 @@ static const char * const longopts_help[] = {
"Create a named pipe (FIFO) if not exists", "Create a named pipe (FIFO) if not exists",
"Mode to check", "Mode to check",
"Owner to check (user:group)", "Owner to check (user:group)",
"Check whether the path is writable or not",
longopts_help_COMMON longopts_help_COMMON
}; };
#include "_usage.c" #include "_usage.c"
@ -249,6 +251,11 @@ checkpath(int argc, char **argv)
eerrorx("%s: owner `%s' not found", eerrorx("%s: owner `%s' not found",
applet, optarg); applet, optarg);
break; break;
case 'W':
if (argv[optind] != NULL)
ewarn("-W/--writable takes only one path, everything else will be ignored");
exit(!is_writable(optarg));
break;
case_RC_COMMON_GETOPT case_RC_COMMON_GETOPT
} }