Esempio n. 1
0
/* hdl_shut - call all shutdown call entries in LIFO order
 */
DLL_EXPORT void hdl_shut (void)
{
HDLSHD *shdent;

    if(MLVL(DEBUG))
        WRMSG( HHC01500, "I" );

    hdl_sdip = TRUE;

    for(shdent = hdl_shdlist; shdent; shdent = hdl_shdlist)
    {
        /* Remove shutdown call entry to ensure it is called once */
        hdl_shdlist = shdent->next;

        {
            if(MLVL(DEBUG))
                WRMSG( HHC01501, "I", shdent->shdname );

            (shdent->shdcall) (shdent->shdarg);

            if(MLVL(DEBUG))
                WRMSG( HHC01502, "I", shdent->shdname );
        }
        free(shdent);
    }

        if(MLVL(DEBUG))
            WRMSG( HHC01504, "I" );
}
Esempio n. 2
0
/*---------------------------------------------------------------------------*/
static int hao_ignoremsg(char *msg)
{
#if defined(OPTION_MSGCLR) || defined(OPTION_MSGHLD)
  static int debuglen = 0;
  char* nocolor = msg;
#endif
  int msglen;

#if defined( OPTION_MSGCLR )
  /* Get past color string if there is one */
  if (!(msglen = skippnlpfx( &nocolor )))       /* Skip past <pnl pfx  */
      return TRUE;                              /* Ignore if now empty */
  if (nocolor > msg)                            /* Color prefix found? */
    memmove( msg, nocolor, msglen+1 );          /* Remove color prefix */
#else /* defined( OPTION_MSGCLR ) */
  msglen = strlen(msg);
#endif /* defined( OPTION_MSGCLR ) */

#if defined(OPTION_MSGCLR) || defined(OPTION_MSGHLD)
  if (!debuglen)
  {
    char prefix[64] = {0};
    MSGBUF( prefix, MLVL_DEBUG_PRINTF_PATTERN, "foo", 999 );
    debuglen = (int)strlen( prefix );
  }

  /* Get past debug prefix if msglevel DEBUG is active */
  if (MLVL( DEBUG ) && msglen >= debuglen)
    memmove( msg, msg + debuglen, (msglen -= debuglen)+1 );
#endif

  /* Ignore our own messages (HHC0007xx, HHC0008xx and HHC0009xx
     are reserved so that hao.c can recognize its own messages) */
  if (0
      || !strncasecmp( msg, "HHC0007", 7 )
      || !strncasecmp( msg, "HHC0008", 7 )
      || !strncasecmp( msg, "HHC0009", 7 )
  )
    return TRUE;  /* (it's one of our hao messages; ignore it) */

  /* To be extra safe, ignore any messages with the string "hao" in them */
  if (0
      || !strncasecmp( msg, "HHC00013I Herc command: 'hao ",      29 )
      || !strncasecmp( msg, "HHC00013I Herc command: 'herc hao ", 34 )
      || !strncasecmp( msg, "HHC01603I hao ",                     14 )
      || !strncasecmp( msg, "HHC01603I herc hao ",                19 )
  )
    return TRUE;  /* (it's one of our hao messages; ignore it) */

  /* Same idea but for messages logged as coming from the .rc file */
  if (!strncasecmp( msg, "> hao ", 6 ))
    return TRUE;

  return FALSE;   /* (message appears to be one we should process) */
}
Esempio n. 3
0
/* hdl_setpath - set path for module load
 * If path is NULL, then return the current path
 * If path length is greater than MAX_PATH, send message and return NULL
 *     indicating an error has occurred.
 * If flag is TRUE, then only set new path if not already defined
 * If flag is FALSE, then always set the new path.
 */
