fix: corrected time conversion on alarm/sleep syscall
[lunaix-os.git] / lunaix-os / kernel / process / task_attr.c
1 #include <lunaix/fs/taskfs.h>
2 #include <lunaix/process.h>
3
4 void
5 __read_pending_sig(struct twimap* map)
6 {
7     struct proc_info* proc = twimap_data(map, struct proc_info*);
8     twimap_printf(map, "%bb", proc->sigctx.sig_pending);
9 }
10
11 void
12 __read_masked_sig(struct twimap* map)
13 {
14     struct proc_info* proc = twimap_data(map, struct proc_info*);
15     twimap_printf(map, "%bb", proc->sigctx.sig_mask);
16 }
17
18 void
19 __read_parent(struct twimap* map)
20 {
21     struct proc_info* proc = twimap_data(map, struct proc_info*);
22     twimap_printf(map, "%d", proc->parent->pid);
23 }
24
25 void
26 __read_ctimestamp(struct twimap* map)
27 {
28     struct proc_info* proc = twimap_data(map, struct proc_info*);
29     twimap_printf(map, "%d", proc->created);
30 }
31
32 void
33 __read_pgid(struct twimap* map)
34 {
35     struct proc_info* proc = twimap_data(map, struct proc_info*);
36     twimap_printf(map, "%d", proc->pgid);
37 }
38
39 void
40 __read_children(struct twimap* map)
41 {
42     struct llist_header* proc_list = twimap_index(map, struct llist_header*);
43     struct proc_info* proc =
44       container_of(proc_list, struct proc_info, siblings);
45     if (!proc)
46         return;
47     twimap_printf(map, "%d ", proc->pid);
48 }
49
50 int
51 __next_children(struct twimap* map)
52 {
53     struct llist_header* proc = twimap_index(map, struct llist_header*);
54     struct proc_info* current = twimap_data(map, struct proc_info*);
55     if (!proc)
56         return 0;
57     map->index = proc->next;
58     if (map->index == &current->children) {
59         return 0;
60     }
61     return 1;
62 }
63
64 void
65 __reset_children(struct twimap* map)
66 {
67     struct proc_info* proc = twimap_data(map, struct proc_info*);
68     if (llist_empty(&proc->children)) {
69         map->index = 0;
70         return;
71     }
72     map->index = proc->children.next;
73 }
74
75 void
76 export_task_attr()
77 {
78     struct twimap* map;
79     map = twimap_create(NULL);
80     map->read = __read_pending_sig;
81     taskfs_export_attr("sig_pending", map);
82
83     map = twimap_create(NULL);
84     map->read = __read_masked_sig;
85     taskfs_export_attr("sig_masked", map);
86
87     map = twimap_create(NULL);
88     map->read = __read_parent;
89     taskfs_export_attr("parent", map);
90
91     map = twimap_create(NULL);
92     map->read = __read_ctimestamp;
93     taskfs_export_attr("created", map);
94
95     map = twimap_create(NULL);
96     map->read = __read_pgid;
97     taskfs_export_attr("pgid", map);
98
99     map = twimap_create(NULL);
100     map->read = __read_children;
101     map->go_next = __next_children;
102     map->reset = __reset_children;
103     taskfs_export_attr("children", map);
104 }