From: Craig Small Date: Wed, 13 Jul 2005 04:16:27 +0000 (+0000) Subject: F for write access X-Git-Tag: v22.11~110 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=aa22d52f186c71c7e56b32963c75e0897d28ca0f;p=psmisc F for write access --- diff --git a/ChangeLog b/ChangeLog index 827349c..71e8b80 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,10 +4,10 @@ Changes in 21.7 * define rpmatch for libraries that dont have it * Fixed small typos in help, thanks to Benno Schulenberg fixes SF# 1150042 - * fusernew - this will be the new fuser once it gets tested on - those strange setups folks out there have * Completed change from Flask to SELinux, thanks to Benno Schulenberg * pstree works better with uClibc, thanks Mike Frysinger + * fuser rewritten: possibly fixes Debian #312560 + * fuser prints F instead of f is access is write, thanks to Tet. Changes in 21.6 =============== diff --git a/doc/fuser.1 b/doc/fuser.1 index 8484a1d..0d89cc3 100644 --- a/doc/fuser.1 +++ b/doc/fuser.1 @@ -32,6 +32,8 @@ current directory. executable being run. .IP \fBf\fP open file. \fBf\fP is omitted in default display mode. +.IP \fBF\fP +open file for writing. \fBF\fP is omitted in default display mode. .IP \fBr\fP root directory. .IP \fBm\fP diff --git a/src/fuser.c b/src/fuser.c index 8586957..4530082 100644 --- a/src/fuser.c +++ b/src/fuser.c @@ -811,7 +811,7 @@ static void print_matches(struct names *names_head, const opt_type opts, const i fflush(stdout); if (opts & OPT_VERBOSE) { fprintf(stderr, " %c%c%c%c%c ", - pptr->access & ACCESS_FILE ? 'f' : '.', + pptr->access & ACCESS_FILE ? (pptr->access & ACCESS_FILEWR ? 'F' : 'f' ) : '.', pptr->access & ACCESS_ROOT ? 'r' : '.', pptr->access & ACCESS_CWD ? 'c' : '.', pptr->access & ACCESS_EXE ? 'e' : '.', @@ -871,7 +871,7 @@ static void check_dir(const pid_t pid, const char *dirname, struct device_list * struct dirent *direntry; struct inode_list *ino_tmp; struct device_list *dev_tmp; - struct stat st; + struct stat st, lst; if ( (dirpath = malloc(MAX_PATHNAME)) == NULL) return; @@ -891,12 +891,22 @@ static void check_dir(const pid_t pid, const char *dirname, struct device_list * fprintf(stderr, _("Cannot stat file %s: %s\n"),filepath, strerror(errno)); } else { for (dev_tmp = dev_head ; dev_tmp != NULL ; dev_tmp = dev_tmp->next) { - if (st.st_dev == dev_tmp->device) - add_matched_proc(dev_tmp->name, pid,uid, access); + if (st.st_dev == dev_tmp->device) { + if (access == ACCESS_FILE && (lstat(filepath, &lst)==0) && (lst.st_mode & S_IWUSR)) { + add_matched_proc(dev_tmp->name, pid,uid, ACCESS_FILEWR|access); + } else { + add_matched_proc(dev_tmp->name, pid,uid, access); + } + } } for (ino_tmp = ino_head ; ino_tmp != NULL ; ino_tmp = ino_tmp->next) { - if (st.st_dev == ino_tmp->device && st.st_ino == ino_tmp->inode) - add_matched_proc(ino_tmp->name, pid,uid, access); + if (st.st_dev == ino_tmp->device && st.st_ino == ino_tmp->inode) { + if (access == ACCESS_FILE && (lstat(filepath, &lst)==0) && (lst.st_mode & S_IWUSR)) { + add_matched_proc(ino_tmp->name, pid,uid, ACCESS_FILEWR|access); + } else { + add_matched_proc(ino_tmp->name, pid,uid, access); + } + } } } } /* while fd_dent */ diff --git a/src/fuser.h b/src/fuser.h index dbdf8f3..2cc563e 100644 --- a/src/fuser.h +++ b/src/fuser.h @@ -26,6 +26,7 @@ struct procs { #define ACCESS_FILE 4 #define ACCESS_ROOT 8 #define ACCESS_MMAP 16 +#define ACCESS_FILEWR 32 struct names { char *filename;