ATLAS Offline Software
VomsProxySvc.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 
10 // Please feel free to contact me (krumnack@iastate.edu) for bug
11 // reports, feature suggestions, praise and complaints.
12 
13 
14 //
15 // includes
16 //
17 
18 #include <EventLoop/VomsProxySvc.h>
19 
21 #include <RootCoreUtils/Assert.h>
22 #include <RootCoreUtils/ThrowMsg.h>
24 #include <errno.h>
25 #include <unistd.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <fcntl.h>
29 #include <unistd.h>
30 #include <sys/types.h>
31 #include <fstream>
32 #include <TSystem.h>
33 
34 //
35 // method implementations
36 //
37 
39 
40 namespace EL
41 {
42  const std::string& VomsProxySvc ::
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 
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 
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
ClassImp
ClassImp(EL::VomsProxySvc) namespace EL
Definition: VomsProxySvc.cxx:38
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
Assert.h
EL::VomsProxySvc::histInitialize
virtual StatusCode histInitialize() override
effects: this is a pre-initialization routine that is called before changeInput is called.
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
EL::VomsProxySvc::GetName
virtual const char * GetName() const override
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
MessageCheck.h
macros for messaging and checking status codes
python.ByteStreamConfig.write
def write
Definition: Event/ByteStreamCnvSvc/python/ByteStreamConfig.py:248
GridTools.h
EL::VomsProxySvc::algServiceName
static const std::string & algServiceName()
description: the name of the service
file
TFile * file
Definition: tile_monitor.h:29
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AlgorithmWorkerData.h:24
getCastorRun.setenv
def setenv()
Definition: getCastorRun.py:9
EL::VomsProxySvc::m_fileName
std::string m_fileName
the name of the file to be created
Definition: VomsProxySvc.h:41
EL::Algorithm::name
virtual const std::string & name() const
RCU_INVARIANT
#define RCU_INVARIANT(x)
Definition: Assert.h:201
EL::VomsProxySvc
Definition: VomsProxySvc.h:24
EL::VomsProxySvc::testInvariant
void testInvariant() const
effects: test the invariant of this object guarantee: no-fail
SH::ensureVomsProxy
void ensureVomsProxy()
ensure that we have a valid VOMS proxy available
Definition: GridTools.cxx:213
ReadFromCoolCompare.fd
fd
Definition: ReadFromCoolCompare.py:196
ThrowMsg.h
EL::VomsProxySvc::setupJob
virtual StatusCode setupJob(Job &job) override
effects: give the algorithm a chance to intialize the job with anything this algorithm needs.
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
EL::VomsProxySvc::m_proxyData
std::string m_proxyData
the data to place inside the proxy file
Definition: VomsProxySvc.h:66
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
str
Definition: BTagTrackIpAccessor.cxx:11
VomsProxySvc.h
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition: PrintMsg.h:58
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition: Assert.h:229