Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/mkfifo.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* mkfifo -- make fifo's (named pipes) | - | ||||||||||||
2 | Copyright (C) 1990-2018 Free Software Foundation, Inc. | - | ||||||||||||
3 | - | |||||||||||||
4 | This program is free software: you can redistribute it and/or modify | - | ||||||||||||
5 | it under the terms of the GNU General Public License as published by | - | ||||||||||||
6 | the Free Software Foundation, either version 3 of the License, or | - | ||||||||||||
7 | (at your option) any later version. | - | ||||||||||||
8 | - | |||||||||||||
9 | This program is distributed in the hope that it will be useful, | - | ||||||||||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | - | ||||||||||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | - | ||||||||||||
12 | GNU General Public License for more details. | - | ||||||||||||
13 | - | |||||||||||||
14 | You should have received a copy of the GNU General Public License | - | ||||||||||||
15 | along with this program. If not, see <https://www.gnu.org/licenses/>. */ | - | ||||||||||||
16 | - | |||||||||||||
17 | /* David MacKenzie <djm@ai.mit.edu> */ | - | ||||||||||||
18 | - | |||||||||||||
19 | #include <config.h> | - | ||||||||||||
20 | #include <stdio.h> | - | ||||||||||||
21 | #include <getopt.h> | - | ||||||||||||
22 | #include <sys/types.h> | - | ||||||||||||
23 | #include <selinux/selinux.h> | - | ||||||||||||
24 | - | |||||||||||||
25 | #include "system.h" | - | ||||||||||||
26 | #include "die.h" | - | ||||||||||||
27 | #include "error.h" | - | ||||||||||||
28 | #include "modechange.h" | - | ||||||||||||
29 | #include "quote.h" | - | ||||||||||||
30 | #include "selinux.h" | - | ||||||||||||
31 | #include "smack.h" | - | ||||||||||||
32 | - | |||||||||||||
33 | /* The official name of this program (e.g., no 'g' prefix). */ | - | ||||||||||||
34 | #define PROGRAM_NAME "mkfifo" | - | ||||||||||||
35 | - | |||||||||||||
36 | #define AUTHORS proper_name ("David MacKenzie") | - | ||||||||||||
37 | - | |||||||||||||
38 | static struct option const longopts[] = | - | ||||||||||||
39 | { | - | ||||||||||||
40 | {GETOPT_SELINUX_CONTEXT_OPTION_DECL}, | - | ||||||||||||
41 | {"mode", required_argument, NULL, 'm'}, | - | ||||||||||||
42 | {GETOPT_HELP_OPTION_DECL}, | - | ||||||||||||
43 | {GETOPT_VERSION_OPTION_DECL}, | - | ||||||||||||
44 | {NULL, 0, NULL, 0} | - | ||||||||||||
45 | }; | - | ||||||||||||
46 | - | |||||||||||||
47 | void | - | ||||||||||||
48 | usage (int status) | - | ||||||||||||
49 | { | - | ||||||||||||
50 | if (status != EXIT_SUCCESS)
| 1-2 | ||||||||||||
51 | emit_try_help (); executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
52 | else | - | ||||||||||||
53 | { | - | ||||||||||||
54 | printf (_("Usage: %s [OPTION]... NAME...\n"), program_name); | - | ||||||||||||
55 | fputs (_("\ | - | ||||||||||||
56 | Create named pipes (FIFOs) with the given NAMEs.\n\ | - | ||||||||||||
57 | "), stdout); | - | ||||||||||||
58 | - | |||||||||||||
59 | emit_mandatory_arg_note (); | - | ||||||||||||
60 | - | |||||||||||||
61 | fputs (_("\ | - | ||||||||||||
62 | -m, --mode=MODE set file permission bits to MODE, not a=rw - umask\n\ | - | ||||||||||||
63 | "), stdout); | - | ||||||||||||
64 | fputs (_("\ | - | ||||||||||||
65 | -Z set the SELinux security context to default type\n\ | - | ||||||||||||
66 | --context[=CTX] like -Z, or if CTX is specified then set the SELinux\n\ | - | ||||||||||||
67 | or SMACK security context to CTX\n\ | - | ||||||||||||
68 | "), stdout); | - | ||||||||||||
69 | fputs (HELP_OPTION_DESCRIPTION, stdout); | - | ||||||||||||
70 | fputs (VERSION_OPTION_DESCRIPTION, stdout); | - | ||||||||||||
71 | emit_ancillary_info (PROGRAM_NAME); | - | ||||||||||||
72 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
73 | exit (status); executed 3 times by 1 test: exit (status); Executed by:
| 3 | ||||||||||||
74 | } | - | ||||||||||||
75 | - | |||||||||||||
76 | int | - | ||||||||||||
77 | main (int argc, char **argv) | - | ||||||||||||
78 | { | - | ||||||||||||
79 | mode_t newmode; | - | ||||||||||||
80 | char const *specified_mode = NULL; | - | ||||||||||||
81 | int exit_status = EXIT_SUCCESS; | - | ||||||||||||
82 | int optc; | - | ||||||||||||
83 | char const *scontext = NULL; | - | ||||||||||||
84 | bool set_security_context = false; | - | ||||||||||||
85 | - | |||||||||||||
86 | initialize_main (&argc, &argv); | - | ||||||||||||
87 | set_program_name (argv[0]); | - | ||||||||||||
88 | setlocale (LC_ALL, ""); | - | ||||||||||||
89 | bindtextdomain (PACKAGE, LOCALEDIR); | - | ||||||||||||
90 | textdomain (PACKAGE); | - | ||||||||||||
91 | - | |||||||||||||
92 | atexit (close_stdout); | - | ||||||||||||
93 | - | |||||||||||||
94 | while ((optc = getopt_long (argc, argv, "m:Z", longopts, NULL)) != -1)
| 2-7 | ||||||||||||
95 | { | - | ||||||||||||
96 | switch (optc) | - | ||||||||||||
97 | { | - | ||||||||||||
98 | case 'm': never executed: case 'm': | 0 | ||||||||||||
99 | specified_mode = optarg; | - | ||||||||||||
100 | break; never executed: break; | 0 | ||||||||||||
101 | case 'Z': never executed: case 'Z': | 0 | ||||||||||||
102 | if (is_smack_enabled ())
| 0 | ||||||||||||
103 | { | - | ||||||||||||
104 | /* We don't yet support -Z to restore context with SMACK. */ | - | ||||||||||||
105 | scontext = optarg; | - | ||||||||||||
106 | } never executed: end of block | 0 | ||||||||||||
107 | else if (is_selinux_enabled () > 0)
| 0 | ||||||||||||
108 | { | - | ||||||||||||
109 | if (optarg)
| 0 | ||||||||||||
110 | scontext = optarg; never executed: scontext = optarg; | 0 | ||||||||||||
111 | else | - | ||||||||||||
112 | set_security_context = true; never executed: set_security_context = 1 ; | 0 | ||||||||||||
113 | } | - | ||||||||||||
114 | else if (optarg)
| 0 | ||||||||||||
115 | { | - | ||||||||||||
116 | error (0, 0, | - | ||||||||||||
117 | _("warning: ignoring --context; " | - | ||||||||||||
118 | "it requires an SELinux/SMACK-enabled kernel")); | - | ||||||||||||
119 | } never executed: end of block | 0 | ||||||||||||
120 | break; never executed: break; | 0 | ||||||||||||
121 | case_GETOPT_HELP_CHAR; never executed: break; executed 2 times by 1 test: case GETOPT_HELP_CHAR: Executed by:
| 0-2 | ||||||||||||
122 | case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); executed 4 times by 1 test: exit ( 0 ); Executed by:
never executed: break; executed 4 times by 1 test: case GETOPT_VERSION_CHAR: Executed by:
| 0-4 | ||||||||||||
123 | default: executed 1 time by 1 test: default: Executed by:
| 1 | ||||||||||||
124 | usage (EXIT_FAILURE); | - | ||||||||||||
125 | } never executed: end of block | 0 | ||||||||||||
126 | } | - | ||||||||||||
127 | - | |||||||||||||
128 | if (optind == argc)
| 0-2 | ||||||||||||
129 | { | - | ||||||||||||
130 | error (0, 0, _("missing operand")); | - | ||||||||||||
131 | usage (EXIT_FAILURE); | - | ||||||||||||
132 | } never executed: end of block | 0 | ||||||||||||
133 | - | |||||||||||||
134 | if (scontext)
| 0-2 | ||||||||||||
135 | { | - | ||||||||||||
136 | int ret = 0; | - | ||||||||||||
137 | if (is_smack_enabled ())
| 0 | ||||||||||||
138 | ret = smack_set_label_for_self (scontext); never executed: ret = smack_set_label_for_self (scontext); | 0 | ||||||||||||
139 | else | - | ||||||||||||
140 | ret = setfscreatecon (se_const (scontext)); never executed: ret = setfscreatecon (se_const (scontext)); | 0 | ||||||||||||
141 | - | |||||||||||||
142 | if (ret < 0)
| 0 | ||||||||||||
143 | die (EXIT_FAILURE, errno, never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"failed to set default file creation context to %s\", 5), quote (scontext)), assume (false))" ")"); int _gl_dummy; })) ? ((erro... (scontext)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "failed to set default file creation context to %s" , 5) , quote (scontext)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ; | 0 | ||||||||||||
144 | _("failed to set default file creation context to %s"), never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"failed to set default file creation context to %s\", 5), quote (scontext)), assume (false))" ")"); int _gl_dummy; })) ? ((erro... (scontext)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "failed to set default file creation context to %s" , 5) , quote (scontext)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ; | 0 | ||||||||||||
145 | quote (scontext)); never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"failed to set default file creation context to %s\", 5), quote (scontext)), assume (false))" ")"); int _gl_dummy; })) ? ((erro... (scontext)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "failed to set default file creation context to %s" , 5) , quote (scontext)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ; | 0 | ||||||||||||
146 | } never executed: end of block | 0 | ||||||||||||
147 | - | |||||||||||||
148 | newmode = MODE_RW_UGO; | - | ||||||||||||
149 | if (specified_mode)
| 0-2 | ||||||||||||
150 | { | - | ||||||||||||
151 | mode_t umask_value; | - | ||||||||||||
152 | struct mode_change *change = mode_compile (specified_mode); | - | ||||||||||||
153 | if (!change)
| 0 | ||||||||||||
154 | die (EXIT_FAILURE, 0, _("invalid mode")); never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"invalid mode\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "invalid mode" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "invalid mode" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))); | 0 | ||||||||||||
155 | umask_value = umask (0); | - | ||||||||||||
156 | umask (umask_value); | - | ||||||||||||
157 | newmode = mode_adjust (newmode, false, umask_value, change, NULL); | - | ||||||||||||
158 | free (change); | - | ||||||||||||
159 | if (newmode & ~S_IRWXUGO)
| 0 | ||||||||||||
160 | die (EXIT_FAILURE, 0, never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"mode must specify only file permission bits\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "mode must specify only file permission bits" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "mode must specify only file permission bits" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ; | 0 | ||||||||||||
161 | _("mode must specify only file permission bits")); never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"mode must specify only file permission bits\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "mode must specify only file permission bits" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "mode must specify only file permission bits" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ; | 0 | ||||||||||||
162 | } never executed: end of block | 0 | ||||||||||||
163 | - | |||||||||||||
164 | for (; optind < argc; ++optind)
| 2 | ||||||||||||
165 | { | - | ||||||||||||
166 | if (set_security_context)
| 0-2 | ||||||||||||
167 | defaultcon (argv[optind], S_IFIFO); never executed: defaultcon (argv[optind], 0010000 ); | 0 | ||||||||||||
168 | if (mkfifo (argv[optind], newmode) != 0)
| 0-2 | ||||||||||||
169 | { | - | ||||||||||||
170 | error (0, errno, _("cannot create fifo %s"), quoteaf (argv[optind])); | - | ||||||||||||
171 | exit_status = EXIT_FAILURE; | - | ||||||||||||
172 | } never executed: end of block | 0 | ||||||||||||
173 | else if (specified_mode && lchmod (argv[optind], newmode) != 0)
| 0-2 | ||||||||||||
174 | { | - | ||||||||||||
175 | error (0, errno, _("cannot set permissions of %s"), | - | ||||||||||||
176 | quoteaf (argv[optind])); | - | ||||||||||||
177 | exit_status = EXIT_FAILURE; | - | ||||||||||||
178 | } never executed: end of block | 0 | ||||||||||||
179 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
180 | - | |||||||||||||
181 | return exit_status; executed 2 times by 1 test: return exit_status; Executed by:
| 2 | ||||||||||||
182 | } | - | ||||||||||||
Source code | Switch to Preprocessed file |