pm支持选择是否完全删除进程

This commit is contained in:
zhangzheng
2023-12-10 00:34:47 +08:00
parent ac86caca8d
commit 796883fb98
4 changed files with 17 additions and 9 deletions

View File

@@ -1,3 +1,4 @@
#pragma once #pragma once
int pm_run_app(const char *path, int flags); int pm_run_app(const char *path, int flags);
int pm_kill_task(int pid, int flags);

View File

@@ -29,7 +29,7 @@ static ns_t ns;
static fs_t ns_fs; static fs_t ns_fs;
int ns_reg(const char *path, obj_handler_t hd, enum node_type type); int ns_reg(const char *path, obj_handler_t hd, enum node_type type);
int ns_node_free(ns_node_t *node); int ns_node_free(ns_node_t *node);
static void _ns_node_del_by_pid(slist_head_t *head, pid_t pid) static void _ns_node_del_by_pid(slist_head_t *head, pid_t pid, int to_del)
{ {
ns_node_t *pos; ns_node_t *pos;
@@ -41,20 +41,26 @@ static void _ns_node_del_by_pid(slist_head_t *head, pid_t pid)
{ {
if (pid == pos->pid) if (pid == pos->pid)
{ {
ns_node_free(pos); if (ns_node_free(pos) == 0)
{
if (to_del)
{
task_unmap(TASK_THIS, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, pos->node_hd));
}
}
} }
} }
else else
{ {
_ns_node_del_by_pid(&pos->sub_dir, pid); _ns_node_del_by_pid(&pos->sub_dir, pid, to_del);
} }
pos = next; pos = next;
} }
} }
void ns_node_del_by_pid(pid_t pid) void ns_node_del_by_pid(pid_t pid, int to_del)
{ {
_ns_node_del_by_pid(&ns.root_node.sub_dir, pid); _ns_node_del_by_pid(&ns.root_node.sub_dir, pid, to_del);
} }
static ns_node_t *node_init(ns_node_t *new_node, ns_node_t *parent, const char *name, obj_handler_t hd, enum node_type type) static ns_node_t *node_init(ns_node_t *new_node, ns_node_t *parent, const char *name, obj_handler_t hd, enum node_type type)
{ {
@@ -206,6 +212,7 @@ end:
*/ */
int ns_node_free(ns_node_t *node) int ns_node_free(ns_node_t *node)
{ {
int ref = 0;
if (!node) if (!node)
{ {
return 0; return 0;
@@ -216,6 +223,7 @@ int ns_node_free(ns_node_t *node)
ns_node_free(node->parent); ns_node_free(node->parent);
} }
node->ref--; node->ref--;
ref = node->ref;
if (node->ref <= 0) if (node->ref <= 0)
{ {
switch (node->type) switch (node->type)
@@ -236,7 +244,7 @@ int ns_node_free(ns_node_t *node)
} }
free(node); free(node);
} }
return node->ref; return ref;
} }
int fs_svr_open(const char *path, int flags, int mode) int fs_svr_open(const char *path, int flags, int mode)
{ {
@@ -474,7 +482,6 @@ int namespace_query(const char *path, obj_handler_t *hd)
return ret_inx; return ret_inx;
} }
void namespace_loop(void) void namespace_loop(void)
{ {
rpc_loop(); rpc_loop();

View File

@@ -23,4 +23,4 @@ int namespace_register(const char *path, obj_handler_t hd, int type);
int namespace_query(const char *path, obj_handler_t *hd); int namespace_query(const char *path, obj_handler_t *hd);
int namespace_pre_alloc_map_fd(void); int namespace_pre_alloc_map_fd(void);
void namespace_loop(void); void namespace_loop(void);
void ns_node_del_by_pid(pid_t pid); void ns_node_del_by_pid(pid_t pid, int to_del);

View File

@@ -27,7 +27,7 @@ void pm_init(void)
int pm_rpc_kill_task(int pid, int flags) int pm_rpc_kill_task(int pid, int flags)
{ {
printf("[pm] kill pid:%d.\n", pid); printf("[pm] kill pid:%d.\n", pid);
ns_node_del_by_pid(pid); ns_node_del_by_pid(pid, flags);
return 0; return 0;
} }
int pm_rpc_run_app(const char *path, int flags) int pm_rpc_run_app(const char *path, int flags)