[apparmor] [patch 09/12] Refactor the process_work_queue code into its own fn

Seth Arnold seth.arnold at canonical.com
Wed Aug 27 01:55:37 UTC 2014


On Mon, Aug 25, 2014 at 05:06:14PM -0700, john.johansen at canonical.com wrote:
> Signed-off-by: John Johansen <john.johansen at canonical.com>
> Acked-by: Steve Beattie <steve at nxnw.org>

Acked-by: Seth Arnold <seth.arnold at canonical.com>

Thanks

> 
> === modified file 'parser/libapparmor_re/hfa.cc'
> ---
>  parser/libapparmor_re/hfa.cc |   50 +++++++++++++++++++++++--------------------
>  parser/libapparmor_re/hfa.h  |    1 
>  2 files changed, 28 insertions(+), 23 deletions(-)
> 
> --- parser/libapparmor_re/hfa.cc.orig
> +++ parser/libapparmor_re/hfa.cc
> @@ -357,12 +357,37 @@
>  		cerr << "  " << (*i)->label << " <= " << (*i)->proto << "\n";
>  }
>  
> +void DFA::process_work_queue(const char *header, dfaflags_t flags)
> +{
> +	int i = 0;
> +
> +	while (!work_queue.empty()) {
> +		if (i % 1000 == 0 && (flags & DFA_DUMP_PROGRESS)) {
> +			cerr << "\033[2K" << header << ": queue "
> +			     << work_queue.size()
> +			     << "\tstates "
> +			     << states.size()
> +			     << "\teliminated duplicates "
> +			     << node_map.dup
> +			     << "\r";
> +		}
> +		i++;
> +
> +		State *from = work_queue.front();
> +		work_queue.pop_front();
> +
> +		/* Update 'from's transitions, and if it transitions to any
> +		 * unknown State create it and add it to the work_queue
> +		 */
> +		update_state_transitions(from);
> +	}  /* while (!work_queue.empty()) */
> +}
> +
>  /**
>   * Construct a DFA from a syntax tree.
>   */
>  DFA::DFA(Node *root, dfaflags_t flags): root(root)
>  {
> -	int i = 0;
>  	diffcount = 0;		/* set by diff_encode */
>  
>  	if (flags & DFA_DUMP_PROGRESS)
> @@ -394,28 +419,7 @@
>  	 *       work_queue at any given time, thus reducing peak memory use.
>  	 */
>  	work_queue.push_back(start);
> -
> -	while (!work_queue.empty()) {
> -		if (i % 1000 == 0 && (flags & DFA_DUMP_PROGRESS)) {
> -			cerr << "\033[2KCreating dfa: queue "
> -			     << work_queue.size()
> -			     << "\tstates "
> -			     << states.size()
> -			     << "\teliminated duplicates "
> -			     << node_map.dup
> -			     << "\r";
> -		}
> -		i++;
> -
> -		State *from = work_queue.front();
> -		work_queue.pop_front();
> -
> -		/* Update 'from's transitions, and if it transitions to any
> -		 * unknown State create it and add it to the work_queue
> -		 */
> -		update_state_transitions(from);
> -
> -	}  /* while (!work_queue.empty()) */
> +	process_work_queue("Creating dfa", flags);
>  
>  	/* cleanup Sets of nodes used computing the DFA as they are no longer
>  	 * needed.
> --- parser/libapparmor_re/hfa.h.orig
> +++ parser/libapparmor_re/hfa.h
> @@ -292,6 +292,7 @@
>  	void dump_node_to_dfa(void);
>  	State *add_new_state(NodeSet *nodes, State *other);
>  	void update_state_transitions(State *state);
> +	void process_work_queue(const char *header, dfaflags_t);
>  	void dump_diff_chain(ostream &os, map<State *, Partition> &relmap,
>  			     Partition &chain, State *state,
>  			     unsigned int &count, unsigned int &total,
> 
> 
> -- 
> AppArmor mailing list
> AppArmor at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/apparmor
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20140826/68c2f2f5/attachment.pgp>


More information about the AppArmor mailing list