diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c --- a/contrib/chg/chg.c +++ b/contrib/chg/chg.c @@ -374,8 +374,7 @@ static int runinstructions(struct cmdser /* * Test whether the command is unsupported or not. This is not designed to - * cover all cases. But it's fast, does not depend on the server and does - * not return false positives. + * cover all cases. But it's fast, does not depend on the server. */ static int isunsupported(int argc, const char *argv[]) { @@ -388,7 +387,12 @@ static int isunsupported(int argc, const for (i = 0; i < argc; ++i) { if (strcmp(argv[i], "--") == 0) break; - if (i == 0 && strcmp("serve", argv[i]) == 0) + /* + * there can be false positives but no false negative + * we cannot assume `serve` will always be first argument + * because global options can be passed before the command name + */ + if (strcmp("serve", argv[i]) == 0) state |= SERVE; else if (strcmp("-d", argv[i]) == 0 || strcmp("--daemon", argv[i]) == 0)