mirror of
https://github.com/zhaojh329/rtty.git
synced 2026-02-27 09:53:17 +08:00
Check whether there is a login program
Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
This commit is contained in:
+24
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user