Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch for v16.2.9 #142

Open
wants to merge 2 commits into
base: origin-v16.2.9-1733599564
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/ceph-crash.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
# vim: ts=4 sw=4 smarttab expandtab

import argparse
import grp
import logging
import os
import pwd
import signal
import socket
import subprocess
Expand Down Expand Up @@ -48,7 +50,8 @@ def post_crash(path):
stderr=subprocess.PIPE,
)
f = open(os.path.join(path, 'meta'), 'rb')
stderr = pr.communicate(input=f.read())
(_, stderr) = pr.communicate(input=f.read())
stderr = stderr.decode()
rc = pr.wait()
f.close()
if rc != 0 or stderr != "":
Expand Down Expand Up @@ -83,8 +86,25 @@ def handler(signum):
print('*** Interrupted with signal %d ***' % signum)
sys.exit(0)

def drop_privs():
if os.getuid() == 0:
try:
ceph_uid = pwd.getpwnam("ceph").pw_uid
ceph_gid = grp.getgrnam("ceph").gr_gid
os.setgroups([])
os.setgid(ceph_gid)
os.setuid(ceph_uid)
except Exception as e:
log.error(f"Unable to drop privileges: {e}")
sys.exit(1)


def main():
global auth_names

# run as unprivileged ceph user
drop_privs()

# exit code 0 on SIGINT, SIGTERM
signal.signal(signal.SIGINT, handler)
signal.signal(signal.SIGTERM, handler)
Expand All @@ -103,7 +123,10 @@ def main():

log.info("monitoring path %s, delay %ds" % (args.path, args.delay * 60.0))
while True:
scrape_path(args.path)
try:
scrape_path(args.path)
except Exception as e:
log.error(f"Error scraping {args.path}: {e}")
if args.delay == 0:
sys.exit(0)
time.sleep(args.delay * 60)
Expand Down