]> git.proxmox.com Git - ceph.git/blame - ceph/src/common/fd.cc
import ceph quincy 17.2.6
[ceph.git] / ceph / src / common / fd.cc
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3/*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2004-2012 Inktank
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15#include "include/compat.h"
7c673cae
FG
16#include "debug.h"
17#include "errno.h"
18
f67539c2 19#ifndef _WIN32
7c673cae
FG
20void dump_open_fds(CephContext *cct)
21{
11fdf7f2
TL
22#ifdef __APPLE__
23 const char *fn = "/dev/fd";
24#else
7c673cae 25 const char *fn = PROCPREFIX "/proc/self/fd";
11fdf7f2 26#endif
7c673cae
FG
27 DIR *d = opendir(fn);
28 if (!d) {
29 lderr(cct) << "dump_open_fds unable to open " << fn << dendl;
30 return;
31 }
32 struct dirent *de = nullptr;
33
34 int n = 0;
35 while ((de = ::readdir(d))) {
36 if (de->d_name[0] == '.')
37 continue;
38 char path[PATH_MAX];
39 snprintf(path, sizeof(path), "%s/%s", fn, de->d_name);
40 char target[PATH_MAX];
41 ssize_t r = readlink(path, target, sizeof(target) - 1);
42 if (r < 0) {
43 r = -errno;
44 lderr(cct) << "dump_open_fds unable to readlink " << path << ": " << cpp_strerror(r) << dendl;
45 continue;
46 }
47 target[r] = 0;
48 lderr(cct) << "dump_open_fds " << de->d_name << " -> " << target << dendl;
49 n++;
50 }
51 lderr(cct) << "dump_open_fds dumped " << n << " open files" << dendl;
52
53 closedir(d);
54}
f67539c2
TL
55#else
56void dump_open_fds(CephContext *cct)
57{
58}
59#endif