Print this page
3244 utmpd.c: fix uninitialized variable, ret_val and other gcc warnings


   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*




  22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  27 /*        All Rights Reserved   */
  28 
  29 /*
  30  * Portions of such source code were derived from Berkeley 4.3 BSD
  31  * under license from the Regents of the University of California.
  32  */
  33 
  34 /*
  35  * utmpd        - utmp daemon
  36  *
  37  *              This program receives requests from  pututxline(3)
  38  *              via a named pipe to watch the process to make sure it cleans up
  39  *              its utmpx entry on termination.
  40  *              The program keeps a list of procs
  41  *              and uses poll() on their /proc files to detect termination.


 160 static void rem_pid();          /* Removes a process from the table */
 161 static int find_pid();          /* Finds a process in the table */
 162 static int proc_to_fd();        /* Takes a pid and returns an fd for its proc */
 163 static void load_tables();      /* Loads up the tables the first time around */
 164 static int pidcmp();            /* For sorting pids */
 165 
 166 static void clean_entry();      /* Removes entry from our table and calls ... */
 167 static void clean_utmpx_ent();  /* Cleans a utmpx entry */
 168 
 169 static void fatal() __NORETURN; /* Prints error message and calls exit */
 170 static void nonfatal();         /* Prints error message */
 171 static void print_tables();     /* Prints out internal tables for Debug */
 172 static int proc_is_alive(pid_t pid);    /* Check if a process is alive */
 173 static void warn_utmp(void);
 174 
 175 /*
 176  * main()  - Main does basic setup and calls wait_for_pids() to do the work
 177  */
 178 
 179 int
 180 main(argc, argv)
 181         char **argv;
 182 {
 183         char *defp;
 184         struct rlimit rlim;
 185         int i;
 186         time_t curtime, now;
 187 
 188         prog_name = argv[0];                    /* Save invocation name */
 189 
 190         if (getuid() != 0)  {
 191                 (void) fprintf(stderr,
 192                         "You must be root to run this program\n");
 193                 fatal("You must be root to run this program");
 194         }
 195 
 196         if (argc > 1) {
 197                 if ((argc == 2 && (int)strlen(argv[1]) >= 2) &&
 198                     (argv[1][0] == '-' && argv[1][1] == 'd')) {
 199                         Debug = 1;
 200                 } else {
 201                         (void) fprintf(stderr,


 332         pidcnt = 0;
 333         Pfd = -1;
 334         setup_pipe();           /* Setup the pipe to receive messages */
 335         scan_utmps();           /* Read in USER procs entries to watch */
 336 }
 337 
 338 
 339 /*
 340  *                      *** The Watcher ***
 341  *
 342  * Wait_for_pids        - wait for the termination of a process in the table.
 343  *                        Returns 1 on normal exist, 0 on failure.
 344  */
 345 
 346 static int
 347 wait_for_pids()
 348 {
 349         register struct pollfd *pfd;
 350         register int i;
 351         pid_t pid;
 352         int ret_val;
 353         int timeout;
 354         static time_t last_timeout  = 0;
 355         static int bad_error  = 0;      /* Count of POLL errors */
 356 
 357         /*
 358          * First time through we initialize last_timeout to now.
 359          */
 360         if (last_timeout == 0)
 361                 last_timeout = time(NULL);
 362 
 363         /*
 364          * Recalculate timeout - checking to see if time expired.
 365          */
 366 
 367         if ((timeout = Poll_timeout - (time(NULL) - last_timeout)) <= 0) {
 368                 timeout = Poll_timeout;
 369                 last_timeout = time(NULL);
 370                 scan_utmps();
 371         }
 372 




   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2014 Shruti V Sampat <shrutisampat@gmail.com>
  23  */
  24 
  25 /*
  26  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  27  * Use is subject to license terms.
  28  */
  29 
  30 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  31 /*        All Rights Reserved   */
  32 
  33 /*
  34  * Portions of such source code were derived from Berkeley 4.3 BSD
  35  * under license from the Regents of the University of California.
  36  */
  37 
  38 /*
  39  * utmpd        - utmp daemon
  40  *
  41  *              This program receives requests from  pututxline(3)
  42  *              via a named pipe to watch the process to make sure it cleans up
  43  *              its utmpx entry on termination.
  44  *              The program keeps a list of procs
  45  *              and uses poll() on their /proc files to detect termination.


 164 static void rem_pid();          /* Removes a process from the table */
 165 static int find_pid();          /* Finds a process in the table */
 166 static int proc_to_fd();        /* Takes a pid and returns an fd for its proc */
 167 static void load_tables();      /* Loads up the tables the first time around */
 168 static int pidcmp();            /* For sorting pids */
 169 
 170 static void clean_entry();      /* Removes entry from our table and calls ... */
 171 static void clean_utmpx_ent();  /* Cleans a utmpx entry */
 172 
 173 static void fatal() __NORETURN; /* Prints error message and calls exit */
 174 static void nonfatal();         /* Prints error message */
 175 static void print_tables();     /* Prints out internal tables for Debug */
 176 static int proc_is_alive(pid_t pid);    /* Check if a process is alive */
 177 static void warn_utmp(void);
 178 
 179 /*
 180  * main()  - Main does basic setup and calls wait_for_pids() to do the work
 181  */
 182 
 183 int
 184 main(int argc, char *argv[])

 185 {
 186         char *defp;
 187         struct rlimit rlim;
 188         int i;
 189         time_t curtime, now;
 190 
 191         prog_name = argv[0];                    /* Save invocation name */
 192 
 193         if (getuid() != 0)  {
 194                 (void) fprintf(stderr,
 195                     "You must be root to run this program\n");
 196                 fatal("You must be root to run this program");
 197         }
 198 
 199         if (argc > 1) {
 200                 if ((argc == 2 && (int)strlen(argv[1]) >= 2) &&
 201                     (argv[1][0] == '-' && argv[1][1] == 'd')) {
 202                         Debug = 1;
 203                 } else {
 204                         (void) fprintf(stderr,


 335         pidcnt = 0;
 336         Pfd = -1;
 337         setup_pipe();           /* Setup the pipe to receive messages */
 338         scan_utmps();           /* Read in USER procs entries to watch */
 339 }
 340 
 341 
 342 /*
 343  *                      *** The Watcher ***
 344  *
 345  * Wait_for_pids        - wait for the termination of a process in the table.
 346  *                        Returns 1 on normal exist, 0 on failure.
 347  */
 348 
 349 static int
 350 wait_for_pids()
 351 {
 352         register struct pollfd *pfd;
 353         register int i;
 354         pid_t pid;
 355         int ret_val = 0;
 356         int timeout;
 357         static time_t last_timeout  = 0;
 358         static int bad_error  = 0;      /* Count of POLL errors */
 359 
 360         /*
 361          * First time through we initialize last_timeout to now.
 362          */
 363         if (last_timeout == 0)
 364                 last_timeout = time(NULL);
 365 
 366         /*
 367          * Recalculate timeout - checking to see if time expired.
 368          */
 369 
 370         if ((timeout = Poll_timeout - (time(NULL) - last_timeout)) <= 0) {
 371                 timeout = Poll_timeout;
 372                 last_timeout = time(NULL);
 373                 scan_utmps();
 374         }
 375