Exemplo n.º 1
0
static
rc_t test_vprintf ( const char *expected, const char *fmt, va_list args )
{
    rc_t rc;
    size_t num_writ;
    char buff [ 4096 ];

    rc = string_vprintf ( buff, sizeof buff, & num_writ, fmt, args );
    if ( rc != 0 )
    {
        /* report return code */
        pLogErr ( klogErr, rc, "string_vprintf returned non-zero rc with format '$(fmt)'", "fmt=%s", fmt );
    }
    else
    {
        size_t buff_size;

        /* verify results. they are:
           1. string itself
           2. number of characters in "num_writ"
        */

        if ( strcmp ( buff, expected ) != 0 )
        {
            /* set an appropriate return code */
            rc = RC ( rcExe, rcString, rcFormatting, rcData, rcIncorrect );

            /* report discrepancy */
            pLogErr ( klogErr, rc,
                      "string_vprintf result differs from expected:\n"
                      "  format   - '$(format)'\n"
                      "  expected - '$(expected)'\n"
                      "  observed - '$(observed)'"
                      , "format=%s,expected=%s,observed=%s"
                      , fmt
                      , expected
                      , buff
                );
        }

        buff_size = strlen ( buff );
        if ( buff_size != num_writ )
        {
            /* report discrepancy */
            pLogMsg ( klogErr,
                      "string_vprintf size differs from expected:\n"
                      "  expected - $(expected)\n"
                      "  observed - $(observed)"
                      , "expected=%zu,observed=%zu"
                      , buff_size
                      , num_writ
                );
        }
#if 1
        rc = 0;
#endif
    }

    return rc;
}
Exemplo n.º 2
0
LIB_EXPORT
rc_t CC
XFSNodeDump ( const struct XFSNode * self )
{
    rc_t RCt;
    char Buffer [ XFS_SIZE_1024 ];

    RCt = XFSNodeDescribe ( self, Buffer, sizeof ( Buffer ) );

    if ( RCt == 0 ) {
        pLogMsg ( klogDebug, "|||>>> $(buf)\n", "buf=%s", Buffer );
    }

    return RCt;
}   /* XFSNodeDump () */
Exemplo n.º 3
0
rc_t CC KMain ( int argc, char *argv [] )
{
    Args *args;
    rc_t rc = ArgsMakeAndHandle ( & args, argc, argv, 0 );
    if ( rc != 0 )
        LogErr ( klogErr, rc, "failed to parse arguments" );
    else
    {
        uint32_t paramc;
        rc = ArgsParamCount ( args, & paramc );
        if ( rc != 0 )
            LogErr ( klogInt, rc, "failed to obtain param count" );
        else
        {
            if ( paramc == 0 )
            {
                rc = RC ( rcExe, rcArgv, rcParsing, rcParam, rcInsufficient );
                LogErr ( klogErr, rc, "missing target object" );
                MiniUsage ( args );
            }
            else if ( paramc > 1 )
            {
                rc = RC ( rcExe, rcArgv, rcParsing, rcParam, rcExcessive );
                LogErr ( klogErr, rc, "expected single target object" );
                MiniUsage ( args );
            }
            else
            {
                const char *target;
                rc = ArgsParamValue ( args, 0, & target );
                if ( rc != 0 )
                    LogErr ( klogInt, rc, "failed to obtain param value" );
                else
                {
                    VDBManager *mgr;

#if TOOLS_USE_SRAPATH != 0
                    char full [ 4096 ];
                    SRAPath *sra_path;
                    rc = SRAPathMake ( & sra_path, NULL );
                    if ( rc == 0 )
                    {
                        if ( ! SRAPathTest ( sra_path, target ) )
                        {
                            rc = SRAPathFind ( sra_path, target, full, sizeof full );
                            if ( rc == 0 )
                                target = full;
                        }
                        SRAPathRelease ( sra_path );
                    }
#endif

                    rc = VDBManagerMakeUpdate ( & mgr, NULL );
                    if ( rc != 0 )
                        LogErr ( klogInt, rc, "failed to open VDB manager" );
                    else
                    {
                        rc = VDBManagerLock ( mgr, target );
                        if ( rc == 0 )
                            pLogMsg ( klogInfo, "locked '$(target)'", "target=%s", target );
                        else switch ( GetRCState ( rc ) )
                        {
                        case rcLocked:
                            pLogMsg ( klogInfo, "'$(target)' was already locked", "target=%s", target );
                            break;
                        default:
                            pLogErr ( klogErr, rc, "failed to lock '$(target)'", "target=%s", target );
                        }

                        VDBManagerRelease ( mgr );
                    }
                }
            }
        }

        ArgsWhack ( args );
    }

    return rc;
}
Exemplo n.º 4
0
static 
rc_t 
WorkerThreadFn ( const KThread *self, void *data )  
{
    KStream* stream = (KStream*)data;
    char buf[256];
    size_t num;
    rc_t rc = KStreamReadAll(stream, buf, 1, &num);
    if (rc == 0)
    {
        if (num == 1) 
        {
            size_t toRead = (unsigned char)buf[0];
            pLogMsg(klogInfo, "KeyringServer: worker received length=$(l)\n", "l=%d", toRead);
            rc = KStreamReadAll(stream, buf, toRead, &num);
            if (rc == 0)
            {
                /*pLogMsg(klogInfo, "KeyringServer: worker received msg='$(buf)'\n", "buf=%.*s", num, buf);*/
                switch (buf[0])
                {
                case 'I':
                    if (buf[0] == 'I') /* init */
                    {
                        LogMsg ( klogInfo, "KeyringServer: received Init");

                        if (keyring == 0)
                        {
                            const KFile* std_in;
                            
                            rc = KFileMakeStdIn ( &std_in );
                            if (rc == 0)
                            {
                                KFile* std_out;
                                rc = KFileMakeStdOut ( &std_out );
                                if (rc == 0)
                                {
                                    rc = KeyRingOpen(&keyring, keyRingFileName, std_in, std_out);
                                    if (rc == 0)
                                    {
                                        LogMsg ( klogInfo, "KeyringServer: Init successful");
                                        pLogMsg(klogInfo, "KeyringServer: sending '$(buf)'\n", "buf=%.*s", string_size(initMsgSuccess), initMsgSuccess);
                                        rc = KStreamWrite(stream, initMsgSuccess, string_size(initMsgSuccess), NULL);
                                    }
                                    else
                                    {
                                        rc_t rc2;
                                        LogErr(klogErr, rc, "KeyringServer: Init failed");
                                        rc2 = KStreamWrite(stream, initMsgFailure, string_size(initMsgFailure), NULL);
                                        if (rc == 0)
                                            rc = rc2;
                                    }
                                    KFileRelease(std_out);
                                }
                                KFileRelease(std_in);
                            }
                        }
                        else
                        {   /* already running */
                            LogMsg ( klogInfo, "KeyringServer: Init successful");
                            rc = KStreamWrite(stream, initMsgSuccess, string_size(initMsgSuccess), NULL);
                        }
                    }
                    break;
                case 'X':
                    if (buf[0] == 'X') /* shutDown */
                    {
                        LogMsg ( klogInfo, "KeyringServer: received Shutdown");
                        shutDown = true;
                    }
                    break;
                case 'P': /* project */
                    if (toRead > 1 && buf[1] == 'A') /* Add */
                    {
                        String pkey;
                        String dlkey;
                        String enckey;

                        size_t idx = 2;
                        /*TODO: make sure idx is in range*/
                        StringInit(&pkey, buf + idx + 1, buf[idx], buf[idx]);
                        pkey.len = string_len(pkey.addr, pkey.size);

                        idx += pkey.size + 1;
                        /*TODO: make sure idx is in range*/
                        StringInit(&dlkey, buf + idx + 1, buf[idx], buf[idx]);
                        dlkey.len = string_len(dlkey.addr, dlkey.size);
                        
                        idx += dlkey.size + 1;
                        /*TODO: make sure idx is in range*/
                        StringInit(&enckey, buf + idx + 1, buf[idx], buf[idx]);
                        enckey.len = string_len(enckey.addr, enckey.size);
                        
                        pLogMsg(klogInfo,  
                                "KeyringServer: received Project Add(pkey='$(pkey)',dlkey='$(dlkey)',enckey='$(.....)')'\n",
                                "pkey=%.*s,dlkey=%.*s,enckey=%.*s", 
                                pkey.len, pkey.addr, dlkey.len, dlkey.addr, enckey.len, enckey.addr);
                        
                        rc = KeyRingAddProject(keyring, &pkey, &dlkey, &enckey);
                        if (rc != 0)
                            LogErr(klogErr, rc, "KeyringServer: KeyRingAddProject() failed");
                    }
                    break;
                default:
                    LogMsg ( klogInfo, "KeyringServer: unrecognised message received");
                    break;
                }
            }
            else
                LogErr(klogErr, rc, "KeyringServer: KStreamRead(body) failed");
        }
        else /* end of stream = the client closed the connection */
            LogMsg(klogInfo, "KeyringServer: worker received EOF\n");
    }
    else
        LogErr(klogErr, rc, "KeyringServer: KStreamRead(length) failed");
    LogMsg ( klogInfo, "KeyringServer: worker done");
    return KThreadRelease(self);
}