@@ -47,12 +47,38 @@ static int (*real___libc_current_sigrtmin)(void) = NULL;
47
47
48
48
static char * watchfile = "/tmp/vars" ;
49
49
50
+ /* The following definitions are stolen from bash-4.2 */
51
+ __attribute__((weak ))
52
+ extern int do_assignment_no_expand (char * );
53
+ __attribute__((weak ))
54
+ extern void set_var_attribute (char * , int , int );
55
+ #define att_exported 1
56
+
50
57
int
51
58
__libc_current_sigrtmin (void )
52
59
{
53
60
return real___libc_current_sigrtmin () + 1 ;
54
61
}
55
62
63
+ static void
64
+ enviable_setenv (char * line )
65
+ {
66
+ char * eq = strchr (line , '=' );
67
+ if (do_assignment_no_expand && set_var_attribute ) {
68
+ /* We're running inside bash. Since bash maintains its
69
+ * own idea of the environment (shell variables marked
70
+ * exported), we need to go through that for child
71
+ * processes to see changes. */
72
+ do_assignment_no_expand (line );
73
+ * eq = '\0' ;
74
+ set_var_attribute (line , att_exported , 0 );
75
+ } else {
76
+ /* Unknown host process -- fall back to libc. */
77
+ * eq = '\0' ;
78
+ setenv (line , eq + 1 , 1 );
79
+ }
80
+ }
81
+
56
82
static void
57
83
enviable_callback (int signum , siginfo_t * si , void * context )
58
84
{
@@ -64,21 +90,19 @@ enviable_callback(int signum, siginfo_t *si, void *context)
64
90
if (!fd ) {
65
91
return ;
66
92
}
67
- char * buf = NULL ;
93
+ char * line = NULL ;
68
94
size_t n = 0 ;
69
95
ssize_t len ;
70
- while ((len = getline (& buf , & n , fd )) > 0 ) {
71
- if (buf [len - 1 ] == '\n' ) {
72
- buf [len - 1 ] = '\0' ;
96
+ while ((len = getline (& line , & n , fd )) > 0 ) {
97
+ if (line [len - 1 ] == '\n' ) {
98
+ line [len - 1 ] = '\0' ;
73
99
} else {
74
100
/* Conservatively reject partial lines. */
75
101
continue ;
76
102
}
77
- char * eq = strchr (buf , '=' );
78
- * eq = '\0' ;
79
- setenv (buf , eq + 1 , 1 );
103
+ enviable_setenv (line );
80
104
}
81
- free (buf );
105
+ free (line );
82
106
fclose (fd );
83
107
}
84
108
0 commit comments