Print this page
4337 eliminate /etc/TIMEZONE


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



  24  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  25  * Use is subject to license terms.
  26  */
  27 
  28 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  29 /*        All Rights Reserved   */
  30 
  31 #pragma ident   "%Z%%M% %I%     %E% SMI"
  32 
  33 /*
  34  * Network Listener Process
  35  *
  36  *              command line:
  37  *
  38  *              listen [ -m minor_prefix ] netspec
  39  *
  40  */
  41 
  42 /* system include files */
  43 
  44 #include <fcntl.h>
  45 #include <signal.h>
  46 #include <stdio.h>
  47 #include <unistd.h>
  48 #include <string.h>
  49 #include <errno.h>
  50 #include <memory.h>
  51 #include <sys/utsname.h>
  52 #include <sys/tiuser.h>


 140 int     Passfd;                 /* pipe used to pass FD (fd 3)  */
 141 int     Pidfd;                  /* locked pid file (fd 4)       */
 142 FILE    *Logfp;                 /* for logging listener activity*/
 143 
 144 struct  pmmsg   Pmmsg;          /* to respond to SAC            */
 145 int     State = PM_STARTING;    /* current SAC state            */
 146 char    Mytag[15];
 147 
 148 char    Lastmsg[BUFSIZ];        /* contains last msg logged (by stampbuf) */
 149 int     Logmax = LOGMAX;        /* number of entriet to allow in logfile  */
 150 
 151 int     Splflag;                /* logfile critical region flag           */
 152 
 153 static char *badnspmsg = "Bad netspec on command line ( Pathname too long )";
 154 static char *badstart  = "Listener failed to start properly";
 155 static char *nologfile = "Unable to open listener log file during initialization";
 156 static char *usage     = "Usage: listen [ -m minor_prefix ] network_device";
 157 static char *nopmtag   = "Fatal error: Unable to get PMTAG from environment";
 158 static char tzenv[BUFSIZ];
 159 
 160 #define TIMEZONE        "/etc/TIMEZONE"
 161 #define TZSTR   "TZ="
 162 
 163 void    check_sac_mesg();       /* routine to process messages from sac */
 164 void    rpc_register();         /* routine to register rpc services */
 165 void    rpc_unregister();       /* routine to unregister rpc services */
 166 extern  struct  netconfig       *getnetconfigent();
 167 extern  char    *t_alloc();
 168 extern  void    logexit();
 169 extern  int     t_errno;
 170 extern  int     errno;
 171 
 172 #ifndef TRUE
 173 #define TRUE    1
 174 #define FALSE   0
 175 #endif
 176 
 177 static void mod_prvaddr(void);
 178 static void pitchcall(struct call_list *pending, struct t_discon *discon);
 179 static void clr_call(struct t_call *call);
 180 static void trycon(struct call_list *phead, int fd);


 283 
 284 #ifdef  DEBUGMODE
 285         sprintf(scratch, "%s/%s/%s", ALTDIR, Mytag, DBGNAME);
 286         Debugfp = fopen(scratch, "w");
 287 #endif
 288 
 289 
 290 #ifdef  DEBUGMODE
 291         if ((!Logfp) || (!Debugfp)) 
 292 #else
 293         if (!Logfp)
 294 #endif
 295                 logexit(1, badstart);
 296 
 297 /*
 298  * In case we started with no environment, find out what timezone we're
 299  * in.  This will get passed to children, so only need to do once.
 300  */
 301 
 302         if (getenv("TZ") == NULL) {
 303                 fp = fopen(TIMEZONE, "r");
 304                 if (fp) {
 305                         while (fgets(tzenv, BUFSIZ, fp)) {
 306                                 if (tzenv[strlen(tzenv) - 1] == '\n')
 307                                         tzenv[strlen(tzenv) - 1] = '\0';
 308                                 if (!strncmp(TZSTR, tzenv, strlen(TZSTR))) {
 309                                         putenv(parse(tzenv));
 310                                         break;
 311                                 }
 312                         }
 313                         fclose(fp);
 314                 }
 315                 else {
 316                         sprintf(scratch, "couldn't open %s, default to GMT", TIMEZONE);

 317                         logmessage(scratch);
 318                 }
 319         }
 320 
 321         logmessage("@(#)listen:listen.c 1.19.9.1");
 322 
 323 #ifdef  DEBUGMODE
 324         logmessage("Listener process with DEBUG capability");
 325 #endif
 326 
 327         sprintf(scratch, "Listener port monitor tag: %s", Mytag_p);
 328         logmessage(scratch);
 329         DEBUG((9, "Minor prefix: %s  Netspec %s", Minor_prefix, Netspec));
 330 
 331         /* fill in Pmmesg fields that always stay the same */
 332 
 333         Pmmsg.pm_maxclass = MAXCLASS;
 334         strcpy(Pmmsg.pm_tag, Mytag_p);
 335         Pmmsg.pm_size = 0;
 336 


