Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
htop
Commits
df003a63
Commit
df003a63
authored
Jan 10, 2018
by
Hisham Muhammad
Browse files
Initialize Lua in ProcessList and load plugins
parent
d08cb255
Changes
4
Hide whitespace changes
Inline
Side-by-side
ProcessList.c
View file @
df003a63
...
@@ -26,6 +26,12 @@ in the source distribution for its full text.
...
@@ -26,6 +26,12 @@ in the source distribution for its full text.
#include <hwloc.h>
#include <hwloc.h>
#endif
#endif
#ifdef HAVE_LUA
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#endif
#ifndef MAX_NAME
#ifndef MAX_NAME
#define MAX_NAME 128
#define MAX_NAME 128
#endif
#endif
...
@@ -70,12 +76,20 @@ typedef struct ProcessList_ {
...
@@ -70,12 +76,20 @@ typedef struct ProcessList_ {
int cpuCount;
int cpuCount;
#ifdef HAVE_LUA
lua_State* L;
#endif
} ProcessList;
} ProcessList;
ProcessList* ProcessList_new(UsersTable* ut, Hashtable* pidWhiteList, uid_t userId);
ProcessList* ProcessList_new(UsersTable* ut, Hashtable* pidWhiteList, uid_t userId);
void ProcessList_delete(ProcessList* pl);
void ProcessList_delete(ProcessList* pl);
void ProcessList_goThroughEntries(ProcessList* pl);
void ProcessList_goThroughEntries(ProcessList* pl);
#ifdef HAVE_LUA
void ProcessList_enableScripting(ProcessList* pl, lua_State* L);
#endif
}*/
}*/
ProcessList
*
ProcessList_init
(
ProcessList
*
this
,
ObjectClass
*
klass
,
UsersTable
*
usersTable
,
Hashtable
*
pidWhiteList
,
uid_t
userId
)
{
ProcessList
*
ProcessList_init
(
ProcessList
*
this
,
ObjectClass
*
klass
,
UsersTable
*
usersTable
,
Hashtable
*
pidWhiteList
,
uid_t
userId
)
{
...
@@ -112,12 +126,40 @@ void ProcessList_done(ProcessList* this) {
...
@@ -112,12 +126,40 @@ void ProcessList_done(ProcessList* this) {
if
(
this
->
topologyOk
)
{
if
(
this
->
topologyOk
)
{
hwloc_topology_destroy
(
this
->
topology
);
hwloc_topology_destroy
(
this
->
topology
);
}
}
#endif
#ifdef HAVE_LUA
lua_close
(
this
->
L
);
#endif
#endif
Hashtable_delete
(
this
->
processTable
);
Hashtable_delete
(
this
->
processTable
);
Vector_delete
(
this
->
processes
);
Vector_delete
(
this
->
processes
);
Vector_delete
(
this
->
processes2
);
Vector_delete
(
this
->
processes2
);
}
}
#ifdef HAVE_LUA
void
ProcessList_initScripting
(
ProcessList
*
this
)
{
lua_State
*
L
=
luaL_newstate
();
luaL_openlibs
(
L
);
this
->
L
=
L
;
lua_newtable
(
L
);
lua_pushvalue
(
L
,
1
);
lua_setglobal
(
L
,
"htop"
);
for
(
int
i
=
0
;
i
<
this
->
settings
->
nPlugins
;
i
++
)
{
char
*
plugin
=
this
->
settings
->
plugins
[
i
];
lua_getglobal
(
L
,
"require"
);
lua_pushliteral
(
L
,
"htop-plugins."
);
lua_pushstring
(
L
,
plugin
);
lua_concat
(
L
,
2
);
int
ok
=
lua_pcall
(
L
,
1
,
1
,
0
);
if
(
ok
==
LUA_OK
)
{
lua_setfield
(
L
,
1
,
plugin
);
}
else
{
lua_pop
(
L
,
1
);
}
}
}
#endif
void
ProcessList_setPanel
(
ProcessList
*
this
,
Panel
*
panel
)
{
void
ProcessList_setPanel
(
ProcessList
*
this
,
Panel
*
panel
)
{
this
->
panel
=
panel
;
this
->
panel
=
panel
;
}
}
...
...
ProcessList.h
View file @
df003a63
...
@@ -20,6 +20,12 @@ in the source distribution for its full text.
...
@@ -20,6 +20,12 @@ in the source distribution for its full text.
#include <hwloc.h>
#include <hwloc.h>
#endif
#endif
#ifdef HAVE_LUA
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#endif
#ifndef MAX_NAME
#ifndef MAX_NAME
#define MAX_NAME 128
#define MAX_NAME 128
#endif
#endif
...
@@ -64,17 +70,29 @@ typedef struct ProcessList_ {
...
@@ -64,17 +70,29 @@ typedef struct ProcessList_ {
int
cpuCount
;
int
cpuCount
;
#ifdef HAVE_LUA
lua_State
*
L
;
#endif
}
ProcessList
;
}
ProcessList
;
ProcessList
*
ProcessList_new
(
UsersTable
*
ut
,
Hashtable
*
pidWhiteList
,
uid_t
userId
);
ProcessList
*
ProcessList_new
(
UsersTable
*
ut
,
Hashtable
*
pidWhiteList
,
uid_t
userId
);
void
ProcessList_delete
(
ProcessList
*
pl
);
void
ProcessList_delete
(
ProcessList
*
pl
);
void
ProcessList_goThroughEntries
(
ProcessList
*
pl
);
void
ProcessList_goThroughEntries
(
ProcessList
*
pl
);
#ifdef HAVE_LUA
void
ProcessList_enableScripting
(
ProcessList
*
pl
,
lua_State
*
L
);
#endif
ProcessList
*
ProcessList_init
(
ProcessList
*
this
,
ObjectClass
*
klass
,
UsersTable
*
usersTable
,
Hashtable
*
pidWhiteList
,
uid_t
userId
);
ProcessList
*
ProcessList_init
(
ProcessList
*
this
,
ObjectClass
*
klass
,
UsersTable
*
usersTable
,
Hashtable
*
pidWhiteList
,
uid_t
userId
);
void
ProcessList_done
(
ProcessList
*
this
);
void
ProcessList_done
(
ProcessList
*
this
);
#ifdef HAVE_LUA
void
ProcessList_initScripting
(
ProcessList
*
this
);
#endif
void
ProcessList_setPanel
(
ProcessList
*
this
,
Panel
*
panel
);
void
ProcessList_setPanel
(
ProcessList
*
this
,
Panel
*
panel
);
void
ProcessList_printHeader
(
ProcessList
*
this
,
RichString
*
header
);
void
ProcessList_printHeader
(
ProcessList
*
this
,
RichString
*
header
);
...
...
htop.c
View file @
df003a63
...
@@ -26,8 +26,11 @@ in the source distribution for its full text.
...
@@ -26,8 +26,11 @@ in the source distribution for its full text.
#include <time.h>
#include <time.h>
#include <unistd.h>
#include <unistd.h>
#ifdef HAVE_LUA
#include <lua.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <lauxlib.h>
#endif
//#link m
//#link m
...
@@ -175,8 +178,6 @@ int main(int argc, char** argv) {
...
@@ -175,8 +178,6 @@ int main(int argc, char** argv) {
else
else
setlocale
(
LC_CTYPE
,
""
);
setlocale
(
LC_CTYPE
,
""
);
lua_State
*
L
=
luaL_newstate
();
CommandLineSettings
flags
=
parseArguments
(
argc
,
argv
);
// may exit()
CommandLineSettings
flags
=
parseArguments
(
argc
,
argv
);
// may exit()
#ifdef HAVE_PROC
#ifdef HAVE_PROC
...
@@ -194,6 +195,10 @@ int main(int argc, char** argv) {
...
@@ -194,6 +195,10 @@ int main(int argc, char** argv) {
Settings
*
settings
=
Settings_new
(
pl
->
cpuCount
);
Settings
*
settings
=
Settings_new
(
pl
->
cpuCount
);
pl
->
settings
=
settings
;
pl
->
settings
=
settings
;
#ifdef HAVE_LUA
ProcessList_initScripting
(
pl
);
#endif
Header
*
header
=
Header_new
(
pl
,
settings
,
2
);
Header
*
header
=
Header_new
(
pl
,
settings
,
2
);
Header_populateFromSettings
(
header
);
Header_populateFromSettings
(
header
);
...
@@ -254,8 +259,6 @@ int main(int argc, char** argv) {
...
@@ -254,8 +259,6 @@ int main(int argc, char** argv) {
if
(
flags
.
pidWhiteList
)
{
if
(
flags
.
pidWhiteList
)
{
Hashtable_delete
(
flags
.
pidWhiteList
);
Hashtable_delete
(
flags
.
pidWhiteList
);
}
}
lua_close
(
L
);
return
0
;
return
0
;
}
}
htop.h
View file @
df003a63
...
@@ -9,6 +9,9 @@ Released under the GNU GPL, see the COPYING file
...
@@ -9,6 +9,9 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
in the source distribution for its full text.
*/
*/
#ifdef HAVE_LUA
#endif
//#link m
//#link m
// ----------------------------------------
// ----------------------------------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment