OpenCoverage

pinky.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/pinky.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* GNU's pinky.-
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/* Created by hacking who.c by Kaveh Ghazi ghazi@caip.rutgers.edu */-
18-
19#include <config.h>-
20#include <getopt.h>-
21#include <pwd.h>-
22#include <stdio.h>-
23-
24#include <sys/types.h>-
25#include "system.h"-
26-
27#include "canon-host.h"-
28#include "die.h"-
29#include "error.h"-
30#include "hard-locale.h"-
31#include "readutmp.h"-
32-
33/* The official name of this program (e.g., no 'g' prefix). */-
34#define PROGRAM_NAME "pinky"-
35-
36#define AUTHORS \-
37 proper_name ("Joseph Arceneaux"), \-
38 proper_name ("David MacKenzie"), \-
39 proper_name ("Kaveh Ghazi")-
40-
41/* If true, display the hours:minutes since each user has touched-
42 the keyboard, or blank if within the last minute, or days followed-
43 by a 'd' if not within the last day. */-
44static bool include_idle = true;-
45-
46/* If true, display a line at the top describing each field. */-
47static bool include_heading = true;-
48-
49/* if true, display the user's full name from pw_gecos. */-
50static bool include_fullname = true;-
51-
52/* if true, display the user's ~/.project file when doing long format. */-
53static bool include_project = true;-
54-
55/* if true, display the user's ~/.plan file when doing long format. */-
56static bool include_plan = true;-
57-
58/* if true, display the user's home directory and shell-
59 when doing long format. */-
60static bool include_home_and_shell = true;-
61-
62/* if true, use the "short" output format. */-
63static bool do_short_format = true;-
64-
65/* if true, display the ut_host field. */-
66#ifdef HAVE_UT_HOST-
67static bool include_where = true;-
68#endif-
69-
70/* The strftime format to use for login times, and its expected-
71 output width. */-
72static char const *time_format;-
73static int time_format_width;-
74-
75static struct option const longopts[] =-
76{-
77 {GETOPT_HELP_OPTION_DECL},-
78 {GETOPT_VERSION_OPTION_DECL},-
79 {NULL, 0, NULL, 0}-
80};-
81-
82/* Count and return the number of ampersands in STR. */-
83-
84static size_t _GL_ATTRIBUTE_PURE-
85count_ampersands (const char *str)-
86{-
87 size_t count = 0;-
88 do-
89 {-
90 if (*str == '&')
*str == '&'Description
TRUEnever evaluated
FALSEevaluated 13 times by 1 test
Evaluated by:
  • pinky
0-13
91 count++;
never executed: count++;
0
92 } while (*str++);
executed 13 times by 1 test: end of block
Executed by:
  • pinky
*str++Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • pinky
FALSEevaluated 1 time by 1 test
Evaluated by:
  • pinky
1-13
93 return count;
executed 1 time by 1 test: return count;
Executed by:
  • pinky
1
94}-
95-
96/* Create a string (via xmalloc) which contains a full name by substituting-
97 for each ampersand in GECOS_NAME the USER_NAME string with its first-
98 character capitalized. The caller must ensure that GECOS_NAME contains-
99 no ','s. The caller also is responsible for free'ing the return value of-
100 this function. */-
101-
102static char *-
103create_fullname (const char *gecos_name, const char *user_name)-
104{-
105 size_t rsize = strlen (gecos_name) + 1;-
106 char *result;-
107 char *r;-
108 size_t ampersands = count_ampersands (gecos_name);-
109-
110 if (ampersands != 0)
ampersands != 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • pinky
0-1
111 {-
112 size_t ulen = strlen (user_name);-
113 size_t product = ampersands * ulen;-
114 rsize += product - ampersands;-
115 if (xalloc_oversized (ulen, ampersands) || rsize < product)
(__builtin_con...oc_count); }))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_constant_p (ulen)Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...p (ampersands)Description
TRUEnever evaluated
FALSEnever evaluated
rsize < productDescription
TRUEnever evaluated
FALSEnever evaluated
0
116 xalloc_die ();
never executed: xalloc_die ();
0
117 }
never executed: end of block
0
118-
119 r = result = xmalloc (rsize);-
120-
121 while (*gecos_name)
*gecos_nameDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • pinky
FALSEevaluated 1 time by 1 test
Evaluated by:
  • pinky
1-12
122 {-
123 if (*gecos_name == '&')
*gecos_name == '&'Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • pinky
0-12
124 {-
125 const char *uname = user_name;-
126 if (islower (to_uchar (*uname)))
((*__ctype_b_l...int) _ISlower)Description
TRUEnever evaluated
FALSEnever evaluated
0
127 *r++ = toupper (to_uchar (*uname++));
never executed: *r++ = (__extension__ ({ int __res; if (sizeof ( to_uchar (*uname++) ) > 1) { if (__builtin_constant_p ( to_uchar (*uname++) )) { int __c = ( to_uchar (*uname++) ); __res = __c < -128 || __c > 255 ? __c : (*__ctype_toupper_loc ())[__c]; } else __res = toupper ( to_uchar (*uname++) ); } else __res = (*__ctype_toupper_loc ())[(int) ( to_uchar (*uname++) )]; __res; })) ;
never executed: end of block
never executed: __res = toupper ( to_uchar (*uname++) );
never executed: __res = (*__ctype_toupper_loc ())[(int) ( to_uchar (*uname++) )];
sizeof ( to_uc...uname++) ) > 1Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...r (*uname++) )Description
TRUEnever evaluated
FALSEnever evaluated
__c < -128Description
TRUEnever evaluated
FALSEnever evaluated
__c > 255Description
TRUEnever evaluated
FALSEnever evaluated
0
128 while (*uname)
*unameDescription
TRUEnever evaluated
FALSEnever evaluated
0
129 *r++ = *uname++;
never executed: *r++ = *uname++;
0
130 }
never executed: end of block
0
131 else-
132 {-
133 *r++ = *gecos_name;-
134 }
executed 12 times by 1 test: end of block
Executed by:
  • pinky
12
135-
136 gecos_name++;-
137 }
executed 12 times by 1 test: end of block
Executed by:
  • pinky
12
138 *r = 0;-
139-
140 return result;
executed 1 time by 1 test: return result;
Executed by:
  • pinky
