| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/users.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /* GNU's users. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | Copyright (C) 1992-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 | /* Written by jla; revised by djm */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | #include <config.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | #include <getopt.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | #include <stdio.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | #include <sys/types.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | #include "system.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | #include "die.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | #include "error.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | #include "long-options.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | #include "quote.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | #include "readutmp.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | /* The official name of this program (e.g., no 'g' prefix). */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | #define PROGRAM_NAME "users" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | #define AUTHORS \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | proper_name ("Joseph Arceneaux"), \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | proper_name ("David MacKenzie") | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | static struct option const long_options[] = | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | {NULL, 0, NULL, 0} | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | }; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | static int | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | userid_compare (const void *v_a, const void *v_b) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | char **a = (char **) v_a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | char **b = (char **) v_b; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | return strcmp (*a, *b); never executed: return __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p ( *a ) && __builtin_constant_p ( *b ) && (__s1_len = __builtin_strlen ( *a ), __s2_len = __builtin_strlen ( *b ), (!((size_t)(const void *)(( *a ) + 1) - (size_t)(const void *)( *a )...ult == 0) { __result = (((const unsigned char *) (const char *) ( *b ))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ( *b ))[3] - __s2[3]); } } __result; }))) : __builtin_strcmp ( *a , *b )))); }) ;never executed: __result = (((const unsigned char *) (const char *) ( *a ))[3] - __s2[3]);never executed: end of blocknever executed: end of blocknever executed: __result = (((const unsigned char *) (const char *) ( *b ))[3] - __s2[3]);never executed: end of blocknever executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | static void | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | list_entries_users (size_t n, const STRUCT_UTMP *this) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | char **u = xnmalloc (n, sizeof *u); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | size_t i; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | size_t n_entries = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | while (n--)
| 1-4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | if (IS_USER_PROCESS (this)) dead code: ((this)->ut_tv.tv_sec) != 0
| - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | char *trimmed_name; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | trimmed_name = extract_trimmed_name (this); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | u[n_entries] = trimmed_name; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | ++n_entries; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | this++; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | qsort (u, n_entries, sizeof (u[0]), userid_compare); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | for (i = 0; i < n_entries; i++)
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | char c = (i < n_entries - 1 ? ' ' : '\n');
| 0-1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | fputs (u[i], stdout); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | putchar (c); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | for (i = 0; i < n_entries; i++)
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | free (u[i]); executed 1 time by 1 test: free (u[i]);Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | free (u); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | /* Display a list of users on the system, according to utmp file FILENAME. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | Use read_utmp OPTIONS to read FILENAME. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | static void | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | users (const char *filename, int options) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | size_t n_users; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | STRUCT_UTMP *utmp_buf; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | if (read_utmp (filename, &n_users, &utmp_buf, options) != 0)
| 0-1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | die (EXIT_FAILURE, errno, "%s", quotef (filename)); never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), \"%s\", quotearg_n_style_colon (0, shell_escape_quoting_style, filename)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , (*__errno_location ...(0, shell_escape_quoting_style, filename)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , "%s", quotearg_n_style_colon (0, shell_escape_quoting_style, filename)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | list_entries_users (n_users, utmp_buf); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | free (utmp_buf); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | void | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | usage (int status) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | if (status != EXIT_SUCCESS)
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | emit_try_help (); executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | printf (_("Usage: %s [OPTION]... [FILE]\n"), program_name); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | printf (_("\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | Output who is currently logged in according to FILE.\n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | If FILE is not specified, use %s. %s as FILE is common.\n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | \n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | "), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | UTMP_FILE, WTMP_FILE); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | fputs (HELP_OPTION_DESCRIPTION, stdout); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | fputs (VERSION_OPTION_DESCRIPTION, stdout); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | emit_ancillary_info (PROGRAM_NAME); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | exit (status); executed 6 times by 1 test: exit (status);Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | int | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | main (int argc, char **argv) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | initialize_main (&argc, &argv); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | set_program_name (argv[0]); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | setlocale (LC_ALL, ""); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | bindtextdomain (PACKAGE, LOCALEDIR); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | textdomain (PACKAGE); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | atexit (close_stdout); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | usage, AUTHORS, (char const *) NULL); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | if (getopt_long (argc, argv, "", long_options, NULL) != -1)
| 1-3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | usage (EXIT_FAILURE); executed 3 times by 1 test: usage ( 1 );Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | switch (argc - optind) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | case 0: /* users */ executed 1 time by 1 test: case 0:Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | users (UTMP_FILE, READ_UTMP_CHECK_PIDS); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | case 1: /* users <utmp file> */ never executed: case 1: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | users (argv[optind], 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | default: /* lose */ never executed: default: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | error (0, 0, _("extra operand %s"), quote (argv[optind + 1])); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | usage (EXIT_FAILURE); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | return EXIT_SUCCESS; executed 1 time by 1 test: return 0 ;Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |