protocol: Connect to a PID-bound named socket
This commit is contained in:
parent
0e1eec940a
commit
4842cf0d9e
3 changed files with 43 additions and 3 deletions
|
@ -134,6 +134,7 @@ static int get_win_status(HANDLE handle) {
|
|||
#endif
|
||||
|
||||
struct worker_context g_worker_context = {.test = NULL};
|
||||
unsigned long long g_ppid = 0;
|
||||
|
||||
#ifdef VANILLA_WIN32
|
||||
struct full_context {
|
||||
|
@ -142,6 +143,7 @@ struct full_context {
|
|||
struct criterion_suite suite;
|
||||
struct criterion_test_extra_data suite_data;
|
||||
cr_worker_func func;
|
||||
unsigned long long ppid;
|
||||
struct test_single_param param;
|
||||
HANDLE sync;
|
||||
DWORD extra_size;
|
||||
|
@ -207,6 +209,8 @@ static void *chld_pump_thread_main(void *nil) {
|
|||
|
||||
void init_proc_compat(void) {
|
||||
#ifndef VANILLA_WIN32
|
||||
g_ppid = get_process_id();
|
||||
|
||||
child_pump_running = true;
|
||||
int err = pthread_create(&child_pump, NULL, chld_pump_thread_main, NULL);
|
||||
if (err) {
|
||||
|
@ -339,6 +343,8 @@ int resume_child(void) {
|
|||
local_ctx.test.data = &local_ctx.test_data;
|
||||
local_ctx.suite.data = &local_ctx.suite_data;
|
||||
|
||||
g_ppid = local_ctx.ppid;
|
||||
|
||||
SetEvent(local_ctx.sync);
|
||||
|
||||
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
|
||||
|
@ -411,6 +417,7 @@ s_proc_handle *fork_process() {
|
|||
.suite = *g_worker_context.suite,
|
||||
.func = g_worker_context.func,
|
||||
.sync = sync,
|
||||
.ppid = get_process_id(),
|
||||
};
|
||||
|
||||
if (g_worker_context.param) {
|
||||
|
@ -502,6 +509,14 @@ unsigned long long get_process_id(void) {
|
|||
#endif
|
||||
}
|
||||
|
||||
unsigned long long get_runner_process_id(void) {
|
||||
#ifdef VANILLA_WIN32
|
||||
return g_ppid;
|
||||
#else
|
||||
return is_runner() ? get_process_id() : (unsigned long long) getppid();
|
||||
#endif
|
||||
}
|
||||
|
||||
unsigned long long get_process_id_of(s_proc_handle *proc) {
|
||||
#ifdef VANILLA_WIN32
|
||||
return (unsigned long long) GetProcessId(proc->handle);
|
||||
|
|
|
@ -57,6 +57,7 @@ s_proc_handle *get_current_process();
|
|||
bool is_current_process(s_proc_handle *proc);
|
||||
|
||||
unsigned long long get_process_id(void);
|
||||
unsigned long long get_runner_process_id(void);
|
||||
unsigned long long get_process_id_of(s_proc_handle *proc);
|
||||
|
||||
void init_proc_compat(void);
|
||||
|
|
|
@ -21,11 +21,15 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <nanomsg/nn.h>
|
||||
#include <nanomsg/reqrep.h>
|
||||
#include <string.h>
|
||||
|
||||
#define URL "ipc://criterion.sock"
|
||||
#include "compat/process.h"
|
||||
|
||||
#define URL "ipc://%scriterion_%llu.sock"
|
||||
|
||||
#define errno_ignore(Stmt) do { int err = errno; Stmt; errno = err; } while (0)
|
||||
|
||||
|
@ -35,7 +39,17 @@ int bind_server(void) {
|
|||
if (sock < 0)
|
||||
return -1;
|
||||
|
||||
if (nn_bind(sock, URL) < 0)
|
||||
#ifdef VANILLA_WIN32
|
||||
char *prefix = "";
|
||||
#else
|
||||
char *prefix = "/tmp/";
|
||||
#endif
|
||||
|
||||
char url[256];
|
||||
int rc = snprintf(url, sizeof (url), URL, prefix, get_process_id());
|
||||
assert(rc < 256);
|
||||
|
||||
if (nn_bind(sock, url) < 0)
|
||||
goto error;
|
||||
|
||||
return sock;
|
||||
|
@ -50,7 +64,17 @@ int connect_client(void) {
|
|||
if (sock < 0)
|
||||
return -1;
|
||||
|
||||
if (nn_connect (sock, URL) < 0)
|
||||
#ifdef VANILLA_WIN32
|
||||
char *prefix = "";
|
||||
#else
|
||||
char *prefix = "/tmp/";
|
||||
#endif
|
||||
|
||||
char url[256];
|
||||
int rc = snprintf(url, sizeof (url), URL, prefix, get_runner_process_id());
|
||||
assert(rc < 256);
|
||||
|
||||
if (nn_connect (sock, url) < 0)
|
||||
goto error;
|
||||
|
||||
return sock;
|
||||
|
|
Loading…
Add table
Reference in a new issue