Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Evergreen:11.2:Test
psmisc
psmisc-22.7-writeonly.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File psmisc-22.7-writeonly.patch of Package psmisc
--- doc/fuser.1 +++ doc/fuser.1 2009-05-11 13:49:21.894401999 +0200 @@ -11,6 +11,7 @@ fuser \- identify processes using files .IR space\ ] .RB [ \-k .RB [ \-i ] +.RB [ \-w ] .RB [ \- \fISIGNAL ] ] .IR name " ..." @@ -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 +++ src/fuser.c 2009-05-11 13:50:26.796428307 +0200 @@ -69,7 +69,7 @@ static void check_map(const pid_t pid, c 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); @@ -97,7 +97,7 @@ static void usage (const char *errormsg) fprintf(stderr, "%s\n", errormsg); fprintf (stderr, _( - "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" " fuser -l\n" " fuser -V\n" "Show which processes use the named files, sockets, or filesystems.\n\n" @@ -113,6 +113,7 @@ static void usage (const char *errormsg) " -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, _( @@ -982,6 +983,9 @@ int main(int argc, char *argv[]) case 'v': opts |= OPT_VERBOSE; break; + case 'w': + opts |= OPT_WRITE; + break; case 'V': print_version(); return 0; @@ -1119,6 +1123,7 @@ static int print_matches(struct names *n 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) { @@ -1189,21 +1194,23 @@ static int print_matches(struct names *n 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) @@ -1562,21 +1569,26 @@ static int ask(const pid_t pid) } /* 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 {
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor