1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2011 New Dream Network
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.
16 #include "common/code_environment.h"
24 #ifdef HAVE_SYS_PRCTL_H
25 #include <sys/prctl.h>
28 code_environment_t g_code_env
= CODE_ENVIRONMENT_UTILITY
;
30 extern "C" const char *code_environment_to_str(enum code_environment_t e
)
33 case CODE_ENVIRONMENT_UTILITY
:
34 return "CODE_ENVIRONMENT_UTILITY";
35 case CODE_ENVIRONMENT_DAEMON
:
36 return "CODE_ENVIRONMENT_DAEMON";
37 case CODE_ENVIRONMENT_LIBRARY
:
38 return "CODE_ENVIRONMENT_LIBRARY";
44 std::ostream
&operator<<(std::ostream
&oss
, enum code_environment_t e
)
46 oss
<< code_environment_to_str(e
);
50 #if defined(HAVE_SYS_PRCTL_H) && defined(PR_GET_NAME) /* Since 2.6.11 */
52 int get_process_name(char *buf
, int len
)
55 /* The man page discourages using this prctl with a buffer shorter
56 * than 16 bytes. With a 16-byte buffer, it might not be
61 return prctl(PR_GET_NAME
, buf
);
66 int get_process_name(char *buf
, int len
)
73 std::string
get_process_name_cpp()
76 if (get_process_name(buf
, sizeof(buf
))) {
79 return std::string(buf
);