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

Issue 202 #205

Merged
merged 15 commits into from Nov 23, 2018
Merged

Issue 202 #205

merged 15 commits into from Nov 23, 2018

Conversation

p-alik
Copy link
Collaborator

@p-alik p-alik commented Nov 20, 2018

For some reason I can't reopen #203.
The PR do the same:

@p-alik p-alik mentioned this pull request Nov 20, 2018
@esabol
Copy link
Collaborator

esabol commented Nov 20, 2018

The only problem with this approach is that mkstemp will actually succeed if you run gearmand or test as root, and temp files will be created in /. I think you should at least unlink the temp file immediately in that scenario.

I think using __mktemp is cleaner, if it's available.

@p-alik
Copy link
Collaborator Author

p-alik commented Nov 20, 2018

I think using __mktemp is cleaner, if it's available.

mktemp marco as you proposed doesn't work in my environment. (Ubuntu 16.04) That's the reason for mkstemp.

@p-alik
Copy link
Collaborator Author

p-alik commented Nov 21, 2018

I think you should at least unlink the temp file immediately in that scenario.

It's done in 6ca3f04

@esabol
Copy link
Collaborator

esabol commented Nov 21, 2018

This is probably fine, but potentially creating a temp file in / still leaves a bad taste. What do you think about using "/tmp/XXXXXXXXX" for the template? You could then use memmove() to remove the /tmp part from lock_name after the mkstemp call, if that's necessary or desirable.

util/signal.cc Outdated
mktemp(lock_name);
// random lock_name required
if (mkstemp(lock_name) != -1)
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Braces doesn't appear to line up properly here. The open brace should be under the "i" in "if". Double check indentation on the next several lines as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

mkstemp based approach is removed. The braces also.
Unfortunately Travis CI tests failing with new random string based approach. They are running fine locally.

@esabol
Copy link
Collaborator

esabol commented Nov 22, 2018

Tests failing... Another option might be to revert the code way back to using unnamed semaphores and only use the named semaphores approach on macOS.

@p-alik
Copy link
Collaborator Author

p-alik commented Nov 22, 2018

Another option might be to revert the code way back to using unnamed semaphores and only use the named semaphores approach on macOS.

I thought about this also. Actually there is no evidence named semaphores cause the issue. Maybe the content of test-suite.log created during Travis CI build could be helpful in this case. So I'll try to get it.

@esabol
Copy link
Collaborator

esabol commented Nov 22, 2018

Maybe the content of test-suite.log created during Travis CI build could be helpful in this case. So I'll try to get it.

I've been thinking that it might be useful if Travis CI were to cat test-suite.log after the make test.

@esabol
Copy link
Collaborator

esabol commented Nov 23, 2018

Ah, ha! The man page for sem_open says, "If O_CREAT is specified in oflag, then two additional arguments must be supplied." So, as I'm sure you've already figured out, we need the 4-argument version of sem_open...

@p-alik
Copy link
Collaborator Author

p-alik commented Nov 23, 2018

Yes, I did. We could merge the PR yet.

thread_local static std::mt19937 rg{std::random_device{}()};
thread_local static std::uniform_int_distribution<std::string::size_type> pick(0, sizeof(chrs) - 2);

// convenient to named semaphore defination
Copy link
Collaborator

Choose a reason for hiding this comment

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

Misspelled "definition" here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, could you can a blank line after the "break;" for "case SIGQUIT" (right before "case SIGPIPE")? Not in the scope of your changes, but it's trivial.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is no blank at the end of case SIGQUIT. Do you mean case SIGPIPE?

Copy link
Collaborator

@esabol esabol Nov 23, 2018

Choose a reason for hiding this comment

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

I was hoping you'd add a blank line after this line:

break;

But too late now that we've merged....

util/signal.cc Outdated
std::string s{"/"};
s.reserve(len--);

while(len--)
Copy link
Collaborator

Choose a reason for hiding this comment

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

There should be a space between "while" and "(".

lock = sem_open(lock_name, O_CREAT|O_EXCL);

const char * lock_name = random_lock_name().c_str();
lock = sem_open(lock_name, O_CREAT|O_EXCL, 0660, 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of 0660, use S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP instead?

I think those S_* constants are defined in sys/stat.h?

#include <sys/stat.h>

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK

std::string s{"/"};
s.reserve(len--);

while(len--)
Copy link
Collaborator

Choose a reason for hiding this comment

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

There should be a space between "while" and "(".

s.reserve(len--);

while(len--)
s += chrs[pick(rg)];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Something tells me that the coding style for this project is to put braces around single statement loops like this. Please confirm.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll add the braces.

s.reserve(len--);

while(len--)
s += chrs[pick(rg)];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Something tells me that the coding style for this project is to put braces around single statement loops like this. Please confirm.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll add the braces

@esabol
Copy link
Collaborator

esabol commented Nov 23, 2018

Also, shouldn't this line be changed?

lock = sem_open(lock_name, 0, 0);

I'm not aware of a 3-argument version of sem_open. Only 2 and 4 arguments, right? I'm surprised this even compiles. Don't we want sem_open(lock_name, O_CREAT|O_EXCL, 0660, 0) here?

@esabol
Copy link
Collaborator

esabol commented Nov 23, 2018

And, not that it matters, but I'm curious why 0660 instead of 0600 for the mode?

@p-alik
Copy link
Collaborator Author

p-alik commented Nov 23, 2018

And, not that it matters, but I'm curious why 0660 instead of 0600 for the mode?

We'll see, if sem_open(lock_name, O_CREAT|O_EXCL, S_IRUSR|S_IWUSR, 0) works. There is no reason for 0660

util/signal.cc Outdated
@@ -243,7 +245,7 @@ bool SignalThread::setup()
}

const char * lock_name = random_lock_name().c_str();
lock = sem_open(lock_name, 0, 0);
lock = sem_open(lock_name, O_CREAT, S_IRUSR|S_IWUSR, 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

No |O_EXCL here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, yes

@p-alik p-alik merged commit d0851c0 into gearman:master Nov 23, 2018
@p-alik p-alik deleted the issue-202 branch November 24, 2018 10:14
@p-alik p-alik mentioned this pull request Nov 24, 2018
33 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants