|
Procster
0.1
Procster-ViewProcessesovertheweb
|
#include <glib.h>#include <proc/readproc.h>#include <proc/sysinfo.h>

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_t * | proc_tree (void) |
| Populate a tree of (proc_t) processes. More... | |
| void | ptree_dump (proc_t *p, int lvl) |
| Dump process tree to STDOUT. More... | |
| GSList * | par_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_t * | proc_to_json (proc_t *proc, char *cmdline) |
| Populate Process node into (Jansson) JSON Object. More... | |
| json_t * | ptree_json (proc_t *p, int lvl) |
| Convert process tree to JSON. More... | |
| json_t * | proc_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... | |
| miniserver * | server_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... | |
| action * | action_find (miniserver *s, const char *url) |
| Lookup an action (during dispatching). More... | |
| #define proc_chn_init | ( | p | ) | ((p)->sd_uunit = NULL) |
Referenced by proc_list_json2(), proc_tree(), and ptree_free().
| #define PROC_FLAGS_DEFAULT PROC_FILLMEM | PROC_FILLCOM | PROC_FILLUSR | PROC_FILLSTATUS | PROC_FILLSTAT |
Referenced by proc_list_json(), proc_list_json2(), and proc_tree().
| #define proc_stime_ux | ( | p | ) | (getbtime() + p->start_time / Hertz) |
Referenced by proc_st_iso(), and proc_to_json().
| #define WITH_SYSTEMD |
| typedef struct miniserver miniserver |
| action* action_find | ( | miniserver * | s, |
| const char * | url | ||
| ) |
Lookup an action (during dispatching).
| s | - Server |
| url | - URL by which action node should be looked up |
References miniserver::actions, and action::url.
Referenced by main(), and ms_answer_to_connection().
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.
| par | - Parent |
| ch | - Child |
Referenced by proc_tree().
Get a list of direct child processes of parent process.
| p | - Parent process whose direct children are being accessed |
Referenced by ptree_dump(), ptree_free(), and ptree_json().
| int proc_kill | ( | int | pid | ) |
Kill process by sending SIGKILL signal to it.
See also man 7 signal and man 2 kill.
| pid | - PID of individual process (>= 1) |
Referenced by answer_to_connection0().
| 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.
| flags | - Flags for openproc() (See man openproc) |
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().
Populate Process node into (Jansson) JSON Object.
Can be used to populate processes in linear list or tree formats.
| proc | - Process |
| cmdline | - Buffer to serialize (approximate) command line with arguments into. |
References list2str(), and proc_stime_ux.
Referenced by proc_list_json2(), and ptree_json().
| 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).
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().
| void ptree_dump | ( | proc_t * | p, |
| int | lvl | ||
| ) |
Dump process tree to STDOUT.
| p | - Root process of the tree |
| lvl | - Level in the process tree (Intial caller should pass 0) |
References gsleader(), leadstr, par_get_ch(), and proc_st_iso().
Referenced by proc_tree().
| 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).
| p | - Root process |
| lvl | - Recursion level (explicit caller should pass 0) |
References freeproc(), g_slist_free(), par_get_ch(), and proc_chn_init.
Referenced by answer_to_connection0(), and proc_list_json2().
Convert process tree to JSON.
| p | - Root process node of the tree (linux kernel, pid=0) |
| lvl | - Recursion level (explicit caller should pass 0) |
References par_get_ch(), and proc_to_json().
Referenced by answer_to_connection0(), and proc_list_json2().
| void server_actions_load | ( | miniserver * | s, |
| action * | actarr, | ||
| int | cnt | ||
| ) |
App: Load actions from C Array of actions.
| s | - Miniserver (to/for which actions will be loaded) |
| actarr | - Array of actions (not action pointers) to add |
| cnt | - Number of actions to add |
References miniserver::actions, and action::url.
Referenced by main().
| miniserver* server_new | ( | json_t * | json | ) |
App: Instantiate server with basic settings (e.g.
docroot, port).
References miniserver::debug, miniserver::docroot, docroot, miniserver::logfh, miniserver::logfname, miniserver::port, and miniserver::reqdebug.
Referenced by main().
| void server_run | ( | miniserver * | s | ) |
App: Start Running Server and accepting requests.
| s | - Server |
References ms_answer_to_connection(), ms_on_client_connect(), ms_req_term_cb(), and miniserver::port.
Referenced by main().