Skip to content

Commit

Permalink
Rearranged codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
caibinwav123456 committed Mar 16, 2022
1 parent dffbdb7 commit af2f8ee
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 53 deletions.
16 changes: 7 additions & 9 deletions IPCIF/src/fs_sh/fs_sh/sh_cmd_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ static int check_args(vector<pair<string,string>>& args,bool mute=false)
}
return 0;
}
static inline void print_error_setmode()
{
printf("the param of the command %s error.\n"
"try \"%s %s\" or \"%s %s\".\n",CMD_SET_EXEC_MODE,
CMD_SET_EXEC_MODE,EXEC_MODE_ALL,
CMD_SET_EXEC_MODE,EXEC_MODE_NORM);
}
#ifdef USE_FS_ENV_VAR
static int print_env(FSEnvSet& env,const vector<pair<string,string>>& args)
{
Expand Down Expand Up @@ -135,15 +142,6 @@ static int print_env(FSEnvSet& env,const vector<pair<string,string>>& args)
}
return 0;
}
#endif
static inline void print_error_setmode()
{
printf("the param of the command %s error.\n"
"try \"%s %s\" or \"%s %s\".\n",CMD_SET_EXEC_MODE,
CMD_SET_EXEC_MODE,EXEC_MODE_ALL,
CMD_SET_EXEC_MODE,EXEC_MODE_NORM);
}
#ifdef USE_FS_ENV_VAR
static inline int handle_set_env_var(ctx_priv_data* privdata,const vector<pair<string,string>>& args,bool& bset)
{
int ret=0;
Expand Down
6 changes: 3 additions & 3 deletions IPCIF/src/fs_sh/parse_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ static int __parse_cmd(const byte* buf,int size,
#ifdef USE_FS_ENV_VAR
if(args.back().second.empty())
{
if(args.size()==1)
if(args.size()==1&&privdata!=NULL)
privdata->env_flags|=CTXPRIV_ENVF_DEL;
}
#endif
Expand All @@ -299,7 +299,7 @@ static int __parse_cmd(const byte* buf,int size,
if(!tdata.valid_trim)
{
#ifdef USE_FS_ENV_VAR
if(args.size()==1)
if(args.size()==1&&privdata!=NULL)
privdata->env_flags|=CTXPRIV_ENVF_DEL;
else
#endif
Expand All @@ -309,7 +309,7 @@ static int __parse_cmd(const byte* buf,int size,
make_token(pbuf,buf,token_buf,args.back().second);
}
#ifdef USE_FS_ENV_VAR
if(args.size()>1&&(privdata->env_flags&CTXPRIV_ENVF_DEL))
if(args.size()>1&&privdata!=NULL&&(privdata->env_flags&CTXPRIV_ENVF_DEL))
{
privdata->env_flags&=(~CTXPRIV_ENVF_DEL);
return ERR_INVALID_CMD;
Expand Down
23 changes: 10 additions & 13 deletions IPCIF/src/fs_sh/sh_cmd_fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,19 +605,16 @@ static inline int handle_set_env_var(ctx_priv_data* privdata,const vector<pair<s
bset=false;
bool del_flag=!!(privdata->env_flags&CTXPRIV_ENVF_DEL);
privdata->env_flags&=(~CTXPRIV_ENVF_DEL);
if(args.size()==1)
{
bool empty=args[0].second.empty();
assert(!((!empty)&&del_flag));
if(((!empty)&&!del_flag)||(empty&&del_flag))
{
if(0!=(ret=privdata->env_cache.SetEnv(args[0].first,args[0].second)))
return_msg(ret,"set environment variable \'%s\' to \'%s\' failed: %s\n",
args[0].first.c_str(),args[0].second.c_str(),get_error_desc(ret));
bset=true;
return 0;
}
}
if(args.size()!=1)
return 0;
bool empty=args[0].second.empty();
assert(!((!empty)&&del_flag));
if(empty&&!del_flag)
return 0;
if(0!=(ret=privdata->env_cache.SetEnv(args[0].first,args[0].second)))
return_msg(ret,"set environment variable \'%s\' to \'%s\' failed: %s\n",
args[0].first.c_str(),args[0].second.c_str(),get_error_desc(ret));
bset=true;
return 0;
}
#endif
Expand Down
6 changes: 3 additions & 3 deletions misc/unittest/fs_sh/parse_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ static int __parse_cmd(const byte* buf,int size,
#ifdef USE_FS_ENV_VAR
if(args.back().second.empty())
{
if(args.size()==1)
if(args.size()==1&&privdata!=NULL)
privdata->env_flags|=CTXPRIV_ENVF_DEL;
}
#endif
Expand All @@ -299,7 +299,7 @@ static int __parse_cmd(const byte* buf,int size,
if(!tdata.valid_trim)
{
#ifdef USE_FS_ENV_VAR
if(args.size()==1)
if(args.size()==1&&privdata!=NULL)
privdata->env_flags|=CTXPRIV_ENVF_DEL;
else
#endif
Expand All @@ -309,7 +309,7 @@ static int __parse_cmd(const byte* buf,int size,
make_token(pbuf,buf,token_buf,args.back().second);
}
#ifdef USE_FS_ENV_VAR
if(args.size()>1&&(privdata->env_flags&CTXPRIV_ENVF_DEL))
if(args.size()>1&&privdata!=NULL&&(privdata->env_flags&CTXPRIV_ENVF_DEL))
{
privdata->env_flags&=(~CTXPRIV_ENVF_DEL);
return ERR_INVALID_CMD;
Expand Down
23 changes: 10 additions & 13 deletions misc/unittest/fs_sh/sh_cmd_fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,19 +609,16 @@ static inline int handle_set_env_var(ctx_priv_data* privdata,const vector<pair<s
bset=false;
bool del_flag=!!(privdata->env_flags&CTXPRIV_ENVF_DEL);
privdata->env_flags&=(~CTXPRIV_ENVF_DEL);
if(args.size()==1)
{
bool empty=args[0].second.empty();
assert(!((!empty)&&del_flag));
if(((!empty)&&!del_flag)||(empty&&del_flag))
{
if(0!=(ret=privdata->env_cache.SetEnv(args[0].first,args[0].second)))
return_msg(ret,"set environment variable \'%s\' to \'%s\' failed: %s\n",
args[0].first.c_str(),args[0].second.c_str(),get_error_desc(ret));
bset=true;
return 0;
}
}
if(args.size()!=1)
return 0;
bool empty=args[0].second.empty();
assert(!((!empty)&&del_flag));
if(empty&&!del_flag)
return 0;
if(0!=(ret=privdata->env_cache.SetEnv(args[0].first,args[0].second)))
return_msg(ret,"set environment variable \'%s\' to \'%s\' failed: %s\n",
args[0].first.c_str(),args[0].second.c_str(),get_error_desc(ret));
bset=true;
return 0;
}
#endif
Expand Down
6 changes: 3 additions & 3 deletions misc/unittest/unittest/fs_sh/parse_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ static int __parse_cmd(const byte* buf,int size,
#ifdef USE_FS_ENV_VAR
if(args.back().second.empty())
{
if(args.size()==1)
if(args.size()==1&&privdata!=NULL)
privdata->env_flags|=CTXPRIV_ENVF_DEL;
}
#endif
Expand All @@ -299,7 +299,7 @@ static int __parse_cmd(const byte* buf,int size,
if(!tdata.valid_trim)
{
#ifdef USE_FS_ENV_VAR
if(args.size()==1)
if(args.size()==1&&privdata!=NULL)
privdata->env_flags|=CTXPRIV_ENVF_DEL;
else
#endif
Expand All @@ -309,7 +309,7 @@ static int __parse_cmd(const byte* buf,int size,
make_token(pbuf,buf,token_buf,args.back().second);
}
#ifdef USE_FS_ENV_VAR
if(args.size()>1&&(privdata->env_flags&CTXPRIV_ENVF_DEL))
if(args.size()>1&&privdata!=NULL&&(privdata->env_flags&CTXPRIV_ENVF_DEL))
{
privdata->env_flags&=(~CTXPRIV_ENVF_DEL);
return ERR_INVALID_CMD;
Expand Down
16 changes: 7 additions & 9 deletions misc/unittest/unittest/fs_sh/sh_cmd_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ static int check_args(vector<pair<string,string>>& args,bool mute=false)
}
return 0;
}
static inline void print_error_setmode()
{
printf("the param of the command %s error.\n"
"try \"%s %s\" or \"%s %s\".\n",CMD_SET_EXEC_MODE,
CMD_SET_EXEC_MODE,EXEC_MODE_ALL,
CMD_SET_EXEC_MODE,EXEC_MODE_NORM);
}
#ifdef USE_FS_ENV_VAR
static int print_env(FSEnvSet& env,const vector<pair<string,string>>& args)
{
Expand Down Expand Up @@ -135,15 +142,6 @@ static int print_env(FSEnvSet& env,const vector<pair<string,string>>& args)
}
return 0;
}
#endif
static inline void print_error_setmode()
{
printf("the param of the command %s error.\n"
"try \"%s %s\" or \"%s %s\".\n",CMD_SET_EXEC_MODE,
CMD_SET_EXEC_MODE,EXEC_MODE_ALL,
CMD_SET_EXEC_MODE,EXEC_MODE_NORM);
}
#ifdef USE_FS_ENV_VAR
static inline int handle_set_env_var(ctx_priv_data* privdata,const vector<pair<string,string>>& args,bool& bset)
{
int ret=0;
Expand Down

0 comments on commit af2f8ee

Please sign in to comment.