Changeset 4e0f545 for perlconfig.c


Ignore:
Timestamp:
Jan 3, 2005, 4:53:33 PM (16 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
95474d7
Parents:
aa1bbf6
Message:
Print Better error message if startup fails due to unreadable .owlconf [BZ 57]
File:
1 edited

Legend:

Unmodified
Added
Removed
  • perlconfig.c

    rc3acb0b r4e0f545  
    152152char *owl_perlconfig_readconfig(char *file)
    153153{
    154   int ret;
     154  int ret, fd;
    155155  PerlInterpreter *p;
    156156  char filename[1024];
    157157  char *embedding[5];
     158  char *err;
    158159  struct stat statbuff;
    159160
     
    174175  owl_global_set_no_have_config(&g);
    175176
     177  /* Before we let perl have at it, we'll do our own checks on the the
     178   *  file to see if it's present, readnable etc.
     179   */
     180
     181  /* Not present, start without it */
    176182  ret=stat(filename, &statbuff);
    177183  if (ret) {
    178     return NULL;
    179   }
     184    return(NULL);
     185  }
     186
     187  /* present, but stat thinks it's unreadable */
     188  if (! (statbuff.st_mode & S_IREAD)) {
     189    return(owl_sprintf("%s present but not readable", filename));
     190  }
     191
     192  /* can we open it? */
     193  fd=open(filename, O_RDONLY);
     194  if (fd==-1) {
     195    return(owl_sprintf("could not open %s for reading", filename));
     196  }
     197  close(fd);
    180198
    181199  ret=perl_parse(p, owl_perl_xs_init, 2, embedding, NULL);
    182200  if (ret || SvTRUE(ERRSV)) {
    183201    STRLEN n_a;
    184     char *err;
    185     err = owl_strdup(SvPV(ERRSV, n_a));
    186     sv_setsv (ERRSV, &PL_sv_undef);     /* and clear the error */
    187     return err;
     202    err=owl_strdup(SvPV(ERRSV, n_a));
     203    sv_setsv(ERRSV, &PL_sv_undef);     /* and clear the error */
     204    return(err);
    188205  }
    189206
     
    191208  if (ret || SvTRUE(ERRSV)) {
    192209    STRLEN n_a;
    193     char *err;
    194     err = owl_strdup(SvPV(ERRSV, n_a));
    195     sv_setsv (ERRSV, &PL_sv_undef);     /* and clear the error */
    196     return err;
     210    err=owl_strdup(SvPV(ERRSV, n_a));
     211    sv_setsv(ERRSV, &PL_sv_undef);     /* and clear the error */
     212    return(err);
    197213  }
    198214
     
    217233  if (SvTRUE(ERRSV)) {
    218234    STRLEN n_a;
    219     char *err;
    220     err = owl_strdup(SvPV(ERRSV, n_a));
     235    err=owl_strdup(SvPV(ERRSV, n_a));
    221236    sv_setsv (ERRSV, &PL_sv_undef);     /* and clear the error */
    222     return err;
     237    return(err);
    223238  }
    224239
Note: See TracChangeset for help on using the changeset viewer.