add lttctl -e option : get xml description
authorcompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Thu, 8 Sep 2005 15:02:34 +0000 (15:02 +0000)
committercompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Thu, 8 Sep 2005 15:02:34 +0000 (15:02 +0000)
git-svn-id: http://ltt.polymtl.ca/svn@1163 04897980-b3bd-0310-b5e0-8ef037075253

ltt/branches/poly/ltt/facility.c
ltt/branches/poly/lttctl/lttctl.c

index 5b2c8ba4f2c76188427f47884fa192bc54dd1499..98ca73714ef422184d6345dc7fb6c220573dd95d 100644 (file)
@@ -135,6 +135,7 @@ int ltt_facility_open(LttFacility *f, LttTrace * t, gchar * pathname)
       freeTypes(&fac->unnamed_types);
       sequence_dispose(&fac->unnamed_types);      
       g_free(fac);
+      if(generated) break; /* use the first good match */
     }
     else {
       g_warning("facility token was expected in file %s", in.name);
index 38f01a035337b68866ffe15ec7bb86e2ee90081b..eeb4fa59d8013235710e981965e7855732b619d1 100644 (file)
@@ -32,6 +32,7 @@ enum trace_ctl_op {
        CTL_OP_START,
        CTL_OP_STOP,
        CTL_OP_DAEMON,
+       CTL_OP_DESCRIPTION,
        CTL_OP_NONE
 };
 
@@ -75,6 +76,7 @@ void show_arguments(void)
        printf("-l            LTT channels root path. (ex. /mnt/relayfs/ltt)\n");
        printf("-z            Size of the subbuffers (will be rounded to next page size)\n");
        printf("-x            Number of subbuffers\n");
+       printf("-e            Get XML facilities description\n");
        printf("\n");
 }
 
@@ -165,6 +167,9 @@ int parse_arguments(int argc, char **argv)
                                        case 'd':
                                                op = CTL_OP_DAEMON;
                                                break;
+          case 'e':
+            op = CTL_OP_DESCRIPTION;
+            break;
                                        case 't':
                                                if(argn+1 < argc) {
                                                        trace_root = argv[argn+1];
@@ -199,7 +204,7 @@ int parse_arguments(int argc, char **argv)
                argn++;
        }
        
-       if(trace_name == NULL) {
+       if(op != CTL_OP_DESCRIPTION && trace_name == NULL) {
                printf("Please specify a trace name.\n");
                printf("\n");
                ret = -1;
@@ -224,6 +229,14 @@ int parse_arguments(int argc, char **argv)
                }
        }
 
+  if(op == CTL_OP_DESCRIPTION) {
+    if(trace_root == NULL) {
+                       printf("Please specify -t trace_root_path with the -e option.\n");
+                       printf("\n");
+                       ret = -1;
+    }
+  }
+
        return ret;
 }
 
@@ -231,27 +244,105 @@ void show_info(void)
 {
        printf("Linux Trace Toolkit Trace Control\n");
        printf("\n");
-       printf("Controlling trace : %s\n", trace_name);
-       printf("\n");
+  if(trace_name != NULL) {
+       printf("Controlling trace : %s\n", trace_name);
+       printf("\n");
+  }
+}
+
+int create_eventdefs(void)
+{
+  int ret = 0;
+  char eventdefs_path[PATH_MAX];
+  char eventdefs_file[PATH_MAX];
+  char facilities_file[PATH_MAX];
+  char read_buf[BUF_SIZE];
+  struct dirent *entry;
+       char *facilities_path = getenv("LTT_FACILITIES");
+       if(facilities_path == NULL) facilities_path =
+          "/usr/share/LinuxTraceToolkitViewer/facilities";
+
+  ret = mkdir(trace_root, S_IRWXU|S_IRWXG|S_IRWXO);
+  if(ret == -1 && errno != EEXIST) {
+    perror("Cannot create trace_root directory");
+    printf("trace_root is %s\n", trace_root);
+    goto error;
+  }
+  
+  size_t trace_root_len = strlen(trace_root);
+  strncpy(eventdefs_path, trace_root, PATH_MAX);
+  strncat(eventdefs_path, "/eventdefs/", PATH_MAX - trace_root_len);
+  size_t eventdefs_path_len = strlen(eventdefs_path);
+  ret = mkdir(eventdefs_path, S_IRWXU|S_IRWXG|S_IRWXO);
+  if(ret == -1 && errno != EEXIST) {
+    perror("Cannot create eventdefs directory");
+    goto error;
+  }
+  
+  DIR *facilities_dir = opendir(facilities_path);
+  
+  while((entry = readdir(facilities_dir)) != NULL) {
+    if(entry->d_name[0] == '.') continue;
+    
+    printf("Appending facility file %s\n", entry->d_name);
+    strncpy(eventdefs_file, eventdefs_path, PATH_MAX);
+    strncat(eventdefs_file, entry->d_name, PATH_MAX - eventdefs_path_len);
+    /* Append to the file */
+    FILE *dest = fopen(eventdefs_file, "a");
+    if(!dest) {
+      perror("Cannot create eventdefs file");
+      continue;
+    }
+    strncpy(facilities_file, facilities_path, PATH_MAX);
+    size_t facilities_dir_len = strlen(facilities_path);
+    strncat(facilities_file, "/", PATH_MAX - facilities_dir_len);
+    strncat(facilities_file, entry->d_name, PATH_MAX - facilities_dir_len-1);
+    FILE *src = fopen(facilities_file, "r");
+    if(!src) {
+      perror("Cannot open eventdefs file for reading");
+      goto close_dest;
+    }
+
+    do {
+      size_t read_size, write_size;
+      read_size = fread(read_buf, sizeof(char), BUF_SIZE, src);
+      if(ferror(src)) {
+        perror("Cannot read eventdefs file");
+        goto close_src;
+      }
+      write_size = fwrite(read_buf, sizeof(char), read_size, dest);
+      if(ferror(dest)) {
+        perror("Cannot write eventdefs file");
+        goto close_src;
+      }
+    } while(!feof(src));
+
+    /* Add spacing between facilities */
+    fwrite("\n", 1, 1, dest);
+    
+close_src:
+    fclose(src);
+close_dest:
+    fclose(dest);
+  }
+
+  closedir(facilities_dir);
+
+  error:
+  return ret;
+
 }
 
