Ticket #1500: full_bg_patch.diff

File full_bg_patch.diff, 7.6 KB (added by IMDagger, 15 years ago)

Last patch and fix for process list

  • src/background.c

    diff --git a/src/background.c b/src/background.c
    index 2ec345b..6dff321 100644
    a b register_task_running (FileOpContext *ctx, pid_t pid, int fd, int to_child, 
    8888    add_select_channel (fd, background_attention, ctx); 
    8989} 
    9090 
    91 void 
    92 unregister_task_running (pid_t pid, int fd) 
     91int 
     92destroy_task_and_return_fd (pid_t pid) 
    9393{ 
    9494    TaskList *p = task_list; 
    9595    TaskList *prev = 0; 
    unregister_task_running (pid_t pid, int fd) 
    102102                task_list = p->next; 
    103103            g_free (p->info); 
    104104            g_free (p); 
    105             break; 
     105            return p->fd; 
    106106        } 
    107107        prev = p; 
    108108        p = p->next; 
    109109    } 
     110 
     111    /* pid not found */ 
     112    return -1; 
     113} 
     114 
     115void 
     116unregister_task_running (pid_t pid, int fd) 
     117{ 
     118    destroy_task_and_return_fd(pid); 
    110119    delete_select_channel (fd); 
    111120} 
    112121 
     122void 
     123unregister_task_with_pid (pid_t pid) 
     124{ 
     125    int fd = destroy_task_and_return_fd(pid); 
     126    if (fd != -1) 
     127        delete_select_channel (fd); 
     128} 
     129 
    113130/* 
    114131 * Try to make the Midnight Commander a background job 
    115132 * 
    background_attention (int fd, void *closure) 
    216233    int have_ctx; 
    217234    union  
    218235    { 
     236      int (*have_ctx0)(int); 
    219237      int (*have_ctx1)(int, char *); 
    220238      int (*have_ctx2)(int, char *, char *); 
    221239      int (*have_ctx3)(int, char *, char *, char *); 
    222240      int (*have_ctx4)(int, char *, char *, char *, char *); 
    223241 
     242      int (*non_have_ctx0)(FileOpContext *, int); 
    224243      int (*non_have_ctx1)(FileOpContext *, int, char *); 
    225244      int (*non_have_ctx2)(FileOpContext *, int, char *, char *); 
    226245      int (*non_have_ctx3)(FileOpContext *, int, char *, char *, char *); 
    227246      int (*non_have_ctx4)(FileOpContext *, int, char *, char *, char *, char *); 
    228247 
     248      char * (*ret_str0)(); 
    229249      char * (*ret_str1)(char *); 
    230250      char * (*ret_str2)(char *, char *); 
    231251      char * (*ret_str3)(char *, char *, char *); 
    background_attention (int fd, void *closure) 
    238258    char *data [MAXCALLARGS]; 
    239259    ssize_t bytes; 
    240260        struct TaskList *p; 
    241         int to_child_fd; 
     261        int to_child_fd = -1; 
    242262    enum ReturnType type; 
    243263 
    244264    ctx = closure; 
    background_attention (int fd, void *closure) 
    285305        data [i][size] = 0;     /* NULL terminate the blocks (they could be strings) */ 
    286306    } 
    287307 
     308        /* Find child task info by descriptor */ 
     309        /* Find before call, because process can destroy self after */ 
     310        for (p = task_list; p; p = p->next) { 
     311                if (p->fd == fd) 
     312                        break; 
     313        } 
     314 
     315        if (p) to_child_fd = p->to_child_fd; 
     316 
     317    if (to_child_fd == -1) 
     318        message (D_ERROR, _(" Background process error "), _(" Unknown error in child ")); 
     319 
    288320    /* Handle the call */ 
    289321    if (type == Return_Integer){ 
    290322        if (!have_ctx) 
    291323            switch (argc){ 
     324            case 0: 
     325                result = routine.have_ctx0 (Background); 
     326                break; 
    292327            case 1: 
    293328                result = routine.have_ctx1 (Background, data [0]); 
    294329                break; 
    background_attention (int fd, void *closure) 
    304339            } 
    305340        else 
    306341            switch (argc){ 
     342            case 0: 
     343                result = routine.non_have_ctx0 (ctx, Background); 
     344                break; 
    307345            case 1: 
    308346                result = routine.non_have_ctx1 (ctx, Background, data [0]); 
    309347                break; 
    background_attention (int fd, void *closure) 
    318356                break; 
    319357            } 
    320358 
    321         /* Find child task info by descriptor */ 
    322         for (p = task_list; p; p = p->next) { 
    323                 if (p->fd == fd) 
    324                         break; 
    325         } 
    326  
    327         to_child_fd = p->to_child_fd; 
    328  
    329359        /* Send the result code and the value for shared variables */ 
    330360        write (to_child_fd, &result, sizeof (int)); 
    331         if (have_ctx) 
     361        if (have_ctx && to_child_fd != -1) 
    332362            write (to_child_fd, ctx, sizeof (FileOpContext)); 
    333363    } else if (type == Return_String) { 
    334364        int len; 
    background_attention (int fd, void *closure) 
    338368         * parameter.  Currently, this is not used here 
    339369         */ 
    340370        switch (argc){ 
     371        case 0: 
     372            resstr = routine.ret_str0 (); 
     373            break; 
    341374        case 1: 
    342375            resstr = routine.ret_str1 (data [0]); 
    343376            break; 
  • src/background.h

    diff --git a/src/background.h b/src/background.h
    index 8ad4d54..2dc4bf4 100644
    a b int parent_call (void *routine, struct FileOpContext *ctx, int argc, ...); 
    3232char *parent_call_string (void *routine, int argc, ...); 
    3333 
    3434void unregister_task_running (pid_t pid, int fd); 
     35void unregister_task_with_pid (pid_t pid); 
    3536extern int we_are_background; 
    3637 
    3738#endif                          /* !WITH_BACKGROUND */ 
  • src/boxes.c

    diff --git a/src/boxes.c b/src/boxes.c
    index 80944e6..e6db6bd 100644
    a b task_cb (int action) 
    883883        sig = SIGKILL; 
    884884    } 
    885885     
    886     if (sig == SIGINT) 
     886    if (sig == SIGKILL) 
    887887        unregister_task_running (tl->pid, tl->fd); 
    888888 
    889889    kill (tl->pid, sig); 
  • src/file.c

    diff --git a/src/file.c b/src/file.c
    index de3d600..fe4f4be 100644
    a b panel_operate_generate_prompt (const WPanel *panel, const int operation, 
    17681768    return g_strdup (format_string); 
    17691769} 
    17701770 
     1771#ifdef WITH_BACKGROUND 
     1772int end_bg_process (FileOpContext *ctx, enum OperationMode mode) { 
     1773    int pid = ctx->pid; 
     1774    ctx->pid = 0; 
     1775 
     1776    unregister_task_with_pid(pid); 
     1777//    file_op_context_destroy(ctx); 
     1778    return 1; 
     1779} 
     1780#endif 
     1781 
    17711782/** 
    17721783 * panel_operate: 
    17731784 * 
    panel_operate (void *source_panel, FileOperation operation, 
    19111922        } 
    19121923    } 
    19131924 
     1925    /* Background also need ctx->ui, but not full */ 
     1926    if (do_bg) 
     1927        file_op_context_create_ui_without_init (ctx, 1); 
     1928    else 
     1929        file_op_context_create_ui (ctx, 1); 
     1930 
    19141931#ifdef WITH_BACKGROUND 
    19151932    /* Did the user select to do a background operation? */ 
    19161933    if (do_bg) { 
    panel_operate (void *source_panel, FileOperation operation, 
    19491966 
    19501967    /* Now, let's do the job */ 
    19511968 
    1952     if (do_bg) 
    1953         ctx->ui = NULL; 
    1954     else 
    1955         file_op_context_create_ui (ctx, 1); 
    1956  
    19571969    /* This code is only called by the tree and panel code */ 
    19581970    if (single_entry) { 
    19591971        /* We now have ETA in all cases */ 
    panel_operate (void *source_panel, FileOperation operation, 
    21812193#ifdef WITH_BACKGROUND 
    21822194    /* Let our parent know we are saying bye bye */ 
    21832195    if (we_are_background) { 
     2196        int cur_pid = getpid(); 
     2197        /* Send pid to parent with child context, it is fork and 
     2198           don't modify real parent ctx */ 
     2199        ctx->pid = cur_pid; 
     2200        parent_call ((void *) end_bg_process, ctx, 0); 
     2201 
    21842202        vfs_shut (); 
    21852203        _exit (0); 
    21862204    } 
  • src/filegui.c

    diff --git a/src/filegui.c b/src/filegui.c
    index 340e12a..e9a31cf 100644
    a b check_progress_buttons (FileOpContext *ctx) 
    222222/* {{{ File progress display routines */ 
    223223 
    224224void 
    225 file_op_context_create_ui (FileOpContext *ctx, int with_eta) 
     225file_op_context_create_ui_without_init (FileOpContext *ctx, int with_eta) 
    226226{ 
    227227    FileOpContextUI *ui; 
    228228    int x_size; 
    file_op_context_create_ui (FileOpContext *ctx, int with_eta) 
    293293                label_new (3, FCOPY_GAUGE_X, sixty)); 
    294294    add_widget (ui->op_dlg, ui->file_label[0] = 
    295295                label_new (3, FCOPY_LABEL_X, fifteen)); 
     296} 
     297 
     298void 
     299file_op_context_create_ui (FileOpContext *ctx, int with_eta) 
     300{ 
     301    FileOpContextUI *ui; 
     302 
     303    g_return_if_fail (ctx != NULL); 
     304    g_return_if_fail (ctx->ui == NULL); 
     305 
     306    file_op_context_create_ui_without_init(ctx, with_eta); 
     307    ui = ctx->ui; 
    296308 
    297309    /* We will manage the dialog without any help, that's why 
    298310       we have to call init_dlg */ 
  • src/fileopctx.h

    diff --git a/src/fileopctx.h b/src/fileopctx.h
    index 4943e28..305fe63 100644
    a b enum OperationMode { 
    144144/* The following functions are implemented separately by each port */ 
    145145 
    146146void file_op_context_create_ui (FileOpContext *ctx, int with_eta); 
     147void file_op_context_create_ui_without_init (FileOpContext *ctx, int with_eta); 
    147148void file_op_context_destroy_ui (FileOpContext *ctx); 
    148149 
    149150FileProgressStatus file_progress_show (FileOpContext *ctx, off_t done, off_t total);