ATLAS Offline Software
Loading...
Searching...
No Matches
VomsProxySvc.cxx File Reference
#include <EventLoop/VomsProxySvc.h>
#include <AsgMessaging/MessageCheck.h>
#include <RootCoreUtils/Assert.h>
#include <SampleHandler/GridTools.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <fstream>
#include <TSystem.h>

Go to the source code of this file.

Functions

 ClassImp (EL::VomsProxySvc) namespace EL

Function Documentation

◆ ClassImp()

ClassImp ( EL::VomsProxySvc )
Author
Nils Krumnack

Definition at line 30 of file VomsProxySvc.cxx.

33{
34 const std::string& VomsProxySvc ::
35 algServiceName ()
36 {
37 static std::string result = "VomsProxySvc";
38 return result;
39 }
40
41
42
43 void VomsProxySvc ::
44 testInvariant () const
45 {
46 RCU_INVARIANT (this != nullptr);
47 }
48
49
50
51 StatusCode VomsProxySvc ::
52 setupJob (Job& /*job*/)
53 {
56
57 const char *X509_USER_PROXY = getenv ("X509_USER_PROXY");
58 std::string file;
59 if (X509_USER_PROXY)
60 {
61 file = X509_USER_PROXY;
62 } else
63 {
64 std::ostringstream str;
65 str << "/tmp/x509up_u" << getuid();
66 file = str.str();
67 }
68 if (file.empty() || gSystem->AccessPathName (file.c_str()) != false)
69 {
70 ANA_MSG_ERROR ("failed to find X509 proxy file: " << file);
71 return StatusCode::FAILURE;
72 }
73
74 {
75 std::ifstream stream (file);
76 char ch;
77 while (stream.get (ch))
78 m_proxyData += ch;
79 if (!stream.eof())
80 {
81 ANA_MSG_ERROR ("error reading X509 proxy file: " << file);
82 return StatusCode::FAILURE;
83 }
84 }
85
86 return StatusCode::SUCCESS;
87 }
88
89
90
91 const char *VomsProxySvc ::
92 GetName () const
93 {
94 RCU_READ_INVARIANT (this);
95 return name().c_str();
96 }
97
98
99
100 StatusCode VomsProxySvc ::
101 histInitialize ()
102 {
103 RCU_READ_INVARIANT (this);
104 if (!SH::checkVomsProxy())
105 {
106 int fd = open (m_fileName.c_str(), O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
107 if (fd == -1)
108 {
109 auto myerrno = errno;
110 ANA_MSG_ERROR ("failed to create file \"" << m_fileName << "\": " << strerror (myerrno));
111 return EL::StatusCode::FAILURE;
112 }
113 int written = write (fd, &m_proxyData[0], m_proxyData.size());
114 if (written == -1)
115 {
116 auto myerrno = errno;
117 ANA_MSG_ERROR ("failed to write to file \"" << m_fileName << "\": " << strerror (myerrno));
118 close (fd);
119 return EL::StatusCode::FAILURE;
120 }
121 if (written < int (m_proxyData.size()))
122 {
123 ANA_MSG_ERROR ("only wrote " << written << " of " << m_proxyData.size() << " bytes to file \"" << m_fileName << "\"");
124 close (fd);
125 return EL::StatusCode::FAILURE;
126 }
127 if (close (fd) == -1)
128 {
129 auto myerrno = errno;
130 ANA_MSG_ERROR ("failed to close file \"" << m_fileName << "\": " << strerror (myerrno));
131 return EL::StatusCode::FAILURE;
132 }
133 if (setenv ("X509_USER_PROXY", m_fileName.c_str(), true) == -1)
134 {
135 auto myerrno = errno;
136 ANA_MSG_ERROR ("failed to set X509_USER_PROXY: " << strerror (myerrno));
137 return EL::StatusCode::FAILURE;
138 }
139 }
140 return EL::StatusCode::SUCCESS;
141 }
142}
#define RCU_INVARIANT(x)
Definition Assert.h:189
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:219
#define RCU_READ_INVARIANT(x)
Definition Assert.h:217
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
::StatusCode StatusCode
StatusCode definition for legacy code.
std::string getenv(const std::string &variableName)
get an environment variable
void ensureVomsProxy()
ensure that we have a valid VOMS proxy available
bool checkVomsProxy()
return whether we have a valid VOMS proxy available
@ open
Definition BinningType.h:40
TFile * file