I suppose this is the least worst way to handle it.
OK
On Sun, Nov 24, 2019 at 10:03:57PM +0100, Klemens Nanni wrote:
> On Tue, Nov 19, 2019 at 03:53:16AM +0100, Florian Obser wrote:
> > I think the file doesn't exist but it's fine check is in the wrong
> > place. It's also stupid that it doesn't fatal(!) for unwind -f
> > nonexistent. I think this needs to be handled further up in main.
> > Maybe. I'll have a look if I don't forget.
> The errno check in parse_config() does indeed look misplaced and other
> parsers log fopen(3) failure directly in pushfile(), but it's not really
> bad either.
>
> Here's a simple diff for failing on missing failes iff `-f' is given.
>
> $ ./obj/unwind -f/nonexistent
> /nonexistent: No such file or directory
> $ ls /etc/unwind.conf
> ls: /etc/unwind.conf: No such file or directory
> $ doas ./obj/unwind -d
> startup
>
> Feedback? OK?
>
>
> Index: parse.y
> ===================================================================
> RCS file: /cvs/src/sbin/unwind/parse.y,v
> retrieving revision 1.15
> diff -u -p -r1.15 parse.y
> --- parse.y 9 Nov 2019 16:28:10 -0000 1.15
> +++ parse.y 24 Nov 2019 20:55:06 -0000
> @@ -776,7 +776,7 @@ popfile(void)
> }
>
> struct uw_conf *
> -parse_config(char *filename)
> +parse_config(char *filename, int require_file)
> {
> struct sym *sym, *next;
>
> @@ -784,7 +784,8 @@ parse_config(char *filename)
>
> file = pushfile(filename, 0);
> if (file == NULL) {
> - if (errno == ENOENT) /* no config file is fine */
> + /* no config file is fine */
> + if (errno == ENOENT && !require_file)
> return (conf);
> log_warn("%s", filename);
> free(conf);
> Index: unwind.c
> ===================================================================
> RCS file: /cvs/src/sbin/unwind/unwind.c,v
> retrieving revision 1.37
> diff -u -p -r1.37 unwind.c
> --- unwind.c 19 Nov 2019 14:46:33 -0000 1.37
> +++ unwind.c 24 Nov 2019 20:51:09 -0000
> @@ -77,7 +77,8 @@ struct uw_conf *main_conf;
> struct imsgev *iev_frontend;
> struct imsgev *iev_resolver;
> struct imsgev *iev_captiveportal;
> -char *conffile;
> +char *conffile = CONF_FILE;
> +int require_file;
>
> pid_t frontend_pid;
> pid_t resolver_pid;
> @@ -132,7 +133,6 @@ main(int argc, char *argv[])
> int control_fd, ta_fd;
> char *csock, *saved_argv0;
>
> - conffile = CONF_FILE;
> csock = UNWIND_SOCKET;
>
> log_init(1, LOG_DAEMON); /* Log to stderr until daemonized. */
> @@ -158,6 +158,7 @@ main(int argc, char *argv[])
> break;
> case 'f':
> conffile = optarg;
> + require_file = 1;
> break;
> case 'n':
> cmd_opts |= OPT_NOACTION;
> @@ -187,7 +188,7 @@ main(int argc, char *argv[])
> else if (captiveportal_flag)
> captiveportal(debug, cmd_opts & (OPT_VERBOSE | OPT_VERBOSE2));
>
> - if ((main_conf = parse_config(conffile)) == NULL)
> + if ((main_conf = parse_config(conffile, require_file)) == NULL)
> exit(1);
>
> if (cmd_opts & OPT_NOACTION) {
> @@ -691,7 +692,7 @@ main_reload(void)
> {
> struct uw_conf *xconf;
>
> - if ((xconf = parse_config(conffile)) == NULL)
> + if ((xconf = parse_config(conffile, require_file)) == NULL)
> return (-1);
>
> if (main_imsg_send_config(xconf) == -1)
> Index: unwind.h
> ===================================================================
> RCS file: /cvs/src/sbin/unwind/unwind.h,v
> retrieving revision 1.33
> diff -u -p -r1.33 unwind.h
> --- unwind.h 22 Nov 2019 15:31:25 -0000 1.33
> +++ unwind.h 24 Nov 2019 20:45:51 -0000
> @@ -176,5 +176,5 @@ void config_clear(struct uw_conf *);
> void print_config(struct uw_conf *);
>
> /* parse.y */
> -struct uw_conf *parse_config(char *);
> +struct uw_conf *parse_config(char *, int);
> int cmdline_symset(char *);
>
--
I'm not entirely sure you are real.