Print this page
10703 smatch unreachable code checking needs reworking
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>


   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 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 /*
  27  * Copyright (c) 2018, Joyent, Inc.
  28  */
  29 
  30 /*
  31  * Reparsed daemon
  32  */
  33 
  34 #include <stdio.h>
  35 #include <stdio_ext.h>
  36 #include <stdlib.h>
  37 #include <unistd.h>
  38 #include <signal.h>
  39 #include <sys/types.h>
  40 #include <sys/stat.h>
  41 #include <fcntl.h>
  42 #include <memory.h>
  43 #include <alloca.h>
  44 #include <ucontext.h>
  45 #include <errno.h>
  46 #include <syslog.h>
  47 #include <string.h>


 170         /*
 171          * Make the process a privilege aware daemon.
 172          * Only "basic" privileges are required.
 173          *
 174          */
 175         if (__init_daemon_priv(PU_RESETGROUPS|PU_CLEARLIMITSET, 0, 0,
 176             (char *)NULL) == -1) {
 177                 syslog(LOG_ERR, "should be run with sufficient privileges");
 178                 exit(3);
 179         }
 180 
 181         /*
 182          * Clear basic privileges not required by reparsed.
 183          */
 184         __fini_daemon_priv(PRIV_PROC_FORK, PRIV_PROC_EXEC, PRIV_PROC_SESSION,
 185             PRIV_FILE_LINK_ANY, PRIV_PROC_INFO, (char *)NULL);
 186 
 187         return (start_reparsed_svcs());
 188 }
 189 
 190 static void
 191 reparsed_door_call_error(int error, int buflen)
 192 {
 193         reparsed_door_res_t rpd_res;
 194 
 195         memset(&rpd_res, 0, sizeof (reparsed_door_res_t));
 196         rpd_res.res_status = error;
 197         rpd_res.res_len = buflen;
 198         (void) door_return((char *)&rpd_res,
 199             sizeof (reparsed_door_res_t), NULL, 0);
 200 
 201         (void) door_return(NULL, 0, NULL, 0);
 202         abort();
 203 }
 204 
 205 /*
 206  *  reparsed_doorfunc
 207  *
 208  *  argp:  "service_type:service_data" string
 209  *  dp & n_desc: not used.
 210  */


 337 
 338         /*
 339          * Clean up any stale associations
 340          */
 341         (void) fdetach(REPARSED_DOOR);
 342 
 343         /*
 344          * Register in the kernel namespace for door_ki_open().
 345          */
 346         if (fattach(doorfd, REPARSED_DOOR) == -1) {
 347                 syslog(LOG_ERR, "Unable to fattach door %s", REPARSED_DOOR);
 348                 (void) close(doorfd);
 349                 (void) close(dfd);
 350                 return (1);
 351         }
 352         (void) close(dfd);
 353 
 354         /*
 355          * Wait for incoming calls
 356          */
 357         /*CONSTCOND*/
 358         while (1)
 359                 (void) pause();
 360 
 361         syslog(LOG_ERR, "Door server exited");
 362         return (10);
 363 }


   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 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 /*
  27  * Copyright 2019 Joyent, Inc.
  28  */
  29 
  30 /*
  31  * Reparsed daemon
  32  */
  33 
  34 #include <stdio.h>
  35 #include <stdio_ext.h>
  36 #include <stdlib.h>
  37 #include <unistd.h>
  38 #include <signal.h>
  39 #include <sys/types.h>
  40 #include <sys/stat.h>
  41 #include <fcntl.h>
  42 #include <memory.h>
  43 #include <alloca.h>
  44 #include <ucontext.h>
  45 #include <errno.h>
  46 #include <syslog.h>
  47 #include <string.h>


 170         /*
 171          * Make the process a privilege aware daemon.
 172          * Only "basic" privileges are required.
 173          *
 174          */
 175         if (__init_daemon_priv(PU_RESETGROUPS|PU_CLEARLIMITSET, 0, 0,
 176             (char *)NULL) == -1) {
 177                 syslog(LOG_ERR, "should be run with sufficient privileges");
 178                 exit(3);
 179         }
 180 
 181         /*
 182          * Clear basic privileges not required by reparsed.
 183          */
 184         __fini_daemon_priv(PRIV_PROC_FORK, PRIV_PROC_EXEC, PRIV_PROC_SESSION,
 185             PRIV_FILE_LINK_ANY, PRIV_PROC_INFO, (char *)NULL);
 186 
 187         return (start_reparsed_svcs());
 188 }
 189 
 190 __NORETURN static void
 191 reparsed_door_call_error(int error, int buflen)
 192 {
 193         reparsed_door_res_t rpd_res;
 194 
 195         memset(&rpd_res, 0, sizeof (reparsed_door_res_t));
 196         rpd_res.res_status = error;
 197         rpd_res.res_len = buflen;
 198         (void) door_return((char *)&rpd_res,
 199             sizeof (reparsed_door_res_t), NULL, 0);
 200 
 201         (void) door_return(NULL, 0, NULL, 0);
 202         abort();
 203 }
 204 
 205 /*
 206  *  reparsed_doorfunc
 207  *
 208  *  argp:  "service_type:service_data" string
 209  *  dp & n_desc: not used.
 210  */


 337 
 338         /*
 339          * Clean up any stale associations
 340          */
 341         (void) fdetach(REPARSED_DOOR);
 342 
 343         /*
 344          * Register in the kernel namespace for door_ki_open().
 345          */
 346         if (fattach(doorfd, REPARSED_DOOR) == -1) {
 347                 syslog(LOG_ERR, "Unable to fattach door %s", REPARSED_DOOR);
 348                 (void) close(doorfd);
 349                 (void) close(dfd);
 350                 return (1);
 351         }
 352         (void) close(dfd);
 353 
 354         /*
 355          * Wait for incoming calls
 356          */

 357         while (1)
 358                 (void) pause();



 359 }