Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
os-info.cc
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "util/os-info.h"
16 
17 #include <iostream>
18 #include <fstream>
19 #include <sstream>
20 #include <stdlib.h>
21 #include <string.h>
22 
23 #include <unistd.h>
24 
25 #include "common/names.h"
26 
27 namespace impala {
28 
29 bool OsInfo::initialized_ = false;
30 string OsInfo::os_version_ = "Unknown";
31 
32 void OsInfo::Init() {
33  DCHECK(!initialized_);
34  // Read from /proc/version
35  ifstream version("/proc/version", ios::in);
36  if (version.good()) getline(version, os_version_);
37  if (version.is_open()) version.close();
38  initialized_ = true;
39 }
40 
42  DCHECK(initialized_);
43  stringstream stream;
44  stream << "OS version: " << os_version_ << endl;
45  return stream.str();
46 }
47 
48 }
static void Init()
Initialize OsInfo.
Definition: os-info.cc:32
static std::string os_version_
Definition: os-info.h:38
static bool initialized_
Definition: os-info.h:37
static std::string DebugString()
Definition: os-info.cc:41