aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorturret <turret@duck.com>2023-12-03 00:01:09 -0600
committerturret <turret@duck.com>2023-12-03 00:01:09 -0600
commitc582ecb341ba81a7ee7976b44df5a37caa3226c1 (patch)
tree0e0c5235f70c415095cfb8a1b10dbd5587de479d
parentd4732a5a399a4d21300af41378b205a3e6aa907a (diff)
downloaddiscord-bot-skeleton-c582ecb341ba81a7ee7976b44df5a37caa3226c1.tar.gz
discord-bot-skeleton-c582ecb341ba81a7ee7976b44df5a37caa3226c1.tar.bz2
discord-bot-skeleton-c582ecb341ba81a7ee7976b44df5a37caa3226c1.zip
subsys: add mode variable & some helper funcs
-rw-r--r--init/subsys.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/init/subsys.c b/init/subsys.c
index a88046d..07a3e16 100644
--- a/init/subsys.c
+++ b/init/subsys.c
@@ -21,6 +21,7 @@ struct subsystem_info {
int (*fn)(void);
int pid;
void *stack;
+ char mode;
};
extern int mainpid;
@@ -45,6 +46,32 @@ static int __subsystem_entry(struct subsystem_info *info)
return ret;
}
+char *subsystem_get_name(int pid)
+{
+ for(int i = 0; i < MAX_SUBSYSTEMS; ++i) {
+ struct subsystem_info *subsystem = subsystems[i];
+ if(!subsystem || subsystem->pid != pid)
+ continue;
+
+ return subsystem->fn_name;
+ }
+ return 0;
+}
+
+int subsystem_change_mode(int pid, char mode)
+{
+ for(int i = 0; i < MAX_SUBSYSTEMS; ++i) {
+ struct subsystem_info *subsystem = subsystems[i];
+ if(!subsystem || subsystem->pid != pid)
+ continue;
+
+ subsystem->mode = mode;
+ return 0;
+ }
+
+ return 1;
+}
+
int subsystem_handle_term(int pid)
{
for(int i = 0; i < MAX_SUBSYSTEMS; ++i) {
@@ -91,6 +118,7 @@ int __impl_start_subsystem(char *fn_name, int (*fn)(void))
info->fn_name = fn_name;
info->fn = fn;
info->stack = stack;
+ info->mode = 'o';
int pid = clone((int (*)(void *))__subsystem_entry, (void *)((long)stack + STACK_SIZE), CLONE_FILES | CLONE_VM | SIGCHLD, info);
info->pid = pid;