1 /* msg.cc: Single unix specification IPC interface for Cygwin.
3 This file is part of Cygwin.
5 This software is a copyrighted work licensed under the terms of the
6 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
9 #ifdef __OUTSIDE_CYGWIN__
19 #include "cygserver.h"
21 #include "transport.h"
23 #include "cygserver_ipc.h"
24 #include "cygserver_msg.h"
26 client_request_msg::client_request_msg ()
27 : client_request (CYGSERVER_REQUEST_MSG
,
28 &_parameters
, sizeof (_parameters
))
33 client_request_msg::serve (transport_layer_base
*const conn
,
34 process_cache
*const cache
)
36 if (msglen () != sizeof (_parameters
.in
))
38 syscall_printf ("bad request body length: expecting %lu bytes, got %lu",
39 sizeof (_parameters
), msglen ());
44 if (support_msgqueues
== TUN_FALSE
)
46 syscall_printf ("Message queue support not started");
48 if (_parameters
.in
.msgop
== MSGOP_msgrcv
)
49 _parameters
.out
.rcv
= -1;
51 _parameters
.out
.ret
= -1;
52 msglen (sizeof (_parameters
.out
));
55 process
*const client
= cache
->process (_parameters
.in
.ipcblk
.cygpid
,
56 _parameters
.in
.ipcblk
.winpid
);
63 if (!conn
->impersonate_client ())
70 if (!adjust_identity_info (&_parameters
.in
.ipcblk
))
73 conn
->revert_to_self ();
78 /* Early revert_to_self since IPC code runs in kernel mode. */
79 conn
->revert_to_self ();
80 /* sysv_msg.cc takes care of itself. */
82 thread
td (client
, &_parameters
.in
.ipcblk
, true);
84 msgop_t msgop
= _parameters
.in
.msgop
; /* Get's overwritten otherwise. */
88 res
= msgctl (&td
, &_parameters
.in
.ctlargs
);
91 res
= msgget (&td
, &_parameters
.in
.getargs
);
94 res
= msgrcv (&td
, &_parameters
.in
.rcvargs
);
97 res
= msgsnd (&td
, &_parameters
.in
.sndargs
);
101 td
.td_retval
[0] = -1;
104 /* Allocated by the call to adjust_identity_info(). */
105 if (_parameters
.in
.ipcblk
.gidlist
)
106 free (_parameters
.in
.ipcblk
.gidlist
);
108 if (msgop
== MSGOP_msgrcv
)
109 _parameters
.out
.rcv
= td
.td_retval
[0];
111 _parameters
.out
.ret
= td
.td_retval
[0];
112 msglen (sizeof (_parameters
.out
));
114 #endif /* __OUTSIDE_CYGWIN__ */