Fix: reference counting of consumer output
[lttng-tools.git] / src / common / utils.c
index f9e6a99eafeec26afa4c7640f8a8d5a2c64178b1..766f224c7e167118d30dbd99c6b32595b4fe99e4 100644 (file)
@@ -1050,9 +1050,11 @@ char *utils_generate_optstring(const struct option *long_options,
                        break;
                }
 
-               optstring[str_pos++] = (char)long_options[i].val;
-               if (long_options[i].has_arg) {
-                       optstring[str_pos++] = ':';
+               if (long_options[i].val != '\0') {
+                       optstring[str_pos++] = (char) long_options[i].val;
+                       if (long_options[i].has_arg) {
+                               optstring[str_pos++] = ':';
+                       }
                }
        }
 
@@ -1062,13 +1064,13 @@ end:
 
 /*
  * Try to remove a hierarchy of empty directories, recursively. Don't unlink
- * any file.
+ * any file. Try to rmdir any empty directory within the hierarchy.
  */
 LTTNG_HIDDEN
 int utils_recursive_rmdir(const char *path)
 {
        DIR *dir;
-       int dir_fd, ret = 0, closeret;
+       int dir_fd, ret = 0, closeret, is_empty = 1;
        struct dirent *entry;
 
        /* Open directory */
@@ -1098,15 +1100,14 @@ int utils_recursive_rmdir(const char *path)
                                PATH_MAX - strlen(subpath) - 1);
                        strncat(subpath, entry->d_name,
                                PATH_MAX - strlen(subpath) - 1);
-                       ret = utils_recursive_rmdir(subpath);
-                       if (ret) {
-                               goto end;
+                       if (utils_recursive_rmdir(subpath)) {
+                               is_empty = 0;
                        }
                        break;
                }
                case DT_REG:
-                       ret = -EBUSY;
-                       goto end;
+                       is_empty = 0;
+                       break;
                default:
                        ret = -EINVAL;
                        goto end;
@@ -1117,7 +1118,7 @@ end:
        if (closeret) {
                PERROR("closedir");
        }
-       if (!ret) {
+       if (is_empty) {
                DBG3("Attempting rmdir %s", path);
                ret = rmdir(path);
        }
This page took 0.024331 seconds and 4 git commands to generate.