lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2b028359-7cf1-434a-83a5-02a3f5e0ac0c@mellanox.com>
Date:   Tue, 2 Jan 2018 22:03:26 +0800
From:   Chris Mi <chrism@...lanox.com>
To:     David Ahern <dsahern@...il.com>, netdev@...r.kernel.org
Cc:     gerlitz.or@...il.com, stephen@...workplumber.org
Subject: Re: [patch iproute2 v3 2/4] utils: Add a function setcmdlinetotal


> On 12/25/17 2:46 AM, Chris Mi wrote:
>> This function calculates how many commands a batch file has and
>> set it to global variable cmdlinetotal.
>>
>> Signed-off-by: Chris Mi <chrism@...lanox.com>
>> ---
>>   include/utils.h |  4 ++++
>>   lib/utils.c     | 20 ++++++++++++++++++++
>>   2 files changed, 24 insertions(+)
>>
>> diff --git a/include/utils.h b/include/utils.h
>> index d3895d56..113a8c31 100644
>> --- a/include/utils.h
>> +++ b/include/utils.h
>> @@ -235,6 +235,10 @@ void print_nlmsg_timestamp(FILE *fp, const struct nlmsghdr *n);
>>   
>>   extern int cmdlineno;
>>   ssize_t getcmdline(char **line, size_t *len, FILE *in);
>> +
>> +extern int cmdlinetotal;
>> +void setcmdlinetotal(const char *name);
>> +
>>   int makeargs(char *line, char *argv[], int maxargs);
>>   int inet_get_addr(const char *src, __u32 *dst, struct in6_addr *dst6);
>>   
>> diff --git a/lib/utils.c b/lib/utils.c
>> index 7ced8c06..53ca389f 100644
>> --- a/lib/utils.c
>> +++ b/lib/utils.c
>> @@ -1202,6 +1202,26 @@ ssize_t getcmdline(char **linep, size_t *lenp, FILE *in)
>>   	return cc;
>>   }
>>   
>> +int cmdlinetotal;
>> +
>> +void setcmdlinetotal(const char *name)
>> +{
>> +	char *line = NULL;
>> +	size_t len = 0;
>> +
>> +	if (name && strcmp(name, "-") != 0) {
>> +		if (freopen(name, "r", stdin) == NULL) {
>> +			fprintf(stderr, "Cannot open file \"%s\" for reading: %s\n",
>> +				name, strerror(errno));
>> +			return;
>> +		}
>> +	}
>> +
>> +	cmdlinetotal = 0;
>> +	while (getcmdline(&line, &len, stdin) != -1)
>> +		cmdlinetotal++;
>> +}
>> +
>>   /* split command line into argument vector */
>>   int makeargs(char *line, char *argv[], int maxargs)
>>   {
>>
> This helper should not be needed. There is no need to read what could be
> a million+ line file multiple times.
Done. I removed this helper. But we can't simply use !feof directly.
I figure out a way to determine if we are reaching the end of file by
reading one more line of the batch file.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