1554  * parse:       Parse TZ= string like init does for consistency
1555  *              Work on string in place since result will
1556  *              either be the same or shorter.
1557  */
1558 
1559 char *
1560 parse(s)
1561 char *s;
1562 {
1563         char *p;
1564         char *tp;
1565         char scratch[BUFSIZ];
1566         int delim;
1567 
1568         tp = p = s + strlen("TZ=");     /* skip TZ= in parsing */
1569         if ((*p == '"') || (*p == '\'')) {
1570                 /* it is quoted */
1571                 delim = *p++;
1572                 for (;;) {
1573                         if (*p == '\0') {
1574                                 /* etc/TIMEZONE ill-formed, go without TZ */
1575                                 sprintf(scratch, "%s ill-formed", TIMEZONE);
1576                                 logmessage(scratch);
1577                                 strcpy(s, "TZ=");
1578                                 return(s);
1579                         }
1580                         if (*p == delim) {
1581                                 *tp = '\0';
1582                                 return(s);
1583                         }
1584                         else {
1585                                 *tp++ = *p++;
1586                         }
1587                 }
1588         }
1589         else { /* look for comment or trailing whitespace */
1590                 for ( ; *p && !isspace(*p) && *p != '#'; ++p)
1591                         ;
1592                 /* if a comment or trailing whitespace, trash it */
1593                 if (*p) {
1594                         *p = '\0';
1595                 }




   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License, Version 1.0 only
   6  * (the "License").  You may not use this file except in compliance
   7  * with the License.
   8  *
   9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 
  23 /*
  24  * Copyright 2014 Garrett D'Amore
  25  */
  26 /*
  27  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  28  * Use is subject to license terms.
  29  */
  30 
  31 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  32 /*        All Rights Reserved   */
  33 


  34 /*
  35  * Network Listener Process
  36  *
  37  *              command line:
  38  *
  39  *              listen [ -m minor_prefix ] netspec
  40  *
  41  */
  42 
  43 /* system include files */
  44 
  45 #include <fcntl.h>
  46 #include <signal.h>
  47 #include <stdio.h>
  48 #include <unistd.h>
  49 #include <string.h>
  50 #include <errno.h>
  51 #include <memory.h>
  52 #include <sys/utsname.h>
  53 #include <sys/tiuser.h>


 141 int     Passfd;                 /* pipe used to pass FD (fd 3)  */
 142 int     Pidfd;                  /* locked pid file (fd 4)       */
 143 FILE    *Logfp;                 /* for logging listener activity*/
 144 
 145 struct  pmmsg   Pmmsg;          /* to respond to SAC            */
 146 int     State = PM_STARTING;    /* current SAC state            */
 147 char    Mytag[15];
 148 
 149 char    Lastmsg[BUFSIZ];        /* contains last msg logged (by stampbuf) */
 150 int     Logmax = LOGMAX;        /* number of entriet to allow in logfile  */
 151 
 152 int     Splflag;                /* logfile critical region flag           */
 153 
 154 static char *badnspmsg = "Bad netspec on command line ( Pathname too long )";
 155 static char *badstart  = "Listener failed to start properly";
 156 static char *nologfile = "Unable to open listener log file during initialization";
 157 static char *usage     = "Usage: listen [ -m minor_prefix ] network_device";
 158 static char *nopmtag   = "Fatal error: Unable to get PMTAG from environment";
 159 static char tzenv[BUFSIZ];
 160 
 161 #define TZFILE  "/etc/default/init"
 162 #define TZSTR   "TZ="
 163 
 164 void    check_sac_mesg();       /* routine to process messages from sac */
 165 void    rpc_register();         /* routine to register rpc services */
 166 void    rpc_unregister();       /* routine to unregister rpc services */
 167 extern  struct  netconfig       *getnetconfigent();
 168 extern  char    *t_alloc();
 169 extern  void    logexit();
 170 extern  int     t_errno;
 171 extern  int     errno;
 172 
 173 #ifndef TRUE
 174 #define TRUE    1
 175 #define FALSE   0
 176 #endif
 177 
 178 static void mod_prvaddr(void);
 179 static void pitchcall(struct call_list *pending, struct t_discon *discon);
 180 static void clr_call(struct t_call *call);
 181 static void trycon(struct call_list *phead, int fd);


 284 
 285 #ifdef  DEBUGMODE
 286         sprintf(scratch, "%s/%s/%s", ALTDIR, Mytag, DBGNAME);
 287         Debugfp = fopen(scratch, "w");
 288 #endif
 289 
 290 
 291 #ifdef  DEBUGMODE
 292         if ((!Logfp) || (!Debugfp)) 
 293 #else
 294         if (!Logfp)
 295 #endif
 296                 logexit(1, badstart);
 297 
 298 /*
 299  * In case we started with no environment, find out what timezone we're
 300  * in.  This will get passed to children, so only need to do once.
 301  */
 302 
 303         if (getenv("TZ") == NULL) {
 304                 fp = fopen(TZFILE, "r");
 305                 if (fp) {
 306                         while (fgets(tzenv, BUFSIZ, fp)) {
 307                                 if (tzenv[strlen(tzenv) - 1] == '\n')
 308                                         tzenv[strlen(tzenv) - 1] = '\0';
 309                                 if (!strncmp(TZSTR, tzenv, strlen(TZSTR))) {
 310                                         putenv(parse(tzenv));
 311                                         break;
 312                                 }
 313                         }
 314                         fclose(fp);
 315                 }
 316                 else {
 317                         sprintf(scratch, "couldn't open %s, default to GMT",
 318                             TZFILE);
 319                         logmessage(scratch);
 320                 }
 321         }
 322 
 323         logmessage("@(#)listen:listen.c 1.19.9.1");
 324 
 325 #ifdef  DEBUGMODE
 326         logmessage("Listener process with DEBUG capability");
 327 #endif
 328 
 329         sprintf(scratch, "Listener port monitor tag: %s", Mytag_p);
 330         logmessage(scratch);
 331         DEBUG((9, "Minor prefix: %s  Netspec %s", Minor_prefix, Netspec));
 332 
 333         /* fill in Pmmesg fields that always stay the same */
 334 
 335         Pmmsg.pm_maxclass = MAXCLASS;
 336         strcpy(Pmmsg.pm_tag, Mytag_p);
 337         Pmmsg.pm_size = 0;
 338 


1556  * parse:       Parse TZ= string like init does for consistency
1557  *              Work on string in place since result will
1558  *              either be the same or shorter.
1559  */
1560 
1561 char *
1562 parse(s)
1563 char *s;
1564 {
1565         char *p;
1566         char *tp;
1567         char scratch[BUFSIZ];
1568         int delim;
1569 
1570         tp = p = s + strlen("TZ=");     /* skip TZ= in parsing */
1571         if ((*p == '"') || (*p == '\'')) {
1572                 /* it is quoted */
1573                 delim = *p++;
1574                 for (;;) {
1575                         if (*p == '\0') {
1576                                 /* etc/default/init ill-formed, go without TZ */
1577                                 sprintf(scratch, "%s ill-formed", TZFILE);
1578                                 logmessage(scratch);
1579                                 strcpy(s, "TZ=");
1580                                 return(s);
1581                         }
1582                         if (*p == delim) {
1583                                 *tp = '\0';
1584                                 return(s);
1585                         }
1586                         else {
1587                                 *tp++ = *p++;
1588                         }
1589                 }
1590         }
1591         else { /* look for comment or trailing whitespace */
1592                 for ( ; *p && !isspace(*p) && *p != '#'; ++p)
1593                         ;
1594                 /* if a comment or trailing whitespace, trash it */
1595                 if (*p) {
1596                         *p = '\0';
1597                 }