Skip to content
Snippets Groups Projects
Commit b4818ec5 authored by Eugine Blikh's avatar Eugine Blikh
Browse files

Add support for environmental variables

parent 6888ed25
No related branches found
No related tags found
No related merge requests found
...@@ -140,12 +140,12 @@ static void tc_validate(void) ...@@ -140,12 +140,12 @@ static void tc_validate(void)
tc.opt.raw = 1; tc.opt.raw = 1;
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[], char *envp[])
{ {
tc_init(); tc_init();
int rc = 0; int rc = 0;
enum tc_opt_mode mode = tc_opt_init(&tc.opt, argc, argv); enum tc_opt_mode mode = tc_opt_init(&tc.opt, argc, argv, envp);
tc_validate(); tc_validate();
switch (mode) { switch (mode) {
case TC_OPT_USAGE: case TC_OPT_USAGE:
......
...@@ -93,7 +93,7 @@ void tc_opt_version(void) ...@@ -93,7 +93,7 @@ void tc_opt_version(void)
exit(0); exit(0);
} }
enum tc_opt_mode tc_opt_init(struct tc_opt *opt, int argc, char **argv) enum tc_opt_mode tc_opt_init(struct tc_opt *opt, int argc, char **argv, char **envp)
{ {
/* usage */ /* usage */
void *tc_options = gopt_sort(&argc, (const char**)argv, tc_options_def); void *tc_options = gopt_sort(&argc, (const char**)argv, tc_options_def);
...@@ -197,6 +197,7 @@ enum tc_opt_mode tc_opt_init(struct tc_opt *opt, int argc, char **argv) ...@@ -197,6 +197,7 @@ enum tc_opt_mode tc_opt_init(struct tc_opt *opt, int argc, char **argv)
opt->mode = TC_OPT_INTERACTIVE; opt->mode = TC_OPT_INTERACTIVE;
} }
opt->pager = NULL; opt->pager = NULL;
opt->envp = envp;
done: done:
gopt_free(tc_options); gopt_free(tc_options);
return opt->mode; return opt->mode;
......
...@@ -63,6 +63,7 @@ struct tc_opt { ...@@ -63,6 +63,7 @@ struct tc_opt {
const char *file; const char *file;
char **cmdv; char **cmdv;
int cmdc; int cmdc;
char **envp;
const char *delim; const char *delim;
size_t delim_len; size_t delim_len;
const char *pager; const char *pager;
...@@ -72,6 +73,6 @@ void tc_opt_usage(void); ...@@ -72,6 +73,6 @@ void tc_opt_usage(void);
void tc_opt_version(void); void tc_opt_version(void);
enum tc_opt_mode enum tc_opt_mode
tc_opt_init(struct tc_opt *opt, int argc, char **argv); tc_opt_init(struct tc_opt *opt, int argc, char **argv, char **envp);
#endif /* TC_OPT_H_INCLUDED */ #endif /* TC_OPT_H_INCLUDED */
...@@ -20,11 +20,8 @@ void tc_pager_start() { ...@@ -20,11 +20,8 @@ void tc_pager_start() {
tc.pager_fd = fileno(stdout); tc.pager_fd = fileno(stdout);
return; return;
} }
char cmd[] = {"/bin/bash"};
char args[] = {"-c"};
int pipefd[2]; int pipefd[2];
const char *const argv[] = {cmd, args, tc.opt.pager, NULL}; const char *const argv[] = {"/bin/bash", "-c", tc.opt.pager, NULL};
if (pipe(pipefd) < 0) if (pipe(pipefd) < 0)
tc_error("Failed to open pipe. Errno: %d", errno); tc_error("Failed to open pipe. Errno: %d", errno);
...@@ -34,7 +31,7 @@ void tc_pager_start() { ...@@ -34,7 +31,7 @@ void tc_pager_start() {
if (pid == 0) { if (pid == 0) {
close(pipefd[1]); close(pipefd[1]);
dup2(pipefd[0], STDIN_FILENO); dup2(pipefd[0], STDIN_FILENO);
execve(argv[0], (char * const*)argv, NULL); execve(argv[0], (char * const*)argv, (char * const*)tc.opt.envp);
tc_error("Can't start pager! Errno: %d", errno); tc_error("Can't start pager! Errno: %d", errno);
} }
close(pipefd[0]); close(pipefd[0]);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment