YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/util/main_util.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
13
// Utilities to be used in the main() function.
14
15
#ifndef YB_UTIL_MAIN_UTIL_H
16
#define YB_UTIL_MAIN_UTIL_H
17
18
#include <fcntl.h>
19
#include <string.h>
20
21
#include <cstdarg>
22
#include <cstdlib>
23
#include <iostream>
24
25
#include "yb/gutil/strings/split.h"
26
27
#include "yb/util/status_fwd.h"
28
#include "yb/util/env.h"
29
#include "yb/util/faststring.h"
30
#include "yb/util/fault_injection.h"
31
#include "yb/util/logging.h"
32
#include "yb/util/path_util.h"
33
34
namespace yb {
35
36
// If the given status is not OK, log or print the status and return from the main() function.
37
75.8k
#define LOG_AND_RETURN_FROM_MAIN_NOT_OK(status) do { \
38
75.8k
    auto&& _status = (status); \
39
75.8k
    if (!_status.ok()) { \
40
1
      if (IsLoggingInitialized()) { \
41
1
        LOG(FATAL) << ToStatus(_status); \
42
1
      } else { \
43
0
        std::cerr << ToStatus(_status) << std::endl; \
44
0
      } \
45
1
      return EXIT_FAILURE; \
46
1
    } \
47
75.8k
  } while (
false75.8k
)
48
49
50
// Given a status, return a copy of it.
51
// For use in the above macro, so it works with both Status and Result.
52
1
inline Status ToStatus(const Status& status) {
53
1
  return status;
54
1
}
55
56
// Generic template to extract status from a result, to be used in the above macro.
57
template<class T>
58
0
Status ToStatus(const Result<T>& result) {
59
0
  return result.status();
60
0
}
Unexecuted instantiation: yb::Status yb::ToStatus<yb::master::MasterOptions>(yb::Result<yb::master::MasterOptions> const&)
Unexecuted instantiation: yb::Status yb::ToStatus<yb::tserver::TabletServerOptions>(yb::Result<yb::tserver::TabletServerOptions> const&)
Unexecuted instantiation: yb::Status yb::ToStatus<yb::pgwrapper::PgProcessConf>(yb::Result<yb::pgwrapper::PgProcessConf> const&)
Unexecuted instantiation: yb::Status yb::ToStatus<std::__1::vector<yb::HostPort, std::__1::allocator<yb::HostPort> > >(yb::Result<std::__1::vector<yb::HostPort, std::__1::allocator<yb::HostPort> > > const&)
61
62
} // namespace yb
63
64
#endif // YB_UTIL_MAIN_UTIL_H