]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(main): Don't pass NULL first argument to path_concat.
authorJim Meyering <jim@meyering.net>
Sun, 4 Jul 2004 18:01:04 +0000 (18:01 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 4 Jul 2004 18:01:04 +0000 (18:01 +0000)
This cleans up the semantics a bit, as we no longer try to open the
same file twice.

src/nohup.c

index 88deba4d53b25878be8e01d4b27f6ab58d4c574c..1bc778154552edc716b40d654aee5d5b5aecfd68 100644 (file)
@@ -109,19 +109,24 @@ main (int argc, char **argv)
       char const *file = "nohup.out";
       int flags = O_CREAT | O_WRONLY | O_APPEND;
       mode_t mode = S_IRUSR | S_IWUSR;
-      int saved_errno;
 
       fd = open (file, flags, mode);
       if (fd == -1)
        {
-         saved_errno = errno;
-         in_home = path_concat (getenv ("HOME"), file, NULL);
-         fd = open (in_home, flags, mode);
+         int saved_errno = errno;
+         char const *home = getenv ("HOME");
+         if (home)
+           {
+             in_home = path_concat (home, file, NULL);
+             fd = open (in_home, flags, mode);
+           }
          if (fd == -1)
            {
              int saved_errno2 = errno;
              error (0, saved_errno, _("failed to open %s"), quote (file));
-             error (0, saved_errno2, _("failed to open %s"), quote (in_home));
+             if (in_home)
+               error (0, saved_errno2, _("failed to open %s"),
+                      quote (in_home));
              exit (NOHUP_FAILURE);
            }
          file = in_home;