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