[hackers] [st] Add support for utmp in st || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Fri, 26 Sep 2014 09:48:29 +0200

commit 5afb3862ba368de8888c0c570098baababc7bc19
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
Date: Thu Aug 28 12:48:29 2014 +0200

    Add support for utmp in st
    
    St runs an interactive shell and not a login shell, and it means
    that profile is not loaded. The default terminal configuration
    in some system is not the correct for st, but since profile is
    not loaded there is no way of getting a script configures the
    correct values.
    
    St doesn't update the utmp files, this is the job of another
    suckless tool, utmp. Utmp also opens a login shell (it is the
    logical behaviour when you create a new user record) it is a
    good option execute utmp and then get a correct input in
    utmp, wtmp and lastlog file, and execute the content of the
    profile.

diff --git a/config.def.h b/config.def.h
index fe81078..cc16f97 100644
--- a/config.def.h
+++ b/config.def.h
_AT_@ -8,6 +8,7 @@
 static char font[] = "Liberation Mono:pixelsize=12:antialias=false:autohint=false";
 static int borderpx = 2;
 static char shell[] = "/bin/sh";
+static char *utmp = NULL;
 
 /* identification sequence returned in DA and DECID */
 static char vtiden[] = "\033[?6c";
diff --git a/st.c b/st.c
index dd3301b..ab3fa6e 100644
--- a/st.c
+++ b/st.c
_AT_@ -1153,16 +1153,22 @@ execsh(void) {
                 else
                         die("who are you?\n");
         }
- unsetenv("COLUMNS");
- unsetenv("LINES");
- unsetenv("TERMCAP");
 
- sh = (pw->pw_shell[0]) ? pw->pw_shell : shell;
+ if (utmp)
+ sh = utmp;
+ else if (pw->pw_shell[0])
+ sh = pw->pw_shell;
+ else
+ sh = shell;
+ args = (opt_cmd) ? opt_cmd : (char *[]){sh, NULL};
         snprintf(buf, sizeof(buf), "%lu", xw.win);
 
+ unsetenv("COLUMNS");
+ unsetenv("LINES");
+ unsetenv("TERMCAP");
         setenv("LOGNAME", pw->pw_name, 1);
         setenv("USER", pw->pw_name, 1);
- setenv("SHELL", sh, 1);
+ setenv("SHELL", args[0], 1);
         setenv("HOME", pw->pw_dir, 1);
         setenv("TERM", termname, 1);
         setenv("WINDOWID", buf, 1);
_AT_@ -1174,7 +1180,6 @@ execsh(void) {
         signal(SIGTERM, SIG_DFL);
         signal(SIGALRM, SIG_DFL);
 
- args = opt_cmd ? opt_cmd : (char *[]){sh, "-i", NULL};
         execvp(args[0], args);
         exit(EXIT_FAILURE);
 }
Received on Fri Sep 26 2014 - 09:48:29 CEST

This archive was generated by hypermail 2.3.0 : Fri Sep 26 2014 - 10:00:13 CEST