Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quote the file path to the Ruby bin directory when starting fluentd as a windows service #1536

Merged
merged 1 commit into from
Apr 19, 2017

Conversation

iantalarico
Copy link
Contributor

@iantalarico iantalarico commented Apr 11, 2017

The the file path is passed to win32-service (which calls windows functions CreateService) and to Process.spawn. Both require spaces to be wrapped in quotes or windows will not properly handle them.

Without this fix fluentd will fail fail when initializing or when starting with a ruby directory that contains spaces.

… windows service.

The the file path is passed to win32-service (which calls windows functions CreateService[1]) and to Process.spawn [2].
Both require spaces to be wrapped in quotes or windows will not properly handle them.

Without this fix fluentd will fail fail when initilizing or when starting.

[1]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms682450(v=vs.85).aspx
[2]: https://ruby-doc.org/core-2.2.0/Process.html#method-c-spawn
@repeatedly
Copy link
Member

@nurse How about this?
Does ruby have the function for this case?

@repeatedly repeatedly requested a review from nurse April 11, 2017 21:52
@iantalarico
Copy link
Contributor Author

It does not have a function that I am aware of.

@nurse
Copy link
Contributor

nurse commented Apr 12, 2017

@repeatedly instead of passing argv as single string, just pass them as array.
see also https://ruby-doc.org/core-2.4.1/Process.html#method-c-spawn

@repeatedly
Copy link
Member

@iantalarico Could you try convert single string to array?

@iantalarico
Copy link
Contributor Author

@repeatedly @nurse I gave this a try but was unable to make it work. Looking the documentation it looks like if I don't just pass a command line string it does not use the shell and will try to execute a built in command. I'm guessing this may not work if we are passing a path to an exe as the command.

@nurse
Copy link
Contributor

nurse commented Apr 13, 2017

@iantalarico Where and How it failed. I thought both ruby_path and rubybin_dir + "/ruby.exe " are full path.

@iantalarico
Copy link
Contributor Author

@nurse It fails on Process.spawn.

If the path is quoted we get the error "Invalid argument - "C:/Program Files (x86)/TestDir/bin/ruby.exe""

If the path is unquoted we get the error "No such file or directory - OpenEvent"

I don't think it's and issue with the path I think it's an issue of what Process.spawn expects when we pass the command and an array.

@nurse
Copy link
Contributor

nurse commented Apr 13, 2017

@iantalarico How did you quote?
It seems you quoted twice, because Invalid argument is raised when path includes double quote.

@iantalarico
Copy link
Contributor Author

@nurse I tried:
""#{rubybin_dir}/ruby.exe""
and
"#{rubybin_dir}/ruby.exe"

@nurse
Copy link
Contributor

nurse commented Apr 13, 2017

@iantalarico Could you show with Process.spawn(... )?

@iantalarico
Copy link
Contributor Author

@nurse
Process.spawn("#{rubybin_dir}/ruby.exe", "#{rubybin_dir}/fluentd", opt, "-x #{INTEVENTOBJ_NAME}")
and
Process.spawn(""#{rubybin_dir}/ruby.exe"", ""#{rubybin_dir}/fluentd"", opt, "-x #{INTEVENTOBJ_NAME}")

@nurse
Copy link
Contributor

nurse commented Apr 13, 2017

Process.spawn("#{rubybin_dir}/ruby.exe", "#{rubybin_dir}/fluentd", opt, "-x #{INTEVENTOBJ_NAME}")

is correct.
And it shows "No such file or directory - OpenEvent" at Process.spawn?
The term "OpenEvent" is shown at that point sounds strange.

@iantalarico
Copy link
Contributor Author

@nurse Yea I was wrong only the first one was failing on process spawn the second one fails on event open:

"C:/Program Files (x86)/TestDir/lib/ruby/gems/2.3.0/gems/win32-event-0.6.3/lib/win32/event.rb:125:in open'" "winsvc.rb:59:in service_stop'", "C:/Program Files (x86)/TestDir/lib/ruby/gems/2.3.0/gems/win32-service-0.8.10/lib/win32/daemon.rb:309:in `block in mainloop'"

It looks like the service is failing in some way in the daemon.

I can dig more into this if need be but I don't see a problem with just passing a command line string?

@nurse
Copy link
Contributor

nurse commented Apr 13, 2017

@iantalarico
Maybe Process.spawn("#{rubybin_dir}/ruby.exe", "#{rubybin_dir}/fluentd", opt, "-x", INTEVENTOBJ_NAME) is correct.
or maybe just it reached an another issue on your environment/setting.

Anyway I need full backtrace of the error.

@iantalarico
Copy link
Contributor Author

@nurse I think that was the full backtrace. I did "err.backtrace.inspect"

@repeatedly repeatedly added enhancement Feature request or improve operations v0.14 labels Apr 14, 2017
@repeatedly
Copy link
Member

After fixed this problem, I will release new v0.14.

@iantalarico
Copy link
Contributor Author

@nurse Is the original backtrace I sent okay? Are you okay with the fix as is? This is essentially what was being done before. If not I can dig into this more.

@nurse
Copy link
Contributor

nurse commented Apr 17, 2017

@iantalarico Backtrace is OK.
Did you try Process.spawn("#{rubybin_dir}/ruby.exe", "#{rubybin_dir}/fluentd", opt, "-x", INTEVENTOBJ_NAME)?

@iantalarico
Copy link
Contributor Author

@nurse It looks like I get the same backtrace:

C:/Program Files (x86)/TestDir/lib/ruby/gems/2.3.0/gems/win32-event-0.6.3/lib/win32/event.rb:125:in open'" "winsvc.rb:59:inservice_stop'", "C:/Program Files (x86)/TestDir/lib/ruby/gems/2.3.0/gems/win32-service-0.8.10/lib/win32/daemon.rb:309:in `block in mainloop'"

@nurse
Copy link
Contributor

nurse commented Apr 18, 2017

Hmm, it is not sufficient to investigate the issue. It seems to need more digging...

@iantalarico
Copy link
Contributor Author

@nurse I'm happy to dig more into this but why is the current solution not acceptable? This is what the current code is doing.

@nurse
Copy link
Contributor

nurse commented Apr 18, 2017

@iantalarico Ah, I wrongly saw CI is failing but it looks false-positive.
And both part looks affect only Windows.
Therefore though array is better, current patch is acceptable.

@repeatedly Could you merge this if CI is ok.

@iantalarico
Copy link
Contributor Author

@nurse Alright thanks. As I said I am happy to look into the array solution more if you feel strongly going that route.

@repeatedly repeatedly merged commit 2ac070c into fluent:master Apr 19, 2017
@repeatedly
Copy link
Member

Thanks for your work 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request or improve operations v0.14
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants