comparison src/channel.c @ 13740:f309afff6f25 v8.0.1742

patch 8.0.1742: cannot get a list of all the jobs commit https://github.com/vim/vim/commit/e1fc51558dc14906a8d9f6a6e7bb1ac2a6ba8f3d Author: Bram Moolenaar <Bram@vim.org> Date: Sat Apr 21 19:49:08 2018 +0200 patch 8.0.1742: cannot get a list of all the jobs Problem: Cannot get a list of all the jobs. Cannot get the command of the job. Solution: When job_info() is called without an argument return a list of jobs. Otherwise, include the command that the job is running. (Yegappan Lakshmanan)
author Christian Brabandt <cb@256bit.org>
date Sat, 21 Apr 2018 20:00:07 +0200
parents 1feeefd8cddb
children 260256caac38
comparison
equal deleted inserted replaced
13739:0b766229da42 13740:f309afff6f25
5000 static job_T *first_job = NULL; 5000 static job_T *first_job = NULL;
5001 5001
5002 static void 5002 static void
5003 job_free_contents(job_T *job) 5003 job_free_contents(job_T *job)
5004 { 5004 {
5005 int i;
5006
5005 ch_log(job->jv_channel, "Freeing job"); 5007 ch_log(job->jv_channel, "Freeing job");
5006 if (job->jv_channel != NULL) 5008 if (job->jv_channel != NULL)
5007 { 5009 {
5008 /* The link from the channel to the job doesn't count as a reference, 5010 /* The link from the channel to the job doesn't count as a reference,
5009 * thus don't decrement the refcount of the job. The reference from 5011 * thus don't decrement the refcount of the job. The reference from
5017 5019
5018 vim_free(job->jv_tty_in); 5020 vim_free(job->jv_tty_in);
5019 vim_free(job->jv_tty_out); 5021 vim_free(job->jv_tty_out);
5020 vim_free(job->jv_stoponexit); 5022 vim_free(job->jv_stoponexit);
5021 free_callback(job->jv_exit_cb, job->jv_exit_partial); 5023 free_callback(job->jv_exit_cb, job->jv_exit_partial);
5024 if (job->argv != NULL)
5025 {
5026 for (i = 0; job->argv[i] != NULL; i++)
5027 vim_free(job->argv[i]);
5028 vim_free(job->argv);
5029 }
5022 } 5030 }
5023 5031
5024 static void 5032 static void
5025 job_free_job(job_T *job) 5033 job_free_job(job_T *job)
5026 { 5034 {
5461 #else 5469 #else
5462 garray_T ga; 5470 garray_T ga;
5463 #endif 5471 #endif
5464 jobopt_T opt; 5472 jobopt_T opt;
5465 ch_part_T part; 5473 ch_part_T part;
5474 int len;
5475 int i;
5466 5476
5467 job = job_alloc(); 5477 job = job_alloc();
5468 if (job == NULL) 5478 if (job == NULL)
5469 return NULL; 5479 return NULL;
5470 5480
5591 goto theend; 5601 goto theend;
5592 cmd = ga.ga_data; 5602 cmd = ga.ga_data;
5593 #endif 5603 #endif
5594 } 5604 }
5595 5605
5606 /* Save the command used to start the job */
5607 len = 0;
5608 for (i = 0; argv[i] != NULL; i++)
5609 len++;
5610 job->argv = (char_u **)alloc(sizeof(char_u *) * (len + 1));
5611 if (job->argv == NULL)
5612 goto theend;
5613 for (i = 0; argv[i] != NULL; i++)
5614 job->argv[i] = vim_strsave((char_u *)argv[i]);
5615 job->argv[i] = NULL;
5616
5596 #ifdef USE_ARGV 5617 #ifdef USE_ARGV
5597 if (ch_log_active()) 5618 if (ch_log_active())
5598 { 5619 {
5599 garray_T ga; 5620 garray_T ga;
5600 int i;
5601 5621
5602 ga_init2(&ga, (int)sizeof(char), 200); 5622 ga_init2(&ga, (int)sizeof(char), 200);
5603 for (i = 0; i < argc; ++i) 5623 for (i = 0; i < argc; ++i)
5604 { 5624 {
5605 if (i > 0) 5625 if (i > 0)
5659 void 5679 void
5660 job_info(job_T *job, dict_T *dict) 5680 job_info(job_T *job, dict_T *dict)
5661 { 5681 {
5662 dictitem_T *item; 5682 dictitem_T *item;
5663 varnumber_T nr; 5683 varnumber_T nr;
5684 list_T *l;
5685 int i;
5664 5686
5665 dict_add_nr_str(dict, "status", 0L, (char_u *)job_status(job)); 5687 dict_add_nr_str(dict, "status", 0L, (char_u *)job_status(job));
5666 5688
5667 item = dictitem_alloc((char_u *)"channel"); 5689 item = dictitem_alloc((char_u *)"channel");
5668 if (item == NULL) 5690 if (item == NULL)
5687 job->jv_tty_out != NULL ? job->jv_tty_out : (char_u *)""); 5709 job->jv_tty_out != NULL ? job->jv_tty_out : (char_u *)"");
5688 5710
5689 dict_add_nr_str(dict, "exitval", job->jv_exitval, NULL); 5711 dict_add_nr_str(dict, "exitval", job->jv_exitval, NULL);
5690 dict_add_nr_str(dict, "exit_cb", 0L, job->jv_exit_cb); 5712 dict_add_nr_str(dict, "exit_cb", 0L, job->jv_exit_cb);
5691 dict_add_nr_str(dict, "stoponexit", 0L, job->jv_stoponexit); 5713 dict_add_nr_str(dict, "stoponexit", 0L, job->jv_stoponexit);
5714
5715 l = list_alloc();
5716 if (l != NULL)
5717 {
5718 dict_add_list(dict, "cmd", l);
5719 for (i = 0; job->argv[i] != NULL; i++)
5720 list_append_string(l, job->argv[i], -1);
5721 }
5722 }
5723
5724 /*
5725 * Implementation of job_info() to return info for all jobs.
5726 */
5727 void
5728 job_info_all(list_T *l)
5729 {
5730 job_T *job;
5731 typval_T tv;
5732
5733 for (job = first_job; job != NULL; job = job->jv_next)
5734 {
5735 tv.v_type = VAR_JOB;
5736 tv.vval.v_job = job;
5737
5738 if (list_append_tv(l, &tv) != OK)
5739 return;
5740 }
5692 } 5741 }
5693 5742
5694 /* 5743 /*
5695 * Send a signal to "job". Implements job_stop(). 5744 * Send a signal to "job". Implements job_stop().
5696 * When "type" is not NULL use this for the type. 5745 * When "type" is not NULL use this for the type.