2022-09-06 19:14:07 -04:00
|
|
|
// Copyright 2017 The Crashpad Authors
|
2017-12-19 12:03:54 -08:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2018-02-20 13:07:16 -08:00
|
|
|
#include "util/linux/scoped_pr_set_ptracer.h"
|
2017-12-19 12:03:54 -08:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/prctl.h>
|
|
|
|
|
2018-02-20 13:07:16 -08:00
|
|
|
#include "base/logging.h"
|
2017-12-19 12:03:54 -08:00
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
2018-02-20 13:07:16 -08:00
|
|
|
ScopedPrSetPtracer::ScopedPrSetPtracer(pid_t pid, bool may_log)
|
|
|
|
: success_(false), may_log_(may_log) {
|
2017-12-19 12:03:54 -08:00
|
|
|
success_ = prctl(PR_SET_PTRACER, pid, 0, 0, 0) == 0;
|
2018-02-20 13:07:16 -08:00
|
|
|
PLOG_IF(ERROR, !success_ && may_log && errno != EINVAL) << "prctl";
|
2017-12-19 12:03:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
ScopedPrSetPtracer::~ScopedPrSetPtracer() {
|
|
|
|
if (success_) {
|
2018-02-20 13:07:16 -08:00
|
|
|
int res = prctl(PR_SET_PTRACER, 0, 0, 0, 0);
|
|
|
|
PLOG_IF(ERROR, res != 0 && may_log_) << "prctl";
|
2017-12-19 12:03:54 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace crashpad
|