From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id BCD1B1B1C3 for ; Tue, 25 Sep 2018 17:15:50 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Sep 2018 08:15:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,302,1534834800"; d="scan'208";a="86425458" Received: from dhunt5-mobl2.ger.corp.intel.com (HELO [10.237.221.37]) ([10.237.221.37]) by orsmga003.jf.intel.com with ESMTP; 25 Sep 2018 08:15:44 -0700 To: "Burakov, Anatoly" , dev@dpdk.org Cc: john.mcnamara@intel.com, stephen@networkplumber.org, lei.a.yao@intel.com, bruce.richardson@intel.com References: <20180912144930.50578-1-david.hunt@intel.com> <20180914135406.52190-1-david.hunt@intel.com> <20180914135406.52190-6-david.hunt@intel.com> <47b4dbc6-48ca-f41c-86cb-e6f5b168ebf9@intel.com> <046d9290-55f9-8433-cbbd-b975f353fa47@intel.com> <5c1ca576-95ff-e150-7c4e-47bf4bfc255b@intel.com> From: "Hunt, David" Message-ID: <030089c0-bd02-4550-fdc3-7534d45754ba@intel.com> Date: Tue, 25 Sep 2018 16:15:43 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <5c1ca576-95ff-e150-7c4e-47bf4bfc255b@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Subject: Re: [dpdk-dev] [PATCH v3 5/8] examples/power: add json string handling X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Sep 2018 15:15:51 -0000 On 25/9/2018 3:15 PM, Burakov, Anatoly wrote: > On 25-Sep-18 3:00 PM, Hunt, David wrote: >>> Now you're removing those newlines you added in previous commit :) >>> >> >> Fixed in previous patch in the next version. >> >> >>>>       if (pol->pkt.core_type == CORE_TYPE_VIRTUAL) { >>>>           /* >>>>            * If the cores in the policy are virtual, we need to map >>>> them >>>> @@ -295,8 +423,6 @@ apply_traffic_profile(struct policy *pol) >>>>         diff = get_pkt_diff(pol); >>>>   -    RTE_LOG(INFO, CHANNEL_MONITOR, "Applying traffic profile\n"); >>>> - >>> >>> Here and in a few other places: these log message removals look to >>> be unrelated to this commit. Also, in my experience, more logging is >>> better than less logging, especially when something goes wrong - >>> maybe instead of removing them, just switch the level to debug? >>> >> >> Changed to Debug instead. Was causing quite a verbose output. > > Hopefully in a separate commit :) > Of Course. :) >> >>>>       if (diff >= (pol->pkt.traffic_policy.max_max_packet_thresh)) { >>>>           for (count = 0; count < pol->pkt.num_vcpu; count++) { >>>>               if (pol->core_share[count].status != 1) >>>> @@ -340,9 +466,6 @@ apply_time_profile(struct policy *pol) >>>>                   if (pol->core_share[count].status != 1) { >>>>                       power_manager_scale_core_max( >>>>                           pol->core_share[count].pcpu); >>>> -                RTE_LOG(INFO, CHANNEL_MONITOR, >>> >>> >>> >>>> +        int idx = 0; >>>> +        int indent = 0; >>>> +        do { >>>> +            n_bytes = read(chan_info->fd, &json_data[idx], 1); >>>> +            if (n_bytes == 0) >>>> +                break; >>>> +            if (json_data[idx] == '{') >>>> +                indent++; >>>> +            if (json_data[idx] == '}') >>>> +                indent--; >>> >>> What happens if someone sends a string with a "{" or "}" inside? >>> >> >> If we get to the end of the buffer without a "}", it calls the >> library to convert, will fail, and move on.  No damage done (I hope). >> Also, a short un-terminated (by "}") string will also exit when no >> characters read. >> So any invalid JSON string that's send to Jansson will fail to parse, >> and the application will be ready for the next (hopefully valid) JSON >> string. > > No, what i meant is something like this: > > { "json_value": "{"} > > According to JSON validator, this is a valid JSON string, but it will > break your code :) > You are correct if this code was designed to be a general purpose JSON string reader. However, it's only designed to take in strings for this sample application, and they do not expect any brace characters embedded within quotes. So I think it's OK for this use case. Patches welcome, though! :) Thanks, Dave.