]> www.infradead.org Git - users/borneoa/openocd-next.git/commitdiff
helper/options: handle errors in `-l`
authorEvgeniy Naydanov <evgeniy.naydanov@syntacore.com>
Tue, 17 Dec 2024 15:13:00 +0000 (18:13 +0300)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sat, 25 Jan 2025 10:34:15 +0000 (10:34 +0000)
Before the patch an error in opening the log file (e.g. can't write a
file) was ignored when specified via `-l`.
E.g.:
```
> touch log
> chmod -w log
> openocd -l log -c shutdown
...
failed to open output log "log"
shutdown command invoked
> echo $?
0
```

After the patch:
```
...
> openocd -l log -c shutdown
...
failed to open output log "log"
> echo $?
1
```

Change-Id: Ibab45f580dc46a499bf967c4afad071f9c2972a2
Signed-off-by: Evgeniy Naydanov <evgeniy.naydanov@syntacore.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8666
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
src/helper/options.c

index 9e332cc8ce572338479c3e9b0191c830b5b43ee1..50977a61060a589a43eb232a95677c1fb4596eaf 100644 (file)
@@ -303,8 +303,12 @@ int parse_cmdline_args(struct command_context *cmd_ctx, int argc, char *argv[])
                                break;
                        }
                        case 'l':               /* --log_output | -l */
-                               command_run_linef(cmd_ctx, "log_output %s", optarg);
+                       {
+                               int retval = command_run_linef(cmd_ctx, "log_output %s", optarg);
+                               if (retval != ERROR_OK)
+                                       return retval;
                                break;
+                       }
                        case 'c':               /* --command | -c */
                                add_config_command(optarg);
                                break;