]> sourceware.org Git - newlib-cygwin.git/blob - winsup/cygserver/msg.cc
* smallprint.c: New file.
[newlib-cygwin.git] / winsup / cygserver / msg.cc
1 /* msg.cc: Single unix specification IPC interface for Cygwin.
2
3 Copyright 2003, 2004 Red Hat, Inc.
4
5 This file is part of Cygwin.
6
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
9 details. */
10
11 #ifdef __OUTSIDE_CYGWIN__
12 #include "woutsup.h"
13
14 #include <errno.h>
15 #include <pthread.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <time.h>
20
21 #include "cygserver.h"
22 #include "process.h"
23 #include "transport.h"
24
25 #include "cygserver_ipc.h"
26 #include "cygserver_msg.h"
27
28 client_request_msg::client_request_msg ()
29 : client_request (CYGSERVER_REQUEST_MSG,
30 &_parameters, sizeof (_parameters))
31 {
32 }
33
34 void
35 client_request_msg::serve (transport_layer_base *const conn,
36 process_cache *const cache)
37 {
38 if (msglen () != sizeof (_parameters.in))
39 {
40 syscall_printf ("bad request body length: expecting %lu bytes, got %lu",
41 sizeof (_parameters), msglen ());
42 error_code (EINVAL);
43 msglen (0);
44 return;
45 }
46 if (support_msgqueues == TUN_FALSE)
47 {
48 syscall_printf ("Message queue support not started");
49 error_code (ENOSYS);
50 if (_parameters.in.msgop == MSGOP_msgrcv)
51 _parameters.out.rcv = -1;
52 else
53 _parameters.out.ret = -1;
54 msglen (sizeof (_parameters.out));
55 return;
56 }
57 process *const client = cache->process (_parameters.in.ipcblk.cygpid,
58 _parameters.in.ipcblk.winpid,
59 _parameters.in.ipcblk.signal_arrived);
60 if (!client)
61 {
62 error_code (EAGAIN);
63 msglen (0);
64 return;
65 }
66 if (!conn->impersonate_client ())
67 {
68 client->release ();
69 error_code (EACCES);
70 msglen (0);
71 return;
72 }
73 if (!adjust_identity_info (&_parameters.in.ipcblk))
74 {
75 client->release ();
76 conn->revert_to_self ();
77 error_code (EACCES);
78 msglen (0);
79 return;
80 }
81 /* Early revert_to_self since IPC code runs in kernel mode. */
82 conn->revert_to_self ();
83 /* sysv_msg.cc takes care of itself. */
84 client->release ();
85 thread td = { client, &_parameters.in.ipcblk, {-1, -1} };
86 int res;
87 msgop_t msgop = _parameters.in.msgop; /* Get's overwritten otherwise. */
88 switch (msgop)
89 {
90 case MSGOP_msgctl:
91 res = msgctl (&td, &_parameters.in.ctlargs);
92 break;
93 case MSGOP_msgget:
94 res = msgget (&td, &_parameters.in.getargs);
95 break;
96 case MSGOP_msgrcv:
97 res = msgrcv (&td, &_parameters.in.rcvargs);
98 break;
99 case MSGOP_msgsnd:
100 res = msgsnd (&td, &_parameters.in.sndargs);
101 break;
102 default:
103 res = ENOSYS;
104 td.td_retval[0] = -1;
105 break;
106 }
107 /* Allocated by the call to adjust_identity_info(). */
108 if (_parameters.in.ipcblk.gidlist)
109 free (_parameters.in.ipcblk.gidlist);
110 error_code (res);
111 if (msgop == MSGOP_msgrcv)
112 _parameters.out.rcv = td.td_retval[0];
113 else
114 _parameters.out.ret = td.td_retval[0];
115 msglen (sizeof (_parameters.out));
116 }
117 #endif /* __OUTSIDE_CYGWIN__ */
This page took 0.039962 seconds and 5 git commands to generate.