changeset 4:e802f3c8af1a

fix ie-docker can execute "docker run" command.
author taiki <taiki@cr.ie.u-ryukyu.ac.jp>
date Mon, 14 Jul 2014 22:45:54 -1000
parents dcca39030bd8
children f4e5b5c0d621
files ie-docker.c
diffstat 1 files changed, 31 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/ie-docker.c	Mon Jul 14 16:38:20 2014 -1000
+++ b/ie-docker.c	Mon Jul 14 22:45:54 2014 -1000
@@ -28,7 +28,7 @@
 #define start_command "start" 
 #define stop_command "stop" 
 
-static char bad_name[] = "Bad process name. Try students/e11/e115711/01 or teachers/kono/02\n";
+static char bad_name[] = "Bad process name. Try students_e11_e115711_01 or teachers_kono_02\n";
 
 #define PSNAME_MAX (512)
 
@@ -85,7 +85,7 @@
         if (c<=' ') return 1;
         if (('a'<=c && c<='z') ||
                 ('0'<=c && c<='9') ||
-                ('/'==c ) ||
+                ('_'==c ) ||
                 ('-'==c )) continue;
         return 1;
         printf("%c", c);
@@ -96,8 +96,22 @@
 void 
 usage()
 {
-    printf("Usage:\n\trun:    run process\n\tbuild:  build docker process from Dockerfile\n\tattach: atach process\n\tdettach: \n\tpull: \n\timages: \n\tcommit:\n");
-    printf("   ps-name should be students/e11/e115711/01 or teachers/kono/02\n");
+    printf("Usage: ie-docker\n");
+    printf("\trun:    run process\n");
+    printf("\tbuild:  build docker process from Dockerfile\n");
+    printf("\tattach: atach process\n");
+    printf("\tdettach: \n");
+    printf("\tpull: \n");
+    printf("\timages: \n");
+    printf("\tcommit:\n");
+    printf("\tps-name should be students_e11_e115711_01 or teachers_kono_02\n");
+}
+
+void
+run_usage()
+{
+    printf("Usage: ie-docker run\n");
+    printf("\tie-docker [option] --name e145701_[process_name] {image name}:{tag} [execute command] [argument]");
 }
 
 /* main(int argc, char **argv) - main process loop */
@@ -138,17 +152,23 @@
     setuid(0);
 
     if (argc >= 3) {
-        if ( strncmp(argv[1], pull_command, 6) == 0 ) {
-            if (regexec(pattern, argv[2], (size_t) 0, NULL, 0)) {
+        if (strncmp(argv[1], run_command, 6) == 0 ) {
+            if (strncmp(argv[3], "--name", 6) != 0) {
+                run_usage();
+                exit(0);
+            }
+
+            if (regexec(pattern, argv[4], (size_t) 0, NULL, 0)) {
                 fprintf(stderr, bad_name);
                 exit(0);
             }
 
-            if (check_name(argv[2])) {
+            if (check_name(argv[3])) {
                 fprintf(stderr, bad_name);
                 exit(0);
             }
 
+            /*           
             char exec[1024];
 
             strncpy(exec,"/usr/local/bin/newps.py -c /etc/libvirt/qemu/fedora19.xml -n ", 900);
@@ -156,37 +176,21 @@
             strncat(exec, argv[2],1000);
             fprintf(stdout, "excuting %s\n",exec );
             system(exec);
+            */
         }
     }
 
 
     PSLISTPTR pslist = get_pslist(pattern);
 
-    char name_xml[1024];
-    name_xml[0] = 0;
-    if (argc>=3) {
-        if ( strncmp(argv[1], "define", 6) == 0 ) {
-            strncpy(name_xml,argv[2],900);
-            strncat(name_xml,".xml",1000);
-        } else if (check_pslist_name(pslist, argv[2])==0) {
-            fprintf(stderr, bad_name);
-            print_pslist(pslist);
-            exit(0);
-        }
-    } else if (argc<2) {
-        print_pslist(pslist);
-        usage();
-        exit(0);
-    }
-
     /* Check argv for proper arguments and run 
      * the corresponding script, if invoked.
      */
 
-    if (argv[1]==0 || strncmp(argv[1], "list", 4) == 0 ) {
+    if (argv[1]==0 || strncmp(argv[1], "ps", 4) == 0 ) {
         print_pslist(pslist);
     } else if (strncmp(argv[1], run_command, 5) == 0) {
-        if (execl(command, command, run_command, argv[2], NULL) < 0) {
+        if (execl(command, command, run_command, argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], NULL) < 0) {
             perror("Execl:");
         }
     } else if (strncmp(argv[1], start_command, 5) == 0) {
@@ -202,7 +206,7 @@
             perror("Execl:");
         }
     } else if (strncmp(argv[1], attach_command, 6) == 0 ) {
-        if (execl(command, command, attach_command, name_xml, NULL) < 0) {
+        if (execl(command, command, attach_command, NULL) < 0) {
             perror("Execl:");
         }
     } else if ( strncmp(argv[1], dettach_command, 8) == 0 ) {