Debian Codegraph @

src/basic/runtime-scope.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "basic-forward.h"
5
6 typedef enum RuntimeScope {
7 RUNTIME_SCOPE_SYSTEM, /* for the system */
8 RUNTIME_SCOPE_USER, /* for a user */
9 RUNTIME_SCOPE_GLOBAL, /* for all users */
10 _RUNTIME_SCOPE_MAX,
11 _RUNTIME_SCOPE_INVALID = -EINVAL,
12 } RuntimeScope;
13
14 DECLARE_STRING_TABLE_LOOKUP(runtime_scope, RuntimeScope);
15 DECLARE_STRING_TABLE_LOOKUP_TO_STRING(runtime_scope_cmdline_option, RuntimeScope);
16
17 static inline mode_t runtime_scope_to_socket_mode(RuntimeScope scope) {
18 /* Returns the right socket mode to use for binding AF_UNIX sockets intended for the specified
19 * scope. If system mode is selected the whole system can connect to it, if user mode is selected
20 * only the user can connect to it. */
21
22 switch (scope) {
23 case RUNTIME_SCOPE_SYSTEM:
24 return 0666;
25
26 case RUNTIME_SCOPE_USER:
27 return 0600;
28
29 default:
30 return MODE_INVALID;
31 }
32 }