Procster  0.1
Procster-ViewProcessesovertheweb
proclister.h File Reference
#include <glib.h>
#include <proc/readproc.h>
#include <proc/sysinfo.h>
Include dependency graph for proclister.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  pstree
 
struct  action
 
struct  miniserver
 
struct  request
 
struct  response
 

Macros

#define WITH_SYSTEMD
 
#define PROC_FLAGS_DEFAULT   PROC_FILLMEM | PROC_FILLCOM | PROC_FILLUSR | PROC_FILLSTATUS | PROC_FILLSTAT
 
#define proc_stime_ux(p)   (getbtime() + p->start_time / Hertz)
 
#define proc_chn_init(p)   ((p)->sd_uunit = NULL)
 

Typedefs

typedef struct pstree pstree
 
typedef struct miniserver miniserver
 
typedef struct request request
 
typedef struct response response
 
typedef struct action action
 
typedef int(* webhandler) (request *req, response *res)
 

Functions

proc_tproc_tree (void)
 Populate a tree of (proc_t) processes. More...
 
void ptree_dump (proc_t *p, int lvl)
 Dump process tree to STDOUT. More...
 
GSListpar_get_ch (proc_t *p)
 Get a list of direct child processes of parent process. More...
 
void par_add_child (proc_t *par, proc_t *ch)
 Add a child process to a parent. More...
 
json_tproc_to_json (proc_t *proc, char *cmdline)
 Populate Process node into (Jansson) JSON Object. More...
 
json_tptree_json (proc_t *p, int lvl)
 Convert process tree to JSON. More...
 
json_tproc_list_json2 (int flags)
 Create Process list JSON. More...
 
void ptree_free (proc_t *p, int lvl)
 Free/Release the tree of processes. More...
 
int proc_kill (int pid)
 Kill process by sending SIGKILL signal to it. More...
 
