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

Reimplement signal handler to avoid async-unsafe functions #97

Closed
wants to merge 7 commits into from

Conversation

zzxuanyuan
Copy link
Contributor

@bbockelm @pcanal This patch copies the code of signal handling in CMSSW. It avoids async-unsafe functions in signal handler functions.

For reference, see the link https://github.com/bbockelm/cmssw/blob/stacktrace_handler_revisit/FWCore/Services/src/InitRootHandlers.cc

I tried this patch with some simple multi-thread test cases and it worked fine. Is there any complicated test cases I can run? I think this patch is not very ready to merge, but it achieved basic functions. Any criticisms are welcome.

#include <memory>

namespace std {
class thread;
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't need a forward dec'l if you already include

Copy link
Member

Choose a reason for hiding this comment

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

And please use ROOT coding standards.

Copy link
Contributor

Choose a reason for hiding this comment

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

(by the way, is there a good online ref for these to link to?)

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks Philippe - Zhe, can you run through this guide and try to get the code to compliance?

@pcanal - when contributing to CVMFS, they provide an automated tool (based on cpplint). I see you reference astyle for managing whitespace. Do you have anything similarly automated you use?

@bbockelm
Copy link
Contributor

bbockelm commented Oct 7, 2015

Hi Zhe,

You may also want to pull in the work done here:

cms-sw/cmssw#11662

Specifically,
a) Allow the read function to timeout.
b) Avoid use of execv on Linux. CERN uses LD_PRELOAD tricks to insert a custom version of this function into the executable. Unlike the POSIX documentation, the version of execv at CERN is not async signal safe.

Brian

@zzxuanyuan
Copy link
Contributor Author

@bbockelm Sure. I will polish up my code.

@zzxuanyuan
Copy link
Contributor Author

Hi Philippe,

@pcanal Could you take a look at this new patch? Is there any test cases I can run with?

Thanks!

{
const char *buffer = text;
size_t count = strlen(text);
ssize_t written = 0;
Copy link
Member

Choose a reason for hiding this comment

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

since written is not used outside the loop, it ought to be declared inside.

@pcanal
Copy link
Member

pcanal commented Oct 19, 2015

Is there any test cases I can run with?

Not specifically. Some of the code would be exercised by calling ::Fatal( ... )

@pcanal
Copy link
Member

pcanal commented Dec 11, 2015

Hi,

What was the result of your testing? Did you create a test we can add to roottest?
Did you already update to follow the coding conventions? (I do not see an newer version so I commented on what I see)

Thanks,
Philippe.

typedef void (*SigHandler_t)(ESignals);

struct TStackTraceHelper {
Copy link
Member

Choose a reason for hiding this comment

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

Class not part of the public interface need to either be defined in an unnamed namepace in the source file or within the ROOT::Internal namespace or as protected/private subclass of the using class.

return 0;
}

static int SignalSafeRead(int fd, char *inbuf, size_t len, int timeout=-1) {
Copy link
Member

Choose a reason for hiding this comment

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

missing function documentation.

@pcanal
Copy link
Member

pcanal commented Dec 11, 2015

Since all the signal handling and processing is essentially standalone, could be move it all in a single (sub)class?

Thanks,
Philippe.

@bbockelm
Copy link
Contributor

bbockelm commented Jan 8, 2016

Hi Philippe,

Talked with Zhe about this yesterday; now that the end-of-semester rush is over, he's coming back to this item. We're working to refactor this to a new class.

Brian

@zzxuanyuan
Copy link
Contributor Author

@pcanal @bbockelm I think there are two possible refactoring approaches.

  1. I could extract all signal handling related functions and attributes out from TSystem(.h,.cxx) and modify both TUnixSystem and TWinNT
  2. I create SignalHandling class in another class and add it as an class member in TUnixSystem. In that sense, I need to overwrite all signal handling functions and point them to the corresponding functions in new class SignalHandling.
    Which one is better? The first one is more clear to me but I am not sure how it will impact the windows machine.

Zhe

@pcanal
Copy link
Member

pcanal commented Jan 12, 2016

I meant a variation of 1, where TSystem calls directly the extracted methods (i.e. essentially this should just be 'refactoring'). Thanks.

@zzxuanyuan
Copy link
Contributor Author

Sure. It makes more sense to me. The only concern I have is how much side effect it will introduce to windows. I just ignore it from now?

@pcanal
Copy link
Member

pcanal commented Jan 12, 2016

well, it would be no more or less than what you have now :). We will need to see how it behaves on Windows once we have merged it.

@bbockelm
Copy link
Contributor

@zzxuanyuan - since this appears to be replaced by #134, can you please close this request?

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.

4 participants