ATLAS Offline Software
Loading...
Searching...
No Matches
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
6
7//
8// includes
9//
10
12
17#include <errno.h>
18#include <unistd.h>
19#include <sys/types.h>
20#include <sys/stat.h>
21#include <fcntl.h>
22#include <unistd.h>
23#include <sys/types.h>
24#include <fstream>
25#include <TSystem.h>
26
27//
28// method implementations
29//
30
32
33namespace EL
34{
35 const std::string& VomsProxySvc ::
36 algServiceName ()
37 {
38 static std::string result = "VomsProxySvc";
39 return result;
40 }
41
42
43
44 void VomsProxySvc ::
45 testInvariant () const
46 {
47 RCU_INVARIANT (this != nullptr);
48 }
49
50
51
52 StatusCode VomsProxySvc ::
53 setupJob (Job& /*job*/)
54 {
57
58 const char *X509_USER_PROXY = getenv ("X509_USER_PROXY");
59 std::string file;
60 if (X509_USER_PROXY)
61 {
62 file = X509_USER_PROXY;
63 } else
64 {
65 std::ostringstream str;
66 str << "/tmp/x509up_u" << getuid();
67 file = str.str();
68 }
69 if (file.empty() || gSystem->AccessPathName (file.c_str()) != false)
70 RCU_THROW_MSG ("failed to find X509 proxy file: " + file);
71
72 {
73 std::ifstream stream (file);
74 char ch;
75 while (stream.get (ch))
76 m_proxyData += ch;
77 if (!stream.eof())
78 RCU_THROW_MSG ("error reading: " + file);
79 }
80
81 return StatusCode::FAILURE;
82 }
83
84
85
86 const char *VomsProxySvc ::
87 GetName () const
88 {
89 RCU_READ_INVARIANT (this);
90 return name().c_str();
91 }
92
93
94
95 StatusCode VomsProxySvc ::
96 histInitialize ()
97 {
98 RCU_READ_INVARIANT (this);
99 if (!SH::checkVomsProxy())
100 {
101 int fd = open (m_fileName.c_str(), O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
102 if (fd == -1)
103 {
104 auto myerrno = errno;
105 ANA_MSG_ERROR ("failed to create file \"" << m_fileName << "\": " << strerror (myerrno));
106 return EL::StatusCode::FAILURE;
107 }
108 int written = write (fd, &m_proxyData[0], m_proxyData.size());
109 if (written == -1)
110 {
111 auto myerrno = errno;
112 ANA_MSG_ERROR ("failed to write to file \"" << m_fileName << "\": " << strerror (myerrno));
113 close (fd);
114 return EL::StatusCode::FAILURE;
115 }
116 if (written < int (m_proxyData.size()))
117 {
118 ANA_MSG_ERROR ("only wrote " << written << " of " << m_proxyData.size() << " bytes to file \"" << m_fileName << "\"");
119 close (fd);
120 return EL::StatusCode::FAILURE;
121 }
122 if (close (fd) == -1)
123 {
124 auto myerrno = errno;
125 ANA_MSG_ERROR ("failed to close file \"" << m_fileName << "\": " << strerror (myerrno));
126 return EL::StatusCode::FAILURE;
127 }
128 if (setenv ("X509_USER_PROXY", m_fileName.c_str(), true) == -1)
129 {
130 auto myerrno = errno;
131 ANA_MSG_ERROR ("failed to set X509_USER_PROXY: " << strerror (myerrno));
132 return EL::StatusCode::FAILURE;
133 }
134 }
135 return EL::StatusCode::SUCCESS;
136 }
137}
#define RCU_INVARIANT(x)
Definition Assert.h:196
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:226
#define RCU_READ_INVARIANT(x)
Definition Assert.h:224
macros for messaging and checking status codes
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:53
ClassImp(EL::VomsProxySvc) namespace EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
::StatusCode StatusCode
StatusCode definition for legacy code.
void ensureVomsProxy()
ensure that we have a valid VOMS proxy available
bool checkVomsProxy()
return whether we have a valid VOMS proxy available
TFile * file