Пример #1
0
int
limLock(int argc, char **argv)
{
    int duration;
    char *optName;

    duration = 0;
    while ((optName = myGetOpt(argc, argv, "l:")) != NULL) {
        switch(optName[0]) {
            case 'l':
                duration = atoi(optarg);
                if (!isint_(optarg) || atoi(optarg) <= 0) {
	            fprintf(stderr, "\
The host locking duration <%s> should be a positive integer\n", optarg);
                    return -2;
		}
		break;
            default:
                return -2;
        }
    }
Пример #2
0
int
limLock(int argc, char **argv)
{
    u_long duration = 0;
    extern int optind;
    extern char *optarg;
    char *optName;

    while ((optName = myGetOpt(argc, argv, "l:")) != NULL) {
        switch(optName[0]) {
            case 'l':
                duration = atoi(optarg);
                if (!isint_(optarg) || atoi(optarg) <= 0) {
	            fprintf(stderr, I18N(258, "The host locking duration <%s> should be a positive integer\n"), optarg); /* catgets 258 */
                    return -2;
		}
		break;
            default:
                return -2;
        }
    }

    if (argc > optind)
        return -2;

    if (ls_lockhost(duration) < 0) {
	ls_perror("failed");
        return(-1);
    }

    if (duration)
        printf(I18N(259, "Host is locked for %lu seconds\n") /* catgets 259 */,
	       (unsigned long)duration);
    else
        printf(I18N(260, "Host is locked\n")); /* catgets 260 */

    fflush(stdout);
    return(0);
}
Пример #3
0
int
limCtrl(int argc, char **argv, int opCode)
{
    char *optName;
    char *localHost;
    int vFlag = 0;
    int config = 0, checkReply;

    fFlag = 0;
    if (strcmp(argv[optind-1], "reconfig") == 0) {
	config = 1;
    }

    while ((optName = myGetOpt(argc, argv, "f|v|")) != NULL) {
        switch (optName[0]) {
            case 'v':
                if (opCode == LIM_CMD_SHUTDOWN)
                    return(-2);
                vFlag = 1;
                break;
            case 'f':
                fFlag = 1;
                break;
            default:
                return(-2);
        }
    }
    exitrc = 0;
    if (config && optind != argc)
        return -2;

    switch (checkReply)  {
	case EXIT_FATAL_ERROR:
            return -1;
	case EXIT_WARNING_ERROR:
            if (fFlag)
                break;
            if (!getConfirm(I18N(250, "Do you want to reconfigure? [y/n] "))) /* catgets 250 */ {
                fprintf(stderr, I18N(251, "Reconfiguration aborted.\n")); /* catgets 251 */
                return(-1);
            }
            break;
        default:
            break;
    }

    if (config) {
        doAllHosts(opCode);
        return(exitrc);
    }

    if (optind == argc) {
	if ((localHost = ls_getmyhostname()) == NULL) {
            ls_perror("ls_getmyhostname");
            return -1;
	}
        operateHost(localHost, opCode, 0);
    }
    else
    {
	doHosts(argc, argv, opCode);
    }

    return(exitrc);

}
Пример #4
0
int
bhc(int argc, char *argv[], int opCode)
{
    struct hostInfoEnt *hostInfo ;
    char **hostPoint ;
    char **hosts=NULL;
    char *optName;
    char message[MAXLINELEN];
    int i;
    int fFlag = FALSE;
    int  all = FALSE, numHosts = 0;
    int  inquerFlag = FALSE;

    while ((optName = myGetOpt(argc, argv, "C:f|")) != NULL) {
        switch (optName[0]) {
            case 'f':
                fFlag = TRUE;
                break;
            case 'C':
                if (strlen(optarg) > MAXLINELEN-1) {
                    printf("Message too long, truncated to %d char.\n", MAXLINELEN-1);
                    strncpy(message, optarg, MAXLINELEN-1);
                    message[MAXLINELEN-1]='\0';
                } else
                    strcpy(message, optarg);
                break;
            default:
                return -2;
        }
    }
    switch (opCode) {
        case HOST_OPEN :
            opStr = (_i18n_msg_get(ls_catd,NL_SETN,901, "Open")); /* catgets  901  */
            break;
        case HOST_CLOSE :
            opStr = (_i18n_msg_get(ls_catd,NL_SETN,902, "Close")); /* catgets  902  */
            break;
        case HOST_REBOOT :
            opStr = (_i18n_msg_get(ls_catd,NL_SETN,903, "Restart slave batch daemon on")); /* catgets  903  */
            break;
        case HOST_SHUTDOWN :
            opStr = (_i18n_msg_get(ls_catd,NL_SETN,904, "Shut down slave batch daemon on")); /* catgets  904  */
            break;
        default :
            fprintf(stderr, (_i18n_msg_get(ls_catd,NL_SETN,905, "Unknown operation code\n"))); /* catgets  905  */
            exit(-1);
    }

    exitrc = 0;
    numHosts = getNames (argc, argv, optind, &hosts, &all, "hostC");
    hostPoint = NULL;
    if (!numHosts && !all)
        numHosts = 1;
    else if (numHosts)
        hostPoint = hosts;


    if ((opCode == HOST_REBOOT || opCode == HOST_SHUTDOWN) &&
        !(numHosts == 0 && all)) {

        if ((hostInfo = getHostList(&numHosts, hostPoint)) == NULL)
            return -1;
    } else {
        if ((hostInfo = lsb_hostinfo (hostPoint, &numHosts)) == NULL) {
            lsb_perror(NULL);
            return -1;
        }
    }

    if (!fFlag && all && (opCode == HOST_REBOOT || opCode == HOST_SHUTDOWN))
        inquerFlag = !doConfirm (opCode, NULL);

    for (i = 0; i < numHosts; i++) {
        if (strcmp(hostInfo[i].host, "lost_and_found") == 0
            && (opCode == HOST_REBOOT || opCode == HOST_SHUTDOWN)) {
            if (!all)
                fprintf(stderr, (_i18n_msg_get(ls_catd,NL_SETN,906, "<lost_and_found> is not a real host, ignored\n"))); /* catgets  906  */
            continue;
        }
        if (inquerFlag && !(doConfirm (opCode, hostInfo[i].host)))
            continue;

        fprintf(stderr, "%s <%s> ...... ", opStr, hostInfo[i].host);
        fflush(stderr);

        ctrlHost (hostInfo[i].host, hostInfo[i].hStatus, opCode, message);
    }
    return exitrc;

}
Пример #5
0
int
breconfig (int argc, char **argv, int configFlag)
{
  char *optName;
  int vFlag = 0;
  int fFlag = 0;
  int checkReply;
  int stdoutsave;
  int fd;
  FILE *fp;
  char *linep;
  char tmpfile[256];
  char *tmpname = "tmpXXXXXX";

  while ((optName = myGetOpt (argc, argv, "f|v|")) != NULL)
    {
      switch (optName[0])
	{
	case 'v':
	  vFlag = 1;
	  break;
	case 'f':
	  fFlag = 1;
	  break;
	default:
	  return (-2);
	}
    }
  if (optind < argc)
    {
      return (-2);
    }

  if (!vFlag && !fFlag)
    {

      fprintf (stderr, "\nChecking configuration files ...\n\n");

      stdoutsave = dup (1);
      sprintf (tmpfile, "/tmp/%s", tmpname);
      mktemp (tmpfile);
      fd = open (tmpfile, O_RDWR | O_CREAT | O_TRUNC, 0666);
      if (fd > 0)
	{

	  dup2 (fd, 1);
	  dup2 (fd, 2);
	  checkReply = checkConf (1, 2);
	  fflush (stderr);
	  close (fd);
	  dup2 (stdoutsave, 1);
	  dup2 (stdoutsave, 2);
	  fp = fopen (tmpfile, "r");
	  if (fp != 0)
	    {
	      if (checkReply == EXIT_FATAL_ERROR
		  || checkReply == EXIT_WARNING_ERROR)
		{
		  if (checkReply == EXIT_FATAL_ERROR)
		    fprintf (stderr, "There are fatal errors.\n\n");
		  else
		    fprintf (stderr, "There are warning errors.\n\n");
		  fflush (stderr);

		  if (getConfirm ((_i18n_msg_get (ls_catd, NL_SETN, 2563, "Do you want to see detailed messages? [y/n] "))))	/* catgets  2563  */
		    while ((linep = getNextLine_ (fp, 0)))
		      fprintf (stderr, "%s\n", linep);
		}
	      else
		fprintf (stderr, I18N (2586, "No errors found.\n\n"));	/* catgets 2586 */
	      fflush (stderr);
	    }
	  fclose (fp);
	  unlink (tmpfile);
	}
      else
	checkReply = checkConf (0, 2);
    }
  else
    checkReply = checkConf (vFlag, 2);

  if (configFlag == MBD_CKCONFIG)
    {
      return (0);
    }

  switch (checkReply)
    {
    case EXIT_FATAL_ERROR:
      return -1;
    case EXIT_WARNING_ERROR:
      if (fFlag)
	break;
      if (configFlag == MBD_RECONFIG)
	{
	  if (!getConfirm
	      ((_i18n_msg_get
		(ls_catd, NL_SETN, 2564,
		 "\nDo you want to reconfigure? [y/n] "))))
	    {			/* catgets  2564  */
	      fprintf (stderr, (_i18n_msg_get (ls_catd, NL_SETN, 2565, "Reconfiguration aborted.\n")));	/* catgets  2565  */
	      return (-1);
	    }
	}
      else
	{
	  if (!getConfirm
	      (I18N (2570, "\nDo you want to restart MBD? [y/n] ")))
	    {			/* catgets  2570  */
	      fprintf (stderr, (I18N (2571, "MBD restart aborted.\n")));	/* catgets  2571  */
	      return (-1);
	    }
	}
    default:
      ;
    }

  if (lsb_reconfig (configFlag) < 0)
    {
      lsb_perror ((_i18n_msg_get (ls_catd, NL_SETN, 2566, "Failed")));	/* catgets  2566  */
      return (-1);
    }

  if (configFlag == MBD_RECONFIG)
    {
      printf ("%s\n", _i18n_msg_get (ls_catd, NL_SETN, 2567, "Reconfiguration initiated"));	/* catgets  2567  */
    }
  else
    {
      printf ("%s\n", I18N (2569, "MBD restart initiated"));	/* catgets  2569  */
    }
  return (0);

}
Пример #6
0
int
sysHist(int argc, char **argv, int opCode)
{
    struct histReq req;
    int all = FALSE, eventFound;
    char **nameList=NULL;
    int numNames = 0;
    char *optName;


    req.opCode = opCode;
    req.names = NULL;
    req.eventFileName = NULL;
    req.eventTime[0] = 0;
    req.eventTime[1] = 0;

    while ((optName = myGetOpt(argc, argv, "t:|f:")) != NULL) {
	switch (optName[0]) {
	case 'f':
            if (strlen(optarg) > MAXFILENAMELEN -1) {
		fprintf(stderr, (_i18n_msg_get(ls_catd,NL_SETN,1051, "%s: File name too long\n")), optarg); /* catgets  1051  */
		return(-1);
            } else
	        req.eventFileName = optarg;
	    break;
        case 't':
            if (getBEtime(optarg, 't', req.eventTime) == -1) {
		ls_perror(optarg);
		return (-1);
            }
            break;
	default:
	    return(-2);
	}
    }

    switch (opCode) {
    case QUEUE_HIST:
    case HOST_HIST:
	if (argc > optind) {
	    numNames = getNames(argc, argv, optind, &nameList, &all, "queueC");
	    if (!all && numNames != 0) {
	        nameList[numNames] = NULL;
		req.names = nameList;
	    }
	}
	break;

    case MBD_HIST:
    case SYS_HIST:
        if (argc > optind)
            return(-2);
	break;

    default:
	fprintf(stderr, (_i18n_msg_get(ls_catd,NL_SETN,1052, "Unknown operation code\n"))); /* catgets  1052  */
	return(-2);
    }

    return (searchEventFile(&req, &eventFound));

}