From c0e56edaf256adb6c60c5a052525a1ffbb927901 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 8 Oct 2012 00:02:30 -0500 Subject: New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate. --- toys/other/login.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'toys/other/login.c') diff --git a/toys/other/login.c b/toys/other/login.c index 8c542a7e..a9e7562c 100644 --- a/toys/other/login.c +++ b/toys/other/login.c @@ -21,6 +21,7 @@ config LOGIN -f Do not perform authentication */ +#define FOR_login #include "toys.h" #define LOGIN_TIMEOUT 60 @@ -28,10 +29,9 @@ config LOGIN #define USER_NAME_MAX_SIZE 32 #define HOSTNAME_SIZE 32 -DEFINE_GLOBALS( +GLOBALS( char *hostname; ) -#define TT this.login static void login_timeout_handler(int sig __attribute__((unused))) { @@ -162,9 +162,8 @@ void setup_environment(const struct passwd *pwd, int clear_env) void login_main(void) { - int f_flag = (toys.optflags & 4) >> 2; - int p_flag = (toys.optflags & 2) >> 1; - int h_flag = toys.optflags & 1; + int f_flag = toys.optflags & FLAG_f; + int h_flag = toys.optflags & FLAG_h; char username[USER_NAME_MAX_SIZE+1], *pass = NULL, **ss; struct passwd * pwd = NULL; struct spwd * spwd = NULL; @@ -215,7 +214,7 @@ query_pass: f_flag = 0; syslog(LOG_WARNING, "invalid password for '%s' on %s %s %s", username, - ttyname(0), (h_flag)?"from":"", (h_flag)?TT.hostname:""); + ttyname(0), h_flag?"from":"", h_flag?TT.hostname:""); sleep(LOGIN_FAIL_TIMEOUT); puts("Login incorrect"); @@ -234,12 +233,12 @@ query_pass: if (change_identity(pwd)) error_exit("Failed to change identity"); - setup_environment(pwd, !p_flag); + setup_environment(pwd, !(toys.optflags & FLAG_p)); handle_motd(); syslog(LOG_INFO, "%s logged in on %s %s %s", pwd->pw_name, - ttyname(0), (h_flag)?"from":"", (h_flag)?TT.hostname:""); + ttyname(0), h_flag?"from":"", h_flag?TT.hostname:""); spawn_shell(pwd->pw_shell); } -- cgit v1.2.3