1 /* Process.c */
2 /**********************************************************************************************************
3 Copyright (c) 2002-2013 Abdul-Rahman Allouche. All rights reserved
4 
5 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 documentation files (the Gabedit), to deal in the Software without restriction, including without limitation
7 the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 
10   The above copyright notice and this permission notice shall be included in all copies or substantial portions
11   of the Software.
12 
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
14 TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
15 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
16 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 DEALINGS IN THE SOFTWARE.
18 ************************************************************************************************************/
19 
20 
21 #include "../../Config.h"
22 #include <stdlib.h>
23 #include <unistd.h>
24 
25 #include "../Common/Global.h"
26 #include "../Utils/Utils.h"
27 #include "../Utils/UtilsInterface.h"
28 #include "../Utils/Constants.h"
29 #include "../Utils/GabeditTextEdit.h"
30 #include "../Common/Run.h"
31 #include "../Common/Windows.h"
32 #include "../NetWork/RemoteCommand.h"
33 #include "../NetWork/Process.h"
34 #ifndef G_OS_WIN32
35 #include <stdio.h>
36 #include <string.h>
37 #include <pwd.h>
38 #include <unistd.h>
39 #include <fcntl.h>
40 #endif /* G_OS_WIN32*/
41 
42 static gint Nlist = 0;
43 static gint NlistTitle = 0;
44 static gchar** Titles = NULL;
45 static gchar*** List = NULL;
46 static GtkWidget* KillButton1 = NULL;
47 static GtkWidget* KillButton2 = NULL;
48 static GtkWidget* KillAllButton = NULL;
49 static GtkWidget* WinUserProcess = NULL;
50 static gchar selectedRow[100] = "-1";
51 static GtkWidget* EntryRemote = NULL;
52 static GtkWidget* EntryLogin = NULL;
53 static GtkWidget* EntryPassWord = NULL;
54 static gboolean Remote = FALSE;
55 static gchar* RemoteHost = NULL;
56 static gchar* RemoteUser = NULL;
57 static gchar* RemotePassWord = NULL;
58 
59 /********************************************************************************/
destroy_win_user_process(GtkWidget * Win,gpointer data)60 static void destroy_win_user_process(GtkWidget* Win, gpointer data)
61 {
62 	destroy_children(Win);
63 	WinUserProcess = NULL;
64 }
65 /********************************************************************************/
authorized_type(gchar * type)66 static gboolean authorized_type(gchar* type)
67 {
68 	gchar *Atypes[]={"UID","PID","PPID","CMD"};
69 	gint i;
70   	for(i=0;i<4;i++)
71 		if(strstr(type,Atypes[i]))
72 			return TRUE;
73 	return FALSE;
74 }
75 /********************************************************************************/
get_title_bordure()76 static gchar* get_title_bordure()
77 {
78   gchar *str = NULL;
79   gchar *dump = NULL;
80   gchar *temp = NULL;
81   gint i = 0;
82 
83   str = g_strdup_printf(" ");
84   for(i=0;i<NlistTitle;i++)
85   {
86 	if(authorized_type(Titles[i]))
87 	{
88 		dump = str;
89 		if(strstr(Titles[i],"CMD"))
90 		{
91 			temp = get_line_chars('=',20);
92   			str = g_strdup_printf("%s   %s ",dump,temp);
93 		}
94 		else
95 		{
96 			temp = get_line_chars('=',10);
97   			str = g_strdup_printf("%s%10s ",dump,temp);
98 		}
99 		g_free(temp);
100 		g_free(dump);
101 	}
102   }
103 
104   return str;
105 }
106 /********************************************************************************/
get_title_process()107 static gchar* get_title_process()
108 {
109   gchar *str = NULL;
110   gchar *dump = NULL;
111   gchar *temp = NULL;
112   gint i = 0;
113 
114   if(authorized_type(Titles[0]))
115   {
116   	str = g_strdup_printf("%10s ",Titles[0]);
117   }
118   else
119   	str = g_strdup_printf(" ");
120   for(i=1;i<NlistTitle;i++)
121   {
122 	if(authorized_type(Titles[i]))
123 	{
124 		dump = str;
125 		if(strstr(Titles[i],"CMD"))
126   			str = g_strdup_printf("%s   %s ",dump,Titles[i]);
127 		else
128   			str = g_strdup_printf("%s%10s ",dump,Titles[i]);
129 		g_free(dump);
130 	}
131   }
132   temp = get_title_bordure();
133   dump = str;
134   str = g_strdup_printf("%s\n%s\n%s\n",temp,dump,temp);
135   g_free(dump);
136   g_free(temp);
137 
138   return str;
139 }
140 /********************************************************************************/
get_row_process(gint row)141 static gchar* get_row_process(gint row)
142 {
143   gchar *str = NULL;
144   gchar *dump = NULL;
145   gint i = 0;
146 
147   str = g_strdup_printf(" ");
148   for(i=0;i<NlistTitle;i++)
149   {
150 	if(authorized_type(Titles[i]))
151 	{
152 		dump = str;
153 		if(strstr(Titles[i],"CMD"))
154   			str = g_strdup_printf("%s   %s ",dump,List[row][i]);
155 		else
156   			str = g_strdup_printf("%s%10s ",dump,List[row][i]);
157 		g_free(dump);
158 	}
159   }
160 
161   return str;
162 }
163 /********************************************************************************/
get_pid(gint row)164 static gchar *get_pid(gint row)
165 {
166 	gchar *pid = NULL;
167 	gint i;
168 
169   	for(i=0;i<NlistTitle;i++)
170   	{
171 		if(strcmp(Titles[i],"PID") == 0)
172 		{
173   			pid =List[row][i];
174 			break;
175 		}
176 	}
177 	return pid;
178 
179 }
180 /********************************************************************************/
get_num_child(gint row)181 static gint get_num_child(gint row)
182 {
183 	gchar *pid = get_pid(row);
184 	gint i;
185 	gint j;
186 
187 	if(!pid)
188 		return -1;
189   	for(i=0;i<NlistTitle;i++)
190 	{
191 		if(strcmp(Titles[i],"PPID") == 0)
192 		{
193  			for(j=0;j<Nlist;j++)
194  			{
195 				if(atoi(pid) ==atoi(List[j][i]))
196 				{
197 				  return j;
198 				}
199  			}
200 		}
201 	}
202 	return -1;
203 
204 }
205 /********************************************************************************/
get_all_children(gint row,gint * Numb)206 static gint* get_all_children(gint row,gint* Numb)
207 {
208 	gint *NumChildren = NULL;
209 	gint num = -1;
210 
211 	*Numb = 0;
212 
213 
214 	num = get_num_child(row);
215 	if(num>-1)
216 	{
217 		NumChildren = g_malloc(sizeof(gint));
218 		NumChildren[0] = num;
219 		(*Numb)++;
220 	}
221 	else
222 		return NULL;
223 
224 	while(num>-1)
225 	{
226 		num = get_num_child(num);
227 		if(num>-1)
228 		{
229 			NumChildren = g_realloc(NumChildren,(*Numb+1)*sizeof(gint));
230 			NumChildren[*Numb] = num;
231 			(*Numb)++;
232 		}
233 	}
234 	return NumChildren;
235 
236 
237 }
238 /********************************************************************************/
get_string_all_children(gint row)239 static gchar *get_string_all_children(gint row)
240 {
241 	gint Numb = 0;
242 	gint *NumChildren = NULL;
243 	gint j;
244   	gchar* rowprocess = NULL;
245   	gchar* str = NULL;
246   	gchar* dump = NULL;
247 
248 	NumChildren = get_all_children(row,&Numb);
249 	if(Numb>0)
250   		str = get_title_process();
251 
252  	for(j=0;j<Numb;j++)
253  	{
254   		rowprocess = get_row_process(NumChildren[j]);
255 		dump = str;
256 		if(j==0)
257   			str = g_strdup_printf("%s%s",dump,rowprocess);
258 		else
259   			str = g_strdup_printf("%s\n%s",dump,rowprocess);
260 		g_free(dump);
261 		if(rowprocess)
262 		{
263 			g_free(rowprocess);
264 			rowprocess = NULL;
265 		}
266  	}
267 	if(NumChildren)
268 		g_free(NumChildren);
269 	return str;
270 
271 }
272 /********************************************************************************/
run_process_remote_all(GtkWidget * win,gpointer data)273 static void run_process_remote_all(GtkWidget*win,gpointer data)
274 {
275 	run_process_all(TRUE);
276 }
277 /********************************************************************************/
run_process_remote_user(GtkWidget * win,gpointer data)278 static void run_process_remote_user(GtkWidget*win,gpointer data)
279 {
280 	if(RemoteUser)
281 		g_free(RemoteUser);
282         RemoteUser = NULL;
283 	if(RemoteHost)
284 		g_free(RemoteHost);
285 	RemoteHost = NULL;
286 	if(RemotePassWord)
287 		g_free(RemotePassWord);
288 	RemotePassWord = NULL;
289 
290 	run_process_user(TRUE,NULL,NULL,NULL);
291 }
292 /********************************************************************************/
changed_host(GtkWidget * combo,gpointer data)293 static void changed_host(GtkWidget *combo,gpointer data)
294 {
295 	GtkWidget **entry = (GtkWidget **)data;
296 	gint nlistuser = 1;
297 	G_CONST_RETURN gchar *hostname;
298 	gint numhost = -1;
299 	GtkWidget* combouser = NULL;
300 	gint i;
301         GList *glist = NULL;
302 
303 	hostname = gtk_entry_get_text(GTK_ENTRY(entry[0]));
304         if(!this_is_an_object((GtkObject*)entry[1]))
305 		return;
306 	combouser = g_object_get_data (G_OBJECT (entry[1]), "Combo");
307         if(!combouser)
308 		return;
309 	if(recenthosts.nhosts>0)
310   	{
311 		for(i=0;i<recenthosts.nhosts;i++)
312   			if(strcmp(hostname,recenthosts.hosts[i].hostname) == 0)
313 			{
314 				numhost = i;
315 				break;
316 			}
317 		if(numhost<0)
318 			return;
319 
320         	nlistuser = recenthosts.hosts[numhost].nusers;
321 		for(i=0;i<recenthosts.hosts[numhost].nusers;i++)
322 		glist = g_list_append(glist,recenthosts.hosts[numhost].users[i].username);
323   	}
324   	else
325 		return;
326 
327 
328   	for (i=0;i<nlistuser;i++)
329         	gtk_combo_box_entry_set_popdown_strings( combouser, glist) ;
330 
331 
332 	g_list_free(glist);
333 }
334 /********************************************************************************/
create_process_remote_frame(GtkWidget * vboxall,GtkWidget ** entry,gboolean all)335 static GtkWidget *create_process_remote_frame( GtkWidget *vboxall,GtkWidget **entry,gboolean all)
336 {
337   GtkWidget *frame;
338   GtkWidget *combo;
339   GtkWidget *vboxframe;
340   gushort i;
341   GtkWidget *Table;
342   gchar      *tlisthost[NHOSTMAX];
343   gchar      *tlistuser[NHOSTMAX];
344   gint nlisthost = 1;
345   gint nlistuser = 1;
346   G_CONST_RETURN gchar *localuser;
347 
348   if(recenthosts.nhosts>0)
349   {
350   	nlisthost = recenthosts.nhosts;
351 	for(i=0;i<nlisthost;i++)
352   		tlisthost[i] = g_strdup(recenthosts.hosts[i].hostname);
353         nlistuser = recenthosts.hosts[0].nusers;
354 	for(i=0;i<recenthosts.hosts[0].nusers;i++)
355   		tlistuser[i] = g_strdup(recenthosts.hosts[0].users[i].username);
356   }
357   else
358   {
359    	localuser = get_local_user();
360   	tlisthost[0] = g_strdup("hostname");
361   	if(localuser)
362   		tlistuser[0] = g_strdup(localuser);
363   	else
364   		tlistuser[0] = g_strdup("login");
365   }
366 
367   frame = gtk_frame_new (_("Remote host"));
368   gtk_container_set_border_width (GTK_CONTAINER (frame), 5);
369   gtk_container_add (GTK_CONTAINER (vboxall), frame);
370   gtk_widget_show (frame);
371 
372   vboxframe = create_vbox(frame);
373   Table = gtk_table_new(2,3,FALSE);
374   gtk_container_add(GTK_CONTAINER(vboxframe),Table);
375 
376 	i = 0;
377 	add_label_table(Table,_("Host name "),(gushort)(i),0);
378 	add_label_table(Table," : ",(gushort)(i),1);
379 	combo = create_combo_box_entry(tlisthost,nlisthost,TRUE,-1,-1);
380 	gtk_table_attach(GTK_TABLE(Table),combo,2,3,i,i+1,
381                   (GtkAttachOptions)(GTK_FILL | GTK_EXPAND) ,
382                   (GtkAttachOptions)(GTK_FILL | GTK_EXPAND),
383                   1,1);
384 	gtk_widget_show (combo);
385 	entry[0] = GTK_BIN(combo)->child;
386         g_object_set_data (G_OBJECT (entry[0]), "Combo",combo);
387         g_signal_connect(G_OBJECT(GTK_COMBO_BOX(combo)), "changed",G_CALLBACK(changed_host),entry);
388 
389 	i = 1;
390 	add_label_table(Table,_("Login "),(gushort)(i),0);
391 	add_label_table(Table," : ",(gushort)(i),1);
392 	combo = create_combo_box_entry(tlistuser,nlistuser,TRUE,-1,-1);
393 	gtk_table_attach(GTK_TABLE(Table),combo,2,3,i,i+1,
394                   (GtkAttachOptions)(GTK_FILL | GTK_EXPAND) ,
395                   (GtkAttachOptions)(GTK_FILL | GTK_EXPAND),
396                   1,1);
397 	entry[1] = GTK_BIN(combo)->child;
398     g_object_set_data (G_OBJECT (entry[1]), "Combo",combo);
399 
400 	i = 2;
401 	if(fileopen.netWorkProtocol==GABEDIT_NETWORK_SSH)
402 	{
403 #ifdef G_OS_WIN32
404 		add_label_table(Table,_("Password "),(gushort)(i),0);
405 		add_label_table(Table," : ",(gushort)(i),1);
406 		entry[i] = gtk_entry_new ();
407 		gtk_entry_set_visibility(GTK_ENTRY (entry[i]),FALSE);
408 		gtk_table_attach(GTK_TABLE(Table),entry[i],2,3,i,i+1,
409                   (GtkAttachOptions)(GTK_FILL | GTK_EXPAND) ,
410                   (GtkAttachOptions)(GTK_FILL | GTK_EXPAND),
411                   1,1);
412 #else
413 		entry[i] = gtk_entry_new ();
414 #endif
415 	}
416 	else
417 	{
418 		entry[i] = gtk_entry_new ();
419 	}
420 
421 
422 	if(fileopen.remotehost)
423 		gtk_entry_set_text(GTK_ENTRY(entry[0]),fileopen.remotehost);
424 	if(fileopen.remoteuser)
425 		gtk_entry_set_text(GTK_ENTRY(entry[1]),fileopen.remoteuser);
426 	if(fileopen.remotepass)
427 		gtk_entry_set_text(GTK_ENTRY(entry[2]),fileopen.remotepass);
428 
429 
430   for (i=0;i<nlisthost;i++)
431         g_free(tlisthost[i]);
432   for (i=0;i<nlistuser;i++)
433         g_free(tlistuser[i]);
434 
435   return frame;
436 }
437 /********************************************************************************/
create_process_remote(gboolean all)438 void create_process_remote(gboolean all)
439 {
440   GtkWidget *fp;
441   GtkWidget *frame;
442   GtkWidget *vboxall;
443   GtkWidget *vboxwin;
444   GtkWidget *hbox;
445   GtkWidget *button;
446   GtkWidget **entry;
447   gchar *title = g_strdup_printf(_("Process in remote host "));
448 
449   entry=g_malloc(3*sizeof(GtkWidget *));
450 
451   /* Principal Window */
452   fp = gtk_window_new(GTK_WINDOW_TOPLEVEL);
453   gtk_window_set_title(GTK_WINDOW(fp),title);
454   gtk_window_set_position(GTK_WINDOW(fp),GTK_WIN_POS_CENTER);
455   gtk_window_set_transient_for(GTK_WINDOW(fp),GTK_WINDOW(Fenetre));
456 
457   gtk_widget_realize(fp);
458   init_child(fp,gtk_widget_destroy,_(" Remote Process "));
459   g_signal_connect(G_OBJECT(fp),"delete_event",(GCallback)destroy_children,NULL);
460 
461   gtk_container_set_border_width (GTK_CONTAINER (fp), 5);
462   vboxall = create_vbox(fp);
463   vboxwin = vboxall;
464 
465   frame = gtk_frame_new (NULL);
466   gtk_container_set_border_width (GTK_CONTAINER (frame), 5);
467   gtk_frame_set_shadow_type( GTK_FRAME(frame),GTK_SHADOW_ETCHED_OUT);
468   gtk_container_add(GTK_CONTAINER(vboxall),frame);
469   gtk_widget_show (frame);
470 
471   vboxall = create_vbox(frame);
472 
473   hbox = create_hbox(vboxall);
474 
475   frame = create_process_remote_frame(hbox,entry,all);
476 
477   EntryRemote = entry[0];
478   EntryLogin  = entry[1];
479   EntryPassWord = entry[2];
480   /* boutons box */
481   hbox = create_hbox(vboxwin);
482   gtk_widget_realize(fp);
483 
484   button = create_button(fp,_("Cancel"));
485   GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
486   gtk_box_pack_start (GTK_BOX( hbox), button, TRUE, TRUE, 3);
487   g_signal_connect_swapped(G_OBJECT(button), "clicked",(GCallback)destroy_children,GTK_OBJECT(fp));
488   gtk_widget_show (button);
489 
490   button = create_button(fp,_("OK"));
491   gtk_box_pack_start (GTK_BOX( hbox), button, TRUE, TRUE, 3);
492   GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
493   gtk_widget_grab_default(button);
494   gtk_widget_show (button);
495   g_signal_connect_swapped(G_OBJECT (EntryPassWord ), "activate", (GCallback) gtk_button_clicked, GTK_OBJECT (button));
496   if(!all) g_signal_connect(G_OBJECT(button), "clicked",G_CALLBACK(run_process_remote_user),(gpointer)NULL);
497   else g_signal_connect(G_OBJECT(button), "clicked",G_CALLBACK(run_process_remote_all),(gpointer)NULL);
498   g_signal_connect_swapped(G_OBJECT(button), "clicked",(GCallback)destroy_children,GTK_OBJECT(fp));
499 
500 
501   /* Show all */
502   gtk_widget_show_all(fp);
503 }
504 /********************************************************************************/
create_children_frame(GtkWidget * box,gint row)505 static GtkWidget* create_children_frame(GtkWidget *box,gint row)
506 {
507   GtkWidget *frame;
508   GtkWidget *vboxframe;
509   GtkWidget *Label;
510   gchar *str = NULL;
511 
512   str = get_string_all_children(row);
513 
514   frame = gtk_frame_new (_("Children Process"));
515   gtk_container_set_border_width (GTK_CONTAINER (frame), 5);
516   gtk_box_pack_start (GTK_BOX( box), frame, TRUE, TRUE, 3);
517   gtk_widget_show (frame);
518 
519   vboxframe = create_vbox(frame);
520   Label = gtk_label_new(str);
521   set_font (Label,FontsStyleResult.fontname);
522   gtk_label_set_justify(GTK_LABEL(Label),GTK_JUSTIFY_LEFT);
523   gtk_box_pack_start (GTK_BOX(vboxframe), Label, FALSE, FALSE, 3);
524   g_free(str);
525 
526   return frame;
527 }
528 /********************************************************************************/
create_label_frame(GtkWidget * box,gint row)529 static GtkWidget* create_label_frame(GtkWidget *box,gint row)
530 {
531   GtkWidget *frame;
532   GtkWidget *vboxframe;
533   GtkWidget *Label;
534   gchar *title = NULL;
535   gchar *rowprocess = NULL;
536   gchar *str = NULL;
537 
538   title = get_title_process();
539   rowprocess = get_row_process(row);
540   str = g_strdup_printf("%s%s",title,rowprocess);
541   g_free(title);
542   g_free(rowprocess);
543 
544   frame = gtk_frame_new (_("Process to kill"));
545   gtk_container_set_border_width (GTK_CONTAINER (frame), 5);
546   gtk_box_pack_start (GTK_BOX( box), frame, TRUE, TRUE, 3);
547   gtk_widget_show (frame);
548 
549   vboxframe = create_vbox(frame);
550   Label = gtk_label_new(str);
551   set_font (Label,FontsStyleResult.fontname);
552   gtk_label_set_justify(GTK_LABEL(Label),GTK_JUSTIFY_LEFT);
553   gtk_box_pack_start (GTK_BOX(vboxframe), Label, FALSE, FALSE, 3);
554   g_free(str);
555 
556   return frame;
557 }
558 /********************************************************************************/
kill_process(GtkWidget * Win,gpointer data)559 static void kill_process(GtkWidget *Win,gpointer data)
560 {
561   	gchar *command = NULL;
562   	gchar *scom = NULL;
563   	gchar *t = NULL;
564 	gint Numb = 0;
565 	gint *NumChildren = NULL;
566 	gint i;
567 	gchar *fout =  g_strdup_printf("%s%stmp%sfout",gabedit_directory(),G_DIR_SEPARATOR_S,G_DIR_SEPARATOR_S);
568 	gchar *ferr =  g_strdup_printf("%s%stmp%sferr",gabedit_directory(),G_DIR_SEPARATOR_S,G_DIR_SEPARATOR_S);
569 
570 
571   	if (GTK_TOGGLE_BUTTON (KillButton1)->active)
572 		scom = g_strdup("kill");
573   	else
574 		scom = g_strdup("kill -KILL");
575 
576 /* killing of children before */
577 	if(GTK_TOGGLE_BUTTON (KillAllButton)->active)
578 	{
579   		NumChildren = get_all_children(atoi(selectedRow),&Numb);
580   		if(Numb>0)
581 		{
582 			for(i=Numb-1;i>=0;i--)
583 			{
584   				command = g_strdup_printf("%s %s",scom,get_pid(NumChildren[i]));
585 				if(Remote)
586 				{
587   					/*rsh (fout,ferr,command, RemoteUser,RemoteHost);*/
588 					remote_command (fout,ferr,command,RemoteHost,RemoteUser,RemotePassWord);
589   					t = cat_file(ferr,FALSE);
590 				}
591 				else
592 				{
593   					t = run_command(command);
594 				}
595   				if(t)
596   				{
597  					Message(t,_("Info"),TRUE);
598 					g_free(t);
599 				}
600 				g_free(command);
601 			}
602   			if(NumChildren)
603   				g_free(NumChildren);
604 		}
605 	}
606 /* killing of parent */
607   	command = g_strdup_printf("%s %s",scom,get_pid(atoi(selectedRow)));
608 	if(Remote)
609 	{
610   	/*	rsh (fout,ferr,command, RemoteUser,RemoteHost);*/
611 		remote_command (fout,ferr,command,RemoteHost,RemoteUser,RemotePassWord);
612   		t = cat_file(ferr,FALSE);
613 	}
614 	else
615 	{
616   		t = run_command(command);
617 	}
618 	if(WinUserProcess)
619 	{
620   		destroy_children(WinUserProcess);
621 		WinUserProcess = NULL;
622 		run_process_user(Remote,RemoteUser,RemoteHost,RemotePassWord);
623 	}
624   	if(t)
625   	{
626 		if(!GTK_TOGGLE_BUTTON (KillAllButton)->active)
627 			Message(t,_("Error"),TRUE);
628 		g_free(t);
629   	}
630 
631   	g_free(scom);
632   	g_free(command);
633   	g_free(ferr);
634   	g_free(fout);
635 
636 }
637 /********************************************************************************/
create_options_frame(GtkWidget * hbox)638 static GtkWidget* create_options_frame(GtkWidget *hbox)
639 {
640   GtkWidget *frame;
641   GtkWidget *vboxframe;
642   GtkWidget *Table;
643   GtkWidget *button1;
644   GtkWidget *button2;
645   GtkWidget *button3;
646 
647 
648   frame = gtk_frame_new (_("Options"));
649   gtk_container_set_border_width (GTK_CONTAINER (frame), 5);
650   gtk_box_pack_start (GTK_BOX( hbox), frame, TRUE, TRUE, 3);
651   gtk_widget_show (frame);
652 
653   vboxframe = create_vbox(frame);
654   Table = gtk_table_new(2,2,FALSE);
655   gtk_container_add(GTK_CONTAINER(vboxframe),Table);
656 
657   button1 = gtk_radio_button_new_with_label( NULL,"kill " );
658   add_widget_table(Table,button1,0,0);
659 
660   button2 = gtk_radio_button_new_with_label(
661                        gtk_radio_button_get_group (GTK_RADIO_BUTTON (button1)),
662                        "kill -KILL ");
663   add_widget_table(Table,button2,0,1);
664   button3 = gtk_check_button_new_with_label(_("Kill all children process "));
665   add_widget_table(Table,button3,1,0);
666 
667   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button2), TRUE);
668   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button3), TRUE);
669 
670   KillButton1 = button1;
671   KillButton2 = button2;
672   KillAllButton = button3;
673 
674   return frame;
675 }
676 /********************************************************************************/
create_kill_process(GtkWidget * Win,gint row)677 static void create_kill_process(GtkWidget*Win,gint row)
678 {
679   GtkWidget *fp;
680   GtkWidget *frame;
681   GtkWidget *vboxall;
682   GtkWidget *vboxwin;
683   GtkWidget *hbox;
684   GtkWidget *button;
685   gchar *title = g_strdup_printf(_("Kill a process"));
686 
687   /* Principal Window */
688   fp = gtk_window_new(GTK_WINDOW_TOPLEVEL);
689   gtk_window_set_title(GTK_WINDOW(fp),title);
690   gtk_window_set_position(GTK_WINDOW(fp),GTK_WIN_POS_CENTER);
691   gtk_window_set_transient_for(GTK_WINDOW(fp),GTK_WINDOW(Fenetre));
692 
693   gtk_widget_realize(fp);
694   init_child(fp,gtk_widget_destroy,_(" Kill "));
695   g_signal_connect(G_OBJECT(fp),"delete_event",(GCallback)destroy_children,NULL);
696 
697   gtk_container_set_border_width (GTK_CONTAINER (fp), 5);
698   vboxall = create_vbox(fp);
699   vboxwin = vboxall;
700 
701   frame = gtk_frame_new (NULL);
702   gtk_container_set_border_width (GTK_CONTAINER (frame), 5);
703   gtk_frame_set_shadow_type( GTK_FRAME(frame),GTK_SHADOW_ETCHED_OUT);
704   gtk_container_add(GTK_CONTAINER(vboxall),frame);
705   gtk_widget_show (frame);
706 
707   vboxall = create_vbox(frame);
708 
709   hbox = create_hbox(vboxall);
710   frame = create_label_frame(hbox,row);
711 
712   hbox = create_hbox(vboxall);
713   frame = create_children_frame(hbox,row);
714 
715   hbox = create_hbox(vboxall);
716   frame = create_options_frame(hbox);
717 
718   /* boutons box */
719   hbox = create_hbox(vboxwin);
720   gtk_widget_realize(fp);
721 
722   button = create_button(fp,_("Cancel"));
723   GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
724   gtk_box_pack_start (GTK_BOX( hbox), button, TRUE, TRUE, 3);
725   g_signal_connect_swapped(G_OBJECT(button), "clicked",(GCallback)destroy_children,GTK_OBJECT(fp));
726   gtk_widget_show (button);
727 
728   button = create_button(fp,_("OK"));
729   gtk_box_pack_start (GTK_BOX( hbox), button, TRUE, TRUE, 3);
730   GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
731   gtk_widget_grab_default(button);
732   gtk_widget_show (button);
733   g_signal_connect_swapped(G_OBJECT(button), "clicked",(GCallback)kill_process,GTK_OBJECT(Win));
734   g_signal_connect_swapped(G_OBJECT(button), "clicked",(GCallback)destroy_children,GTK_OBJECT(fp));
735 
736 
737   gtk_widget_show_all(fp);
738 }
739 /*************************************************************************************************/
eventDispatcher(GtkWidget * widget,GdkEventButton * event,gpointer user_data)740 static void eventDispatcher(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
741 {
742 
743 	GtkTreePath *path;
744 	GtkTreeIter iter;
745 	GtkTreeModel *model;
746 
747 	if (!event) return;
748 	if (event->window == gtk_tree_view_get_bin_window (GTK_TREE_VIEW (widget))
749 	    && !gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), event->x, event->y, NULL, NULL, NULL, NULL)) {
750 		gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (widget)));
751 	}
752 	if(gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), event->x, event->y, &path, NULL, NULL, NULL))
753 	{
754 		if(path)
755 		{
756 			model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
757 			gtk_tree_selection_select_path  (gtk_tree_view_get_selection (GTK_TREE_VIEW (widget)), path);
758 			sprintf(selectedRow ,"%s",gtk_tree_path_to_string(path));
759 			gtk_tree_model_get_iter (model, &iter, path);
760 			gtk_tree_path_free(path);
761   			if (event->type == GDK_2BUTTON_PRESS && ((GdkEventButton *) event)->button == 1)
762 				create_kill_process(widget,atoi(selectedRow));
763 		}
764 		else sprintf(selectedRow,"-1");
765 	}
766 	GTK_WIDGET_GET_CLASS(widget)->button_press_event(widget, event);
767 }
768 /********************************************************************************/
init_list()769 static void init_list()
770 {
771 	Nlist = 0;
772 	NlistTitle = 0;
773 	Titles = NULL;
774 	List = NULL;
775 }
776 /********************************************************************************/
free_list()777 static void free_list()
778 {
779 	gint i;
780 	gint j;
781  	if(Nlist == 0 || NlistTitle == 0)
782  	{
783 		init_list();
784 		return;
785  	}
786  	if(Titles)
787 	{
788 		for(i=0;i<NlistTitle;i++)
789 			if(Titles[i]) g_free(Titles[i]);
790 		g_free(Titles);
791 	}
792 
793 	if(List)
794 	{
795 		for(i=0;i<Nlist;i++)
796 		{
797 			for(j=0;j<NlistTitle;j++)
798 					if(List[i][j]) g_free(List[i][j]);
799 			if(List[i]) g_free(List[i]);
800 		}
801 		g_free(List);
802 	}
803 
804 	init_list();
805 
806 }
807 /********************************************************************************/
create_gtk_list_process()808 static GtkWidget* create_gtk_list_process()
809 {
810 	gint i;
811 	gint j;
812 	GtkWidget* gtklist = NULL;
813 	gint *Width = NULL;
814 	GtkListStore *store;
815 	GtkTreeModel *model;
816 	GtkCellRenderer *renderer;
817 	GtkTreeViewColumn *column;
818 	GtkTreeSelection *select;
819 	GtkTreeIter iter;
820 	GType* types = NULL;
821 
822 	if(NlistTitle<1) return gtklist;
823 	Width = g_malloc(NlistTitle*sizeof(gint));
824 	for (j=0;j<NlistTitle;j++)
825 	{
826   		Width[j] = strlen(Titles[j]);
827   		for(i=0;i<Nlist;i++) if(Width[j]<(gint)strlen(List[i][j]) ) Width[j] = strlen(List[i][j]);
828 	}
829 
830 	types = g_malloc(NlistTitle*sizeof(GType));
831 	for (i=0;i<NlistTitle;i++) types[i] = G_TYPE_STRING;
832   	store = gtk_list_store_newv (NlistTitle, types);
833 	g_free(types);
834 	model = GTK_TREE_MODEL (store);
835 
836 	gtklist = gtk_tree_view_new_with_model (model);
837 	gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (gtklist), TRUE);
838 	gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (gtklist), TRUE);
839 	gtk_tree_view_set_reorderable(GTK_TREE_VIEW (gtklist), TRUE);
840 	for (j=0;j<NlistTitle;j++) Width[j] = (gint)(Width[j]*8);
841 
842 	for (i=0;i<NlistTitle;i++)
843 	{
844 		column = gtk_tree_view_column_new ();
845 		gtk_tree_view_column_set_title (column, Titles[i]);
846 		renderer = gtk_cell_renderer_text_new ();
847 		gtk_tree_view_column_pack_start (column, renderer, TRUE);
848 		gtk_tree_view_column_set_min_width(column, Width[i]);
849 		gtk_tree_view_column_set_attributes (column, renderer, "text", i, NULL);
850 		gtk_tree_view_append_column (GTK_TREE_VIEW (gtklist), column);
851 	}
852   	g_free( Width);
853 
854 	select = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtklist));
855 	gtk_tree_selection_set_mode (select, GTK_SELECTION_SINGLE);
856 	for(i=0;i<Nlist;i++)
857 	{
858 		gtk_list_store_append(store, &iter);
859 		for(j=0;j<NlistTitle;j++) gtk_list_store_set (store, &iter, j, List[i][j], -1);
860 	}
861 	g_signal_connect(gtklist, "button_press_event", G_CALLBACK(eventDispatcher), NULL);
862 
863 	return gtklist;
864 }
865 /********************************************************************************/
reduce_list()866 static void reduce_list()
867 {
868 	gint i;
869 	gint j;
870 	gint k;
871 	gchar** titles = NULL;
872 	gchar*** listOfRows = NULL;
873 	static gint max = 4;
874 	gint n[] = {-1,-1,-1,-1}; /* PID  PPID TIME CMD */
875 
876 	if(Nlist<1) return;
877 	if(NlistTitle<max) return;
878 
879 	for(j=0;j<NlistTitle;j++)
880 	{
881 		if(strstr(Titles[j],"PID") && !strstr(Titles[j],"PPID")) { n[0] = j; continue;}
882 		if(strstr(Titles[j],"PPID")) { n[1] = j; continue;}
883 		if(strstr(Titles[j],"TIME") && !strstr(Titles[j],"STIME")) { n[2] = j; continue;}
884 		if(strstr(Titles[j],"CMD")) { n[3] = j; continue;}
885 	}
886 	for(i=0;i<max;i++)
887 		if(n[i]<0) return;
888 
889 	titles = g_malloc(max*sizeof(gchar*));
890 
891 	for(i=0; i<max; i++)
892 		titles[i] = g_strdup(Titles[n[i]]);
893 
894 	if(Titles)
895 	{
896 		for(j=0;j<NlistTitle;j++) if(Titles[j]) g_free(Titles[j]);
897 		g_free(Titles);
898 		Titles = NULL;
899 	}
900 
901 
902 	listOfRows = g_malloc(Nlist*sizeof(gchar**));
903 	for(k=0;k<Nlist;k++)
904 		listOfRows[k] = g_malloc(max*sizeof(gchar*));
905 
906 	for(k=0;k<Nlist;k++)
907 	{
908 		for(i=0; i<max; i++)
909 			listOfRows[k][i] = g_strdup(List[k][n[i]]);
910 	}
911 
912 	if(List)
913 	{
914 		for(k=0;k<Nlist;k++)
915 		{
916 			for(j=0;j<NlistTitle;j++) if(List[k][j]) g_free(List[k][j]);
917 			if(List[k]) g_free(List[k]);
918 		}
919 		g_free(List);
920 	}
921 
922 	NlistTitle = max;
923 	Titles = titles;
924 	List = listOfRows;
925 
926 }
927 /********************************************************************************/
get_list_from_file(gchar * namefile)928 static void get_list_from_file(gchar* namefile)
929 {
930  FILE *fd;
931  gchar *t = NULL;
932 #ifndef G_OS_WIN32
933  gchar *dump = NULL;
934 #endif
935  gint taille = BSIZE;
936  gint i;
937  gchar tmp[BSIZE];
938  gint nListAll = 0;
939 
940 #define NMAXTITLES 20
941 
942  free_list();
943  t=g_malloc(taille);
944 
945  fd = FOpen(namefile, "r");
946  if(fd)
947  {
948 	Titles = g_malloc(NMAXTITLES*sizeof(gchar*));
949 	for(i=0;i<NMAXTITLES;i++)
950 	{
951 		Titles[i] = g_malloc(100*sizeof(gchar));
952 		sprintf(Titles[i]," ");
953 	}
954 	NlistTitle = NMAXTITLES;
955 
956 	while(!feof(fd))
957 	{
958     		if(fgets(t,taille, fd))
959 		{
960 			sscanf(t,"%s",tmp);
961 			if(!strstr(t,"UID")) continue;
962 			/* if(strcmp(tmp,"UID")!=0) continue; */
963 
964 			NlistTitle = sscanf(t,"%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s",
965 			Titles[0],Titles[1],Titles[2],Titles[3],Titles[4],Titles[5],Titles[6],
966 			Titles[7],Titles[8],Titles[9],Titles[10],Titles[11],Titles[12],Titles[13],
967 			Titles[14],Titles[15],Titles[16],Titles[17],Titles[18],Titles[19]
968 			);
969 			break;
970 		}
971 	}
972 	if(NlistTitle==0)
973 	{
974 		free_list();
975 		return;
976 	}
977   	while(!feof(fd))
978   	{
979     		if(!fgets(t,taille, fd)) break;
980 		if(List == NULL)
981 		{
982 			List = g_malloc(sizeof(gchar**));
983 			List[0] = g_malloc(NMAXTITLES*sizeof(gchar*));
984 			for(i=0;i<NMAXTITLES;i++)
985 				List[0][i] = g_malloc(BSIZE*sizeof(gchar));
986 		}
987 		else
988 		{
989 			List = g_realloc(List,(Nlist+1)*sizeof(gchar**));
990 			List[Nlist] = g_malloc(NMAXTITLES*sizeof(gchar*));
991 			for(i=0;i<NMAXTITLES;i++)
992 				List[Nlist][i] = g_malloc(BSIZE*sizeof(gchar));
993 		}
994 		nListAll = sscanf(t,"%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s",
995 			List[Nlist][0],List[Nlist][1],List[Nlist][2],List[Nlist][3],
996 			List[Nlist][4],List[Nlist][5],List[Nlist][6],List[Nlist][7],
997 			List[Nlist][8],List[Nlist][9],List[Nlist][10],List[Nlist][11],
998 			List[Nlist][12],List[Nlist][13],List[Nlist][14],List[Nlist][15],
999 			List[Nlist][16],List[Nlist][17],List[Nlist][18],List[Nlist][19]
1000 			);
1001 		if(nListAll>NlistTitle)
1002 		{
1003 			gchar buffer[BSIZE];
1004 			gint i;
1005 
1006 			for(i=1; i<=nListAll-NlistTitle;i++)
1007 			{
1008 				if(strlen(List[Nlist][NlistTitle-1+i])<1) continue;
1009 				sprintf(buffer,"%s",List[Nlist][NlistTitle-1]);
1010 				sprintf(List[Nlist][NlistTitle-1],"%s %s",buffer,List[Nlist][NlistTitle-1+i]);
1011 			}
1012 		}
1013 		Nlist++;
1014   	}
1015  	fclose(fd);
1016 #ifdef G_OS_WIN32
1017 	unlink (namefile);
1018 #else
1019  	dump = g_strdup_printf("rm %s",namefile);
1020 	{int ierre = system(dump);}
1021 	g_free(dump);
1022 
1023 #endif
1024  }
1025  g_free(t);
1026 }
1027 /********************************************************************************/
create_list_result_command(GtkWidget * gtklist,gchar * strerr,gchar * title)1028 static GtkWidget* create_list_result_command(GtkWidget* gtklist,gchar* strerr,gchar* title)
1029 {
1030   GtkWidget *Win;
1031   GtkWidget *frame;
1032   GtkWidget *scr;
1033   GtkWidget *hbox;
1034   GtkWidget *vbox;
1035   GtkWidget *vboxall;
1036   GtkWidget *vboxwin;
1037   GtkWidget *button;
1038   GtkWidget* Text;
1039   GtkWidget* Frame[2];
1040 
1041 
1042   Win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1043   gtk_window_set_title(GTK_WINDOW(Win),title);
1044   gtk_window_set_position(GTK_WINDOW(Win),GTK_WIN_POS_CENTER);
1045 
1046   gtk_widget_realize(Win);
1047 
1048   init_child(Win,gtk_widget_destroy,_(" List of process "));
1049 
1050 
1051   g_signal_connect(G_OBJECT(Win),"delete_event",(GCallback)destroy_children,NULL);
1052 
1053 
1054   gtk_container_set_border_width (GTK_CONTAINER (Win), 5);
1055   vboxall = create_vbox(Win);
1056   vboxwin = vboxall;
1057 
1058 
1059   frame = gtk_frame_new (NULL);
1060   gtk_container_set_border_width (GTK_CONTAINER (frame), 5);
1061   gtk_frame_set_shadow_type( GTK_FRAME(frame),GTK_SHADOW_ETCHED_OUT);
1062   gtk_container_add(GTK_CONTAINER(vboxall),frame);
1063   gtk_widget_show (frame);
1064   vboxall = create_vbox(frame);
1065 
1066   Frame[0] = NULL;
1067   Frame[1] = NULL;
1068 
1069   if(gtklist)
1070   {
1071   	frame = gtk_frame_new (_("Output"));
1072   	gtk_container_set_border_width (GTK_CONTAINER (frame), 5);
1073   	gtk_frame_set_shadow_type( GTK_FRAME(frame),GTK_SHADOW_ETCHED_OUT);
1074   	gtk_container_add(GTK_CONTAINER(vboxall),frame);
1075   	gtk_widget_show (frame);
1076   	vbox = create_vbox(frame);
1077   	scr=gtk_scrolled_window_new(NULL,NULL);
1078 	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scr),
1079                    GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1080 
1081   	gtk_box_pack_start(GTK_BOX (vbox), scr,TRUE, TRUE, 2);
1082   	gtk_container_add(GTK_CONTAINER(scr),gtklist);
1083         set_base_style(gtklist,50000,50000,50000);
1084 
1085 	Frame[0] = frame;
1086   }
1087 
1088   Text = NULL;
1089   if(strerr)
1090   {
1091   Text = create_text_widget(vboxall,_("Error"),&Frame[1]);
1092   set_font (Text,FontsStyleResult.fontname);
1093   set_base_style(Text,FontsStyleResult.BaseColor.red ,FontsStyleResult.BaseColor.green ,FontsStyleResult.BaseColor.blue);
1094   set_text_style(Text,FontsStyleResult.TextColor.red ,0,0);
1095   }
1096 
1097 
1098   /* boutons box */
1099   hbox = gtk_hbox_new (FALSE, 4);
1100   gtk_box_pack_start (GTK_BOX(vboxwin), hbox, FALSE, FALSE, 5);
1101   gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
1102   gtk_widget_realize(Win);
1103   button = create_button(Win,_("OK"));
1104   gtk_box_pack_end (GTK_BOX( hbox), button, FALSE, FALSE, 5);
1105   GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
1106   gtk_widget_grab_default(button);
1107   g_signal_connect_swapped(G_OBJECT(button), "clicked",(GCallback)destroy_win_user_process,GTK_OBJECT(Win));
1108   gtk_widget_show (button);
1109   gtk_window_set_default_size (GTK_WINDOW(Win), 4*ScreenWidth/5, 4*ScreenHeight/5);
1110   if(Frame[0])
1111   {
1112   	gtk_widget_set_size_request(GTK_WIDGET(Frame[0]),-1,3*ScreenHeight/5);
1113 	if(Frame[1])
1114   		gtk_widget_set_size_request(GTK_WIDGET(Frame[1]),-1,1*ScreenHeight/10);
1115   }
1116 
1117   if(Text && strerr)
1118 	gabedit_text_insert (GABEDIT_TEXT(Text), NULL, NULL, NULL,strerr,-1);
1119   return Win;
1120 }
1121 /********************************************************************************/
run_process_all(gboolean remote)1122 void run_process_all(gboolean remote)
1123 {
1124 	gchar *fout =  g_strdup_printf("%s%stmp%sfout",gabedit_directory(),G_DIR_SEPARATOR_S,G_DIR_SEPARATOR_S);
1125 	gchar *ferr =  g_strdup_printf("%s%stmp%sferr",gabedit_directory(),G_DIR_SEPARATOR_S,G_DIR_SEPARATOR_S);
1126 
1127 
1128   gchar *command;
1129   GtkWidget* Text[2];
1130   GtkWidget* Frame[2];
1131   GtkWidget* Win;
1132   gchar *strout;
1133   gchar *Uidstrout;
1134   gchar *strerr;
1135   G_CONST_RETURN gchar *remoteuser = NULL;
1136   G_CONST_RETURN gchar *remotehost = NULL;
1137   G_CONST_RETURN gchar *remotepassword = NULL;
1138   gchar *title = NULL;
1139 
1140 	Remote = remote;
1141 
1142 #ifdef G_OS_WIN32
1143 	if(!remote)
1144 	{
1145 		Message(_("Sorry, This option is available for unix system only"),_("Error"),TRUE);
1146 		g_free(fout);
1147 		g_free(ferr);
1148 		return;
1149 	}
1150 #endif
1151 	if(remote)
1152 	{
1153   		remotehost = gtk_entry_get_text(GTK_ENTRY(EntryRemote));
1154   		remoteuser = gtk_entry_get_text(GTK_ENTRY(EntryLogin));
1155 		remotepassword = gtk_entry_get_text(GTK_ENTRY(EntryPassWord));
1156   		command = g_strdup_printf("ps -lef");
1157   		title = g_strdup_printf(_("All process in %s host "),remotehost);
1158   		/*rsh (fout,ferr,command, remoteuser,remotehost);*/
1159 		remote_command (fout,ferr,command,remotehost,remoteuser,remotepassword);
1160 		g_free(command);
1161   		add_host(remotehost,remoteuser,"","tmp");
1162 	}
1163 	else
1164 	{
1165 		command = g_strdup("ps -lef");
1166   		title = g_strdup_printf(_("All process in local host "));
1167   		run_local_command(fout,ferr,command,FALSE);
1168   		g_free(command);
1169 	}
1170   Win = create_text_result_command(Text,Frame,title);
1171   g_free(title);
1172   strout = cat_file(fout,FALSE);
1173   strerr = cat_file(ferr,FALSE);
1174   if(!strout && !strerr)
1175   	destroy_children(Win);
1176   else
1177   {
1178   	if(strout)
1179 	{
1180   		Uidstrout = strout;
1181 		while(Uidstrout[0] != '\0' && Uidstrout[0] != 'U' && Uidstrout[0] != 'I' && Uidstrout[0] != 'D')
1182 			Uidstrout++;
1183  		gabedit_text_insert (GABEDIT_TEXT(Text[0]), NULL, NULL, NULL,Uidstrout,-1);
1184 		g_free(strout);
1185 	}
1186   	if(strerr)
1187 	{
1188  		gabedit_text_insert (GABEDIT_TEXT(Text[1]), NULL, NULL, NULL,strerr,-1);
1189 		g_free(strerr);
1190 	}
1191   	gtk_widget_show_all(Win);
1192   	if(!strout)
1193   		gtk_widget_hide(Frame[0]);
1194   }
1195 
1196   g_free(fout);
1197   g_free(ferr);
1198 }
1199 /********************************************************************************/
run_process_user(gboolean remote,gchar * remoteuser,gchar * remotehost,gchar * remotepassword)1200 void run_process_user(gboolean remote,gchar *remoteuser,gchar *remotehost,gchar *remotepassword)
1201 {
1202 	gchar *fout =  g_strdup_printf("%s%stmp%sfout",gabedit_directory(),G_DIR_SEPARATOR_S,G_DIR_SEPARATOR_S);
1203 	gchar *ferr =  g_strdup_printf("%s%stmp%sferr",gabedit_directory(),G_DIR_SEPARATOR_S,G_DIR_SEPARATOR_S);
1204 
1205 
1206   gchar *command;
1207   GtkWidget* gtklist;
1208   GtkWidget* Win;
1209   gchar *strerr;
1210   G_CONST_RETURN gchar *localuser = NULL;
1211   gchar localhost[100];
1212   gchar *title = NULL;
1213 
1214 	Remote = remote;
1215 
1216 #ifdef G_OS_WIN32
1217 	if(!remote)
1218 	{
1219 		Message(_("Sorry, This option is available for unix system only"),_("Error"),TRUE);
1220 		g_free(fout);
1221 		g_free(ferr);
1222 		return;
1223 	}
1224 #else
1225 	localuser = get_local_user();
1226   	gethostname(localhost,100);
1227 #endif /* G_OS_WIN32 */
1228   	if(!localuser && !remote)
1229   	{
1230 		Message(_("Sorry, I can not obtain user name"),_("Error"),TRUE);
1231 		g_free(fout);
1232 		g_free(ferr);
1233 		return;
1234   	}
1235 
1236 	if(remote)
1237 	{
1238 		if(!remotehost)
1239 		{
1240   			G_CONST_RETURN gchar* remotehost0 = gtk_entry_get_text(GTK_ENTRY(EntryRemote));
1241 			if(RemoteHost) g_free(RemoteHost);
1242 			RemoteHost = g_strdup(remotehost0);
1243 			remotehost = g_strdup(remotehost0);
1244 	 	}
1245   		if(!remoteuser)
1246 		{
1247 			G_CONST_RETURN gchar* remoteuser0 = gtk_entry_get_text(GTK_ENTRY(EntryLogin));
1248 			if(RemoteUser) g_free(RemoteUser);
1249 			RemoteUser = g_strdup(remoteuser0);
1250 			remoteuser = g_strdup(remoteuser0);
1251 		}
1252   		if(!remotepassword)
1253 		{
1254 			G_CONST_RETURN gchar* remotepassword0 = gtk_entry_get_text(GTK_ENTRY(EntryPassWord));
1255 			if(RemotePassWord) g_free(RemotePassWord);
1256 			RemotePassWord = g_strdup(remotepassword0);
1257 			remotepassword = g_strdup(remotepassword0);
1258 		}
1259 
1260 		command = g_strdup_printf("ps -fu %s",remoteuser);
1261 		remote_command (fout,ferr,command,remotehost,remoteuser,remotepassword);
1262 		g_free(command);
1263   		add_host(remotehost,remoteuser,"","tmp");
1264   		title = g_strdup_printf(_("Process in host : \"%s\" ;  for user : \"%s\" "),remotehost,remoteuser);
1265 	}
1266 	else
1267 	{
1268   		command = g_strdup_printf("ps -lfu %s",localuser);
1269   		run_local_command(fout,ferr,command,FALSE);
1270   		g_free(command);
1271   		title = g_strdup_printf(_("Process in host : \"%s\" ;  for user : \"%s\" "),localhost,localuser);
1272 	}
1273 	if(WinUserProcess)
1274 		destroy_children(WinUserProcess);
1275 
1276   	get_list_from_file(fout);
1277 
1278 	reduce_list();
1279 
1280   	gtklist = create_gtk_list_process();
1281   	strerr = cat_file(ferr,FALSE);
1282 
1283   	Win =  create_list_result_command(gtklist,strerr,title);
1284 
1285 	g_free(title);
1286   	WinUserProcess = Win;
1287   	gtk_widget_show_all(Win);
1288 
1289   	g_free(fout);
1290   	g_free(ferr);
1291 
1292 }
1293 /********************************************************************************/
1294