Procster  0.1
Procster-ViewProcessesovertheweb
proclister.h
Go to the documentation of this file.
1 #include <glib.h>
2 #define WITH_SYSTEMD
3 #include <proc/readproc.h>
4 #include <proc/sysinfo.h> // Hertz, getbtime
5 
6 // Need PROC_FILLSTATUS for ppid, need PROC_FILLSTAT for times.
7 #define PROC_FLAGS_DEFAULT PROC_FILLMEM | PROC_FILLCOM | PROC_FILLUSR | PROC_FILLSTATUS | PROC_FILLSTAT
8 // process start time as EPOC timestamp
9 #define proc_stime_ux(p) (getbtime() + p->start_time / Hertz)
10 // Centos 7.6 does not have member lxcname:
11 // procutil.c:27:20: error: ‘proc_t’ has no member named ‘lxcname’
12 //#define proc_chn_init(p) (p)->lxcname = NULL
13 #define proc_chn_init(p) ((p)->sd_uunit = NULL)
14 
15 proc_t * proc_tree(void);
16 void ptree_dump(proc_t * p, int lvl);
17 // Process tree parnt-child relations helpers
18 GSList * par_get_ch(proc_t * p);
19 void par_add_child(proc_t * par, proc_t * ch);
20 //
21 json_t * proc_to_json(proc_t * proc, char * cmdline);
22 json_t * ptree_json(proc_t * p, int lvl);
23 json_t * proc_list_json2(int flags);
24 void ptree_free(proc_t * p, int lvl);
25 int proc_kill(int pid);
26 
27 typedef struct pstree {
28  GHashTable * idx; // Index for fast lookup
29  PROCTAB * proctab; // Handle to opened procps "process table"
30  proc_t * p0; // Root of the process tree
31  GSList * list; // For temporarily unresolved parents
32  int debug; // Debugging on
33 } pstree;
34 
36 typedef struct miniserver miniserver;
37 typedef struct request request;
38 typedef struct response response;
39 typedef struct action action;
40 typedef int (*webhandler)( request * req, response * res);
41 
42 miniserver * server_new(json_t * json);
43 void server_actions_load(miniserver * s, action * actarr, int cnt);
44 void server_run(miniserver * s);
45 action * action_find(miniserver * s, const char * url);
46 
47 struct action {
48  char * actlbl;
49  char * name;
50  char * url;
51  char * conttype;
53  int auth;
54 };
55 struct miniserver {
56  char * docroot;
57  int port;
60  void * server; // Lower level server object
61  int debug;
62  int reqdebug;
63  char * logfname;
64  FILE * logfh;
65 };
66 struct request {
67  char * url;
68 
69  char * method;
70  int methodnum;
71  // For future POST
72  char * cont;
73  int contlen;
74  char * conttype;
75  struct action * act;
78 };
79 struct response {
80  struct action * act;
81  void * conn;
82  // Content: Either cont,contlen OR json
84  char * cont;
85  int contlen;
86  char * conttype;
87  int memmode; // For cont. Default: _FREE
88  // int fd; // Option for sending file
89  // Response Status code (e.g. 200, 404 ...)
90  int code;
91 };
92 // Req, Res combo (helper for containing bot req, res)
93 // OR just link req to res by req->res;
int port
Definition: proclister.h:57
PROCTAB * proctab
Definition: proclister.h:29
GHashTable * idx
Definition: proclister.h:28
int jsonindent
Definition: proclister.h:58
char * url
Definition: proclister.h:67
int debug
Definition: proclister.h:61
void ptree_free(proc_t *p, int lvl)
Free/Release the tree of processes.
Definition: procutil.c:234
json_t * ptree_json(proc_t *p, int lvl)
Convert process tree to JSON.
Definition: procutil.c:208
int debug
Definition: proclister.h:32
int memmode
Definition: proclister.h:87
Definition: proclister.h:47
int proc_kill(int pid)
Kill process by sending SIGKILL signal to it.
Definition: procutil.c:48
Definition: proclister.h:55
void server_actions_load(miniserver *s, action *actarr, int cnt)
App: Load actions from C Array of actions.
Definition: miniserver.c:128
void ptree_dump(proc_t *p, int lvl)
Dump process tree to STDOUT.
Definition: procutil.c:184
webhandler hdlr
Request handler callback (function pointer)
Definition: proclister.h:52
int auth
Require (Basic) authentication. TODO: Enum to the kind of auth.
Definition: proclister.h:53
proc_t * p0
Definition: proclister.h:30
json_t * proc_list_json2(int flags)
Create Process list JSON.
Definition: proclist.c:160
char * conttype
Definition: proclister.h:74
char * cont
Definition: proclister.h:72
proc_t * proc_tree(void)
Populate a tree of (proc_t) processes.
Definition: proctree.c:89
char * conttype
Definition: proclister.h:86
Definition: proclister.h:27
json_t * json
Definition: proclister.h:83
void * conn
Lower level http conn/response, similar to miniserver->server;.
Definition: proclister.h:81
static action actarr[]
Definition: ms_test.c:31
response * res
Associated Response.
Definition: proclister.h:77
char * actlbl
Short id label (no spaces)
Definition: proclister.h:48
int reqdebug
Definition: proclister.h:62
void * GSList
Definition: covmodels.c:30
struct action * act
Action that dispatched handler.
Definition: proclister.h:75
void * proc_t
Definition: covmodels.c:31
struct action * act
Definition: proclister.h:80
action * action_find(miniserver *s, const char *url)
Lookup an action (during dispatching).
Definition: miniserver.c:181
char * url
URL that this action gets dispatched on.
Definition: proclister.h:50
char * conttype
Content type this action plans to produce under normal conditions.
Definition: proclister.h:51
Definition: proclister.h:79
struct pstree pstree
FILE * logfh
Definition: proclister.h:64
void * server
Definition: proclister.h:60
int(* webhandler)(request *req, response *res)
Definition: proclister.h:40
int contlen
Definition: proclister.h:85
char * cont
Definition: proclister.h:84
int contlen
Definition: proclister.h:73
json_t * proc_to_json(proc_t *proc, char *cmdline)
Populate Process node into (Jansson) JSON Object.
Definition: procutil.c:136
GSList * par_get_ch(proc_t *p)
Get a list of direct child processes of parent process.
Definition: procutil.c:38
int methodnum
Definition: proclister.h:70
char * name
Descriptive name.
Definition: proclister.h:49
char * docroot
Definition: proclister.h:56
miniserver * ms
Server under which we are running.
Definition: proclister.h:76
char * logfname
Definition: proclister.h:63
Definition: proclister.h:66
GSList * actions
Definition: proclister.h:59
void server_run(miniserver *s)
App: Start Running Server and accepting requests.
Definition: miniserver.c:98
int code
Definition: proclister.h:90
miniserver * server_new(json_t *json)
App: Instantiate server with basic settings (e.g.
Definition: miniserver.c:61
void par_add_child(proc_t *par, proc_t *ch)
Add a child process to a parent.
Definition: procutil.c:29
char * method
Definition: proclister.h:69
GSList * list
Definition: proclister.h:31
void * json_t
Definition: covmodels.c:29