+
 int lttctl_daemon(struct lttctl_handle *handle, char *trace_name)
 {
        char channel_path[PATH_MAX] = "";
        pid_t pid;
        int ret;
        char *lttd_path = getenv("LTT_DAEMON");
-       char *facilities_path = getenv("LTT_FACILITIES");
        struct sigaction act;
-  char eventdefs_path[PATH_MAX];
-  char eventdefs_file[PATH_MAX];
-  char facilities_file[PATH_MAX];
-  char read_buf[BUF_SIZE];
-  struct dirent *entry;
 
        if(lttd_path == NULL) lttd_path = "lttd";
-       if(facilities_path == NULL) facilities_path =
-          "/usr/share/LinuxTraceToolkitViewer/facilities";
        
        strcat(channel_path, channel_root);
        strcat(channel_path, "/");
@@ -277,65 +368,8 @@ int lttctl_daemon(struct lttctl_handle *handle, char *trace_name)
                /* Now the trace is created, go on and create the supplementary files... */
     
                printf("Creating supplementary trace files\n");
-    size_t trace_root_len = strlen(trace_root);
-    strncpy(eventdefs_path, trace_root, PATH_MAX);
-    strncat(eventdefs_path, "/eventdefs/", PATH_MAX - trace_root_len);
-    size_t eventdefs_path_len = strlen(eventdefs_path);
-    ret = mkdir(eventdefs_path, S_IRWXU|S_IRWXG|S_IRWXO);
-    if(ret) {
-      perror("Cannot create eventdefs directory");
-      goto start_error;
-    }
-    
-    
-    DIR *facilities_dir = opendir(facilities_path);
-    
-    while((entry = readdir(facilities_dir)) != NULL) {
-      if(entry->d_name[0] == '.') continue;
-                 
-      printf("Appending facility file %s\n", entry->d_name);
-      strncpy(eventdefs_file, eventdefs_path, PATH_MAX);
-      strncat(eventdefs_file, entry->d_name, PATH_MAX - eventdefs_path_len);
-      /* Append to the file */
-      FILE *dest = fopen(eventdefs_file, "a");
-      if(!dest) {
-        perror("Cannot create eventdefs file");
-        continue;
-      }
-      strncpy(facilities_file, facilities_path, PATH_MAX);
-      size_t facilities_dir_len = strlen(facilities_path);
-      strncat(facilities_file, "/", PATH_MAX - facilities_dir_len);
-      strncat(facilities_file, entry->d_name, PATH_MAX - facilities_dir_len-1);
-      FILE *src = fopen(facilities_file, "r");
-      if(!src) {
-        perror("Cannot open eventdefs file for reading");
-        goto close_dest;
-      }
-
-      do {
-        size_t read_size, write_size;
-        read_size = fread(read_buf, sizeof(char), BUF_SIZE, src);
-        if(ferror(src)) {
-          perror("Cannot read eventdefs file");
-          goto close_src;
-        }
-        write_size = fwrite(read_buf, sizeof(char), read_size, dest);
-        if(ferror(dest)) {
-          perror("Cannot write eventdefs file");
-          goto close_src;
-        }
-      } while(!feof(src));
-
-      /* Add spacing between facilities */
-      fwrite("\n", 1, 1, dest);
-      
-close_src:
-      fclose(src);
-close_dest:
-      fclose(dest);
-    }
-
-    closedir(facilities_dir);
+    ret = create_eventdefs();
+    if(ret) goto start_error;
 
        } else if(pid == 0) {
                /* child */
@@ -396,6 +430,9 @@ int main(int argc, char ** argv)
                case CTL_OP_DAEMON:
                        ret = lttctl_daemon(handle, trace_name);
                        break;
+    case CTL_OP_DESCRIPTION:
+      ret = create_eventdefs();
+      break;
                case CTL_OP_NONE:
                        break;
        }
This page took 0.026545 seconds and 4 git commands to generate.