From: Craig Small Date: Sun, 6 Nov 2005 22:15:00 +0000 (+0000) Subject: combined flags in fuser work again X-Git-Tag: v22.11~98 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b2dd816ea70e650147329a09cb96df591b1dec89;p=psmisc combined flags in fuser work again --- diff --git a/ChangeLog b/ChangeLog index 59c35ca..42a0a9b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ + +Changes in 21.9 +=============== +2005-11-05 Rene Rebe + * fixed print_matches to only print unmatched objects if -a is + specified and to output the header for -v + * fixed argument parsing to handle groups like -av again + Changes in 21.8 =============== * fuser returns 1 if no match found like before. diff --git a/configure.in b/configure.in index 40796d4..fd0099b 100644 --- a/configure.in +++ b/configure.in @@ -1,5 +1,5 @@ dnl Process this file with autoconf to produce a configure script. -AC_INIT([psmisc],[21.8]) +AC_INIT([psmisc],[21.9cvs]) AC_PREREQ(2.59) AC_CONFIG_SRCDIR([src/comm.h]) AC_CONFIG_HEADER([config.h]) diff --git a/src/fuser.c b/src/fuser.c index 83c901c..446d2f3 100644 --- a/src/fuser.c +++ b/src/fuser.c @@ -582,7 +582,8 @@ int main(int argc, char *argv[]) struct ip6_connections *udp6_connection_list = NULL; struct inode_list *match_inodes = NULL; struct names *names_head, *this_name, *names_tail; - int optc, option; + int optc; + char *option; char *nsptr; ipv4_only = ipv6_only = 0; @@ -596,7 +597,7 @@ int main(int argc, char *argv[]) /* getopt doesnt like things like -SIGBLAH */ for(optc = 1; optc < argc; optc++) { if (argv[optc][0] == '-') { /* its an option */ - option=argv[optc][1]; + option=argv[optc] + 1; if (argv[optc][1] == '-') { /* its a long option */ if (argv[optc][2] == '\0') { continue; @@ -604,7 +605,7 @@ int main(int argc, char *argv[]) /* FIXME longopts */ continue; } - switch(argv[optc][1]) { + while (*option) switch(*option++) { case '4': ipv4_only = 1; break; @@ -662,8 +663,8 @@ int main(int argc, char *argv[]) print_version(); return 0; default: - if ( isupper(argv[optc][1]) || isdigit(argv[optc][1])) { - sig_number = get_signal(argv[optc]+1,"fuser"); + if ( isupper(*option) || isdigit(*option) ) { + sig_number = get_signal(option,"fuser"); break; } fprintf(stderr,"%s: Invalid option %c\n",argv[0] , argv[optc][1]); @@ -761,25 +762,27 @@ static int print_matches(struct names *names_head, const opt_type opts, const in { struct names *nptr; struct procs *pptr; - char first; + char head = 0; + char first = 1; int len; struct passwd *pwent = NULL; - int have_match = 1; + int have_match = 0; - - if (opts & OPT_VERBOSE) - fprintf(stderr, _("\n%*s USER PID ACCESS COMMAND\n"), - NAME_FIELD, ""); for (nptr = names_head; nptr != NULL ; nptr = nptr->next) { - fprintf(stderr, "%s", nptr->filename); - first = 1; - len = strlen(nptr->filename); - if (!(opts & OPT_VERBOSE)) { - putc(':', stderr); - len++; + if (nptr->matched_procs != NULL || opts & OPT_ALLFILES) { + if (head == 0 && opts & OPT_VERBOSE) { + fprintf(stderr, _("\n%*s USER PID ACCESS COMMAND\n"), + NAME_FIELD, ""); + head = 1; + } + + fprintf(stderr, "%s:", nptr->filename); + len = strlen(nptr->filename) + 1; } + + first = 1; for (pptr = nptr->matched_procs; pptr != NULL ; pptr = pptr->next) { - have_match = 0; + have_match = 1; if (opts & (OPT_VERBOSE|OPT_USER)) { if (pwent == NULL || pwent->pw_uid != pptr->uid) pwent = getpwuid(pptr->uid); @@ -831,13 +834,13 @@ static int print_matches(struct names *names_head, const opt_type opts, const in len = 0; first = 0; } - if (nptr->matched_procs == NULL || !(opts & OPT_VERBOSE)) + if (nptr->matched_procs != NULL || opts & OPT_ALLFILES) putc('\n', stderr); if (opts & OPT_KILL) kill_matched_proc(nptr->matched_procs, opts, sig_number); } /* next name */ - return have_match; + return !have_match; }