+
Skip to content

Conversation

NsCDE
Copy link
Contributor

@NsCDE NsCDE commented Jun 7, 2020

Hi Thomas,

I don't know what was more difficult: to make my 1st PR in life or how to do ~/ substitution.

I have put define in log.h and renamed env variable to FVWM3_LOGDIR as you requested. Please review. I hope this is ok.

Copy link
Member

@ThomasAdam ThomasAdam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @NsCDE,

Thanks for this! I've left a few comments in-line. You're definitely on the right lines here.

However, we should probably standardise on this a little bit, building on your ideas here.

  1. We already perform a $HOME lookup in fvwm/fvwm3.c where we use getpwuid() -- so we should centralise that check somewhere in libs/;
  2. We want to not only expand ~/ but $HOME as well via getenv() -- just like you have with FVWM3_LOGDIR.
  3. This check will be useful for the logfile, and the check in fvwm/fvwm3.c.

To that end, I've come up with this pull-request:

#127

... which also includes a man page addition for the environment variable.

I've tested this in FvwmConsole by doing this like:

SetEnv FVWM3_LOGFILE "/tmp/fvwm3.log"

Then pkill -USR2 fvwm3 which starts logging to that file. Then back in FvwmConsole:

UnsetEnv FVWM3_LOGFILE

... then pkill -USR2 fvwm3, and logging resumes from ~/fvwm3-output.log.

Let me know what you think, and thanks again for the pull-request, @NsCDE.

if (strncmp(path, "~/", 2) == 0)
{
/* Remove only ~ we need / between homedir and the rest */
memmove(path, path + 1, strlen(path));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent start. This memmove though will overrun if path isn't NUL-terminated. strlen(...) + 1 will fix that.

pwd = getpwuid(getuid());
if (pwd)
{
path = strcat(pwd->pw_dir, path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path is allocated via fxstrdup() and needs freeing here, if it's to be allocated in this way, via temporary variable, otherwise we'll leak memory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Thomas,

I'm glad you expanded this and got idea for consolidating generally things about homedir, shell paths and repetative usage of getpwuid in fvwm code.

Yesterday, while searching for similart things in the code, I saw fvwm/session.c, libs/fsm.c, and modules/FvwmScript/Instructions.c are calling getpwuid to find pw->pw_dir too. Since you produced the whole centralized .c+.h files for handling canonification of homedir and path in all the code, this can be consolidated too.

For a C language, I am what people here is Balkan like to say "I'm not a gynecologist, but I can take a look". :-) That said, I will be more carefull to free() things in the future. I have one patch for FvwmButtons (window name and indicator) for a long time too, but this can probably wait post 1.0, it needs to be revisited for fvwm3 ...

P. S.
Simply drop this and apply #127

Cheers ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yesterday, while searching for similart things in the code, I saw fvwm/session.c, libs/fsm.c, and modules/FvwmScript/Instructions.c are calling getpwuid to find pw->pw_dir too. Since you produced the whole centralized .c+.h files for handling canonification of homedir and path in all the code, this can be consolidated too.

Well, feel free to transition those callers across to this, too -- no rush though.

For a C language, I am what people here is Balkan like to say "I'm not a gynecologist, but I can take a look". :-)

Heh -- an interesting sentiment there. :)

That said, I will be more carefull to free() things in the future. I have one patch for FvwmButtons (window name and indicator) for a long time too, but this can probably wait post 1.0, it needs to be revisited for fvwm3 ...

Do please open up a pull-request with that patch, against FVWM3 and I'll take a look...

P. S.
Simply drop this and apply #127

Will do. Thanks again.

@ThomasAdam
Copy link
Member

Closing per review comments. Superseded by #127

@ThomasAdam ThomasAdam closed this Jun 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载