• R/O
  • SSH
  • HTTPS

yash: Commit


Commit MetaInfo

Revision4015 (tree)
Time2020-04-17 23:56:07
Authormagicant

Log Message

Export correct value of $LINENO (#39279)

Change Summary

Incremental Difference

--- yash/trunk/NEWS (revision 4014)
+++ yash/trunk/NEWS (revision 4015)
@@ -15,6 +15,8 @@
1515 and exited.
1616 * Line-editing no longer hangs when the terminfo database maps a
1717 key to an empty string.
18+ * When $LINENO is exported, external commands now receive the
19+ correct value of the variable.
1820 . Updated the sample initialization script (yashrc):
1921 + A wrapper function for the "crontab" command is now installed
2022 to prevent accidental removal by "crontab -r" where the user
--- yash/trunk/exec.c (revision 4014)
+++ yash/trunk/exec.c (revision 4015)
@@ -796,7 +796,7 @@
796796 char *argv0 = NULL;
797797 pid_t cpid = 0;
798798
799- current_lineno = c->c_lineno;
799+ update_lineno(c->c_lineno);
800800
801801 finally_exit = (type == E_SELF);
802802 if (finally_exit) {
--- yash/trunk/variable.c (revision 4014)
+++ yash/trunk/variable.c (revision 4015)
@@ -1,6 +1,6 @@
11 /* Yash: yet another shell */
22 /* variable.c: deals with shell variables and parameters */
3-/* (C) 2007-2019 magicant */
3+/* (C) 2007-2020 magicant */
44
55 /* This program is free software: you can redistribute it and/or modify
66 * it under the terms of the GNU General Public License as published by
@@ -293,8 +293,8 @@
293293 v->v_value = NULL;
294294 v->v_getter = lineno_getter;
295295 // variable_set(VAR_LINENO, v);
296- if (v->v_type & VF_EXPORT)
297- update_environment(L VAR_LINENO);
296+ // if (v->v_type & VF_EXPORT)
297+ // update_environment(L VAR_LINENO);
298298 }
299299
300300 /* set $MAILCHECK */
@@ -1010,8 +1010,22 @@
10101010 /********** Getters **********/
10111011
10121012 /* line number of the currently executing command */
1013-unsigned long current_lineno;
1013+static unsigned long current_lineno;
10141014
1015+/* Sets `current_lineno' and re-exports $LINENO if it is exported. */
1016+void update_lineno(unsigned long lineno)
1017+{
1018+ current_lineno = lineno;
1019+
1020+ variable_T *var = search_variable(L VAR_LINENO);
1021+ if (var != NULL && var->v_getter == lineno_getter &&
1022+ (var->v_type & VF_EXPORT)) {
1023+ // Need to update the environment so the correct value is exported to
1024+ // external commands
1025+ lineno_getter(var);
1026+ }
1027+}
1028+
10151029 /* getter for $LINENO */
10161030 void lineno_getter(variable_T *var)
10171031 {
--- yash/trunk/variable.h (revision 4014)
+++ yash/trunk/variable.h (revision 4015)
@@ -1,6 +1,6 @@
11 /* Yash: yet another shell */
22 /* variable.h: deals with shell variables and parameters */
3-/* (C) 2007-2018 magicant */
3+/* (C) 2007-2020 magicant */
44
55 /* This program is free software: you can redistribute it and/or modify
66 * it under the terms of the GNU General Public License as published by
@@ -82,8 +82,6 @@
8282 PA_count,
8383 } path_T;
8484
85-extern unsigned long current_lineno;
86-
8785 extern void init_environment(void);
8886 extern void init_variables(void);
8987
@@ -124,6 +122,8 @@
124122 extern void open_new_environment(_Bool temp);
125123 extern void close_current_environment(void);
126124
125+extern void update_lineno(unsigned long lineno);
126+
127127 extern char **decompose_paths(const wchar_t *paths)
128128 __attribute__((malloc,warn_unused_result));
129129 extern char *const *get_path_array(path_T name);
Show on old repository browser