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
16#include <errno.h>
17#include <unistd.h>
18#include <sys/types.h>
19#include <sys/stat.h>
20#include <fcntl.h>
21#include <unistd.h>
22#include <sys/types.h>
23#include <fstream>
24#include <TSystem.h>
25
26//
27// method implementations
28//
29
31
32namespace EL
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
macros for messaging and checking status codes
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
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