Explorar el Código

Small refactoring

Serj Kalichev hace 1 año
padre
commit
26c4f753c2
Se han modificado 1 ficheros con 37 adiciones y 33 borrados
  1. 37 33
      klish/ksession/ksession_parse.c

+ 37 - 33
klish/ksession/ksession_parse.c

@@ -519,42 +519,46 @@ kexec_t *ksession_parse_for_exec(ksession_t *session, const char *raw_line,
 			return NULL;
 		}
 
-		// Only the first component can have 'restore=true' attribute
-		if ((iter != faux_list_head(split)) &&
-			kentry_restore(kpargv_command(pargv))) {
-			faux_error_sprintf(error, "The command \"%s\" "
-				"can't be destination of pipe",
-				kentry_name(kpargv_command(pargv)));
-			kpargv_free(pargv);
-			kexec_free(exec);
-			faux_list_free(split);
-			return NULL;
-		}
+		// First component
+		if (iter == faux_list_head(split)) {
 
-		// Only the first component can have 'interactive=true' attribute
-		if ((iter != faux_list_head(split)) &&
-			kentry_interactive(kpargv_command(pargv))) {
-			faux_error_sprintf(error, "The filter \"%s\" "
-				"can't be interactive",
-				kentry_name(kpargv_command(pargv)));
-			kpargv_free(pargv);
-			kexec_free(exec);
-			faux_list_free(split);
-			return NULL;
-		}
 
-		// Interactive command can't have filters
-		if ((iter != faux_list_head(split)) &&
-			kexec_interactive(exec)) {
-			faux_error_sprintf(error, "The interactive command \"%s\" "
-				"can't have filters",
-				kentry_name(kpargv_command(pargv)));
-			kpargv_free(pargv);
-			kexec_free(exec);
-			faux_list_free(split);
-			return NULL;
-		}
+		// Components after pipe "|"
+		} else {
 
+			// Only the first component can have 'restore=true' attribute
+			if (kentry_restore(kpargv_command(pargv))) {
+				faux_error_sprintf(error, "The command \"%s\" "
+					"can't be destination of pipe",
+					kentry_name(kpargv_command(pargv)));
+				kpargv_free(pargv);
+				kexec_free(exec);
+				faux_list_free(split);
+				return NULL;
+			}
+
+			// Only the first component can have 'interactive=true' attribute
+			if (kentry_interactive(kpargv_command(pargv))) {
+				faux_error_sprintf(error, "The filter \"%s\" "
+					"can't be interactive",
+					kentry_name(kpargv_command(pargv)));
+				kpargv_free(pargv);
+				kexec_free(exec);
+				faux_list_free(split);
+				return NULL;
+			}
+
+			// Interactive command can't have filters
+			if (kexec_interactive(exec)) {
+				faux_error_sprintf(error, "The interactive command \"%s\" "
+					"can't have filters",
+					kentry_name(kpargv_command(pargv)));
+				kpargv_free(pargv);
+				kexec_free(exec);
+				faux_list_free(split);
+				return NULL;
+			}
+		}
 
 		// Fill the kexec_t
 		context = kcontext_new(KCONTEXT_TYPE_ACTION);