ATLAS Offline Software
Functions
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  {
62  RCU_CHANGE_INVARIANT (this);
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 }
sendEI_SPB.ch
ch
Definition: sendEI_SPB.py:35
get_generator_info.result
result
Definition: get_generator_info.py:21
SH::checkVomsProxy
bool checkVomsProxy()
return whether we have a valid VOMS proxy available
Definition: GridTools.cxx:206
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
python.ByteStreamConfig.write
def write
Definition: Event/ByteStreamCnvSvc/python/ByteStreamConfig.py:247
file
TFile * file
Definition: tile_monitor.h:29
RCU_INVARIANT
#define RCU_INVARIANT(x)
Definition: Assert.h:201
SH::ensureVomsProxy
void ensureVomsProxy()
ensure that we have a valid VOMS proxy available
Definition: GridTools.cxx:213
ReadFromCoolCompare.fd
fd
Definition: ReadFromCoolCompare.py:196
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
Trk::open
@ open
Definition: BinningType.h:40
SCT_ConditionsAlgorithms::CoveritySafe::getenv
std::string getenv(const std::string &variableName)
get an environment variable
Definition: SCT_ConditionsUtilities.cxx:17
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
str
Definition: BTagTrackIpAccessor.cxx:11
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition: PrintMsg.h:58
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition: Assert.h:229