Subject: sushi(8) and environment vars
To: None <tech-userlevel@netbsd.org>
From: Peter Postma <peter.postma@chello.nl>
List: tech-userlevel
Date: 02/26/2004 15:51:02
--LZvS9be/3tNcYl/X
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Hello,
I've made a patch for sushi(8) for setting environment variables at startup.
This might be useful when a user needs a different terminal type.
I noticed that PuTTY needs TERM=rxvt to display everything correct and to get
the key's working, with this patch you can set it from the config file:
% cat /etc/sushi.conf
env TERM rxvt
This variable is only valid during the sushi session.
The patch also fixes the searchpaths when the config file does not contain any.
--
Peter Postma
--LZvS9be/3tNcYl/X
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="sushi-env.diff"
Index: sushi.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/sushi/sushi.c,v
retrieving revision 1.16
diff -u -r1.16 sushi.c
--- sushi.c 12 Nov 2003 13:31:08 -0000 1.16
+++ sushi.c 26 Feb 2004 14:32:31 -0000
@@ -80,6 +80,8 @@
int i;
MTREE_ENTRY *mte = NULL;
+ parse_config();
+
catalog = catopen("sushi", 0);
if (getenv("LANG") == NULL)
lang_id = NULL;
@@ -98,7 +100,6 @@
initCDKColor();
raw();
- parse_config();
tree_init();
i = 0;
for (p = searchpaths[i]; p != NULL; i++) {
@@ -171,23 +172,10 @@
size_t len;
int i, j;
char *p, *t, *word;
- char *key;
+ char *key, *env;
char **n;
- conf = fopen("/etc/sushi.conf", "r");
- if (conf == NULL) {
- searchpaths = (char **)malloc(sizeof(char *) * 6);
- if (searchpaths == NULL)
- bailout("malloc: %s", strerror(errno));
- searchpaths[0] = "/usr/share/sushi";
- searchpaths[1] = "/usr/pkg/share/sushi";
- searchpaths[2] = "/usr/X11R6/share/sushi";
- searchpaths[3] = "/etc/sushi";
- i = 4;
- } else {
- searchpaths = (char **)malloc(sizeof(char *));
- if (searchpaths == NULL)
- bailout("malloc: %s", strerror(errno));
+ if ((conf = fopen("/etc/sushi.conf", "r")) != NULL) {
i = 0;
while ((p = fgetln(conf, &len))) {
if (len == 1 || p[len - 1] == '#' || p[len - 1] != '\n')
@@ -208,12 +196,12 @@
n = (char **)realloc(searchpaths,
sizeof(char *) * (i + 2));
if (n == NULL)
- bailout("malloc: %s", strerror(errno));
+ err(1, "realloc");
searchpaths = n;
searchpaths[i] = (char *)malloc(sizeof(char)
* len + 1);
if (searchpaths[i] == NULL)
- bailout("malloc: %s", strerror(errno));
+ err(1, "malloc");
searchpaths[i] = strdup(word);
for (j = 0; j < len; j++)
if (searchpaths[i][j] == '\n' ||
@@ -231,15 +219,33 @@
/* now get the string */
word = next_word(&p);
keylabel[j] = strdup(word);
+ } else if (strcmp(key, "env") == 0) {
+ env = next_word(&p);
+ word = next_word(&p);
+ if (strcmp(word, "") == 0)
+ errx(1, "Invalid env value");
+ setenv(env, word, 1);
} else {
- bailout("%s: %s", catgets(catalog, 1, 21,
+ errx(1, "%s: %s", catgets(catalog, 1, 21,
"Bad keyword in config file"), key);
}
} /* while */
}
+
+ if (searchpaths == NULL) {
+ searchpaths = (char **)malloc(sizeof(char *) * 6);
+ if (searchpaths == NULL)
+ err(1, "malloc");
+ searchpaths[0] = "/usr/share/sushi";
+ searchpaths[1] = "/usr/pkg/share/sushi";
+ searchpaths[2] = "/usr/X11R6/share/sushi";
+ searchpaths[3] = "/etc/sushi";
+ i = 4;
+ }
+
searchpaths[i] = (char *)malloc(sizeof(char) * PATH_MAX);
if (searchpaths[i] == NULL)
- bailout("malloc: %s", strerror(errno));
+ err(1, "malloc");
if (getenv("HOME") != NULL) {
strlcpy(searchpaths[i], getenv("HOME"), PATH_MAX);
strlcat(searchpaths[i], "/sushi", PATH_MAX);
--LZvS9be/3tNcYl/X--