Skip to content

Commit

Permalink
Check whether there is a login program
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <[email protected]>
  • Loading branch information
Jianhui Zhao committed Jan 12, 2018
1 parent a58ccc3 commit a2feaa0
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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"
Expand All @@ -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)
{
Expand Down

0 comments on commit a2feaa0

Please sign in to comment.