From: Craig Small Date: Tue, 10 May 2005 00:41:17 +0000 (+0000) Subject: closer to killing things in fusernew X-Git-Tag: v22.11~114 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8ee3205d4549bbe096f3b9f7bd203efdad695861;p=psmisc closer to killing things in fusernew --- diff --git a/src/fusernew.c b/src/fusernew.c index c2c5098..131a944 100644 --- a/src/fusernew.c +++ b/src/fusernew.c @@ -56,6 +56,7 @@ static void check_map(const pid_t pid, const char *filename, struct device_list static struct stat *get_pidstat(const pid_t pid, const char *filename); static uid_t getpiduid(const pid_t pid); static void print_matches(struct names *names_head, const opt_type opts); +static void kill_matched_proc(struct procs *pptr, const opt_type opts); static dev_t get_netdev(void); int parse_mount(struct names *this_name, struct device_list **dev_list); @@ -702,6 +703,8 @@ int main(int argc, char *argv[]) break; } } /* for */ + } else { + usage(_("No process specification given")); } /* Check conflicting operations */ if (opts & OPT_MOUNTPOINT) { @@ -808,8 +811,10 @@ static void print_matches(struct names *names_head, const opt_type opts) } if (nptr->matched_procs == NULL || !(opts & OPT_VERBOSE)) putc('\n', stderr); + if (opts & OPT_KILL) + kill_matched_proc(nptr->matched_procs, opts); - } + } /* next name */ } @@ -979,3 +984,39 @@ static void debug_match_lists(struct names *names_head, struct inode_list *ino_h (unsigned long)dptr->device); } } + +/* 0 = no, 1=yes */ +static int ask(const pid_t pid) +{ + int c, res; + size_t len = 0; + char *line = NULL; + + fflush(stdout); + while(1) { + fprintf(stderr, _("Kill process %d ? (y/N) "), pid); + fflush(stderr); + if (getline(&line, &len, stdin) < 0) + return 0; + if (line[0] == '\n') { + free(line); + return 0; + } + res = rpmatch(line); + if (res >= 0) { + free(line); + return res; + } + } /* while */ +} + +static void kill_matched_proc(struct procs *proc_head, const opt_type opts) +{ + struct procs *pptr; + + for (pptr = proc_head ; pptr != NULL ; pptr = pptr->next ) { + if ( (opts & OPT_INTERACTIVE) && (ask(pptr->pid) == 0)) + continue; + fprintf(stderr, "debug killing proc %d\n", pptr->pid); + } +}