Bug 5967 - LIGO: -i option to globus-rls-cli requires file end with end-of-line character
: LIGO: -i option to globus-rls-cli requires file end with end-of-line character
Status: RESOLVED FIXED
: Replica Location
RLS
: development
: All All
: P3 normal
: ---
Assigned To:
:
:
:
:
  Show dependency treegraph
 
Reported: 2008-03-31 10:21 by
Modified: 2008-05-28 19:16 (History)


Attachments


Note

You need to log in before you can comment on or make changes to this bug.


Description From 2008-03-31 10:21:06
The -i option to globus-rls-cli will fail on the last line of an input file if
it does not end with an end-of-line character but instead ends with EOF. The
error received is

ERROR: Input line length > 1024

The problem is this bit of code:

if (ptr && ptr[strlen(ptr)-1]!='\n') { /* long line check */
    fprintf(stderr, "ERROR: Input line length > %d\n", MAX_BULK_LINE_LENGTH);
    cleanexit(1);
  }

While it is true that in UNIX a plain text file that does not end in '\n' is
considered malformed, it would be nice if globus-rls-cli could handle the last
line ending with EOF and not '\n'.

So please consider this an enhancement request.
------- Comment #1 From 2008-04-02 18:47:17 -------
OK. I've changed that. It should work now. Also, I made a couple additional
changes. First, I also added the return '\r' character as a string token
delimiter, just in case. And I added line numbers to the error message output.
I can just imagine a LIGO sysadmin getting a message that a line is too long or
a line has too few arguments and then having to go figure out which one out of
thousands of lines!

Summary:
1. Accept EOF as terminator of last line
2. Add '\r' for token delimiters
3. Output line numbers on error messages

The changes are committed to TRUNK since the '-i' option has not yet been
backported to the globus_4_0_branch. Plan is to backport the '-i' feature
(which will have this fix) before 4.0.8.

Here's a diff and then a code snip.

Diff:
-----
Index: cli.c
===================================================================
RCS file: /home/globdev/CVS/globus-packages/replica/rls/client/cli.c,v
retrieving revision 1.15
diff -r1.15 cli.c
745a746
>   int  lineno;
789,793c790
<   if (ptr && ptr[strlen(ptr)-1]!='\n') { /* long line check */
<     fprintf(stderr, "ERROR: Input line length > %d\n", MAX_BULK_LINE_LENGTH);
<     cleanexit(1);
<   }
<   if (feof(in->infile)) {
---
>   if (!ptr && feof(in->infile)) {
796c793,798
<   in->fargv[0]=strtok(ptr, " \t\n");
---
>   if (ptr && !feof(in->infile) && ptr[strlen(ptr)-1]!='\n') { /* long line check */
>     fprintf(stderr, "ERROR: Input line length exceeds %d on line %d\n", 
>             MAX_BULK_LINE_LENGTH, in->lineno);
>     cleanexit(1);
>   }
>   in->fargv[0]=strtok(ptr, " \t\r\n");
798,799c800,803
<     if (! (in->fargv[i]=strtok(NULL, " \t\n")) )
<       fprintf(stderr, "ERROR: Input line too short.  Not enough args.\n");
---
>     if (! (in->fargv[i]=strtok(NULL, " \t\r\n")) ) {
>       fprintf(stderr, "ERROR: Input line too short. Not enough args on line %d\n", in->lineno);
>       cleanexit(1);
>     }
800a805
>   in->lineno++;
807a813
>   s->lineno = 0;
819a826
>   s->lineno = 1;
-----

Snip:
-----
static char **
bulk_next_args_from_file(bulk_input *in)

{
  char *line;
  char *ptr;
  int i;

  assert(in->pos < MAX_BULK_ELEMENTS);
  line=(in->inbuf)+((MAX_BULK_LINE_LENGTH+1) * in->pos);
  in->pos++;

  if (feof(in->infile)) {
    return NULL;
  }
  ptr = fgets(line, MAX_BULK_LINE_LENGTH, in->infile);
  if (!ptr && feof(in->infile)) {
    return NULL;
  }
  if (ptr && !feof(in->infile) && ptr[strlen(ptr)-1]!='\n') { /* long line
check */
    fprintf(stderr, "ERROR: Input line length exceeds %d on line %d\n",
            MAX_BULK_LINE_LENGTH, in->lineno);
    cleanexit(1);
  }
  in->fargv[0]=strtok(ptr, " \t\r\n");
  for (i=1; i < in->step; i++) {
    if (! (in->fargv[i]=strtok(NULL, " \t\r\n")) ) {
      fprintf(stderr, "ERROR: Input line too short. Not enough args on line
%d\n", in->lineno);
      cleanexit(1);
    }
  }
  in->lineno++;
  return in->fargv;
}
-----
------- Comment #2 From 2008-04-03 10:35:56 -------
I forgot. One additional thing that was fixed was a Segmentation Fault on exit
when there were too few arguments. Now it exits cleanly.