ksysguardd fails to grab vlan stats on Ubuntu 12.04 LTS

Asked by BatteryKing on 2013-01-29

I am trying to use ksysguard to grab stats for multiple interfaces. When I select say eth0, it works. When I select a vlan, say eth0.101, it fails and just returns zeros for all stats I can think to ask for. I downloaded and looked at the source code to pine around for ideas and I came up with the file:
/kde-workspace-4.8.5/ksysguard/ksysguardd/Linux/netdev.c line 196

Before this line on line 191 it looks like the parser for the /proc/net/dev file looks for the ':' token in the interface stat line it is looking at. However on line 196 it assumes this token is at position 7 of the line. Actual code [ sscanf(buf + 7, "%llu %llu %llu %llu %llu %llu %llu %llu " ]. The problem I see with this is the device label of say "eth0.101:" is greater than 7 characters. I figure this is bound to cause issues specific to longer than seven character named vlan devices that would not be seen with shorter named devices such as eth0. I would think doing something like pointer arithmetic of say take the 'buf' pointer minus the 'pos' pointer plus 1 in place of the hard coded 7 on line 196 would work a lot better in the case one is trying to parse out vlan device stats as it would start the sscanf() parser in the right place.

If possible would like advise of how to fix this and get it right as for example I am not familiar with patching bugs beyond knowledge that launchpad exists, basic Linux usage knowledge, and some C and C++ knowledge. I am still trying to figure out things like how does one recompile KDE specific apps such as this one.

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu kde-workspace Edit question
Assignee:
No assignee Edit question
Solved by:
BatteryKing
Solved:
2013-01-31
Last query:
2013-01-31
Last reply:
2013-01-30
Manfred Hampl (m-hampl) said : #1

As this program is taken over from KDE I guess the right address for this issue will be www.kde.org or https://bugs.kde.org/

BatteryKing (jmcsnyder) said : #2

https://bugs.kde.org/ account registration seems to be broken in that when I try to create an account I do not get the confirmation email I need to finish the registration before I can post my bug report to them. I am using the same email I used to create the email account for this site, which continues to send me messages just fine (such as for this ticket), but nothing comes from the bugs.kde.org site. In order to report that the account registration process does not work on the bugs.kde.org site I need to have an account on said site, so I seem to be in a catch 22 situation. Any suggestions?

BatteryKing (jmcsnyder) said : #3

I still haven't figured out how to contact kde and report the bug. I did however figure out how to get the kde build environment to work and I successfully modified and recompiled the source code to pick up vlan traffic here is a code snippit of the ksysguard/ksysguardd/Linux/netdev.c file starting at line 173 detailing what I did to correct the issue (the delim_name_offset and label_delim_pos variables I created to replace the fixed value of 7 for the device label length):

  int delim_name_offset= 7;
  char* label_delim_pos;

  sprintf( format, "%%%d[^\n]\n", (int)sizeof( buf ) - 1 );
  sprintf( devFormat, "%%%ds", (int)sizeof( tag ) - 1 );

  /*Update the values for the wifi interfaces if there is a /proc/net/wireless file*/
  if (*netDevBufP != '\0') {
                /* skip 2 first lines */
                for (i = 0; i < 2; i++) {
                        sscanf(netDevBufP, format, buf);
                        buf[sizeof(buf) - 1] = '\0';
                        netDevBufP += strlen(buf) + 1; /* move netDevBufP to next line */
                }

                for (i = 0; sscanf(netDevBufP, format, buf) == 1; ++i) {
                        buf[sizeof(buf) - 1] = '\0';
                        netDevBufP += strlen(buf) + 1; /* move netDevBufP to next line */

                        if (sscanf(buf, devFormat, tag)) {
                                char* pos = strchr(tag, ':');
                                if (pos) {
                                        label_delim_pos= strchr(buf, ':');
                                        delim_name_offset= label_delim_pos - buf + 1;
                                        FORALL( DEFVARS );
                                        *pos = '\0';
                                        FORALL( SETZERO );
                                        sscanf(buf + delim_name_offset, "%llu %llu %llu %llu %llu %llu %llu %llu "