Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: zproc is not implemented on windows #1840

Merged
merged 1 commit into from
Feb 2, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 52 additions & 43 deletions src/zproc.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* =========================================================================
zproc - process configuration and status

Copyright (c) the Contributors as noted in the AUTHORS file.
This file is part of CZMQ, the high-level C binding for 0MQ:
http://czmq.zeromq.org.
Copyright (c) the Contributors as noted in the AUTHORS file.
This file is part of CZMQ, the high-level C binding for 0MQ:
http://czmq.zeromq.org.

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
file, You can obtain one at http://mozilla.org/MPL/2.0/.
=========================================================================
*/

Expand Down Expand Up @@ -41,7 +41,7 @@ content of the messages in any way. See test example on how to use it.
|zmq://stdin |zmq://stdout |zmq://stderr |
| [zproc supervisor] |
+----------------------------------------+

----------> zeromq magic here <-----------

+----------------------------------------+
Expand All @@ -62,7 +62,7 @@ content of the messages in any way. See test example on how to use it.
# if defined (__UTYPE_OSX)
// issue#1836
#include <crt_externs.h>
#define environ (*_NSGetEnviron ())
#define environ (*_NSGetEnviron ())
# else
extern char **environ; // should be declared as a part of unistd.h, but fail in some targets in Travis
// declare it explicitly
Expand Down Expand Up @@ -195,7 +195,10 @@ arr_print (char**self) {
// ####### internal helpers for zproc #######

struct _zproc_t {
#if ! defined (__WINDOWS__)
#if defined (__WINDOWS__)
PROCESS_INFORMATION piProcInfo;
STARTUPINFO siStartInfo;
#else
//TODO: there is no windows port, so lets exclude pid from struct
// zproc wasn't ported there, so no reason to do so
pid_t pid;
Expand All @@ -222,10 +225,7 @@ struct _zproc_t {
zproc_t*
zproc_new ()
{
#if defined (__WINDOWS__)
zsys_error ("zproc_set_stdin not implemented for Windows");
return NULL;
#elif ZMQ_VERSION_MAJOR < 4
#if ZMQ_VERSION_MAJOR < 4
zsys_error ("Cannot use zproc with zmq older than 4");
return NULL;
#endif
Expand Down Expand Up @@ -689,6 +689,9 @@ zproc_run (zproc_t *self)
int
zproc_wait (zproc_t *self, bool wait) {
#if defined (__WINDOWS__)
if (self->piProcInfo.hProcess == 0)
return 0;

zsys_error ("zproc not yet implemented for Windows");
return -1;
#else
Expand Down Expand Up @@ -780,7 +783,7 @@ zproc_set_verbose (zproc_t *self, bool verbose) {

// --------------------------------------------------------------------------
// Returns CZMQ version as a single 6-digit integer encoding the major
// version (x 10000), the minor version (x 100) and the patch.
// version (x 10000), the minor version (x 100) and the patch.

int
zproc_czmq_version (void)
Expand All @@ -792,7 +795,7 @@ zproc_czmq_version (void)
// --------------------------------------------------------------------------
// Returns true if the process received a SIGINT or SIGTERM signal.
// It is good practice to use this method to exit any infinite loop
// processing messages.
// processing messages.

bool
zproc_interrupted (void)
Expand Down Expand Up @@ -823,12 +826,12 @@ zproc_hostname (void)


// --------------------------------------------------------------------------
// Move the current process into the background. The precise effect
// Move the current process into the background. The precise effect
// depends on the operating system. On POSIX boxes, moves to a specified
// working directory (if specified), closes all file handles, reopens
// working directory (if specified), closes all file handles, reopens
// stdin, stdout, and stderr to the null device, and sets the process to
// ignore SIGHUP. On Windows, does nothing. Returns 0 if OK, -1 if there
// was an error.
// was an error.

void
zproc_daemonize (const char *workdir)
Expand All @@ -838,12 +841,12 @@ zproc_daemonize (const char *workdir)


// --------------------------------------------------------------------------
// Drop the process ID into the lockfile, with exclusive lock, and
// switch the process to the specified group and/or user. Any of the
// arguments may be null, indicating a no-op. Returns 0 on success,
// -1 on failure. Note if you combine this with zsys_daemonize, run
// Drop the process ID into the lockfile, with exclusive lock, and
// switch the process to the specified group and/or user. Any of the
// arguments may be null, indicating a no-op. Returns 0 on success,
// -1 on failure. Note if you combine this with zsys_daemonize, run
// after, not before that method, or the lockfile will hold the wrong
// process ID.
// process ID.

void
zproc_run_as (const char *lockfile, const char *group, const char *user)
Expand All @@ -853,11 +856,11 @@ zproc_run_as (const char *lockfile, const char *group, const char *user)


// --------------------------------------------------------------------------
// Configure the number of I/O threads that ZeroMQ will use. A good
// rule of thumb is one thread per gigabit of traffic in or out. The
// Configure the number of I/O threads that ZeroMQ will use. A good
// rule of thumb is one thread per gigabit of traffic in or out. The
// default is 1, sufficient for most applications. If the environment
// variable ZSYS_IO_THREADS is defined, that provides the default.
// Note that this method is valid only before any socket is created.
// variable ZSYS_IO_THREADS is defined, that provides the default.
// Note that this method is valid only before any socket is created.

void
zproc_set_io_threads (size_t io_threads)
Expand All @@ -867,10 +870,10 @@ zproc_set_io_threads (size_t io_threads)


// --------------------------------------------------------------------------
// Configure the number of sockets that ZeroMQ will allow. The default
// Configure the number of sockets that ZeroMQ will allow. The default
// is 1024. The actual limit depends on the system, and you can query it
// by using zsys_socket_limit (). A value of zero means "maximum".
// Note that this method is valid only before any socket is created.
// by using zsys_socket_limit (). A value of zero means "maximum".
// Note that this method is valid only before any socket is created.

void
zproc_set_max_sockets (size_t max_sockets)
Expand All @@ -880,12 +883,12 @@ zproc_set_max_sockets (size_t max_sockets)


// --------------------------------------------------------------------------
// Set network interface name to use for broadcasts, particularly zbeacon.
// Set network interface name to use for broadcasts, particularly zbeacon.
// This lets the interface be configured for test environments where required.
// For example, on Mac OS X, zbeacon cannot bind to 255.255.255.255 which is
// the default when there is no specified interface. If the environment
// variable ZSYS_INTERFACE is set, use that as the default interface name.
// Setting the interface to "*" means "use all available interfaces".
// For example, on Mac OS X, zbeacon cannot bind to 255.255.255.255 which is
// the default when there is no specified interface. If the environment
// variable ZSYS_INTERFACE is set, use that as the default interface name.
// Setting the interface to "*" means "use all available interfaces".

void
zproc_set_biface (const char *value)
Expand All @@ -906,8 +909,8 @@ zproc_biface (void)

// --------------------------------------------------------------------------
// Set log identity, which is a string that prefixes all log messages sent
// by this process. The log identity defaults to the environment variable
// ZSYS_LOGIDENT, if that is set.
// by this process. The log identity defaults to the environment variable
// ZSYS_LOGIDENT, if that is set.

void
zproc_set_log_ident (const char *value)
Expand All @@ -917,13 +920,13 @@ zproc_set_log_ident (const char *value)


// --------------------------------------------------------------------------
// Sends log output to a PUB socket bound to the specified endpoint. To
// collect such log output, create a SUB socket, subscribe to the traffic
// you care about, and connect to the endpoint. Log traffic is sent as a
// single string frame, in the same format as when sent to stdout. The
// Sends log output to a PUB socket bound to the specified endpoint. To
// collect such log output, create a SUB socket, subscribe to the traffic
// you care about, and connect to the endpoint. Log traffic is sent as a
// single string frame, in the same format as when sent to stdout. The
// log system supports a single sender; multiple calls to this method will
// bind the same sender to multiple endpoints. To disable the sender, call
// this method with a null argument.
// this method with a null argument.

void
zproc_set_log_sender (const char *endpoint)
Expand All @@ -934,7 +937,7 @@ zproc_set_log_sender (const char *endpoint)

// --------------------------------------------------------------------------
// Enable or disable logging to the system facility (syslog on POSIX boxes,
// event log on Windows). By default this is disabled.
// event log on Windows). By default this is disabled.

void
zproc_set_log_system (bool logsystem)
Expand Down Expand Up @@ -1027,7 +1030,13 @@ zproc_test (bool verbose)
printf (" * zproc: ");

#if defined (__WINDOWS__)
printf ("SKIPPED (on Windows)\n");
printf ("Very limited (on Windows) ");
{
zproc_t *self = zproc_new ();
assert (self);
zproc_destroy (&self);
}
printf ("OK\n");
return;
#endif
#if ZMQ_VERSION_MAJOR < 4
Expand Down