Jelajahi Sumber

:bug: Debug pid_list

Loquicom 6 tahun lalu
induk
melakukan
952869089e
3 mengubah file dengan 9 tambahan dan 13 penghapusan
  1. 4 3
      command.c
  2. 4 4
      command.h
  3. 1 6
      mysh.c

+ 4 - 3
command.c

@@ -30,7 +30,7 @@ pid_node* add_pid(pid_list* pl, pid_t pid) {
     pid_node* pn = malloc(sizeof (pid_node));
     pn->pid = pid;
     pn->next = NULL;
-    if (pl->first = NULL) {
+    if (pl->first == NULL) {
         pn->prev = NULL;
         pl->first = pn;
         pl->last = pn;
@@ -43,7 +43,7 @@ pid_node* add_pid(pid_list* pl, pid_t pid) {
 }
 
 pid_node* search_pid(pid_list* pl, pid_t pid) {
-    pid_node pn = pl->first;
+    pid_node* pn = pl->first;
     while (pn != NULL) {
         if (pn->pid == pid) {
             return pn;
@@ -85,7 +85,8 @@ void clean_pid(pid_list* pl) {
         free(pn);
         pn = tmp;
     }
-    free(pl);
+    pl->first = NULL;
+    pl->last = NULL;
 }
 
 boolean is_internal_cmd(const char* cmd) {

+ 4 - 4
command.h

@@ -16,12 +16,12 @@
 typedef struct pid_node pid_node;
 struct pid_node{
     pid_t pid;
-    pid_node prev;
-    pid_node next;
+    pid_node* prev;
+    pid_node* next;
 };
 typedef struct{
-    pid_node first;
-    pid_node last;
+    pid_node* first;
+    pid_node* last;
 }pid_list;
 
 /* --- Extern --- */

+ 1 - 6
mysh.c

@@ -56,12 +56,7 @@ int main(int argc, char* argv[]) {
     int a;
     //Initialisation structures
     error_finit("mysh.log");
-    ini_pid_list(&pidlist);
-    
-    printf("%d\n", is_executable_file("../TP4/exo1"));
-    
-    error.exit();
-    
+    ini_pid_list(&pidlist);   
     //Recup ligne
     //printf("%s\n", fgets(str, 500, stdin));&
     memset(str, 0, 500);