YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/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
50.8k
#define LOG_AND_RETURN_FROM_MAIN_NOT_OK(status) do { \
38
50.8k
    auto&& _status = (status); \
39
50.8k
    if (!_status.ok()) { \
40
0
      if (IsLoggingInitialized()) { \
41
0
        LOG(FATAL) << ToStatus(_status); \
42
0
      } else { \
43
0
        std::cerr << ToStatus(_status) << std::endl; \
44
0
      } \
45
0
      return EXIT_FAILURE; \
46
0
    } \
47
50.8k
  } while (false)
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
0
inline Status ToStatus(const Status& status) {
53
0
  return status;
54
0
}
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: _ZN2yb8ToStatusINS_6master13MasterOptionsEEENS_6StatusERKNS_6ResultIT_EE
Unexecuted instantiation: _ZN2yb8ToStatusINS_7tserver19TabletServerOptionsEEENS_6StatusERKNS_6ResultIT_EE
Unexecuted instantiation: _ZN2yb8ToStatusINS_9pgwrapper13PgProcessConfEEENS_6StatusERKNS_6ResultIT_EE
Unexecuted instantiation: _ZN2yb8ToStatusINSt3__16vectorINS_8HostPortENS1_9allocatorIS3_EEEEEENS_6StatusERKNS_6ResultIT_EE
61
62
} // namespace yb
63
64
#endif // YB_UTIL_MAIN_UTIL_H