commit - 02f3bb77b3b9ba6d37db0410efee7bbaf3b6838e
commit + d8687dc93b75d4f78fa69863360a92295852ac0f
blob - 4cce31d0d8784c6f9d64047773cce4c730f8db6d
blob + 00820a53c513998384af2849c1311c660ceeef6f
--- gotsys/gotsys.1
+++ gotsys/gotsys.1
.Pa /git/gotsys.git
will be used.
.El
-.It Cm check Oo Fl q Oc Oo Ar file Oc
+.It Cm check Oo Fl q Oc Oo Fl f Ar file Oc
Read a
.Xr gotsys.conf 5
configuration
.Cm gotsys check
are as follows:
.Bl -tag -width Ds
+.It Fl f Ar file
+The path to the configuration
+.Ar file
+to read.
+A hyphen
+.Pq -
+can be used to read standard input:
+.Cm gotsys check -f -
.It Fl q
Stay silent on standard output.
Only report errors.
blob - b68016a33e6553f16f8997cbd3487c9348d10252
blob + e34190c73c19bf0cca2f7bc7a680a3985af5fc9d
--- gotsys/gotsys.c
+++ gotsys/gotsys.c
__dead static void
usage_check(void)
{
- fprintf(stderr, "usage: %s check [-q] [file]\n", getprogname());
+ fprintf(stderr, "usage: %s check [-q] [-f file]\n", getprogname());
exit(1);
}
static const struct got_error *
+unveil_none(void)
+{
+ if (unveil("/", "") != 0)
+ return got_error_from_errno("unveil");
+
+ if (unveil(NULL, NULL) != 0)
+ return got_error_from_errno("unveil");
+
+ return NULL;
+}
+
+static const struct got_error *
unveil_conf(const char *config_file)
{
#ifdef PROFILE
{
const struct got_error *err;
int ch, fd = -1, quiet = 0;
- const char *configfile;
+ char *configfile = NULL;
struct gotsys_conf gotsysconf;
struct stat sb;
case 'q':
quiet = 1;
break;
+ case 'f':
+ if (strcmp(optarg, "-") == 0) {
+ fd = STDIN_FILENO;
+ configfile = strdup("stdin");
+ if (configfile == NULL)
+ return got_error_from_errno("strdup");
+ break;
+ }
+ configfile = realpath(optarg, NULL);
+ if (configfile == NULL) {
+ return got_error_from_errno2("realpath",
+ optarg);
+ }
+ got_path_strip_trailing_slashes(configfile);
+ break;
default:
usage_check();
/* NOTREACHED */
argc -= optind;
argv += optind;
- if (argc > 1)
+ if (argc > 0)
usage_check();
- configfile = (argc == 1 ? argv[0] : GOTSYSD_SYSCONF_FILENAME);
+ if (fd != STDIN_FILENO && configfile == NULL) {
+ configfile = strdup(GOTSYSD_SYSCONF_FILENAME);
+ if (configfile == NULL)
+ return got_error_from_errno("strdup");
+ }
#ifndef PROFILE
if (pledge("stdio rpath unveil", NULL) == -1) {
goto done;
}
#endif
- err = unveil_conf(configfile);
- if (err)
- return err;
+ if (fd == STDIN_FILENO) {
+ err = unveil_none();
+ if (err)
+ goto done;
+ } else {
+ err = unveil_conf(configfile);
+ if (err)
+ goto done;
- fd = open(configfile, O_RDONLY);
- if (fd == -1)
- return got_error_from_errno2("open", configfile);
+ fd = open(configfile, O_RDONLY);
+ if (fd == -1) {
+ err = got_error_from_errno2("open", configfile);
+ goto done;
+ }
+ }
#ifndef PROFILE
if (pledge("stdio", NULL) == -1) {
goto done;
}
#endif
-
- if (fstat(fd, &sb) == -1) {
- err = got_error_from_errno2("fstat", configfile);
- goto done;
+ if (fd != STDIN_FILENO) {
+ if (fstat(fd, &sb) == -1) {
+ err = got_error_from_errno2("fstat", configfile);
+ goto done;
+ }
+ if (!S_ISREG(sb.st_mode)) {
+ err = got_error_fmt(GOT_ERR_BAD_PATH,
+ "%s is not a regular file", configfile);
+ goto done;
+ }
}
- if (!S_ISREG(sb.st_mode)) {
- err = got_error_fmt(GOT_ERR_BAD_PATH,
- "%s is not a regular file", configfile);
- goto done;
- }
err = gotsys_conf_parse(configfile, &gotsysconf, &fd);
if (err)
if (!quiet)
printf("configuration OK\n");
done:
- if (fd != -1 && close(fd) == -1 && err == NULL)
+ if (fd != -1 && fd != STDIN_FILENO && close(fd) == -1 && err == NULL)
err = got_error_from_errno2("close", configfile);
+ free(configfile);
return err;
}
blob - b670e5bee998649e54afac2f9b831ffdd87d57b4
blob + 0179f72316c7d4f18967447b61697e71f36ca6d8
--- regress/gotsysd/test_gotsysd.sh
+++ regress/gotsysd/test_gotsysd.sh
permit rw anonymous
}
EOF
- gotsys check ${testroot}/bad-gotsys.conf \
+ gotsys check -f ${testroot}/bad-gotsys.conf \
> $testroot/stdout 2> $testroot/stderr
ret=$?
if [ $ret -eq 0 ]; then