1
141}-
142-
143/* Return a string representing the time between WHEN and the time-
144 that this function is first run. */-
145-
146static const char *-
147idle_string (time_t when)-
148{-
149 static time_t now = 0;-
150 static char buf[INT_STRLEN_BOUND (long int) + 2];-
151 time_t seconds_idle;-
152-
153 if (now == 0)
now == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • pinky
FALSEnever evaluated
0-1
154 time (&now);
executed 1 time by 1 test: time (&now);
Executed by:
  • pinky
1
155-
156 seconds_idle = now - when;-
157 if (seconds_idle < 60) /* One minute. */
seconds_idle < 60Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • pinky
0-1
158 return " ";
never executed: return " ";
0
159 if (seconds_idle < (24 * 60 * 60)) /* One day. */
seconds_idle < (24 * 60 * 60)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • pinky
0-1
160 {-
161 int hours = seconds_idle / (60 * 60);-
162 int minutes = (seconds_idle % (60 * 60)) / 60;-
163 sprintf (buf, "%02d:%02d", hours, minutes);-
164 }
never executed: end of block
0
165 else-
166 {-
167 unsigned long int days = seconds_idle / (24 * 60 * 60);-
168 sprintf (buf, "%lud", days);-
169 }
executed 1 time by 1 test: end of block
Executed by:
  • pinky
1
170 return buf;
executed 1 time by 1 test: return buf;
Executed by:
  • pinky
1
171}-
172-
173/* Return a time string. */-
174static const char *-
175time_string (const STRUCT_UTMP *utmp_ent)-
176{-
177 static char buf[INT_STRLEN_BOUND (intmax_t) + sizeof "-%m-%d %H:%M"];-
178-
179 /* Don't take the address of UT_TIME_MEMBER directly.-
180 Ulrich Drepper wrote:-
181 "... GNU libc (and perhaps other libcs as well) have extended-
182 utmp file formats which do not use a simple time_t ut_time field.-
183 In glibc, ut_time is a macro which selects for backward compatibility-
184 the tv_sec member of a struct timeval value." */-
185 time_t t = UT_TIME_MEMBER (utmp_ent);-
186 struct tm *tmp = localtime (&t);-
187-
188 if (tmp)
tmpDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • pinky
FALSEnever evaluated
0-1
189 {-
190 strftime (buf, sizeof buf, time_format, tmp);-
191 return buf;
executed 1 time by 1 test: return buf;
Executed by:
  • pinky
1
192 }-
193 else-
194 return timetostr (t, buf);
never executed: return timetostr (t, buf);
0
195}-
196-
197/* Display a line of information about UTMP_ENT. */-
198-
199static void-
200print_entry (const STRUCT_UTMP *utmp_ent)-
201{-
202 struct stat stats;-
203 time_t last_change;-
204 char mesg;-
205-
206#define DEV_DIR_WITH_TRAILING_SLASH "/dev/"-
207#define DEV_DIR_LEN (sizeof (DEV_DIR_WITH_TRAILING_SLASH) - 1)-
208-
209 char line[sizeof (utmp_ent->ut_line) + DEV_DIR_LEN + 1];-
210 char *p = line;-
211-
212 /* Copy ut_line into LINE, prepending '/dev/' if ut_line is not-
213 already an absolute file name. Some system may put the full,-
214 absolute file name in ut_line. */-
215 if ( ! IS_ABSOLUTE_FILE_NAME (utmp_ent->ut_line))
(((utmp_ent->u...e)[0]) == '/')Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • pinky
0 != 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • pinky
0-1
216 p = stpcpy (p, DEV_DIR_WITH_TRAILING_SLASH);
executed 1 time by 1 test: p = stpcpy (p, "/dev/");
Executed by:
  • pinky
1
217 stzncpy (p, utmp_ent->ut_line, sizeof (utmp_ent->ut_line));-
218-
219 if (stat (line, &stats) == 0)
stat (line, &stats) == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • pinky
FALSEnever evaluated
0-1
220 {-
221 mesg = (stats.st_mode & S_IWGRP) ? ' ' : '*';
(stats.st_mode & (0200 >> 3) )Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • pinky
FALSEnever evaluated
0-1
222 last_change = stats.st_atime;-
223 }
executed 1 time by 1 test: end of block
Executed by:
  • pinky
1
224 else-
225 {-
226 mesg = '?';-
227 last_change = 0;-
228 }
never executed: end of block
0
229-
230 printf ("%-8.*s", UT_USER_SIZE, UT_USER (utmp_ent));-
231-
232 if (include_fullname)
include_fullnameDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • pinky
FALSEnever evaluated
0-1
233 {-
234 struct passwd *pw;-
235 char name[UT_USER_SIZE + 1];-
236-
237 stzncpy (name, UT_USER (utmp_ent), UT_USER_SIZE);-
238 pw = getpwnam (name);-
239 if (pw == NULL)
pw == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • pinky
0-1
240 /* TRANSLATORS: Real name is unknown; at most 19 characters. */-
241 printf (" %19s", _(" ???"));
never executed: printf (" %19s", dcgettext (((void *)0), " ???" , 5) );
0
242 else-
243 {-
244 char *const comma = strchr (pw->pw_gecos, ',');
__builtin_constant_p ( ',' )Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • pinky
FALSEnever evaluated
!__builtin_con...pw->pw_gecos )Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • pinky
FALSEnever evaluated
( ',' ) == '\0'Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • pinky
0-1
245 char *result;-
246-
247 if (comma)
commaDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • pinky
FALSEnever evaluated
0-1
248 *comma = '\0';
executed 1 time by 1 test: *comma = '\0';
Executed by:
  • pinky
1
249-
250 result = create_fullname (pw->pw_gecos, pw->pw_name);-
251 printf (" %-19.19s", result);-
252 free (result);-
253 }
executed 1 time by 1 test: end of block
Executed by:
  • pinky
1
254 }-
255-
256 printf (" %c%-8.*s",-
257 mesg, (int) sizeof (utmp_ent->ut_line), utmp_ent->ut_line);-
258-
259 if (include_idle)
include_idleDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • pinky
FALSEnever evaluated
0-1
260 {-
261 if (last_change)
last_changeDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • pinky
FALSEnever evaluated
0-1
262 printf (" %-6s", idle_string (last_change));
executed 1 time by 1 test: printf (" %-6s", idle_string (last_change));
Executed by:
  • pinky
1
263 else-
264 /* TRANSLATORS: Idle time is unknown; at most 5 characters. */-
265 printf (" %-6s", _("?????"));
never executed: printf (" %-6s", dcgettext (((void *)0), "?????" , 5) );
0
266 }-
267-
268 printf (" %s", time_string (utmp_ent));-
269-
270#ifdef HAVE_UT_HOST-
271 if (include_where && utmp_ent->ut_host[0])
include_whereDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • pinky
FALSEnever evaluated
utmp_ent->ut_host[0]Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • pinky
FALSEnever evaluated
0-1
272 {-
273 char ut_host[sizeof (utmp_ent->ut_host) + 1];-
274 char *host = NULL;-
275 char *display = NULL;-
276-
277 /* Copy the host name into UT_HOST, and ensure it's nul terminated. */-
278 stzncpy (ut_host, utmp_ent->ut_host, sizeof (utmp_ent->ut_host));-
279-
280 /* Look for an X display. */-
281 display = strchr (ut_host, ':');
__builtin_constant_p ( ':' )Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • pinky
FALSEnever evaluated
!__builtin_con..._p ( ut_host )Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • pinky
FALSEnever evaluated
( ':' ) == '\0'Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • pinky
0-1
282 if (display)
displayDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • pinky
FALSEnever evaluated
0-1
283 *display++ = '\0';
executed 1 time by 1 test: *display++ = '\0';
Executed by:
  • pinky
1
284-
285 if (*ut_host)
*ut_hostDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • pinky
0-1
286 /* See if we can canonicalize it. */-
287 host = canon_host (ut_host);
never executed: host = canon_host (ut_host);
0
288 if ( ! host)
! hostDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • pinky
FALSEnever evaluated
0-1
289 host = ut_host;
executed 1 time by 1 test: host = ut_host;
Executed by:
  • pinky
1
290-
291 if (display)
displayDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • pinky
FALSEnever evaluated
0-1
292 printf (" %s:%s", host, display);
executed 1 time by 1 test: printf (" %s:%s", host, display);
Executed by:
  • pinky
1
293 else-
294 printf (" %s", host);
never executed: printf (" %s", host);
0
295-
296 if (host != ut_host)
host != ut_hostDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • pinky
0-1
297 free (host);
never executed: free (host);
0
298 }
executed 1 time by 1 test: end of block
Executed by:
  • pinky
