Пример #1
0
/* end-of-loop increment routine */
void incHebGregDate( 
    date_t *dtHeb,
    date_t *dtGreg, 
    long *dtAbs, 
    int *wkday, 
    year_t *theYear
    )
{
  incDate (dtGreg, 1L);
  *dtHeb = nextHebDate (*dtHeb);
  (*dtAbs)++;
  *wkday = (*wkday + 1) % 7;

  if (TISHREI == dtHeb->mm &&   /* if Rosh Hashana then reset YearData */
      1 == dtHeb->dd)
    {
      *theYear = yearData (dtHeb->yy);
      if (sedraAllWeek_sw || sedrot_sw)
        reset_sedra (dtHeb->yy);
      if (printOmer_sw)
        reset_Omer (dtHeb->yy);
      init_holidays(dtHeb->yy);
    }
}
Пример #2
0
int main(int argc, char* argv[])
{
    date_t tempDate;
    long startAbs, endAbs;
    char *envStr;
    int envArgc;
    char *envArgv[40];		/* this should be big enough */

    progname = argv[0];

    set_default_city();
    if ((envStr = getenv(ENV_OPTS)) && strcmp(envStr, ""))
    {
        int i;

        tokenize(envStr, &envArgc, envArgv);
        for (i = 1; i < argc; i++)	/* append argv onto envArgv  */
            envArgv[envArgc++] = argv[i];
        handleArgs(envArgc, envArgv);
    }
    else
        handleArgs(argc, argv);

    tempDate.yy = theYear;
    if (theYear < (hebrewDates_sw ? 3761 : 1))
        die("Sorry, hebcal can only handle dates in the common era.", "");

    switch (rangeType)
    {
    case TODAY:
        printHebDates_sw = 1;
        tempDate.dd = theDay;
        tempDate.mm = theMonth;
        tempDate.yy = theYear;
        startAbs = endAbs = greg2abs(tempDate);
        break;
    case DAY:
        printHebDates_sw = 1;
        tempDate.dd = theDay;
        tempDate.mm = theMonth;
        tempDate.yy = theYear;
        if (hebrewDates_sw)
            startAbs = endAbs = hebrew2abs(tempDate);
        else
            startAbs = endAbs = greg2abs(tempDate);
        break;
    case MONTH:
        tempDate.dd = 1;
        tempDate.mm = theMonth;
        tempDate.yy = theYear;
        if (hebrewDates_sw)
        {
            startAbs = hebrew2abs(tempDate);
            tempDate.dd = max_days_in_heb_month(tempDate.mm, tempDate.yy);
            endAbs = hebrew2abs(tempDate);
        }
        else
        {
            startAbs = greg2abs(tempDate);
            tempDate.dd = MonthLengths[LEAP(theYear)][theMonth];
            endAbs = greg2abs(tempDate);
        }
        break;

    case YEAR:
        if (hebrewDates_sw)
        {
            tempDate.dd = 1;
            tempDate.mm = TISHREI;
            tempDate.yy = theYear;
            startAbs = hebrew2abs(tempDate);
	    /* start yearly calendar with the day before RH (i.e. Erev
	     * Rosh Hashanah)
	     */
	    startAbs--;

            tempDate.yy += numYears;
            endAbs = hebrew2abs(tempDate) - 1;
        }
        else
        {
            tempDate.dd = 1;
            tempDate.mm = JAN;
            tempDate.yy = theYear;
            startAbs = greg2abs(tempDate);

            tempDate.yy += numYears;
            endAbs = greg2abs(tempDate) - 1;
        }
        break;

    default:
        die("Oh, NO! internal error #17q!", "");
        /* this is dead code, but it silences some uninitialized variable 
           warnings in gcc   */
        startAbs = endAbs =0;
    }

    tempDate = abs2hebrew(startAbs);
    if (ok_to_run)
    {
        init_holidays(tempDate.yy);	/* load the holiday array */
        main_calendar(startAbs, endAbs);

        return 0;			/* success!  Kol hakavod to thorough programmers */
    }
    else
        return 1;
}
Пример #3
0
/*---------------------------------------------------------------------------*
 *	program entry
 *---------------------------------------------------------------------------*/
int
main(int argc, char **argv)
{
	int i;
	msg_vr_req_t mvr;

#ifdef I4B_EXTERNAL_MONITOR
	int sockfd = -1;		/* local monitor socket */
#ifndef I4B_NOTCPIP_MONITOR
	int remotesockfd = -1;		/* tcp/ip monitor socket */
#endif
#endif

	setlocale (LC_ALL, "");

	while ((i = getopt(argc, argv, "mc:d:fFlL:Pr:s:t:u:")) != -1)
	{
		switch (i)
		{
#ifdef I4B_EXTERNAL_MONITOR
			case 'm':
				inhibit_monitor = 1;
				break;
#endif

			case 'c':
				configfile = optarg;
				break;

#ifdef DEBUG
			case 'd':
				if(*optarg == 'n')
					debug_noscreen = 1;
				else if((sscanf(optarg, "%i", &debug_flags)) == 1)
					do_debug = 1;
				else
					usage();
				break;
#endif

			case 'f':
				do_fullscreen = 1;
				do_fork = 0;
#ifndef USE_CURSES
				fprintf(stderr, "Sorry, no fullscreen mode available - daemon compiled without USE_CURSES\n");
				exit(1);
#endif
				break;

			case 'F':
				do_fork = 0;
				break;

			case 'l':
				uselogfile = 1;
				break;

			case 'L':
				strlcpy(logfile, optarg, sizeof(logfile));
				break;

			case 'P':
				do_print = 1;
				break;

			case 'r':
				rdev = optarg;
				do_rdev = 1;
				break;

			case 's':
				if(isdigit(*optarg))
				{
					int facility;
					logfacility = strtoul(optarg, NULL, 10);
					facility = logfacility << 3;

					if((facility < LOG_KERN) ||
					   (facility > LOG_FTP && facility < LOG_LOCAL0) ||
					   (facility > LOG_LOCAL7))
					{
						fprintf(stderr, "Error, option -s has invalid logging facility %d", logfacility);
						usage();
					}
					logfacility = facility;
				}
				else
				{
					fprintf(stderr, "Error: option -s requires a numeric argument!\n");
					usage();
				}
				break;

			case 't':
				ttype = optarg;
				do_ttytype = 1;
				break;

			case 'u':
				if(isdigit(*optarg))
				{
					unit_length = strtoul(optarg, NULL, 10);
					if(unit_length < ULSRC_CMDLMIN)
						unit_length = ULSRC_CMDLMIN;
					else if(unit_length > ULSRC_CMDLMAX)
						unit_length = ULSRC_CMDLMAX;
					got_unitlen = 1;
				}
				else
				{
					fprintf(stderr, "Error: option -T requires a numeric argument!\n");
					usage();
				}
				break;

			case '?':
			default:
				usage();
				break;
		}
	}
#ifdef DEBUG
	if(!do_debug)
		debug_noscreen = 0;
#endif

	if(!do_print)
	{
		umask(UMASK);	/* set our umask ... */

		init_log();	/* initialize the logging subsystem */
	}

	check_pid();	/* check if we are already running */

	if(!do_print)
	{
		if(do_fork || (do_fullscreen && do_rdev)) /* daemon mode ? */
			daemonize();

		write_pid();	/* write our pid to file */

		/* set signal handler(s) */

		signal(SIGCHLD, sigchild_handler); /* process handling	*/
		signal(SIGHUP,  rereadconfig);	/* reread configuration	*/
		signal(SIGUSR1, reopenfiles);	/* reopen acct/log files*/
		signal(SIGPIPE, SIG_IGN);	/* handled manually	*/
		signal(SIGINT,  do_exit);	/* clean up on SIGINT	*/
		signal(SIGTERM, do_exit);	/* clean up on SIGTERM	*/
		signal(SIGQUIT, do_exit);	/* clean up on SIGQUIT	*/
	}

	/* open isdn device */

	if((isdnfd = open(I4BDEVICE, O_RDWR)) < 0)
	{
		dolog(LL_ERR, "main: cannot open %s: %s", I4BDEVICE, strerror(errno));
		exit(1);
	}

	/* check kernel and userland have same version/release numbers */

	if((ioctl(isdnfd, I4B_VR_REQ, &mvr)) < 0)
	{
		dolog(LL_ERR, "main: ioctl I4B_VR_REQ failed: %s", strerror(errno));
		do_exit(1);
	}

	if(mvr.version != VERSION)
	{
		dolog(LL_ERR, "main: version mismatch, kernel %d, daemon %d", mvr.version, VERSION);
		do_exit(1);
	}

	if(mvr.release != REL)
	{
		dolog(LL_ERR, "main: release mismatch, kernel %d, daemon %d", mvr.release, REL);
		do_exit(1);
	}

	if(mvr.step != STEP)
	{
		dolog(LL_ERR, "main: step mismatch, kernel %d, daemon %d", mvr.step, STEP);
		do_exit(1);
	}

	/* init controller state array */

	init_controller();

	/* read runtime configuration file and configure ourselves */

	configure(configfile, 0);

	if(config_error_flag)
	{
		dolog(LL_ERR, "there were %d error(s) in the configuration file, terminating!", config_error_flag);
		exit(1);
	}

	/* set controller ISDN protocol */

	init_controller_protocol();

	/* init active controllers, if any */

	signal(SIGCHLD, SIG_IGN);		/*XXX*/

	init_active_controller();

	signal(SIGCHLD, sigchild_handler);	/*XXX*/

	/* handle the rates stuff */

	if((i = readrates(ratesfile)) == ERROR)
	{
		if(rate_error != NULL)
			dolog(LL_ERR, "%s", rate_error);
		exit(1);
	}

	if(i == GOOD)
	{
		got_rate = 1;	/* flag, ratesfile read and ok */
		DBGL(DL_RCCF, (dolog(LL_DBG, "ratesfile %s read successfully", ratesfile)));
	}
	else
	{
		if(rate_error != NULL)
			dolog(LL_WRN, "%s", rate_error);
	}

	/* if writing accounting info, open file, set unbuffered */

	if(useacctfile)
	{
		if((acctfp = fopen(acctfile, "a")) == NULL)
		{
			dolog(LL_ERR, "ERROR, can't open acctfile %s for writing, terminating!", acctfile);
			exit(1);
		}
		setvbuf(acctfp, NULL, _IONBF, 0);
	}

	/* initialize alias processing */

	if(aliasing)
		init_alias(aliasfile);

	/* init holidays */

	init_holidays(holidayfile);

	/* init remote monitoring */

#ifdef I4B_EXTERNAL_MONITOR
	if(do_monitor)
	{
		monitor_init();
		sockfd = monitor_create_local_socket();
#ifndef I4B_NOTCPIP_MONITOR
		remotesockfd = monitor_create_remote_socket(monitorport);
#endif
	}
#endif

	/* in case fullscreendisplay, initialize */

#ifdef USE_CURSES
	if(do_fullscreen)
	{
		init_screen();
	}
#endif

	/* init realtime priority */

#ifdef USE_RTPRIO
  	if(rt_prio != RTPRIO_NOTUSED)
  	{
  		struct rtprio rtp;

  		rtp.type = RTP_PRIO_REALTIME;
  		rtp.prio = rt_prio;

  		if((rtprio(RTP_SET, getpid(), &rtp)) == -1)
  		{
			dolog(LL_ERR, "rtprio failed: %s", strerror(errno));
			do_exit(1);
		}
	}
#endif

	starttime = time(NULL);	/* get starttime */

	srandom(580403);	/* init random number gen */

	mloop(		/* enter loop of no return .. */
#ifdef I4B_EXTERNAL_MONITOR
		sockfd
#ifndef I4B_NOTCPIP_MONITOR
		, remotesockfd
#endif
#endif
		);
	do_exit(0);
	return(0);
}
Пример #4
0
/*ARGSUSED*/
int
schedinit(int argc, char *argv[])
  {
  char   *id = "schedinit";

  struct utsname name;

  struct sigaction act, oact;
  char   *ptr, canon[PBS_MAXHOSTNAME + 1];

  DBPRT(("\n%s\n", schd_VersionString));
  log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id,
             schd_VersionString);

  /*
   * If this is the initial startup configuration, then schd_TimeNow will
   * be 0.  Initialize it to the current time, so it can be tested against
   * various times when initializing.
   */

  if (schd_TimeNow == 0)
    {
    schd_TimeNow = time(NULL);
    DBPRT(("%s: initialize/startup at %s", id, ctime(&schd_TimeNow)));
    }

  /*
   * Determine location of configuration file.  Check for the presence of
   * the PBSSCHED_CONFIG environment variable.  If not defined, fall back
   * to the compiled default CONFIGFILE.
   *
   * Since neither the environment variables nor the compiled-in default
   * can be changed (with the exception of someone wreaking havoc with
   * a debugger or something), this only needs to be done once.
   */
  if (schd_CfgFilename == NULL)
    {
    ptr = getenv("PBSSCHED_CONFIG");

    if (ptr == NULL)
      ptr = CONFIGFILE;

    schd_CfgFilename = schd_strdup(ptr);

    if (schd_CfgFilename == NULL)
      {
      (void)sprintf(log_buffer, "schd_strdup() failed for configfile");
      log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
      DBPRT(("%s: %s\n", id, log_buffer));
      return (-1);
      }

    }

  /*
   * From this point on, goto cleanup_and_error: to clean up any allocated
   * storage for filenames.
   */

  DBPRT(("SCHEDINIT: Reading configuration from '%s'\n", schd_CfgFilename));

  /* Reset the configuration to a "known" state. */
  reset_config();

  /* Determine on what host this scheduler running. */
  uname(&name);

  if (get_fullhostname(name.nodename, canon, PBS_MAXHOSTNAME) == 0)
    {
    strncpy(schd_ThisHost, canon, PBS_MAXHOSTNAME);
    }
  else
    {
    (void)sprintf(log_buffer,
                  "Failed to canonicalize uname %s (using it anyway)",
                  name.nodename);
    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
    DBPRT(("%s: %s\n", id, log_buffer));
    strncpy(schd_ThisHost, name.nodename, PBS_MAXHOSTNAME);
    }

  schd_lowercase(schd_ThisHost);

  DBPRT(("%s: This host is '%s'\n", id, schd_ThisHost));

  /*
   * Register the state of the config file.  The call to reset_config()
   * above will have cleared all file watches.
   */

  if (schd_register_file(schd_CfgFilename))
    {
    (void)sprintf(log_buffer, "cannot watch %s", schd_CfgFilename);
    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
    DBPRT(("%s: %s\n", id, log_buffer));

    goto cleanup_and_error;
    }

  /* Read the configuration file. */
  if (schd_get_config(schd_CfgFilename))
    return (-1);


  /* if we are NOT making a distinction between Prime and Non-Prime Time,
   * then simply empty the holidays array; otherwise, try to read and load
   * the holidays file.
   */
  if (!schd_ENFORCE_PRIME_TIME)
    init_holidays();
  else
    {
    /*
     * Register the state of the holidays file.  This allows schd_req() to
     * reload it if it is changed.
     */
    if (schd_register_file(HOLIDAYS_FILE))
      {
      (void)sprintf(log_buffer, "cannot watch %s", HOLIDAYS_FILE);
      log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
      DBPRT(("%s: %s\n", id, log_buffer));

      goto cleanup_and_error;
      }

    /* Get a list of prime/non-prime times from the holidays file */
    if (schd_read_holidays() < 0)
      return (-1);
    }

  /*
   * Set up a signal handler for SIGHUP.  catch_HUP() will re-read the
   * configuration file.
   */
  act.sa_flags   = 0;

  act.sa_handler = catch_HUP;

  sigemptyset(&act.sa_mask);

  if (sigaction(SIGHUP, &act, &oact))
    {
    (void)sprintf(log_buffer, "Failed to setup SIGHUP handler.");
    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
    DBPRT(("%s: %s\n", id, log_buffer));
    }

  DBPRT(("SCHEDINIT: configuration complete.\n"));

  return (0);

cleanup_and_error:

  /*
   * Some error occurred.  Remove watches and free the storage allocated
   * for the filenames.
   */

  if (schd_CfgFilename)
    {
    schd_forget_file(schd_CfgFilename);
    free(schd_CfgFilename);
    }

  schd_CfgFilename     = NULL;

  return (-1);
  }