1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
/* This file is part of genrc
Copyryght (C) 2018 Sergey Poznyakoff
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
*/
#include "genrc.h"
struct genrc_pid_source {
char *name;
GENRC_PID_CLOSURE *(*init)(int argc, char **argv);
};
struct genrc_pid_source sourcetab[] = {
{ "FILE", genrc_pid_file_init },
{ "CONFIG", genrc_pid_config_init },
{ "GREP", genrc_pid_grep_init },
{ "PROC", genrc_pid_proc_init },
{ "PS", genrc_pid_ps_init },
{ NULL }
};
GENRC_PID_CLOSURE *
get_pid_closure(char const *str)
{
struct genrc_pid_source *s;
struct wordsplit ws;
GENRC_PID_CLOSURE *pc;
ws.ws_error = genrc_error;
ws.ws_delim = ":";
if (wordsplit(str, &ws,
WRDSF_NOCMD|WRDSF_NOVAR|WRDSF_QUOTE|
WRDSF_DELIM|WRDSF_ENOMEMABRT|WRDSF_SHOWERR|WRDSF_ERROR))
exit(1);
if (ws.ws_wordc == 0)
usage_error("GENRC_PID_FROM argument is empty");
for (s = sourcetab; ; s++) {
if (!s->name)
usage_error("%s: unsupported PID source", str);
if (strcmp(s->name, ws.ws_wordv[0]) == 0)
break;
}
pc = s->init(ws.ws_wordc, ws.ws_wordv);
if (!pc)
exit(1);
pc->name = xstrdup(str);
return pc;
}
int
get_pid_list(GENRC_PID_CLOSURE *clos, PIDLIST *plist)
{
pidlist_clear(plist);
return clos->pid(clos, plist);
}
|