From a2feaa01caae42b396923e734f101fc1566e3bb5 Mon Sep 17 00:00:00 2001 From: Jianhui Zhao Date: Fri, 12 Jan 2018 14:48:06 +0800 Subject: [PATCH] Check whether there is a login program Signed-off-by: Jianhui Zhao --- src/main.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main.c b/src/main.c index 06562a7..2a3330d 100755 --- a/src/main.c +++ b/src/main.c @@ -41,6 +41,7 @@ struct uwsc_client *cl; static char buf[4096 * 10]; static struct blob_buf b; static char mac[13]; +static char login[128]; LIST_HEAD(tty_sessions); @@ -211,6 +212,22 @@ static void uwsc_onclose(struct uwsc_client *cl) uloop_end(); } +static int find_login() +{ + FILE *fp = popen("which login", "r"); + if (fp) { + if (fgets(login, sizeof(login), fp)) + login[strlen(login) - 1] = 0; + pclose(fp); + + if (!login[0]) + return -1; + return 0; + } + + return -1; +} + static void usage(const char *prog) { fprintf(stderr, "Usage: %s [option]\n" @@ -235,6 +252,13 @@ int main(int argc, char **argv) return -1; } + if (find_login() < 0) { + fprintf(stderr, "The program 'login' is not found\n"); + return -1; + } + + printf("[%s]\n", login); + while ((opt = getopt(argc, argv, "i:h:p:")) != -1) { switch (opt) {