« UCMWB/Document Visibility | Main | ucmwb 1.2.3 release/Perl'isms »

UCMWB su bug

  • Fixed an issue with ucmwb running after su'ed to another user
  • Addressed some issues about PC running CC in the RAN network

Stupid coding

It never ceases to amaze me what some programmers do that when I look at it seem to be just foolish things. Here's today's example:

In ucmwb a bug was discovered when a user first su's to some other user then runs ucmwb (in this case the user is su'ing to ccadm). The while the main window dutifully displays the list of WORs for the su'ed user, the view browser does not. Instead it displays the list of views for the original user. Turns out that there was specific code for Solaris to call cuserid instead of getenv("USER"). So Linux was working but Solaris failed. Why the difference?

But along with that I noticed the following code:

    QSting homePath = QDir::homePath();

    if (homePath.isEmpty()) {
      qDebug() << "homePath is empty!";
      // Note the following is a Unix'ism and non portable!
      homePath = QString("/home/") + appUsername;
    }

    qDebug() << "homePath = " << homePath;
    QString settingsFilename = QDir::homePath() + QString("/.ucmwbrc");
    QString settingsDirname  = QDir::homePath() + QString("/.ucmwb.d");
    QString filterFilename   = settingsDirname + QString("/filters");

OK so first ask yourself what do you see wrong here.....?

Pencils down!

Here's my questions:

  1. Why go through the effort of getting the user's homePath, check to see if it's empty and then compose one with "/home" + appUsername only then to totally ignore all that work and get it again for settingsFilename?
  2. Why then do this operation of obtaining homePath yet again to set settingsDirname?
  3. If homePath were determined to be empty, aren't you ignoring what you set it to?

Naturally I fixed this to be:

    QSting homePath = QDir::homePath();

    if (homePath.isEmpty()) {
      // Note the following is a Unix'ism and non portable!
      homePath = QString("/home/") + appUsername;
    }

    QString settingsFilename = homePath + QString("/.ucmwbrc");
    QString settingsDirname  = homePath + QString("/.ucmwb.d");
    QString filterFilename   = settingsDirname + QString("/filters");

TrackBack

TrackBack URL for this entry:
http://defaria.com/mt/mt-tb.cgi/63