DLL_EXPORT char *hdl_setpath(char *path, int flag)
{
    char    pathname[MAX_PATH];         /* pathname conversion */

    if (path == NULL)
        return hdl_modpath;             /* return module path to caller */

    if ( strlen(path) > MAX_PATH )
    {
        WRMSG( HHC01505, "E", (int)strlen(path), MAX_PATH );
        return NULL;
    }

    hostpath(pathname, path, sizeof(pathname));

    if (flag)
    {
        if (hdl_modpath)
        {
            if (!hdl_arg_p)
            {
                free(hdl_modpath);
            }
            else
            {
                WRMSG( HHC01506, "W", pathname );
                WRMSG( HHC01507, "W", hdl_modpath );
                return hdl_modpath;
            }
        }
    }
    else
    {
        hdl_arg_p = TRUE;
        if(hdl_modpath)
            free(hdl_modpath);
    }

    hdl_modpath = strdup(pathname);

    if (MLVL(VERBOSE))
        WRMSG( HHC01508, "I", hdl_modpath );

    return hdl_modpath;
}
Esempio n. 4
0
/*-------------------------------------------------------------------*/
int HercCmdLine (char* pszCmdLine)
{
    int      argc;
    char*    argv[ MAX_ARGS ];
    char*    cmdline  = NULL;
    int      rc       = -1;

    /* Save unmodified copy of the command line in case
       its format is unusual and needs customized parsing. */
    cmdline = strdup( pszCmdLine );

    /* Parse the command line into its individual arguments.
       Note: original command line now sprinkled with nulls */
    parse_args( pszCmdLine, MAX_ARGS, argv, &argc );

    /* Our primary Hercules command function gets first crack. */
    if ((rc = CallHercCmd( CMDFUNC_ARGS )) != HERRINVCMD)
        goto HercCmdExit;
    ASSERT( argv[0] ); /* (herc handles any/all empty commands) */

#if defined( _FEATURE_SYSTEM_CONSOLE )
    /* See if maybe it's a command that the guest understands. */
    if ( sysblk.scpimply && can_send_command() )
        scp_command( cmdline, FALSE, sysblk.scpecho ? TRUE : FALSE );
    else
#endif
        /* Error: unknown/unsupported command */
        WRMSG( HHC01600, "E", argv[0] );

HercCmdExit:

    /* Free our saved copy */
    free( cmdline );

    if (MLVL( DEBUG ))
    {
        char msgbuf[32];
        MSGBUF( msgbuf, "RC = %d", rc );
        WRMSG( HHC90000, "D", msgbuf );
    }

    return rc;
}
Esempio n. 5
0
/*-------------------------------------------------------------------*/
int http_command(int argc, char *argv[])
{
    int rc = 0;

    if ( !http_struct_init )
    {
        memset(&http_serv,0,sizeof(HTTP_SERV));
        initialize_condition( &http_serv.http_wait_shutdown );
        initialize_lock( &http_serv.http_lock_shutdown );
        initialize_lock( &http_lock_root );
        http_struct_init = TRUE;
    }

    http_serv.httpstmtold = FALSE;

    if ( argc == 2 && CMD(argv[0],rootx,4) &&
         ( ( strlen(argv[0]) == 5 && argv[2] != NULL && strcmp(argv[2],"httproot") == 0 ) ||
           ( strlen(argv[0]) == 4 ) ) )
    {
        if ( strlen(argv[0]) == 5 )
        {
            http_serv.httpstmtold = TRUE;
        }

        obtain_lock( &http_lock_root );
        if (http_serv.httproot)
        {
            free(http_serv.httproot);
            http_serv.httproot = NULL;
        }

        if ( strlen(argv[1]) > 0 )
        {
            char    pathname[MAX_PATH];

            hostpath(pathname, argv[1], sizeof(pathname));

            if ( pathname[strlen(pathname)-1] != PATHSEPC )
                strlcat( pathname, PATHSEPS, sizeof(pathname) );

            http_serv.httproot = strdup(pathname);
        }
        release_lock( &http_lock_root );

        http_root();

        if ( MLVL(VERBOSE) )
            WRMSG(HHC02204, "I", http_serv.httpstmtold ? "httproot": "root",
                        http_serv.httproot ? http_serv.httproot : "<not specified>");

        if ( http_serv.httpstmtold )
            http_startup(TRUE);

        rc = 0;
    }
    else if ( (argc == 2 || argc == 3 || argc == 5) && CMD(argv[0],portx,4) &&
              ( ( strlen(argv[0]) == 5 && argv[5] != NULL && strcmp(argv[5],"httpport") == 0 ) ||
                ( strlen(argv[0]) == 4 ) ) )
    {
        if ( strlen(argv[0]) == 5 )
        {
            http_serv.httpstmtold = TRUE;
        }

        if ( sysblk.httptid != 0 )
        {
            WRMSG( HHC01812, "E" );
            rc = -1;
        }
        else
        {
            char c;

            if (sscanf(argv[1], "%hu%c", &http_serv.httpport, &c) != 1
                    || http_serv.httpport == 0
                    || (http_serv.httpport < 1024 && http_serv.httpport != 80) )
            {
                rc = -1;
            }
            if ( rc >= 0 && argc == 3 && CMD(argv[2],noauth,6) )
            {
                http_serv.httpauth = 0;
            }
            else if ( rc >=0 && argc == 5 && CMD(argv[2],auth,4) )
            {
                if ( strlen( argv[3] ) < 1 || strlen( argv[4] ) < 1 )
                {
                    WRMSG( HHC01814, "E" );
                    rc = -1;
                }
                else
                {
                    if (http_serv.httpuser)
                        free(http_serv.httpuser);
                    http_serv.httpuser = strdup(argv[3]);

                    if (http_serv.httppass)
                        free(http_serv.httppass);
                    http_serv.httppass = strdup(argv[4]);

                    http_serv.httpauth = 1;
                }
            }
            else if ( argc != 2 || rc < 0 )
            {
                WRMSG( HHC02299, "E", "http" );
                rc = -1;
            }

            if ( rc >= 0 && MLVL(VERBOSE) )
            {
                char msgbuf[128];
                if ( http_serv.httpauth == 1 )
                {
                    MSGBUF( msgbuf, "port=%hu auth userid<%s> password<%s>",
                            http_serv.httpport,
                          ( http_serv.httpuser == NULL || strlen(http_serv.httpuser) == 0 ) ?
                                "" : http_serv.httpuser,
                          ( http_serv.httppass == NULL || strlen(http_serv.httppass) == 0 ) ?
                                "" : http_serv.httppass );
                }
                else
                    MSGBUF( msgbuf, "port=%hu noauth", http_serv.httpport );

                WRMSG( HHC02204, "I", http_serv.httpstmtold ? "httpport":"port", msgbuf );

                if ( http_serv.httpstmtold )
                    http_startup(TRUE);

            }   /* VERBOSE */
        }
    }
    else if ( argc == 1 && CMD(argv[0],start,3) )
    {
        if ( http_serv.httpport == 0 )
        {
            WRMSG( HHC01815, "E", "not valid");
            rc = -1;
        }
        else
            rc = http_startup(FALSE);
    }
    else if (argc == 1 && CMD(argv[0],stop,4))
    {
        if ( sysblk.httptid != 0 )
        {
            http_shutdown(NULL);
            WRMSG( HHC01805, "I" );
            rc = 1;
        }
        else
        {
            http_serv.httpshutdown = TRUE;
            WRMSG( HHC01806, "W", "already stopped" );
            rc = 1;
        }
    }
    else if ( argc == 0 )
    {
        if ( sysblk.httptid != 0 )
        {
            if ( http_serv.httpbinddone )
            {
                WRMSG( HHC01809, "I" );
                rc = 0;
            }
            else
            {
                WRMSG( HHC01813, "I" );
                rc = 1;
            }
        }
        else
        {
            WRMSG( HHC01810, "I" );
            rc = 1;
        }

        WRMSG(HHC01811, "I", http_get_root());

        WRMSG(HHC01808, "I", http_get_port(), http_get_portauth());
    }
    else
    {
        WRMSG( HHC02299, "E", "http" );
        rc = -1;
    }
    return rc;
}
Esempio n. 6
0
DLL_EXPORT void writemsg(const char *srcfile, int line, const char* function,
                         int grp, int lvl, char *color, char *msg, ...)
{
    char   *bfr     =   NULL;
    char   *msgbuf  =   NULL;
    int     rc      =   1;
    int     errmsg  =   FALSE;
    int     siz     =   1024;
    char    file[FILENAME_MAX];
    char    prefix[64];
    va_list vl;

    bfr = strdup(srcfile);
    strlcpy(file, basename(bfr), sizeof(file));
    free(bfr);
    bfr = NULL;

    memset(prefix, 0, sizeof(prefix));

#ifdef OPTION_MSGLCK
    if(!sysblk.msggrp || (sysblk.msggrp && !grp))
        WRGMSG_ON;
#endif

  #ifdef NEED_LOGMSG_FFLUSH
    fflush(stdout);
  #endif

    BFR_VSNPRINTF();

    if (!bfr)
    {
#ifdef OPTION_MSGLCK
        if(!sysblk.msggrp || (sysblk.msggrp && !grp))
            WRGMSG_OFF;
#endif
        return;
    }

    if ( strlen(bfr) > 10 && SNCMP(bfr,"HHC",3) && (bfr[8] == 'S' || bfr[8] == 'E' || bfr[8] == 'W') )
        errmsg = TRUE;

#if defined( OPTION_MSGCLR )
    if ( !strlen(color) )
    {
        if ( errmsg )
            color = "<pnl,color(lightred,black),keep>";
        else
            color = "";
    }
#else
    color = "";
#endif // defined( OPTION_MSGCLR )

    if ( lvl & MLVL_DEBUG )
    {
#if defined( OPTION_MSGCLR )
        if (strlen(color) > 0 && !sysblk.shutdown && sysblk.panel_init && !sysblk.daemon_mode)
            MSGBUF(prefix, "%s" MLVL_DEBUG_PRINTF_PATTERN, color, file, line);
        else
#endif
            MSGBUF(prefix, MLVL_DEBUG_PRINTF_PATTERN, file, line);
    }
    else
    {
#if defined( OPTION_MSGCLR )
        if (strlen(color) > 0 && !sysblk.shutdown && sysblk.panel_init && !sysblk.daemon_mode)
        {
            MSGBUF(prefix, "%s", color );
        }
#endif // defined( OPTION_MSGCLR )
    }

    if(bfr)
    {
        size_t l = strlen(prefix)+strlen(bfr)+256;
        msgbuf = calloc(1,l);
        if (msgbuf)
        {
            if ( strlen(bfr) > 10 && SNCMP(bfr, "HHC", 3) )
                snprintf( msgbuf, l-1, "%s%s", prefix, ( sysblk.emsg & EMSG_TEXT ) ? &bfr[10] : bfr );
            else
                snprintf( msgbuf, l-1, "%s%s", prefix, bfr );
            log_write( 0, msgbuf );
            free(msgbuf);
        }
        free(bfr);
    }

    if ( errmsg && !MLVL(DEBUG) )
        logmsg("HHC00007" "I" " " HHC00007 "\n", function, file, line);

  #ifdef NEED_LOGMSG_FFLUSH
    fflush(stdout);
  #endif

#ifdef OPTION_MSGLCK
    if(!sysblk.msggrp || (sysblk.msggrp && !grp))
        WRGMSG_OFF;
#endif

    log_wakeup(NULL);
}