2008-08-08 02:14:10 +02:00
|
|
|
--- doc/fuser.1
|
2009-05-15 21:46:50 +02:00
|
|
|
+++ doc/fuser.1 2009-05-11 13:49:21.894401999 +0200
|
|
|
|
@@ -11,6 +11,7 @@ fuser \- identify processes using files
|
2008-08-08 02:14:10 +02:00
|
|
|
.IR space\ ]
|
|
|
|
.RB [ \-k
|
|
|
|
.RB [ \-i ]
|
|
|
|
+.RB [ \-w ]
|
2009-05-15 21:46:50 +02:00
|
|
|
.RB [ \- \fISIGNAL
|
2008-08-08 02:14:10 +02:00
|
|
|
] ]
|
2009-05-15 21:46:50 +02:00
|
|
|
.IR name " ..."
|
2008-08-08 02:14:10 +02:00
|
|
|
@@ -74,6 +75,9 @@ other \fBfuser\fP processes. The effecti
|
|
|
|
.IP \fB\-i\fP
|
|
|
|
Ask the user for confirmation before killing a process. This option is
|
|
|
|
silently ignored if \fB\-k\fP is not present too.
|
|
|
|
+.IP \fB\-w\fP
|
|
|
|
+Kill only processes which have write access. This option is
|
|
|
|
+silently ignored if \fB\-k\fP is not present too.
|
|
|
|
.IP \fB\-l\fP
|
|
|
|
List all known signal names.
|
|
|
|
.IP \fB\-m\fP
|
|
|
|
--- src/fuser.c
|
2009-05-15 21:46:50 +02:00
|
|
|
+++ src/fuser.c 2009-05-11 13:50:26.796428307 +0200
|
|
|
|
@@ -69,7 +69,7 @@ static void check_map(const pid_t pid, c
|
2008-08-08 02:14:10 +02:00
|
|
|
static struct stat *get_pidstat(const opt_type opts, const pid_t pid, const char *filename, char *real);
|
|
|
|
static uid_t getpiduid(const pid_t pid);
|
|
|
|
static int print_matches(struct names *names_head, const opt_type opts, const int sig_number);
|
|
|
|
-static void kill_matched_proc(struct procs *pptr, const opt_type opts, const int sig_number);
|
|
|
|
+static int kill_matched_proc(struct procs *pptr, const opt_type opts, const int sig_number);
|
|
|
|
|
|
|
|
int parse_mount(struct names *this_name, struct device_list **dev_list);
|
|
|
|
static void add_device(struct device_list **dev_list, struct names *this_name, dev_t device);
|
2009-05-15 21:46:50 +02:00
|
|
|
@@ -97,7 +97,7 @@ static void usage (const char *errormsg)
|
2008-08-08 02:14:10 +02:00
|
|
|
fprintf(stderr, "%s\n", errormsg);
|
|
|
|
|
|
|
|
fprintf (stderr, _(
|
2009-05-15 21:46:50 +02:00
|
|
|
- "Usage: fuser [ -fuv ] [ -a | -s ] [ -4 | -6 ] [ -c | -m | -n SPACE ] [ -k [ -i ] [ -SIGNAL ]] NAME...\n"
|
|
|
|
+ "Usage: fuser [ -fuv ] [ -a | -s ] [ -4 | -6 ] [ -c | -m | -n SPACE ] [ -k [ -i ] [ -w ] [ -SIGNAL ]] NAME...\n"
|
2008-08-08 02:14:10 +02:00
|
|
|
" fuser -l\n"
|
|
|
|
" fuser -V\n"
|
2009-05-15 21:46:50 +02:00
|
|
|
"Show which processes use the named files, sockets, or filesystems.\n\n"
|
|
|
|
@@ -113,6 +113,7 @@ static void usage (const char *errormsg)
|
2008-08-08 02:14:10 +02:00
|
|
|
" -SIGNAL send this signal instead of SIGKILL\n"
|
|
|
|
" -u display user IDs\n"
|
|
|
|
" -v verbose output\n"
|
|
|
|
+ " -w kill only processes with write access\n"
|
|
|
|
" -V display version information\n"));
|
|
|
|
#ifdef WITH_IPV6
|
|
|
|
fprintf (stderr, _(
|
2009-05-15 21:46:50 +02:00
|
|
|
@@ -982,6 +983,9 @@ int main(int argc, char *argv[])
|
2008-08-08 02:14:10 +02:00
|
|
|
case 'v':
|
|
|
|
opts |= OPT_VERBOSE;
|
|
|
|
break;
|
|
|
|
+ case 'w':
|
|
|
|
+ opts |= OPT_WRITE;
|
|
|
|
+ break;
|
|
|
|
case 'V':
|
|
|
|
print_version();
|
|
|
|
return 0;
|
2009-05-15 21:46:50 +02:00
|
|
|
@@ -1119,6 +1123,7 @@ static int print_matches(struct names *n
|
2008-08-08 02:14:10 +02:00
|
|
|
int len = 0;
|
|
|
|
struct passwd *pwent = NULL;
|
|
|
|
int have_match = 0;
|
|
|
|
+ int have_kill = 0;
|
|
|
|
|
|
|
|
for (nptr = names_head; nptr != NULL ; nptr = nptr->next) {
|
|
|
|
if (opts & OPT_SILENT) {
|
2009-05-15 21:46:50 +02:00
|
|
|
@@ -1189,21 +1194,23 @@ static int print_matches(struct names *n
|
2008-08-08 02:14:10 +02:00
|
|
|
len = 0;
|
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
- if (opts & OPT_VERBOSE) {
|
|
|
|
- /* put a newline if showing all files and no procs*/
|
|
|
|
- if (nptr->matched_procs == NULL && (opts & OPT_ALLFILES))
|
|
|
|
- putc('\n', stderr);
|
|
|
|
- } else {
|
|
|
|
- if (nptr->matched_procs != NULL || (opts & OPT_ALLFILES))
|
|
|
|
- putc('\n', stderr);
|
|
|
|
- }
|
|
|
|
+ if (opts & OPT_VERBOSE) {
|
|
|
|
+ /* put a newline if showing all files and no procs*/
|
|
|
|
+ if (nptr->matched_procs == NULL && (opts & OPT_ALLFILES))
|
|
|
|
+ putc('\n', stderr);
|
|
|
|
+ } else {
|
|
|
|
+ if (nptr->matched_procs != NULL || (opts & OPT_ALLFILES))
|
|
|
|
+ putc('\n', stderr);
|
|
|
|
+ }
|
|
|
|
} /* be silent */
|
|
|
|
if (opts & OPT_KILL)
|
|
|
|
- kill_matched_proc(nptr->matched_procs, opts, sig_number);
|
|
|
|
+ have_kill = kill_matched_proc(nptr->matched_procs, opts, sig_number);
|
|
|
|
|
|
|
|
} /* next name */
|
|
|
|
- return (have_match==1?0:1);
|
|
|
|
-
|
|
|
|
+ if (opts & OPT_KILL)
|
|
|
|
+ return (have_kill==1?0:1);
|
|
|
|
+ else
|
|
|
|
+ return (have_match==1?0:1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct stat *get_pidstat(const opt_type opts, const pid_t pid, const char *filename, char *real)
|
2009-05-15 21:46:50 +02:00
|
|
|
@@ -1562,21 +1569,26 @@ static int ask(const pid_t pid)
|
2008-08-08 02:14:10 +02:00
|
|
|
} /* while */
|
|
|
|
}
|
|
|
|
|
|
|
|
-static void kill_matched_proc(struct procs *proc_head, const opt_type opts, const int sig_number)
|
|
|
|
+static int kill_matched_proc(struct procs *proc_head, const opt_type opts, const int sig_number)
|
|
|
|
{
|
|
|
|
struct procs *pptr;
|
|
|
|
+ int ret = 0;
|
|
|
|
|
|
|
|
for (pptr = proc_head ; pptr != NULL ; pptr = pptr->next ) {
|
|
|
|
if ( (opts & OPT_INTERACTIVE) && (ask(pptr->pid) == 0))
|
|
|
|
continue;
|
|
|
|
+ if ((opts & OPT_WRITE) && ((pptr->access & ACCESS_FILEWR) == 0))
|
|
|
|
+ continue;
|
|
|
|
if ( kill (pptr->pid, sig_number) < 0) {
|
|
|
|
fprintf(stderr, _("Could not kill process %d: %s\n"),
|
|
|
|
pptr->pid,
|
|
|
|
strerror(errno)
|
|
|
|
);
|
|
|
|
+ continue;
|
|
|
|
}
|
|
|
|
-
|
|
|
|
+ ret = 1;
|
|
|
|
}
|
|
|
|
+ return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static dev_t find_net_dev(void)
|
|
|
|
--- src/fuser.h
|
|
|
|
+++ src/fuser.h 2008-08-07 14:26:48.000000000 +0200
|
|
|
|
@@ -1,6 +1,6 @@
|
|
|
|
|
|
|
|
/* Option Flags */
|
|
|
|
-typedef unsigned char opt_type;
|
|
|
|
+typedef unsigned short opt_type;
|
|
|
|
|
|
|
|
#define OPT_VERBOSE 1
|
|
|
|
#define OPT_ALLFILES 2
|
|
|
|
@@ -10,6 +10,7 @@ typedef unsigned char opt_type;
|
|
|
|
#define OPT_SILENT 32
|
|
|
|
#define OPT_USER 64
|
|
|
|
#define OPT_MOUNTPOINT 128
|
|
|
|
+#define OPT_WRITE 256
|
|
|
|
|
|
|
|
|
|
|
|
struct procs {
|