void crc_init(unsigned int *crc_table, int little_endian);
void terminal_size(unsigned *x, unsigned *y);
int yesno(char *prompt, int def);
-void for_each_pid_with_name_in(char **names, int (*callback)(pid_t pid, char *name));
+void names_to_pid(char **names, int (*callback)(pid_t pid, char *name));
// net.c
int xsocket(int domain, int type, int protocol);
#include "toys.h"
// Execute a callback for each PID that matches a process name from a list.
-void name_to_pid(char **names, int (*callback)(pid_t pid, char *name))
+void names_to_pid(char **names, int (*callback)(pid_t pid, char *name))
{
DIR *dp;
struct dirent *entry;
if (!(dp = opendir("/proc"))) perror_exit("opendir");
while ((entry = readdir(dp))) {
- int fd, n;
unsigned u;
char *cmd, **curname;
if (!(cmd = readfile(libbuf, libbuf, sizeof(libbuf)))) continue;
for (curname = names; *curname; curname++)
- if (*curname == '/' ? !strcmp(cmd, *curname)
- : !strcmp(basename(cmd), basename(*curname))
- if (!callback(u, *curname)) break;
+ if (**curname == '/' ? !strcmp(cmd, *curname)
+ : !strcmp(basename(cmd), basename(*curname)))
+ if (callback(u, *curname)) break;
if (*curname) break;
}
closedir(dp);
void pidof_main(void)
{
toys.exitval = 1;
- name_to_pid(toys.optargs, print_pid);
+ names_to_pid(toys.optargs, print_pid);
if (!toys.exitval) xputc('\n');
}