Thread (10 messages) flat view 10 messages, 5 authors, 2017-08-16

Re: [PATCH] sub-process: print the cmd when a capability is unsupported

From: Lars Schneider <hidden>
Date: 2017-08-15 19:35:39

On 15 Aug 2017, at 21:29, Christian Couder [off-list ref] wrote:

On Tue, Aug 15, 2017 at 9:00 PM, Lars Schneider
[off-list ref] wrote:
quoted
quoted
On 15 Aug 2017, at 19:36, Christian Couder [off-list ref] wrote:

In handshake_capabilities() we use warning() when a capability
is not supported, so the exit code of the function is 0 and no
further error is shown. This is a problem because the warning
message doesn't tell us which subprocess cmd failed.

On the contrary if we cannot write a packet from this function,
we use error() and then subprocess_start() outputs:

  initialization for subprocess '<cmd>' failed

so we can know which subprocess cmd failed.

Let's improve the warning() message, so that we can know which
subprocess cmd failed.

Signed-off-by: Christian Couder <redacted>
---
sub-process.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/sub-process.c b/sub-process.c
index 6edb97c1c6..6b133f8dce 100644
--- a/sub-process.c
+++ b/sub-process.c
@@ -158,7 +158,8 @@ static int handshake_version(struct child_process *process,
static int handshake_capabilities(struct child_process *process,
                               struct subprocess_capability *capabilities,
-                               unsigned int *supported_capabilities)
+                               unsigned int *supported_capabilities,
+                               const char *cmd)
{
     int i;
     char *line;
@@ -184,8 +185,8 @@ static int handshake_capabilities(struct child_process *process,
                     if (supported_capabilities)
                             *supported_capabilities |= capabilities[i].flag;
             } else {
-                     warning("external filter requested unsupported filter capability '%s'",
-                             p);
+                     warning("subprocess '%s' requested unsupported capability '%s'",
+                             cmd, p);
Wouldn't it be possible to use "process->argv[0]"?
Shouldn't that be the same as "cmd"?
Well in sub-process.h there is:

/* Members should not be accessed directly. */
struct subprocess_entry {
   struct hashmap_entry ent; /* must be the first member! */
   const char *cmd;
   struct child_process process;
};

so if cmd is always the same as process->argv[0], maybe there is no
need for the cmd member in the first place?
The struct is a hash map entry. `cmd` is the key for a `process`.
Therefore, I think this is still necessary.

Does this make sense?

- Lars
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help