miniserverserver_new (json_t *json)
 App: Instantiate server with basic settings (e.g. More...
 
void server_actions_load (miniserver *s, action *actarr, int cnt)
 App: Load actions from C Array of actions. More...
 
void server_run (miniserver *s)
 App: Start Running Server and accepting requests. More...
 
actionaction_find (miniserver *s, const char *url)
 Lookup an action (during dispatching). More...
 

Macro Definition Documentation

◆ proc_chn_init

#define proc_chn_init (   p)    ((p)->sd_uunit = NULL)

◆ PROC_FLAGS_DEFAULT

#define PROC_FLAGS_DEFAULT   PROC_FILLMEM | PROC_FILLCOM | PROC_FILLUSR | PROC_FILLSTATUS | PROC_FILLSTAT

◆ proc_stime_ux

#define proc_stime_ux (   p)    (getbtime() + p->start_time / Hertz)

Referenced by proc_st_iso(), and proc_to_json().

◆ WITH_SYSTEMD

#define WITH_SYSTEMD

Typedef Documentation

◆ action

typedef struct action action

◆ miniserver

typedef struct miniserver miniserver

◆ pstree

typedef struct pstree pstree

◆ request

typedef struct request request

◆ response

typedef struct response response

◆ webhandler

typedef int(* webhandler) (request *req, response *res)

Function Documentation

◆ action_find()

action* action_find ( miniserver s,
const char *  url 
)

Lookup an action (during dispatching).

Parameters
s- Server
url- URL by which action node should be looked up
Returns
Action node matched or NULL for no action matching passed URL.

References miniserver::actions, and action::url.

Referenced by main(), and ms_answer_to_connection().

◆ par_add_child()

void par_add_child ( proc_t par,
proc_t ch 
)

Add a child process to a parent.

Child is added to an "abused" (not meant for this purpose) struct member (however still a pointer member "lxcname") of the process structure. Facilitates appropriate casts to allow smooth operation and easy use.

Parameters
par- Parent
ch- Child

Referenced by proc_tree().

◆ par_get_ch()

GSList* par_get_ch ( proc_t p)

Get a list of direct child processes of parent process.

Parameters
p- Parent process whose direct children are being accessed
Returns
- List of children

Referenced by ptree_dump(), ptree_free(), and ptree_json().

◆ proc_kill()

int proc_kill ( int  pid)

Kill process by sending SIGKILL signal to it.

See also man 7 signal and man 2 kill.

Parameters
pid- PID of individual process (>= 1)
Returns
0 for process being killed successfully, 1 and up for errors

Referenced by answer_to_connection0().

◆ proc_list_json2()

json_t* proc_list_json2 ( int  flags)

Create Process list JSON.

Serialization is done using Jansson JSON library by building AoO and serializing it. The linear list of processes can be built using single stack based process entry buffer.

Parameters
flags- Flags for openproc() (See man openproc)
Returns
JSON array of (process) objects as jansson library data structure (has to be freed by caller)

References IS_KTHREAD, main(), proc_chn_init, PROC_FLAGS_DEFAULT, proc_list_json2(), proc_to_json(), proc_tree(), ptree_free(), and ptree_json().

Referenced by answer_to_connection0(), and proc_list_json2().

◆ proc_to_json()

json_t* proc_to_json ( proc_t proc,
char *  cmdline 
)

Populate Process node into (Jansson) JSON Object.

Can be used to populate processes in linear list or tree formats.

Parameters
proc- Process
cmdline- Buffer to serialize (approximate) command line with arguments into.
Todo:
See https://groups.google.com/g/jansson-users/c/xD8QLQF3ex8 and the need to use json_object_set_new()

References list2str(), and proc_stime_ux.

Referenced by proc_list_json2(), and ptree_json().

◆ proc_tree()

proc_t* proc_tree ( void  )

Populate a tree of (proc_t) processes.

Because of intricate linkages of process tree - and not wanting them broken or incomplete - we do not support partial or filtered process trees (although the implementation contains some bulletproofing for this).

Returns
Root process node of the tree.

References g_slist_free(), main(), par_add_child(), proc_chn_init, PROC_FLAGS_DEFAULT, and ptree_dump().

Referenced by answer_to_connection0(), and proc_list_json2().

◆ ptree_dump()

void ptree_dump ( proc_t p,
int  lvl 
)

Dump process tree to STDOUT.

Parameters
p- Root process of the tree
lvl- Level in the process tree (Intial caller should pass 0)
Returns
None

References gsleader(), leadstr, par_get_ch(), and proc_st_iso().

Referenced by proc_tree().

◆ ptree_free()

void ptree_free ( proc_t p,
int  lvl 
)

Free/Release the tree of processes.

Release custom used (OLD:lxcname) "sd_uunit" member (GSList *) and mark it unallocated (NULL) to not accidentally free it wrongly (or leak memory).

Parameters
p- Root process
lvl- Recursion level (explicit caller should pass 0)
Returns
None

References freeproc(), g_slist_free(), par_get_ch(), and proc_chn_init.

Referenced by answer_to_connection0(), and proc_list_json2().

◆ ptree_json()

json_t* ptree_json ( proc_t p,
int  lvl 
)

Convert process tree to JSON.

Parameters
p- Root process node of the tree (linux kernel, pid=0)
lvl- Recursion level (explicit caller should pass 0)
Returns
Jansson JSON root node

References par_get_ch(), and proc_to_json().

Referenced by answer_to_connection0(), and proc_list_json2().

◆ server_actions_load()

void server_actions_load ( miniserver s,
action actarr,
int  cnt 
)

App: Load actions from C Array of actions.

Parameters
s- Miniserver (to/for which actions will be loaded)
actarr- Array of actions (not action pointers) to add
cnt- Number of actions to add
Returns
none

References miniserver::actions, and action::url.

Referenced by main().

◆ server_new()

miniserver* server_new ( json_t json)

App: Instantiate server with basic settings (e.g.

docroot, port).

  • docroot
  • port
  • JSON indent/prettiness

References miniserver::debug, miniserver::docroot, docroot, miniserver::logfh, miniserver::logfname, miniserver::port, and miniserver::reqdebug.

Referenced by main().

◆ server_run()

void server_run ( miniserver s)

App: Start Running Server and accepting requests.

Parameters
s- Server
Returns
None

References ms_answer_to_connection(), ms_on_client_connect(), ms_req_term_cb(), and miniserver::port.

Referenced by main().