This commit is contained in:
albert 2002-11-25 21:36:43 +00:00
parent 19e565177b
commit f40af35b77
2 changed files with 23 additions and 23 deletions

40
pgrep.c
View File

@ -72,7 +72,7 @@ usage (int opt)
static union el * static union el *
split_list (const char *str, char sep, int (*convert)(const char *, union el *)) split_list (const char *restrict str, int (*convert)(const char *, union el *))
{ {
char *copy = strdup (str); char *copy = strdup (str);
char *ptr = copy; char *ptr = copy;
@ -85,7 +85,7 @@ split_list (const char *str, char sep, int (*convert)(const char *, union el *))
exit (3); exit (3);
do { do {
sep_pos = strchr (ptr, sep); sep_pos = strchr (ptr, ',');
if (sep_pos) if (sep_pos)
*sep_pos = 0; *sep_pos = 0;
if (convert (ptr, &list[i])) if (convert (ptr, &list[i]))
@ -116,7 +116,7 @@ split_list (const char *str, char sep, int (*convert)(const char *, union el *))
plain number, FALSE if there are any non-digits. */ plain number, FALSE if there are any non-digits. */
static int static int
strict_atol (const char *str, long *value) strict_atol (const char *restrict str, long *restrict value)
{ {
int res = 0; int res = 0;
int sign = 1; int sign = 1;
@ -139,7 +139,7 @@ strict_atol (const char *str, long *value)
} }
static int static int
conv_uid (const char *name, union el *e) conv_uid (const char *restrict name, union el *restrict e)
{ {
struct passwd *pwd; struct passwd *pwd;
@ -158,7 +158,7 @@ conv_uid (const char *name, union el *e)
static int static int
conv_gid (const char *name, union el *e) conv_gid (const char *restrict name, union el *restrict e)
{ {
struct group *grp; struct group *grp;
@ -177,7 +177,7 @@ conv_gid (const char *name, union el *e)
static int static int
conv_pgrp (const char *name, union el *e) conv_pgrp (const char *restrict name, union el *restrict e)
{ {
if (! strict_atol (name, &e->num)) { if (! strict_atol (name, &e->num)) {
fprintf (stderr, "%s: invalid process group: %s\n", fprintf (stderr, "%s: invalid process group: %s\n",
@ -191,7 +191,7 @@ conv_pgrp (const char *name, union el *e)
static int static int
conv_sid (const char *name, union el *e) conv_sid (const char *restrict name, union el *restrict e)
{ {
if (! strict_atol (name, &e->num)) { if (! strict_atol (name, &e->num)) {
fprintf (stderr, "%s: invalid session id: %s\n", fprintf (stderr, "%s: invalid session id: %s\n",
@ -205,7 +205,7 @@ conv_sid (const char *name, union el *e)
static int static int
conv_num (const char *name, union el *e) conv_num (const char *restrict name, union el *restrict e)
{ {
if (! strict_atol (name, &e->num)) { if (! strict_atol (name, &e->num)) {
fprintf (stderr, "%s: not a number: %s\n", fprintf (stderr, "%s: not a number: %s\n",
@ -217,7 +217,7 @@ conv_num (const char *name, union el *e)
static int static int
conv_str (const char *name, union el *e) conv_str (const char *restrict name, union el *restrict e)
{ {
e->str = strdup (name); e->str = strdup (name);
return (1); return (1);
@ -225,7 +225,7 @@ conv_str (const char *name, union el *e)
static int static int
match_numlist (long value, const union el *list) match_numlist (long value, const union el *restrict list)
{ {
int found = 0; int found = 0;
if (list == NULL) if (list == NULL)
@ -241,7 +241,7 @@ match_numlist (long value, const union el *list)
} }
static int static int
match_strlist (const char *value, const union el *list) match_strlist (const char *restrict value, const union el *restrict list)
{ {
int found = 0; int found = 0;
if (list == NULL) if (list == NULL)
@ -257,7 +257,7 @@ match_strlist (const char *value, const union el *list)
} }
static void static void
output_numlist (const union el *list) output_numlist (const union el *restrict list)
{ {
int i; int i;
for (i = 1; i < list[0].num; i++) for (i = 1; i < list[0].num; i++)
@ -268,7 +268,7 @@ output_numlist (const union el *list)
} }
static void static void
output_strlist (const union el *list) output_strlist (const union el *restrict list)
{ {
int i; int i;
for (i = 1; i < list[0].num; i++) for (i = 1; i < list[0].num; i++)
@ -527,42 +527,42 @@ parse_opts (int argc, char **argv)
opt_delim = strdup (optarg); opt_delim = strdup (optarg);
break; break;
case 'P': case 'P':
opt_ppid = split_list (optarg, ',', conv_num); opt_ppid = split_list (optarg, conv_num);
if (opt_ppid == NULL) if (opt_ppid == NULL)
usage (opt); usage (opt);
++criteria_count; ++criteria_count;
break; break;
case 'g': case 'g':
opt_pgrp = split_list (optarg, ',', conv_pgrp); opt_pgrp = split_list (optarg, conv_pgrp);
if (opt_pgrp == NULL) if (opt_pgrp == NULL)
usage (opt); usage (opt);
break; break;
case 's': case 's':
opt_sid = split_list (optarg, ',', conv_sid); opt_sid = split_list (optarg, conv_sid);
if (opt_sid == NULL) if (opt_sid == NULL)
usage (opt); usage (opt);
++criteria_count; ++criteria_count;
break; break;
case 'u': case 'u':
opt_euid = split_list (optarg, ',', conv_uid); opt_euid = split_list (optarg, conv_uid);
if (opt_euid == NULL) if (opt_euid == NULL)
usage (opt); usage (opt);
++criteria_count; ++criteria_count;
break; break;
case 'U': case 'U':
opt_uid = split_list (optarg, ',', conv_uid); opt_uid = split_list (optarg, conv_uid);
if (opt_uid == NULL) if (opt_uid == NULL)
usage (opt); usage (opt);
++criteria_count; ++criteria_count;
break; break;
case 'G': case 'G':
opt_gid = split_list (optarg, ',', conv_gid); opt_gid = split_list (optarg, conv_gid);
if (opt_gid == NULL) if (opt_gid == NULL)
usage (opt); usage (opt);
++criteria_count; ++criteria_count;
break; break;
case 't': case 't':
opt_term = split_list (optarg, ',', conv_str); opt_term = split_list (optarg, conv_str);
if (opt_term == NULL) if (opt_term == NULL)
usage (opt); usage (opt);
++criteria_count; ++criteria_count;

View File

@ -75,7 +75,7 @@ static void display_kill_version(){
} }
/***** kill or nice a process */ /***** kill or nice a process */
static void hurt_proc(int tty, int uid, int pid, char *cmd){ static void hurt_proc(int tty, int uid, int pid, const char *restrict const cmd){
int failed; int failed;
int saved_errno; int saved_errno;
char dn_buf[1000]; char dn_buf[1000];
@ -245,8 +245,8 @@ static void kill_usage(void){
} }
/***** kill */ /***** kill */
static void kill_main(int argc, char *argv[]){ static void kill_main(int argc, const char *restrict argv[]){
char *sigptr; const char *sigptr;
int signo = SIGTERM; int signo = SIGTERM;
int exitvalue = 0; int exitvalue = 0;
if(argc<2) kill_usage(); if(argc<2) kill_usage();