[PATCH weston, v2] weston-terminal: Add cwd and command options
ahmet acar
oavc-fujie at yandex.com
Wed Sep 23 09:45:41 PDT 2015
Add 'cwd' (current working directory) and 'command' (run specified
command immediately after startup) to weston-terminal.
v2:
-improve commit title and description
-remove unneeded 'Changes from' thing
-use weston_config_section_get_string() instead off
-follow wayland coding style guidelines
-use fprintf () to be consistent the rest of code
-give a more descriptive error messages
NOTE: i didn't replace strcat with strncat or snprintf.
Because i tested it both with weston.ini and cmdline switch.
simply, it works, So it is safe here? But i agree with you in general.
i am thinking of its security implications.But no catch anythings yet.
clients/terminal.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/clients/terminal.c b/clients/terminal.c
index 7406f50..39016b0 100644
--- a/clients/terminal.c
+++ b/clients/terminal.c
@@ -52,6 +52,8 @@ static char *option_font;
static int option_font_size;
static char *option_term;
static char *option_shell;
+static char *option_cwd;
+static char *option_command;
static struct wl_list terminal_list;
@@ -3047,6 +3049,13 @@ terminal_run(struct terminal *terminal, const char *path)
else
terminal_resize(terminal, 80, 24);
+ if (option_command) {
+ strcat(option_command, "\n");
+ if (write(master, option_command, strlen(option_command)) == -1)
+ fprintf(stderr, "'startup command' (%s) couldn't executed: %m",
+ option_command);
+ }
+
return 0;
}
@@ -3055,6 +3064,8 @@ static const struct weston_option terminal_options[] = {
{ WESTON_OPTION_STRING, "font", 0, &option_font },
{ WESTON_OPTION_INTEGER, "font-size", 0, &option_font_size },
{ WESTON_OPTION_STRING, "shell", 0, &option_shell },
+ { WESTON_OPTION_STRING, "cwd", 0, &option_cwd },
+ { WESTON_OPTION_STRING, "command", 0, &option_command },
};
int main(int argc, char *argv[])
@@ -3079,6 +3090,7 @@ int main(int argc, char *argv[])
weston_config_section_get_string(s, "font", &option_font, "mono");
weston_config_section_get_int(s, "font-size", &option_font_size, 14);
weston_config_section_get_string(s, "term", &option_term, "xterm");
+ weston_config_section_get_string(s, "command", &option_command, NULL);
weston_config_destroy(config);
if (parse_options(terminal_options,
@@ -3087,7 +3099,9 @@ int main(int argc, char *argv[])
" --fullscreen or -f\n"
" --font=NAME\n"
" --font-size=SIZE\n"
- " --shell=NAME\n", argv[0]);
+ " --shell=NAME\n"
+ " --cwd=PATH\n"
+ " --command=CMDLINE\n", argv[0]);
return 1;
}
@@ -3099,6 +3113,12 @@ int main(int argc, char *argv[])
wl_list_init(&terminal_list);
terminal = terminal_create(d);
+
+ if (option_cwd) {
+ if(chdir(option_cwd) == -1)
+ fprintf(stderr, "failed to changing directory as %s: %m\n",
+ option_cwd);
+ }
+
if (terminal_run(terminal, option_shell))
exit(EXIT_FAILURE);
More information about the wayland-devel
mailing list