1 /*
2  * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
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 
16 #ifndef OHOS_FILEMGMT_BACKUP_B_GUARD_SIGNAL_H
17 #define OHOS_FILEMGMT_BACKUP_B_GUARD_SIGNAL_H
18 
19 /**
20  * @file b_guard_signal.h
21  * @brief 异常安全的临时调整信号处理程序方法
22  *
23  */
24 
25 #include <csignal>
26 
27 #include "nocopyable.h"
28 
29 namespace OHOS::FileManagement::Backup {
30 class BGuardSignal final : protected NoCopyable {
31 public:
32     /**
33      * @brief 构造器,其中会把给定信号的处理程序重置为默认值
34      *
35      * @param sig 给定信号
36      */
37     explicit BGuardSignal(int sig);
38 
39     /**
40      * @brief 析构器,其中会还原给定信号的处理程序
41      *
42      */
43     ~BGuardSignal() final;
44 
45 private:
46     BGuardSignal() = delete;
47     sighandler_t prevHandler_ {nullptr};
48     int sig_ {-1};
49 };
50 } // namespace OHOS::FileManagement::Backup
51 
52 #endif // OHOS_FILEMGMT_BACKUP_B_GUARD_SIGNAL_H