1
299#endif-
300-
301 putchar ('\n');-
302}
executed 1 time by 1 test: end of block
Executed by:
  • pinky
1
303-
304/* Display a verbose line of information about UTMP_ENT. */-
305-
306static void-
307print_long_entry (const char name[])-
308{-
309 struct passwd *pw;-
310-
311 pw = getpwnam (name);-
312-
313 printf (_("Login name: "));-
314 printf ("%-28s", name);-
315-
316 printf (_("In real life: "));-
317 if (pw == NULL)
pw == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
318 {-
319 /* TRANSLATORS: Real name is unknown; no hard limit. */-
320 printf (" %s", _("???\n"));-
321 return;
never executed: return;
0
322 }-
323 else-
324 {-
325 char *const comma = strchr (pw->pw_gecos, ',');
__builtin_constant_p ( ',' )Description
TRUEnever evaluated
FALSEnever evaluated
!__builtin_con...pw->pw_gecos )Description
TRUEnever evaluated
FALSEnever evaluated
( ',' ) == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0
326 char *result;-
327-
328 if (comma)
commaDescription
TRUEnever evaluated
FALSEnever evaluated
0
329 *comma = '\0';
never executed: *comma = '\0';
0
330-
331 result = create_fullname (pw->pw_gecos, pw->pw_name);-
332 printf (" %s", result);-
333 free (result);-
334 }
never executed: end of block
0
335-
336 putchar ('\n');-
337-
338 if (include_home_and_shell)
include_home_and_shellDescription
TRUEnever evaluated
FALSEnever evaluated
0
339 {-
340 printf (_("Directory: "));-
341 printf ("%-29s", pw->pw_dir);-
342 printf (_("Shell: "));-
343 printf (" %s", pw->pw_shell);-
344 putchar ('\n');-
345 }
never executed: end of block
0
346-
347 if (include_project)
include_projectDescription
TRUEnever evaluated
FALSEnever evaluated
0
348 {-
349 FILE *stream;-
350 char buf[1024];-
351 const char *const baseproject = "/.project";-
352 char *const project =-
353 xmalloc (strlen (pw->pw_dir) + strlen (baseproject) + 1);-
354 stpcpy (stpcpy (project, pw->pw_dir), baseproject);-
355-
356 stream = fopen (project, "r");-
357 if (stream)
streamDescription
TRUEnever evaluated
FALSEnever evaluated
0
358 {-
359 size_t bytes;-
360-
361 printf (_("Project: "));-
362-
363 while ((bytes = fread (buf, 1, sizeof (buf), stream)) > 0)
(bytes = fread...),stream)) > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
364 fwrite (buf, 1, bytes, stdout);
never executed: (__extension__ ((__builtin_constant_p ( 1 ) && __builtin_constant_p ( bytes ) && (size_t) ( 1 ) * (size_t) ( bytes ) <= 8 && (size_t) ( 1 ) != 0) ? ({ const char *__ptr = (const char *) ( buf ); FILE *__stream = (stdout); size_t __cnt; for (__cnt = (size_...; }) : (((__builtin_constant_p ( 1 ) && (size_t) ( 1 ) == 0) || (__builtin_constant_p ( bytes ) && (size_t) ( bytes ) == 0)) ? ((void) ( buf ), (void) (stdout), (void) ( 1 ), (void) ( bytes ), (size_t) 0) : fwrite_unlocked ( buf , 1 , bytes , stdout)))) ;
never executed: break;
(__builtin_exp...r++))) == (-1)Description
TRUEnever evaluated
FALSEnever evaluated
__cnt > 0Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_expe...write_end), 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
365 fclose (stream);-
366 }
never executed: end of block
0
367-
368 free (project);-
369 }
never executed: end of block
0
370-
371 if (include_plan)
include_planDescription
TRUEnever evaluated
FALSEnever evaluated
0
372 {-
373 FILE *stream;-
374 char buf[1024];-
375 const char *const baseplan = "/.plan";-
376 char *const plan =-
377 xmalloc (strlen (pw->pw_dir) + strlen (baseplan) + 1);-
378 stpcpy (stpcpy (plan, pw->pw_dir), baseplan);-
379-
380 stream = fopen (plan, "r");-
381 if (stream)
streamDescription
TRUEnever evaluated
FALSEnever evaluated
0
382 {-
383 size_t bytes;-
384-
385 printf (_("Plan:\n"));-
386-
387 while ((bytes = fread (buf, 1, sizeof (buf), stream)) > 0)
(bytes = fread...),stream)) > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
388 fwrite (buf, 1, bytes, stdout);
never executed: (__extension__ ((__builtin_constant_p ( 1 ) && __builtin_constant_p ( bytes ) && (size_t) ( 1 ) * (size_t) ( bytes ) <= 8 && (size_t) ( 1 ) != 0) ? ({ const char *__ptr = (const char *) ( buf ); FILE *__stream = (stdout); size_t __cnt; for (__cnt = (size_...; }) : (((__builtin_constant_p ( 1 ) && (size_t) ( 1 ) == 0) || (__builtin_constant_p ( bytes ) && (size_t) ( bytes ) == 0)) ? ((void) ( buf ), (void) (stdout), (void) ( 1 ), (void) ( bytes ), (size_t) 0) : fwrite_unlocked ( buf , 1 , bytes , stdout)))) ;
never executed: break;
(__builtin_exp...r++))) == (-1)Description
TRUEnever evaluated
FALSEnever evaluated
__cnt > 0Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_expe...write_end), 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
389 fclose (stream);-
390 }
never executed: end of block
0
391-
392 free (plan);-
393 }
never executed: end of block
0
394-
395 putchar ('\n');-
396}
never executed: end of block
0
397-
398/* Print the username of each valid entry and the number of valid entries-
399 in UTMP_BUF, which should have N elements. */-
400-
401static void-
402print_heading (void)-
403{-
404 printf ("%-8s", _("Login"));-
405 if (include_fullname)
include_fullnameDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • pinky
FALSEnever evaluated
0-1
406 printf (" %-19s", _("Name"));
executed 1 time by 1 test: printf (" %-19s", dcgettext (((void *)0), "Name" , 5) );
Executed by:
  • pinky
1
407 printf (" %-9s", _(" TTY"));-
408 if (include_idle)
include_idleDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • pinky
FALSEnever evaluated
0-1
409 printf (" %-6s", _("Idle"));
executed 1 time by 1 test: printf (" %-6s", dcgettext (((void *)0), "Idle" , 5) );
Executed by:
  • pinky
1
410 printf (" %-*s", time_format_width, _("When"));-
411#ifdef HAVE_UT_HOST-
412 if (include_where)
include_whereDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • pinky
FALSEnever evaluated
0-1
413 printf (" %s", _("Where"));
executed 1 time by 1 test: printf (" %s", dcgettext (((void *)0), "Where" , 5) );
Executed by:
  • pinky
1
414#endif-
415 putchar ('\n');-
416}
executed 1 time by 1 test: end of block
Executed by:
  • pinky
