some coverity fixes.
[minix.git] / servers / vm / queryexit.c
blobb70efc83753f6c80459084eb3ebfd78b67215ccb
2 #define _SYSTEM 1
4 #include <minix/callnr.h>
5 #include <minix/com.h>
6 #include <minix/config.h>
7 #include <minix/const.h>
8 #include <minix/ds.h>
9 #include <minix/endpoint.h>
10 #include <minix/keymap.h>
11 #include <minix/minlib.h>
12 #include <minix/type.h>
13 #include <minix/ipc.h>
14 #include <minix/sysutil.h>
15 #include <minix/syslib.h>
16 #include <minix/safecopies.h>
17 #include <minix/bitmap.h>
18 #include <minix/vm.h>
19 #include <minix/ds.h>
21 #include <errno.h>
22 #include <string.h>
23 #include <env.h>
24 #include <stdio.h>
26 #include "glo.h"
27 #include "proto.h"
28 #include "util.h"
30 struct query_exit_struct {
31 int avail;
32 endpoint_t ep;
34 static struct query_exit_struct array[NR_PROCS];
36 /*===========================================================================*
37 * do_query_exit *
38 *===========================================================================*/
39 int do_query_exit(message *m)
41 int i, nr;
42 endpoint_t ep = NONE;
44 for (i = 0; i < NR_PROCS; i++) {
45 if (!array[i].avail) {
46 array[i].avail = 1;
47 ep = array[i].ep;
48 array[i].ep = 0;
50 break;
54 nr = 0;
55 for (i = 0; i < NR_PROCS; i++) {
56 if (!array[i].avail)
57 nr++;
59 m->VM_QUERY_RET_PT = ep;
60 m->VM_QUERY_IS_MORE = (nr > 0);
62 return OK;
65 /*===========================================================================*
66 * do_notify_sig *
67 *===========================================================================*/
68 int do_notify_sig(message *m)
70 int i, avails = 0;
71 endpoint_t ep = m->VM_NOTIFY_SIG_ENDPOINT;
72 endpoint_t ipc_ep = m->VM_NOTIFY_SIG_IPC;
73 int r;
74 struct vmproc *vmp;
75 int pslot;
77 if(vm_isokendpt(ep, &pslot) != OK) return ESRCH;
78 vmp = &vmproc[pslot];
80 /* Only record the event if we've been asked to report it. */
81 if(!(vmp->vm_flags & VMF_WATCHEXIT))
82 return OK;
84 for (i = 0; i < NR_PROCS; i++) {
85 /* its signal is already here */
86 if (!array[i].avail && array[i].ep == ep)
87 goto out;
88 if (array[i].avail)
89 avails++;
91 if (!avails) {
92 /* no slot for signals, unlikely */
93 printf("VM: no slot for signals!\n");
94 return ENOMEM;
97 for (i = 0; i < NR_PROCS; i++) {
98 if (array[i].avail) {
99 array[i].avail = 0;
100 array[i].ep = ep;
102 break;
106 out:
107 /* only care when IPC server starts up,
108 * and bypass the process to be signal is IPC itself.
110 if (ipc_ep != 0 && ep != ipc_ep) {
111 r = notify(ipc_ep);
112 if (r != OK)
113 printf("VM: notify IPC error!\n");
115 return OK;
118 /*===========================================================================*
119 * do_watch_exit *
120 *===========================================================================*/
121 int do_watch_exit(message *m)
123 endpoint_t e = m->VM_WE_EP;
124 struct vmproc *vmp;
125 int p;
126 if(vm_isokendpt(e, &p) != OK) return ESRCH;
127 vmp = &vmproc[p];
128 vmp->vm_flags |= VMF_WATCHEXIT;
130 return OK;
133 /*===========================================================================*
134 * init_query_exit *
135 *===========================================================================*/
136 void init_query_exit(void)
138 int i;
140 for (i = 0; i < NR_PROCS; i++) {
141 array[i].avail = 1;
142 array[i].ep = 0;