kill: modernization after undeprecation
cover kill: modernization after undeprecation
Hi Karel, et.al.,
Here are few patches to kill which was undeprecated late last year, see commit 32fca0e9c49599667d19f157fade6fa46908271a. I had a look of the command and decided it should get the same usage(), coding style, etc, fixes that are done to other commands earlier.
The only notable change in this series is second last patch which will make kill to use pid_t. I am sure that is better than having int representing pids, altough int might often work. The patch also makes some pid_t's to be casted long which may be a bit overkill. Perhaps it is better to grant enough head room to pid space than cry when type wrap results to kill of arbitrary process(es).
The following changes since commit 02658d9bb56976b462724b306e9e1f4385ef4b93:
tests: make utmpdump TZ independent (2013-03-04 13:10:09 +0100)
are available in the git repository at:
git://github.com/kerolasa/lelux-utiliteetit.git 2013wk09
for you to fetch changes up to 4f6dba8146a461dee9e62b5cf5ff62425ad01681:
docs: add long options and tidy up kill.1 (2013-03-07 23:08:53 +0000)
----------------------------------------------------------------
Sami Kerola (7):
kill: add long options
kill: align with howto-usage-function.txt
kill: use libc error printing facilities and exit values kill, procs: fix coding style
kill, procs: move function declarations to kill.h kill, procs: use pid_t for pids
docs: add long options and tidy up kill.1
misc-utils/kill.1 | 88 ++++++----- misc-utils/kill.c | 442 ++++++++++++++++++++++++++--------------------------- misc-utils/kill.h | 8 +- misc-utils/procs.c | 170 +++++++++++---------- 4 files changed, 360 insertions(+), 348 deletions(-)
PATCH 1/7 kill: add long options
--- misc-utils/kill.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
misc-utils/kill.c +5 -5
@@ -193,11 +193,11 @@ int main (int argc, char *argv[])printf (UTIL_LINUX_VERSION );return 0 ; } -if (!strcmp (arg,"-a" )) { +if (!strcmp (arg,"-a" ) || !strcmp (arg,"--all" )) { check_all++;continue ; } -if (!strcmp (arg,"-l" )) { +if (!strcmp (arg,"-l" ) || !strcmp (arg,"--list" )) {if (argc <2 ) {printsignals (stdout);return 0 ;
@@ -214,13 +214,13 @@ int main (int argc, char *argv[])printsig (numsig);return 0 ; } -if (!strcmp (arg,"-p" )) { +if (!strcmp (arg,"-p" ) || !strcmp (arg,"--pid" )) { do_pid++;if (do_kill)return usage (1 );continue ; } -if (!strcmp (arg,"-s" )) { +if (!strcmp (arg,"-s" ) || !strcmp (arg,"--signal" )) {if (argc <2 ) {return usage (1 ); }
@@ -235,7 +235,7 @@ int main (int argc, char *argv[]) }continue ; } -if (!strcmp (arg,"-q" )) { +if (!strcmp (arg,"-q" ) || !strcmp (arg,"--queue" )) {if (argc <2 )return usage (1 ); argc--, argv++;
Signature · 1 line
1.8.1.5
PATCH 2/7 kill: align with howto-usage-function.txt
In reply to Sami Kerola--- misc-utils/kill.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-)
misc-utils/kill.c +18 -7
@@ -405,14 +405,25 @@ static void printsignals (FILE *fp)fputc ('\n' , fp); } -static int usage (int status) +static int usage (int status) { -FILE *fp; - - fp = (status ==0 ? stdout : stderr); -fprintf (fp,_ ("usage: %s [ -s signal | -p ] [ -a ] pid ...\n" ), progname); -fprintf (fp,_ (" %s -l [ signal ]\n" ), progname); -return status; +FILE *out; + out = (status ==0 ? stdout : stderr); + +fputs (USAGE_HEADER , out); +fprintf (out,_ (" %s [options] <pid | commandname> [...]\n" ), program_invocation_short_name); +fputs (USAGE_OPTIONS , out); +fputs (_ (" -a, --all all commands including not same uid as parent process\n" ), out); +fputs (_ (" -s, --signal <sig> send specified signal\n" ), out); +fputs (_ (" -q, --queue <sig> use sigqueue(2) rather than kill(2)\n" ), out); +fputs (_ (" -p, --pid print pids without signaling them\n" ), out); +fputs (_ (" -l, --list <name> list signal names\n" ), out); +fputs (USAGE_SEPARATOR , out); +fputs (USAGE_HELP , out); +fputs (USAGE_VERSION , out); +fprintf (out,USAGE_MAN_TAIL ("kill(1)" )); + +return status; }static int kill_verbose (char *procname,int pid,int sig)
Signature · 1 line
1.8.1.5
PATCH 3/7 kill: use libc error printing facilities and exit values
In reply to Sami Kerola--- misc-utils/kill.c | 54 +++++++++++++++++++++++------------------------------- misc-utils/procs.c | 2 +- 2 files changed, 24 insertions(+), 32 deletions(-)
misc-utils/kill.c +23 -31
@@ -148,8 +148,6 @@ static void printsignals (FILE *fp);static int usage (int status);static int kill_verbose (char *procname,int pid,int sig); -static char *progname; -#ifdef HAVE_SIGQUEUE static int use_sigval;static union sigval sigdata;
@@ -158,21 +156,17 @@ static union sigval sigdata;int main (int argc,char *argv[]) {int errors, numsig, pid; -char *ep, *arg, *p; +char *ep, *arg;int do_pid, do_kill, check_all;int *pids, *ip; - progname = argv[0 ]; -if ((p =strrchr (progname,'/' )) !=NULL ) - progname = p+1 ; -setlocale (LC_ALL ,"" );bindtextdomain (PACKAGE ,LOCALEDIR );textdomain (PACKAGE );atexit (close_stdout); numsig =SIGTERM ; - do_pid = (!strcmp (progname,"pid" ));/* Yecch */ + do_pid = (!strcmp (program_invocation_short_name,"pid" ));/* Yecch */ do_kill =0 ; check_all =0 ;
@@ -191,7 +185,7 @@ int main (int argc, char *argv[])if (!strcmp (arg,"-v" ) || !strcmp (arg,"-V" ) || !strcmp (arg,"--version" )) {printf (UTIL_LINUX_VERSION ); -return 0 ; +return EXIT_SUCCESS ; }if (!strcmp (arg,"-a" ) || !strcmp (arg,"--all" )) { check_all++;
@@ -200,44 +194,42 @@ int main (int argc, char *argv[])if (!strcmp (arg,"-l" ) || !strcmp (arg,"--list" )) {if (argc <2 ) {printsignals (stdout); -return 0 ; +return EXIT_SUCCESS ; }if (argc >2 ) { -return usage (1 ); +return usage (EXIT_FAILURE ); }/* argc == 2, accept "kill -l $?" */ arg = argv[1 ]; -if ((numsig =arg_to_signum (arg,1 )) <0 ) { -fprintf (stderr,_ ("%s: unknown signal %s\n" ), progname, arg); -return 1 ; - } +if ((numsig =arg_to_signum (arg,1 )) <0 ) +errx (EXIT_FAILURE ,_ ("unknown signal: %s" ), arg);printsig (numsig); -return 0 ; +return EXIT_SUCCESS ; }if (!strcmp (arg,"-p" ) || !strcmp (arg,"--pid" )) { do_pid++;if (do_kill) -return usage (1 ); +return usage (EXIT_FAILURE );continue ; }if (!strcmp (arg,"-s" ) || !strcmp (arg,"--signal" )) {if (argc <2 ) { -return usage (1 ); +return usage (EXIT_FAILURE ); } do_kill++;if (do_pid) -return usage (1 ); +return usage (EXIT_FAILURE ); argc--, argv++; arg = *argv;if ((numsig =arg_to_signum (arg,0 )) <0 ) {nosig (arg); -return 1 ; +return EXIT_FAILURE ; }continue ; }if (!strcmp (arg,"-q" ) || !strcmp (arg,"--queue" )) {if (argc <2 ) -return usage (1 ); +return usage (EXIT_FAILURE ); argc--, argv++; arg = *argv;#ifdef HAVE_SIGQUEUE
@@ -256,16 +248,16 @@ int main (int argc, char *argv[])break ; arg++;if ((numsig =arg_to_signum (arg,0 )) <0 ) { -return usage (1 ); +return usage (EXIT_FAILURE ); } do_kill++;if (do_pid) -return usage (1 ); +return usage (EXIT_FAILURE );continue ; }if (! *argv) { -return usage (1 ); +return usage (EXIT_FAILURE ); }if (do_pid) { numsig =-1 ;
@@ -274,7 +266,7 @@ int main (int argc, char *argv[])/* we're done with the options. the rest of the arguments should be process ids and names. kill them. */ -for (errors =0 ; (arg = *argv) !=NULL ; argv++) { +for (errors =EXIT_SUCCESS ; (arg = *argv) !=NULL ; argv++) { pid =strtol (arg, &ep,10 );if (! *ep) errors +=kill_verbose (arg, pid, numsig);
@@ -282,8 +274,7 @@ int main (int argc, char *argv[]) pids =get_pids (arg, check_all);if (! pids) { errors++; -fprintf (stderr,_ ("%s: can't find process \"%s\"\n" ), - progname, arg); +warnx (_ ("cannot find process \"%s\"" ), arg);continue ; }for (ip = pids; *ip >=0 ; ip++)
@@ -291,7 +282,9 @@ int main (int argc, char *argv[])free (pids); } } -return (errors); +if (errors !=EXIT_SUCCESS ) + errors =EXIT_FAILURE ; +return errors; }#ifdef SIGRTMIN
@@ -362,7 +355,7 @@ static int arg_to_signum (char *arg, int maskbit)static void nosig (char *name) { -fprintf (stderr,_ ("%s: unknown signal %s; valid signals:\n" ), progname, name); +warnx (_ ("unknown signal %s; valid signals:" ), name);printsignals (stderr); }
@@ -442,8 +435,7 @@ static int kill_verbose (char *procname, int pid, int sig) rc =kill (pid, sig);if (rc <0 ) { -fprintf (stderr,"%s " , progname); -perror (procname); +warn (_ ("sending signal to %s failed" ), procname);return 1 ; }return 0 ;
misc-utils/procs.c +1 -1
@@ -41,7 +41,7 @@ get_pids (char *process_name, int get_all) { dir =opendir ("/proc" );if (! dir) { -perror ("opendir /proc" ); +warn ("opendir /proc" );return NULL ; } uid =getuid ();
Signature · 1 line
1.8.1.5
PATCH 4/7 kill, procs: fix coding style
In reply to Sami Kerola--- misc-utils/kill.c | 405 ++++++++++++++++++++++++++--------------------------- misc-utils/procs.c | 172 ++++++++++++----------- 2 files changed, 290 insertions(+), 287 deletions(-)
misc-utils/kill.c +201 -204
@@ -141,150 +141,147 @@ struct signv {extern char *mybasename (char *); -static int arg_to_signum (char *arg,int mask); -static void nosig (char *name); -static void printsig (int sig); -static void printsignals (FILE *fp); -static int usage (int status); -static int kill_verbose (char *procname,int pid,int sig); +static int arg_to_signum (char *arg,int mask); +static void nosig (char *name); +static void printsig (int sig); +static void printsignals (FILE *fp); +static int usage (int status); +static int kill_verbose (char *procname,int pid,int sig);#ifdef HAVE_SIGQUEUE static int use_sigval;static union sigval sigdata;#endif -int main (int argc,char *argv[]) +int main (int argc,char **argv) { -int errors, numsig, pid; -char *ep, *arg; -int do_pid, do_kill, check_all; -int *pids, *ip; - -setlocale (LC_ALL ,"" ); -bindtextdomain (PACKAGE ,LOCALEDIR ); -textdomain (PACKAGE ); -atexit (close_stdout); - - numsig =SIGTERM ; - do_pid = (!strcmp (program_invocation_short_name,"pid" ));/* Yecch */ - do_kill =0 ; - check_all =0 ; - -/* loop through the arguments. -actually, -a is the only option can be used with other options. -`kill' is basically a one-option-at-most program. */ -for (argc--, argv++; argc >0 ; argc--, argv++) { - arg = *argv; -if (*arg !='-' ) { -break ; - } -if (!strcmp (arg,"--" )) { - argc--, argv++; -break ; - } -if (!strcmp (arg,"-v" ) || !strcmp (arg,"-V" ) || - !strcmp (arg,"--version" )) { -printf (UTIL_LINUX_VERSION ); -return EXIT_SUCCESS ; - } -if (!strcmp (arg,"-a" ) || !strcmp (arg,"--all" )) { - check_all++; -continue ; - } -if (!strcmp (arg,"-l" ) || !strcmp (arg,"--list" )) { -if (argc <2 ) { -printsignals (stdout); -return EXIT_SUCCESS ; - } -if (argc >2 ) { -return usage (EXIT_FAILURE ); - } -/* argc == 2, accept "kill -l $?" */ - arg = argv[1 ]; -if ((numsig =arg_to_signum (arg,1 )) <0 ) -errx (EXIT_FAILURE ,_ ("unknown signal: %s" ), arg); -printsig (numsig); -return EXIT_SUCCESS ; - } -if (!strcmp (arg,"-p" ) || !strcmp (arg,"--pid" )) { - do_pid++; -if (do_kill) -return usage (EXIT_FAILURE ); -continue ; - } -if (!strcmp (arg,"-s" ) || !strcmp (arg,"--signal" )) { -if (argc <2 ) { -return usage (EXIT_FAILURE ); - } - do_kill++; -if (do_pid) -return usage (EXIT_FAILURE ); - argc--, argv++; - arg = *argv; -if ((numsig =arg_to_signum (arg,0 )) <0 ) { -nosig (arg); -return EXIT_FAILURE ; - } -continue ; - } -if (!strcmp (arg,"-q" ) || !strcmp (arg,"--queue" )) { -if (argc <2 ) -return usage (EXIT_FAILURE ); - argc--, argv++; - arg = *argv; +int errors, numsig, pid; +char *ep, *arg; +int do_pid, do_kill, check_all; +int *pids, *ip; + +setlocale (LC_ALL ,"" ); +bindtextdomain (PACKAGE ,LOCALEDIR ); +textdomain (PACKAGE ); +atexit (close_stdout); + + numsig =SIGTERM ; + do_pid = (!strcmp (program_invocation_short_name,"pid" ));/* Yecch */ + do_kill =0 ; + check_all =0 ; + +/* Loop through the arguments. Actually, -a is the only option +* can be used with other options. 'kill' is basically a +* one-option-at-most program. */ +for (argc--, argv++; argc >0 ; argc--, argv++) { + arg = *argv; +if (*arg !='-' ) +break ; +if (!strcmp (arg,"--" )) { + argc--, argv++; +break ; + } +if (!strcmp (arg,"-v" ) || !strcmp (arg,"-V" ) || + !strcmp (arg,"--version" )) { +printf (UTIL_LINUX_VERSION ); +return EXIT_SUCCESS ; + } +if (!strcmp (arg,"-a" ) || !strcmp (arg,"--all" )) { + check_all++; +continue ; + } +if (!strcmp (arg,"-l" ) || !strcmp (arg,"--list" )) { +if (argc <2 ) { +printsignals (stdout); +return EXIT_SUCCESS ; + } +if (argc >2 ) { +return usage (EXIT_FAILURE ); + } +/* argc == 2, accept "kill -l $?" */ + arg = argv[1 ]; +if ((numsig =arg_to_signum (arg,1 )) <0 ) +errx (EXIT_FAILURE ,_ ("unknown signal: %s" ), + arg); +printsig (numsig); +return EXIT_SUCCESS ; + } +if (!strcmp (arg,"-p" ) || !strcmp (arg,"--pid" )) { + do_pid++; +if (do_kill) +return usage (EXIT_FAILURE ); +continue ; + } +if (!strcmp (arg,"-s" ) || !strcmp (arg,"--signal" )) { +if (argc <2 ) +return usage (EXIT_FAILURE ); + do_kill++; +if (do_pid) +return usage (EXIT_FAILURE ); + argc--, argv++; + arg = *argv; +if ((numsig =arg_to_signum (arg,0 )) <0 ) { +nosig (arg); +return EXIT_FAILURE ; + } +continue ; + } +if (!strcmp (arg,"-q" ) || !strcmp (arg,"--queue" )) { +if (argc <2 ) +return usage (EXIT_FAILURE ); + argc--, argv++; + arg = *argv;#ifdef HAVE_SIGQUEUE - sigdata.sival_int =strtos32_or_err (arg,_ ("invalid sigval argument" )); - use_sigval =1 ; + sigdata.sival_int = +strtos32_or_err (arg,_ ("invalid sigval argument" )); + use_sigval =1 ;#endif -continue ; - } -/* `arg' begins with a dash but is not a known option. -so it's probably something like -HUP, or -1/-n -try to deal with it. --n could be signal n, or pid -n (i.e. process group n). -In case of doubt POSIX tells us to assume a signal. -If a signal has been parsed, assume it's a pid, break */ -if (do_kill) -break ; - arg++; -if ((numsig =arg_to_signum (arg,0 )) <0 ) { -return usage (EXIT_FAILURE ); +continue ; + } +/* 'arg' begins with a dash but is not a known option. +* So it is probably something like -HUP, or -1/-n try to +* deal with it. -n could be signal n, or pid -n (i.e., +* process group n). In case of doubt POSIX tells us to +* assume a signal. If a signal has been parsed, assume +* it i+ +s a pid, break. */ +if (do_kill) +break ; + arg++; +if ((numsig =arg_to_signum (arg,0 )) <0 ) +return usage (EXIT_FAILURE ); + do_kill++; +if (do_pid) +return usage (EXIT_FAILURE ); +continue ; } - do_kill++; + +if (!*argv) +return usage (EXIT_FAILURE );if (do_pid) -return usage (EXIT_FAILURE ); -continue ; - } - -if (! *argv) { -return usage (EXIT_FAILURE ); - } -if (do_pid) { - numsig =-1 ; - } - -/* we're done with the options. -the rest of the arguments should be process ids and names. -kill them. */ -for (errors =EXIT_SUCCESS ; (arg = *argv) !=NULL ; argv++) { - pid =strtol (arg, &ep,10 ); -if (! *ep) - errors +=kill_verbose (arg, pid, numsig); -else { - pids =get_pids (arg, check_all); -if (! pids) { - errors++; -warnx (_ ("cannot find process \"%s\"" ), arg); -continue ; - } -for (ip = pids; *ip >=0 ; ip++) - errors +=kill_verbose (arg, *ip, numsig); -free (pids); + numsig =-1 ; + +/* We are done with the options. The rest of the arguments +* should be process ids and names, and kill them. */ +for (errors =EXIT_SUCCESS ; (arg = *argv) !=NULL ; argv++) { + pid =strtol (arg, &ep,10 ); +if (!*ep) + errors +=kill_verbose (arg, pid, numsig); +else { + pids =get_pids (arg, check_all); +if (!pids) { + errors++; +warnx (_ ("cannot find process \"%s\"" ), arg); +continue ; + } +for (ip = pids; *ip >=0 ; ip++) + errors +=kill_verbose (arg, *ip, numsig); +free (pids); + } } - } -if (errors !=EXIT_SUCCESS ) - errors =EXIT_FAILURE ; -return errors; +if (errors !=EXIT_SUCCESS ) + errors =EXIT_FAILURE ; +return errors; }#ifdef SIGRTMIN
@@ -310,92 +307,92 @@ static int rtsig_to_signum(char *sig) num = maxi ?SIGRTMAX - num :SIGRTMIN + num; -if (num <SIGRTMIN || num >SIGRTMAX ) +if (num <SIGRTMIN ||SIGRTMAX < num)return -1 ;return num; }#endif -static int signame_to_signum (char *sig) +static int signame_to_signum (char *sig) { -size_t n; +size_t n; -if (!strncasecmp (sig,"sig" ,3 )) - sig +=3 ; +if (!strncasecmp (sig,"sig" ,3 )) + sig +=3 ;#ifdef SIGRTMIN -/* RT signals */ -if (!strncasecmp (sig,"rt" ,2 )) -return rtsig_to_signum (sig +2 ); +/* RT signals */ +if (!strncasecmp (sig,"rt" ,2 )) +return rtsig_to_signum (sig +2 );#endif -/* Normal sugnals */ -for (n =0 ; n <ARRAY_SIZE (sys_signame); n++) { -if (!strcasecmp (sys_signame[n].name, sig)) -return sys_signame[n].val; - } -return (-1 ); +/* Normal sugnals */ +for (n =0 ; n <ARRAY_SIZE (sys_signame); n++) { +if (!strcasecmp (sys_signame[n].name, sig)) +return sys_signame[n].val; + } +return -1 ; } -static int arg_to_signum (char *arg,int maskbit) +static int arg_to_signum (char *arg,int maskbit) { -int numsig; -char *ep; - -if (isdigit (*arg)) { - numsig =strtol (arg, &ep,10 ); -if (numsig >=NSIG && maskbit && (numsig &128 ) !=0 ) - numsig -=128 ; -if (*ep !=0 || numsig <0 || numsig >=NSIG ) -return (-1 ); -return (numsig); - } -return signame_to_signum (arg); +int numsig; +char *ep; + +if (isdigit (*arg)) { + numsig =strtol (arg, &ep,10 ); +if (NSIG <= numsig && maskbit && (numsig &128 ) !=0 ) + numsig -=128 ; +if (*ep !=0 || numsig <0 ||NSIG <= numsig) +return -1 ; +return numsig; + } +return signame_to_signum (arg); } -static void nosig (char *name) +static void nosig (char *name) { -warnx (_ ("unknown signal %s; valid signals:" ), name); -printsignals (stderr); +warnx (_ ("unknown signal %s; valid signals:" ), name); +printsignals (stderr); } -static void printsig (int sig) +static void printsig (int sig) { -size_t n; +size_t n; -for (n =0 ; n <ARRAY_SIZE (sys_signame); n++) { -if (sys_signame[n].val == sig) { -printf ("%s\n" , sys_signame[n].name); -return ; +for (n =0 ; n <ARRAY_SIZE (sys_signame); n++) { +if (sys_signame[n].val == sig) { +printf ("%s\n" , sys_signame[n].name); +return ; + } } - }#ifdef SIGRTMIN -if (sig >=SIGRTMIN && sig <=SIGRTMAX ) { -printf ("RT%d\n" , sig -SIGRTMIN ); -return ; - } +if (SIGRTMIN <= sig && sig <=SIGRTMAX ) { +printf ("RT%d\n" , sig -SIGRTMIN ); +return ; + }#endif -printf ("%d\n" , sig); +printf ("%d\n" , sig); } -static void printsignals (FILE *fp) +static void printsignals (FILE *fp) { -size_t n, lth, lpos =0 ; - -for (n =0 ; n <ARRAY_SIZE (sys_signame); n++) { - lth =1 +strlen (sys_signame[n].name); -if (lpos+lth >72 ) { -fputc ('\n' , fp); - lpos =0 ; - }else if (lpos) -fputc (' ' , fp); - lpos += lth; -fputs (sys_signame[n].name, fp); - } +size_t n, lth, lpos =0 ; + +for (n =0 ; n <ARRAY_SIZE (sys_signame); n++) { + lth =1 +strlen (sys_signame[n].name); +if (lpos + lth >72 ) { +fputc ('\n' , fp); + lpos =0 ; + }else if (lpos) +fputc (' ' , fp); + lpos += lth; +fputs (sys_signame[n].name, fp); + }#ifdef SIGRTMIN -fputs (" RT<N> RTMIN+<N> RTMAX-<N>" , fp); +fputs (" RT<N> RTMIN+<N> RTMAX-<N>" , fp);#endif -fputc ('\n' , fp); +fputc ('\n' , fp); }static int usage (int status)
@@ -419,24 +416,24 @@ static int usage(int status)return status; } -static int kill_verbose (char *procname,int pid,int sig) +static int kill_verbose (char *procname,int pid,int sig) { -int rc; +int rc; -if (sig <0 ) { -printf ("%d\n" , pid); -return 0 ; - } +if (sig <0 ) { +printf ("%d\n" , pid); +return 0 ; + }#ifdef HAVE_SIGQUEUE -if (use_sigval) - rc =sigqueue (pid, sig, sigdata); - else +if (use_sigval) + rc =sigqueue (pid, sig, sigdata); + else#endif - rc =kill (pid, sig); + rc =kill (pid, sig); -if (rc <0 ) { -warn (_ ("sending signal to %s failed" ), procname); -return 1 ; - } -return 0 ; +if (rc <0 ) { +warn (_ ("sending signal to %s failed" ), procname); +return 1 ; + } +return 0 ; }
misc-utils/procs.c +89 -83
199 lines not on this page · raw message
Signature · 1 line
1.8.1.5
PATCH 5/7 kill, procs: move function declarations to kill.h
In reply to Sami Kerola--- misc-utils/kill.c | 2 -- misc-utils/kill.h | 8 +++++++- misc-utils/procs.c | 1 - 3 files changed, 7 insertions(+), 4 deletions(-)
misc-utils/kill.c +0 -2
@@ -139,8 +139,6 @@ struct signv {#endif }; -extern char *mybasename (char *); -static int arg_to_signum (char *arg,int mask);static void nosig (char *name);static void printsig (int sig);
misc-utils/kill.h +7 -1
@@ -1 +1,7 @@ -extern int *get_pids (char *process_name,int get_all); +#ifndef UTIL_LINUX_KILL +#define UTIL_LINUX_KILL + +extern int *get_pids (char *process_name,int get_all); +extern char *mybasename (char *); + +#endif
misc-utils/procs.c +0 -1
@@ -23,7 +23,6 @@#include "kill.h" #include "xalloc.h" -extern char *mybasename (char *);static char *parse_parens (char *buf);int *get_pids (char *process_name,int get_all)
Signature · 1 line
1.8.1.5
PATCH 6/7 kill, procs: use pid_t for pids
In reply to Sami KerolaReference: http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/linux/threads.h#n30
--- misc-utils/kill.c | 6 +++--- misc-utils/kill.h | 2 +- misc-utils/procs.c | 17 ++++++++--------- 3 files changed, 12 insertions(+), 13 deletions(-)
misc-utils/kill.c +3 -3
@@ -156,7 +156,7 @@ int main(int argc, char **argv)int errors, numsig, pid;char *ep, *arg;int do_pid, do_kill, check_all; -int *pids, *ip; +pid_t *pids, *ip;setlocale (LC_ALL ,"" );bindtextdomain (PACKAGE ,LOCALEDIR );
@@ -414,12 +414,12 @@ static int usage(int status)return status; } -static int kill_verbose (char *procname,int pid,int sig) +static int kill_verbose (char *procname,pid_t pid,int sig) {int rc;if (sig <0 ) { -printf ("%d\n" , pid); +printf ("%ld\n" , (long )pid);return 0 ; }#ifdef HAVE_SIGQUEUE
misc-utils/kill.h +1 -1
@@ -1,7 +1,7 @@#ifndef UTIL_LINUX_KILL #define UTIL_LINUX_KILL -extern int *get_pids (char *process_name,int get_all); +extern pid_t *get_pids (char *process_name,int get_all);extern char *mybasename (char *);#endif
misc-utils/procs.c +8 -9
@@ -25,16 +25,16 @@static char *parse_parens (char *buf); -int *get_pids (char *process_name,int get_all) +pid_t *get_pids (char *process_name,int get_all) {DIR *dir;struct dirent *ent;int status; -char *dname, fname[100 ], *cp, buf[256 ]; +char fname[100 ], *cp, buf[256 ], *end;struct stat st;uid_t uid;FILE *fp; -int pid, *pids, num_pids, pids_size; +pid_t pid, *pids, num_pids, pids_size; dir =opendir ("/proc" );if (!dir) {
@@ -46,11 +46,10 @@ int *get_pids(char *process_name, int get_all) num_pids = pids_size =0 ;while ((ent =readdir (dir)) !=NULL ) { - dname = ent->d_name; -if (!isdigit (*dname)) + pid =strtol (ent->d_name, &end,10 ); +if (errno || ent->d_name == end || (end && *end))continue ; - pid =atoi (dname); -sprintf (fname,"/proc/%d/cmdline" , pid); +sprintf (fname,"/proc/%ld/cmdline" , (long )pid);/* get the process owner */ status =stat (fname, &st);if (status !=0 )
@@ -66,7 +65,7 @@ int *get_pids(char *process_name, int get_all)/* an empty command line means the process is swapped out */ if (!cp || !*cp) {/* get the process name from the statfile */ -sprintf (fname,"/proc/%d/stat" , pid); +sprintf (fname,"/proc/%ld/stat" , (long )pid); fp =fopen (fname,"r" );if (!fp)continue ;
@@ -83,7 +82,7 @@ int *get_pids(char *process_name, int get_all)continue ;while (pids_size < num_pids +2 ) { pids_size +=5 ; - pids = (int *)xrealloc (pids,sizeof (int ) * pids_size); + pids =xrealloc (pids,sizeof (pid_t) * pids_size); }if (pids) { pids[num_pids++] = pid;
Signature · 1 line
1.8.1.5
PATCH 7/7 docs: add long options and tidy up kill.1
In reply to Sami Kerola--- misc-utils/kill.1 | 88 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 46 insertions(+), 42 deletions(-)
misc-utils/kill.1 +46 -42
@@ -1,7 +1,7 @@ .\" Copyright 1994 Salvatore Valente ([email protected]) .\" Copyright 1992 Rickard E. Faith ([email protected]) .\" May be distributed under the GNU General Public License -.TH KILL 1 "February 2011" "util-linux" "User Commands" +.TH KILL 1 "March 2013" "util-linux" "User Commands" .SH NAME kill \- terminate a process .SH SYNOPSIS
@@ -19,15 +19,14 @@ kill \- terminate a process .SH DESCRIPTION The command .B kill -sends the specified signal to the specified process or process group. -If no signal is specified, the TERM signal is sent. The TERM signal -will kill processes which do not catch this signal. For other processes, -it may be necessary to use the KILL (9) signal, since this signal cannot -be caught. +sends the specified signal to the specified process or process group. If no +signal is specified, the TERM signal is sent. The TERM signal will kill +processes which do not catch this signal. For other processes, it may be +necessary to use the KILL (9) signal, since this signal cannot be caught. .PP -Most modern shells have a builtin kill function, with a usage rather similar -to that of the command described here. The `-a' and `-p' options, -and the possibility to specify processes by command name are a local extension. +Most modern shells have a builtin kill function, with a usage rather similar to +that of the command described here. The '-a' and '-p' options, and the +possibility to specify processes by command name are a local extension. .PP If sig is 0, then no signal is sent, but error checking is still performed. .SH OPTIONS
@@ -38,7 +37,6 @@ Specify the list of processes that should signal. Each .I pid can be one of five things: - .RS .TP .I n
@@ -57,65 +55,66 @@ All processes with pid larger than 1 will be signaled. .BI - n where .I n -is larger than 1. -All processes in process group +is larger than 1. All processes in process group .I n -are signaled. When an argument of the form `-n' is given, -and it is meant to denote a process group, -either the signal must be specified first, or the argument must be preceded -by a `--' option, otherwise it will be taken as the signal to send. +are signaled. When an argument of the form '-n' is given, and it is meant to +denote a process group, either the signal must be specified first, or the +argument must be preceded by a '--' option, otherwise it will be taken as the +signal to send. +.RE .TP .I commandname All processes invoked using that name will be signaled. -.RE .TP -.BI \-s " signal" -Specify the signal to send. -The signal may be given as a signal name or number. +\fB\-s\fR, \fB\-\-signal\fR \fIsignal\fR +Specify the signal to send. The signal may be given as a signal name or +number. .TP -.B \-l +\fB\-l\fR, \fB\-\-list\fR [\fIsignal\fR] Print a list of signal names. These are found in -.I /usr/include/linux/signal.h +.I /usr/\:include/\:linux/\:signal.h .TP -.B \-a -Do not restrict the commandname-to-pid conversion to processes -with the same uid as the present process. +\fB\-a\fR, \fB\-\-all\fR +Do not restrict the commandname-to-pid conversion to processes with the same +uid as the present process. .TP -.B \-p +\fB\-p\fR, \fB\-\-pid\fR Specify that .B kill -should only print the process id (pid) -of the named processes, and not send any signals. +should only print the process id (pid) of the named processes, and not send any +signals. .TP -.BI \-q " sigval" +\fB\-q\fR, \fB\-\-queue\fR \fIsigval\fR Use .BR sigqueue (2) rather than .BR kill (2) -and the sigval argument is used to specify an integer to be sent with the -signal. If the receiving process has installed a handler for this signal using -the SA_SIGINFO flag to +and the +.I sigval +argument is used to specify an integer to be sent with the signal. If the +receiving process has installed a handler for this signal using the SA_SIGINFO +flag to .BR sigaction (2), then it can obtain this data via the si_value field of the siginfo_t structure. .SH NOTES -It's not possible to send a signal to explicitly selected thread in a +It is not possible to send a signal to explicitly selected thread in a multithreaded process by .BR kill (2) -syscall. If +syscall. If .BR kill(2) -is used to send a signal to a thread group, then -kernel selects arbitrary member of the thread group that has not blocked -the signal. For more details see +is used to send a signal to a thread group, then kernel selects arbitrary +member of the thread group that has not blocked the signal. For more details +see .BR clone (2) CLONE_THREAD description. - +.PP The command .BR kill (1) as well as syscall .BR kill (2) accepts TID (thread ID, see .BR gettid (2)) -as argument. In this case the kill behavior is not changed and the signal is +as argument. In this case the kill behavior is not changed and the signal is also delivered to the thread group rather than to the specified thread. .SH "SEE ALSO" .BR bash (1),
@@ -124,8 +123,13 @@ also delivered to the thread group rather than to the specified thread. .BR sigvec (2), .BR signal (7) .SH AUTHOR -Taken from BSD 4.4. The ability to translate process names to process -ids was added by Salvatore Valente <[email protected]>. +Taken from BSD 4.4. The ability to translate process names to process ids was +added by +.MT [email protected] +Salvatore Valente +.ME . .SH AVAILABILITY The kill command is part of the util-linux package and is available from -ftp://ftp.kernel.org/pub/linux/utils/util-linux/. +.UR ftp://\:ftp.kernel.org\:/pub\:/linux\:/utils\:/util-linux/ +Linux Kernel Archive +.UE .
Signature · 1 line
1.8.1.5
Quoted 7 lines · Sami Kerola
Sami Kerola (7):
kill: add long options
kill: align with howto-usage-function.txt
kill: use libc error printing facilities and exit values kill, procs: fix coding stylekill, procs: move function declarations to
kill.h
Not applied this one. The include/ headers are usually for lib/ stuff. The another reason that the misc-util/proc.c code would be better to move to lib/procutils.c (after some refactoring) -- I'll do that.
Quoted 8 lines
kill, procs: use
pid_tfor pids
docs: add long options and tidy up kill.1misc-utils/kill.1 | 88 ++++++----- misc-utils/kill.c | 442 ++++++++++++++++++++++++++--------------------------- misc-utils/kill.h | 8 +- misc-utils/procs.c | 170 +++++++++++---------- 4 files changed, 360 insertions(+), 348 deletions(-)
Applied, thanks.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com