1
417-
418/* Display UTMP_BUF, which should have N entries. */-
419-
420static void-
421scan_entries (size_t n, const STRUCT_UTMP *utmp_buf,-
422 const int argc_names, char *const argv_names[])-
423{-
424 if (hard_locale (LC_TIME))
hard_locale ( 2 )Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • pinky
0-1
425 {-
426 time_format = "%Y-%m-%d %H:%M";-
427 time_format_width = 4 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2;-
428 }
never executed: end of block
0
429 else-
430 {-
431 time_format = "%b %e %H:%M";-
432 time_format_width = 3 + 1 + 2 + 1 + 2 + 1 + 2;-
433 }
executed 1 time by 1 test: end of block
Executed by:
  • pinky
1
434-
435 if (include_heading)
include_headingDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • pinky
FALSEnever evaluated
0-1
436 print_heading ();
executed 1 time by 1 test: print_heading ();
Executed by:
  • pinky
1
437-
438 while (n--)
n--Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • pinky
FALSEevaluated 1 time by 1 test
Evaluated by:
  • pinky
1-4
439 {-
440 if (IS_USER_PROCESS (utmp_buf))
dead code: ((utmp_buf)->ut_tv.tv_sec) != 0
((utmp_buf)-> ut_user )[0]Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • pinky
FALSEnever evaluated
((utmp_buf)->ut_type == ( 7 ))Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • pinky
FALSEevaluated 3 times by 1 test
Evaluated by:
  • pinky
-
441 {-
442 if (argc_names)
argc_namesDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • pinky
0-1
443 {-
444 for (int i = 0; i < argc_names; i++)
i < argc_namesDescription
TRUEnever evaluated
FALSEnever evaluated
0
445 if (STREQ_LEN (UT_USER (utmp_buf), argv_names[i], UT_USER_SIZE))
never executed: __result = (((const unsigned char *) (const char *) ( ((utmp_buf)-> ut_user ) ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( argv_names[i] ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
( (__extension...SIZE ))) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...UT_USER_SIZE )Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...-> ut_user ) )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( ((utm...T_USER_SIZE ))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...rgv_names[i] )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( argv_...T_USER_SIZE ))Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
446 {-
447 print_entry (utmp_buf);-
448 break;
never executed: break;
0
449 }-
450 }
never executed: end of block
0
451 else-
452 print_entry (utmp_buf);
executed 1 time by 1 test: print_entry (utmp_buf);
Executed by:
  • pinky
1
453 }-
454 utmp_buf++;-
455 }
executed 4 times by 1 test: end of block
Executed by:
  • pinky
