[dahdi-commits] tzafrir: branch tools/tzafrir/sysfs r8745 - /tools/team/tzafrir/sysfs/
SVN commits to the DAHDI project
dahdi-commits at lists.digium.com
Thu Jun 3 13:58:07 CDT 2010
Author: tzafrir
Date: Thu Jun 3 13:58:04 2010
New Revision: 8745
URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=8745
Log:
Fix dahdi_cfg keep_going:
* Make sure we really keep_going when we should.
* Cleanup code paths: if lstat() fails, handle it immediately
so the rest of the code is not conditional.
* Fix an error message (printed 'pname' which is empty, and not 'prefix')
* Fix chan_pathnames[] handling:
- Needed to strdup() the string
- Moved handling into a single location
- Remove '/dev/dahdi/' prefix if exists.
* Remove uneeded chan_indexes[] mapping.
* Parser debugging is DEBUG_PARSER, not DEBUG_APPLY
* Improve/fix 'Channel map' printing format.
Modified:
tools/team/tzafrir/sysfs/dahdi_cfg.c
Modified: tools/team/tzafrir/sysfs/dahdi_cfg.c
URL: http://svnview.digium.com/svn/dahdi/tools/team/tzafrir/sysfs/dahdi_cfg.c?view=diff&rev=8745&r1=8744&r2=8745
==============================================================================
--- tools/team/tzafrir/sysfs/dahdi_cfg.c (original)
+++ tools/team/tzafrir/sysfs/dahdi_cfg.c Thu Jun 3 13:58:04 2010
@@ -143,7 +143,6 @@
static int path_channels;
static char *chan_pathnames[DAHDI_MAX_CHANNELS];
static int belong2span[DAHDI_MAX_CHANNELS];
-static int chan_indexes[DAHDI_MAX_CHANNELS];
static char *span_names[DAHDI_MAX_SPANS];
static const char *sigtype_to_str(const int sig)
@@ -347,6 +346,8 @@
struct stat stbuf;
char tmppath[PATH_MAX];
int span;
+ int n;
+ char *tmp;
/* Check legacy (no dial_byname) case */
if (sscanf(span_string, "%i", &span) == 1) {
@@ -358,36 +359,42 @@
* Relative paths -- below /dev/dahdi
*/
snprintf(path, sizeof(path), "%s%s", (tmppath[0] == '/') ? "" : "/dev/dahdi/", tmppath);
- if (lstat(path, &stbuf) >= 0) {
- int n;
- char *tmp;
-
- if (! S_ISLNK(stbuf.st_mode)) {
+ if (lstat(path, &stbuf) < 0) {
+ if(keep_going) {
+ return 0;
+ } else {
+ error("Failed lstat(%s): %s\n", path, strerror(errno));
+ return -1;
+ }
+ }
+ if (! S_ISLNK(stbuf.st_mode)) {
+ if(keep_going) {
+ return 0;
+ } else {
error("span '%s' (%s) is not a symlink\n", span_string, path);
return -1;
}
- n = readlink(path, tmppath, sizeof(tmppath));
- if (n < 0) {
+ }
+ n = readlink(path, tmppath, sizeof(tmppath));
+ if (n < 0) {
+ if(keep_going) {
+ return 0;
+ } else {
error("failed reading symlink '%s': %s\n", path, strerror(errno));
return -1;
}
- tmppath[n] = '\0';
- if((tmp = strrchr(tmppath, '/')) != NULL) {
- tmp++; /* skip the last slash */
- } else {
- tmp = tmppath;
- }
- if (debug & DEBUG_APPLY) {
- printf("%s: map '%s' to '%s'\n", __func__, tmppath, tmp);
- fflush(stdout);
- }
- span_string = tmp;
+ }
+ tmppath[n] = '\0';
+ if((tmp = strrchr(tmppath, '/')) != NULL) {
+ tmp++; /* skip the last slash */
} else {
- if (debug & DEBUG_APPLY) {
- printf("Failed lstat(%s): %s\n", path, strerror(errno));
- fflush(stdout);
- }
- }
+ tmp = tmppath;
+ }
+ if (debug & DEBUG_PARSER) {
+ printf("%s: map '%s' to '%s'\n", __func__, tmppath, tmp);
+ fflush(stdout);
+ }
+ span_string = tmp;
if (sscanf(span_string, "%d", &span) != 1) {
if(keep_going) {
return 0;
@@ -396,11 +403,12 @@
return -1;
}
}
- /* Compare addresses (modified or not) */
- if(span_string == tmppath) {
+ if(span_names[span] == NULL) {
span_names[span] = strdup(path);
- printf("%s: %d -> %s\n", __func__, span, span_names[span]);
- fflush(stdout);
+ if (debug & DEBUG_PARSER) {
+ printf("%s: %d -> %s\n", __func__, span, span_names[span]);
+ fflush(stdout);
+ }
}
return span;
}
@@ -420,7 +428,7 @@
}
span = span_string2num(realargs[0]);
if (span == 0) {
- if (debug & DEBUG_APPLY) {
+ if (debug & DEBUG_PARSER) {
printf("Skipping bad span '%s'\n", realargs[0]);
}
return 0;
@@ -518,6 +526,14 @@
}
channo = minor(stbuf.st_rdev);
path_channels++;
+ if (! chan_pathnames[channo]) {
+ char *p = strstr(path, "/dev/dahdi/");
+ if (p)
+ p = path + strlen("/dev/dahdi/");
+ else
+ p = path;
+ chan_pathnames[channo] = strdup(p);
+ }
return channo;
}
@@ -539,7 +555,7 @@
*pname = '\0';
in_span = span_string2num(prefix);
if(in_span <= 0) {
- error("Bad span string '%s'\n", pname);
+ error("Bad span string '%s'\n", prefix);
return -1;
}
if(only_span_num && only_span_num != in_span)
@@ -595,9 +611,7 @@
if (realchan == 0)
continue;
chans[realchan]=1;
- chan_pathnames[realchan] = pname;
belong2span[realchan] = in_span;
- chan_indexes[realchan] = y;
//fprintf(stderr, "DEBUG: %s\t%d -> %d\n", pname, y, realchan);
}
} else {
@@ -620,9 +634,7 @@
if (realchan == 0)
continue;
chans[realchan]=1;
- chan_pathnames[realchan] = pname;
belong2span[realchan] = in_span;
- chan_indexes[realchan] = chan;
//fprintf(stderr, "DEBUG: %s\t%d -> %d\n", pname, chan, realchan);
}
}
@@ -1430,12 +1442,10 @@
if(skip_chan(x))
continue;
if(showpaths) {
- y = chan_indexes[x];
- snprintf(channame, sizeof(channame), "%s!%02d",
- (chan_pathnames[x]) ? chan_pathnames[x] : "<NONAME>", y);
+ snprintf(channame, sizeof(channame), "%03d (%s)", x,
+ (chan_pathnames[x]) ? chan_pathnames[x] : "<NONAME>");
} else {
- y = x;
- snprintf(channame, sizeof(channame), "%02d", y);
+ snprintf(channame, sizeof(channame), "%03d", x);
}
if ((cc[x].sigtype != DAHDI_SIG_SLAVE) && (cc[x].sigtype)) {
configs++;
@@ -1667,7 +1677,10 @@
finish:
if (errcnt) {
fprintf(stderr, "\n%d error(s) detected\n\n", errcnt);
- exit(1);
+ if(keep_going)
+ fprintf(stderr, "Continue configuration...\n");
+ else
+ exit(1);
}
if (verbose || showpaths) {
printconfig(fd);
More information about the dahdi-commits
mailing list