ATLAS Offline Software
Loading...
Searching...
No Matches
VomsProxySvc.cxx File Reference
#include <EventLoop/VomsProxySvc.h>
#include <AsgMessaging/MessageCheck.h>
#include <RootCoreUtils/Assert.h>
#include <RootCoreUtils/ThrowMsg.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 )

Definition at line 38 of file VomsProxySvc.cxx.

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