[zeromq-dev] [czmq] API design of zproc_run

Luca Boccassi luca.boccassi at gmail.com
Sun Mar 19 19:51:22 CET 2017


On Sun, 2017-03-19 at 10:07 +0100, Michal Vyskocil wrote:
> Hi,
> 
> I have finished a first draft of zproc class for czmq. It should
> provide
> nice and easy to use API to execute and communicate with subcommands.
> I was
> inspired by Python https://docs.python.org/3/library/subprocess.html
> module. zproc use zeromq sockets to pass data in or from the
> subprocess.
> That means that the concept of unix pipes now runs through any libzmq
> transport well :)
> 
> Right now it works for libzmq4 and Linux and OSX.
> I tried to make API simple and easy to use and to provide zproject
> API
> model from start. The problem is zproc_run. Right now I simply copy
> execve
> from unix, so the prototype look this way.
> 
> int zproc_run (zproc_t *self, const char *filename, char *const
> argv[], char *const envp[])
> 
> 
> 
> There are three problems
> 
>    1. Incompatible with API model
>    2. Does not look really nice to me
>    3. argv [0] is different from filename, so developer must not
> forget to
>    pass at least something as argv.
> 
> 
> 
> Given my knowledge of czmq API, I'd say the best way to go is to
> 
> //  Adds an argument to process command line
> void zproc_arg (zproc_t *self, const char *format, ...);
> 
> //   Adds an enviroment variable for a process
> void zproc_env (zproc_t *self, const char *key, const char *format,
> ...);
> 
> // Execute the subprocess, return -1 if execution fails
> int zproc_run ();
> 
> 
> So the sample usage would be
> 
> 
> zproc_t *cat = zproc_new ();
> zproc_arg (self, "%s", "cat");              // Note that filename and
> argv[0] are two distincs things
> zproc_arg (self, "%s", "-A");
> zproc_arg (self, "%s", "/etc/passwd");
> 
> zproc_env (self, "LC_ALL", "%s", "C");
> zproc_run ();
> 
> 
> However I am not convinced if this is the best API ever. And I still
> did
> not solved argv[0] problem. Are there any ideas for better API?

Looks fine to me! I would recommend having sensible default values when
possible.

Could you expand a bit more on the argv[0] issue?

Kind regards,
Luca Boccassi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: This is a digitally signed message part
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20170319/7b92a9a9/attachment.sig>


More information about the zeromq-dev mailing list