mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-18 09:32:47 +08:00
Add warning when trying to change read-only variable
darcs-hash:20060410153626-ac50b-700ff7687647b8aab47ba79d759d1739cbe60425.gz
This commit is contained in:
parent
f812b9b26c
commit
bd9c843fd1
|
@ -26,6 +26,18 @@ Functions used for implementing the set builtin.
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "translate.h"
|
#include "translate.h"
|
||||||
|
|
||||||
|
static void my_env_set( wchar_t *key, wchar_t *val, int scope )
|
||||||
|
{
|
||||||
|
switch( env_set( key, val, scope | ENV_USER ) )
|
||||||
|
{
|
||||||
|
case ENV_PERM:
|
||||||
|
{
|
||||||
|
sb_printf( sb_err, _(L"%ls: Tried to change the read-only variable '%ls'\n"), L"set", key );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Extract the name from a destination argument of the form name[index1 index2...]
|
Extract the name from a destination argument of the form name[index1 index2...]
|
||||||
*/
|
*/
|
||||||
|
@ -512,7 +524,7 @@ int builtin_set( wchar_t **argv )
|
||||||
!erase &&
|
!erase &&
|
||||||
!list )
|
!list )
|
||||||
{
|
{
|
||||||
env_set( name, 0, scope );
|
my_env_set( name, 0, scope );
|
||||||
finished = 1;
|
finished = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -572,7 +584,7 @@ int builtin_set( wchar_t **argv )
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fill_buffer_from_list(&result_sb, &val_l);
|
fill_buffer_from_list(&result_sb, &val_l);
|
||||||
env_set(name, (wchar_t *) result_sb.buff, scope);
|
my_env_set(name, (wchar_t *) result_sb.buff, scope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -585,7 +597,7 @@ int builtin_set( wchar_t **argv )
|
||||||
fill_buffer_from_list( &result_sb,
|
fill_buffer_from_list( &result_sb,
|
||||||
&val_l );
|
&val_l );
|
||||||
|
|
||||||
env_set(name,
|
my_env_set(name,
|
||||||
(wchar_t *) result_sb.buff,
|
(wchar_t *) result_sb.buff,
|
||||||
scope);
|
scope);
|
||||||
}
|
}
|
||||||
|
|
11
env.c
11
env.c
|
@ -608,7 +608,7 @@ static env_node_t *env_get_node( const wchar_t *key )
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void env_set( const wchar_t *key,
|
int env_set( const wchar_t *key,
|
||||||
const wchar_t *val,
|
const wchar_t *val,
|
||||||
int var_mode )
|
int var_mode )
|
||||||
{
|
{
|
||||||
|
@ -626,7 +626,7 @@ void env_set( const wchar_t *key,
|
||||||
if( (var_mode & ENV_USER ) &&
|
if( (var_mode & ENV_USER ) &&
|
||||||
hash_get( &env_read_only, key ) )
|
hash_get( &env_read_only, key ) )
|
||||||
{
|
{
|
||||||
return;
|
return ENV_PERM;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( wcscmp( key, L"umask" ) == 0)
|
if( wcscmp( key, L"umask" ) == 0)
|
||||||
|
@ -650,7 +650,7 @@ void env_set( const wchar_t *key,
|
||||||
/*
|
/*
|
||||||
Do not actually create a umask variable, on env_get, it will be calculated dynamically
|
Do not actually create a umask variable, on env_get, it will be calculated dynamically
|
||||||
*/
|
*/
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -749,7 +749,7 @@ void env_set( const wchar_t *key,
|
||||||
node = top;
|
node = top;
|
||||||
while( node->next && !node->new_scope )
|
while( node->next && !node->new_scope )
|
||||||
node = node->next;
|
node = node->next;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -809,7 +809,8 @@ void env_set( const wchar_t *key,
|
||||||
{
|
{
|
||||||
handle_locale();
|
handle_locale();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
13
env.h
13
env.h
|
@ -41,6 +41,11 @@
|
||||||
*/
|
*/
|
||||||
#define ENV_UNIVERSAL 32
|
#define ENV_UNIVERSAL 32
|
||||||
|
|
||||||
|
/**
|
||||||
|
Error code for trying to alter read-only variable
|
||||||
|
*/
|
||||||
|
#define ENV_PERM 1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Initialize environment variable data
|
Initialize environment variable data
|
||||||
*/
|
*/
|
||||||
|
@ -61,9 +66,15 @@ void env_destroy();
|
||||||
\param val The value
|
\param val The value
|
||||||
\param mode The type of the variable. Can be any combination of ENV_GLOBAL, ENV_LOCAL, ENV_EXPORT and ENV_USER. If mode is zero, the current variable space is searched and the current mode is used. If no current variable with the same name is found, ENV_LOCAL is assumed.
|
\param mode The type of the variable. Can be any combination of ENV_GLOBAL, ENV_LOCAL, ENV_EXPORT and ENV_USER. If mode is zero, the current variable space is searched and the current mode is used. If no current variable with the same name is found, ENV_LOCAL is assumed.
|
||||||
|
|
||||||
|
\returns 0 on suicess or an error code on failiure.
|
||||||
|
|
||||||
|
The current error codes are:
|
||||||
|
|
||||||
|
* ENV_PERM, can only be returned when setting as a user, e.g. ENV_USER is set. This means that the user tried to change a read-only variable.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void env_set( const wchar_t *key,
|
int env_set( const wchar_t *key,
|
||||||
const wchar_t *val,
|
const wchar_t *val,
|
||||||
int mode );
|
int mode );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user