bin/*: improve error message on failure of nilfs_open()

The error message on failure of nilfs_open() function has two issues
in commands lscp, lssu, mkcp, chcp, rmcp, and dumpseg:

 1) When device name is omitted, a null pointer is passed to a string
    type field of the error message and a broken message is printed as
    below:

      lssu: (null): cannot open NILFS

 2) Description of errno is not shown in the error message.

This fixes these issues.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
This commit is contained in:
Ryusuke Konishi 2014-08-23 10:52:00 +09:00
parent 106bdc1ebc
commit fc2fe67724
6 changed files with 12 additions and 8 deletions

View File

@ -139,7 +139,8 @@ int main(int argc, char *argv[])
nilfs = nilfs_open(dev, NULL, NILFS_OPEN_RDWR | NILFS_OPEN_GCLK);
if (nilfs == NULL) {
fprintf(stderr, "%s: %s: cannot open NILFS\n", progname, dev);
fprintf(stderr, "%s: cannot open NILFS on %s: %m\n",
progname, dev ? : "device");
exit(1);
}

View File

@ -218,7 +218,8 @@ int main(int argc, char *argv[])
nilfs = nilfs_open(dev, NULL, NILFS_OPEN_RAW);
if (nilfs == NULL) {
fprintf(stderr, "%s: %s: cannot open NILFS\n", progname, dev);
fprintf(stderr, "%s: cannot open NILFS on %s: %m\n",
progname, dev ? : "device");
exit(1);
}

View File

@ -401,8 +401,8 @@ int main(int argc, char *argv[])
nilfs = nilfs_open(dev, NULL, NILFS_OPEN_RDONLY);
if (nilfs == NULL) {
fprintf(stderr, "%s: %s: cannot open NILFS\n",
progname, dev);
fprintf(stderr, "%s: cannot open NILFS on %s: %m\n",
progname, dev ? : "device");
exit(EXIT_FAILURE);
}

View File

@ -382,8 +382,8 @@ int main(int argc, char *argv[])
nilfs = nilfs_open(dev, NULL, open_flags);
if (nilfs == NULL) {
fprintf(stderr, "%s: %s: cannot open NILFS\n",
progname, dev);
fprintf(stderr, "%s: cannot open NILFS on %s: %m\n",
progname, dev ? : "device");
exit(1);
}

View File

@ -123,7 +123,8 @@ int main(int argc, char *argv[])
nilfs = nilfs_open(dev, NULL, NILFS_OPEN_RDWR | NILFS_OPEN_GCLK);
if (nilfs == NULL) {
fprintf(stderr, "%s: %s: cannot open NILFS\n", progname, dev);
fprintf(stderr, "%s: cannot open NILFS on %s: %m\n",
progname, dev ? : "device");
exit(1);
}

View File

@ -193,7 +193,8 @@ int main(int argc, char *argv[])
nilfs = nilfs_open(dev, NULL, NILFS_OPEN_RDWR);
if (nilfs == NULL) {
fprintf(stderr, "%s: %s: cannot open NILFS\n", progname, dev);
fprintf(stderr, "%s: cannot open NILFS on %s: %m\n",
progname, dev ? : "device");
exit(1);
}