4
456}
executed 1 time by 1 test: end of block
Executed by:
  • pinky
1
457-
458/* Display a list of who is on the system, according to utmp file FILENAME. */-
459-
460static void-
461short_pinky (const char *filename,-
462 const int argc_names, char *const argv_names[])-
463{-
464 size_t n_users;-
465 STRUCT_UTMP *utmp_buf = NULL;-
466-
467 if (read_utmp (filename, &n_users, &utmp_buf, 0) != 0)
read_utmp (fil...p_buf, 0) != 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • pinky
0-1
468 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
469-
470 scan_entries (n_users, utmp_buf, argc_names, argv_names);-
471-
472 IF_LINT (free (utmp_buf));-
473}
executed 1 time by 1 test: end of block
Executed by:
  • pinky
1
474-
475static void-
476long_pinky (const int argc_names, char *const argv_names[])-
477{-
478 for (int i = 0; i < argc_names; i++)
i < argc_namesDescription
TRUEnever evaluated
FALSEnever evaluated
0
479 print_long_entry (argv_names[i]);
never executed: print_long_entry (argv_names[i]);
0
480}
never executed: end of block
0
481-
482void-
483usage (int status)-
484{-
485 if (status != EXIT_SUCCESS)
status != 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • pinky
FALSEevaluated 12 times by 1 test
Evaluated by:
  • pinky
3-12
486 emit_try_help ();
executed 3 times by 1 test: end of block
Executed by:
  • pinky
3
487 else-
488 {-
489 printf (_("Usage: %s [OPTION]... [USER]...\n"), program_name);-
490 fputs (_("\-
491\n\-
492 -l produce long format output for the specified USERs\n\-
493 -b omit the user's home directory and shell in long format\n\-
494 -h omit the user's project file in long format\n\-
495 -p omit the user's plan file in long format\n\-
496 -s do short format output, this is the default\n\-
497"), stdout);-
498 fputs (_("\-
499 -f omit the line of column headings in short format\n\-
500 -w omit the user's full name in short format\n\-
501 -i omit the user's full name and remote host in short format\n\-
502 -q omit the user's full name, remote host and idle time\n\-
503 in short format\n\-
504"), stdout);-
505 fputs (HELP_OPTION_DESCRIPTION, stdout);-
506 fputs (VERSION_OPTION_DESCRIPTION, stdout);-
507 printf (_("\-
508\n\-
509A lightweight 'finger' program; print user information.\n\-
510The utmp file will be %s.\n\-
511"), UTMP_FILE);-
512 emit_ancillary_info (PROGRAM_NAME);-
513 }
executed 12 times by 1 test: end of block
Executed by:
  • pinky
12
514 exit (status);
executed 15 times by 1 test: exit (status);
Executed by:
  • pinky
15
515}-
516-
517int-
518main (int argc, char **argv)-
519{-
520 int optc;-
521 int n_users;-
522-
523 initialize_main (&argc, &argv);-
524 set_program_name (argv[0]);-
525 setlocale (LC_ALL, "");-
526 bindtextdomain (PACKAGE, LOCALEDIR);-
527 textdomain (PACKAGE);-
528-
529 atexit (close_stdout);-
530-
531 while ((optc = getopt_long (argc, argv, "sfwiqbhlp", longopts, NULL)) != -1)
(optc = getopt... *)0) )) != -1Description
TRUEevaluated 27 times by 1 test
Evaluated by:
  • pinky
FALSEevaluated 1 time by 1 test
Evaluated by:
  • pinky
1-27
532 {-
533 switch (optc)-
534 {-
535 case 's':
executed 1 time by 1 test: case 's':
Executed by:
  • pinky
1
536 do_short_format = true;-
537 break;
executed 1 time by 1 test: break;
Executed by:
  • pinky
1
538-
539 case 'l':
executed 1 time by 1 test: case 'l':
Executed by:
  • pinky
1
540 do_short_format = false;-
541 break;
executed 1 time by 1 test: break;
Executed by:
  • pinky
1
542-
543 case 'f':
executed 1 time by 1 test: case 'f':
Executed by:
  • pinky
1
544 include_heading = false;-
545 break;
executed 1 time by 1 test: break;
Executed by:
  • pinky
1
546-
547 case 'w':
executed 1 time by 1 test: case 'w':
Executed by:
  • pinky
1
548 include_fullname = false;-
549 break;
executed 1 time by 1 test: break;
Executed by:
  • pinky
1
550-
551 case 'i':
executed 1 time by 1 test: case 'i':
Executed by:
  • pinky
1
552 include_fullname = false;-
553#ifdef HAVE_UT_HOST-
554 include_where = false;-
555#endif-
556 break;
executed 1 time by 1 test: break;
Executed by:
  • pinky
1
557-
558 case 'q':
executed 1 time by 1 test: case 'q':
Executed by:
  • pinky
1
559 include_fullname = false;-
560#ifdef HAVE_UT_HOST-
561 include_where = false;-
562#endif-
563 include_idle = false;-
564 break;
executed 1 time by 1 test: break;
Executed by:
  • pinky
1
565-
566 case 'h':
executed 1 time by 1 test: case 'h':
Executed by:
  • pinky
1
567 include_project = false;-
568 break;
executed 1 time by 1 test: break;
Executed by:
  • pinky
1
569-
570 case 'p':
executed 1 time by 1 test: case 'p':
Executed by:
  • pinky
1
571 include_plan = false;-
572 break;
executed 1 time by 1 test: break;
Executed by:
  • pinky
1
573-
574 case 'b':
executed 1 time by 1 test: case 'b':
Executed by:
  • pinky
1
575 include_home_and_shell = false;-
576 break;
executed 1 time by 1 test: break;
Executed by:
  • pinky
1
577-
578 case_GETOPT_HELP_CHAR;
never executed: break;
executed 12 times by 1 test: case GETOPT_HELP_CHAR:
Executed by:
  • pinky
0-12
579-
580 case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
executed 3 times by 1 test: exit ( 0 );
Executed by:
  • pinky
never executed: break;
executed 3 times by 1 test: case GETOPT_VERSION_CHAR:
Executed by:
  • pinky
0-3
581-
582 default:
executed 3 times by 1 test: default:
Executed by:
  • pinky
3
583 usage (EXIT_FAILURE);-
584 }
never executed: end of block
0
585 }-
586-
587 n_users = argc - optind;-
588-
589 if (!do_short_format && n_users == 0)
!do_short_formatDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • pinky
n_users == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-1
590 {-
591 error (0, 0, _("no username specified; at least one must be\-
592 specified when using -l"));-
593 usage (EXIT_FAILURE);-
594 }
never executed: end of block
0
595-
596 if (do_short_format)
do_short_formatDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • pinky
FALSEnever evaluated
0-1
597 short_pinky (UTMP_FILE, n_users, argv + optind);
executed 1 time by 1 test: short_pinky ( "/var/run/utmp" , n_users, argv + optind);
Executed by:
  • pinky
1
598 else-
599 long_pinky (n_users, argv + optind);
never executed: long_pinky (n_users, argv + optind);
0
600-
601 return EXIT_SUCCESS;
executed 1 time by 1 test: return 0 ;
Executed by:
  • pinky
1
602}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2