View | Details | Raw Unified | Return to bug 185435
Collapse All | Expand All

(-)Makefile (-7 / +5 lines)
Lines 2-8 Link Here
2
# $FreeBSD$
2
# $FreeBSD$
3
3
4
PORTNAME=	pkg_cleanup
4
PORTNAME=	pkg_cleanup
5
PORTVERSION=	1.1
5
PORTVERSION=	2.0
6
CATEGORIES=	ports-mgmt
6
CATEGORIES=	ports-mgmt
7
DISTFILES=
7
DISTFILES=
8
8
Lines 9-21 Link Here
9
MAINTAINER=	shurd@sasktel.net
9
MAINTAINER=	shurd@sasktel.net
10
COMMENT=	Interactive program for deinstalling 'leaf' packages
10
COMMENT=	Interactive program for deinstalling 'leaf' packages
11
11
12
MAN1=		pkg_cleanup.1
13
14
WRKSRC=		${WRKDIR}/${PORTNAME}
12
WRKSRC=		${WRKDIR}/${PORTNAME}
15
13
16
PLIST_FILES=	sbin/pkg_cleanup
14
PLIST_FILES=	sbin/pkg_cleanup \
15
		man/man1/pkg_cleanup.1.gz
17
16
18
NO_STAGE=	yes
19
.include <bsd.port.pre.mk>
17
.include <bsd.port.pre.mk>
20
18
21
.if ${OSVERSION} >= 900000 && ${OSVERSION} < 900038
19
.if ${OSVERSION} >= 900000 && ${OSVERSION} < 900038
Lines 33-39 Link Here
33
	make -C ${WRKSRC}
31
	make -C ${WRKSRC}
34
32
35
do-install:
33
do-install:
36
	${INSTALL_PROGRAM} ${WRKSRC}/pkg_cleanup ${PREFIX}/sbin/pkg_cleanup
34
	${INSTALL_PROGRAM} ${WRKSRC}/pkg_cleanup ${STAGEDIR}${PREFIX}/sbin/pkg_cleanup
37
	${INSTALL_MAN} ${WRKSRC}/pkg_cleanup.1 ${MAN1PREFIX}/man/man1
35
	${INSTALL_MAN} ${WRKSRC}/pkg_cleanup.1 ${STAGEDIR}${MAN1PREFIX}/man/man1
38
36
39
.include <bsd.port.post.mk>
37
.include <bsd.port.post.mk>
(-)files/pkg_cleanup.c (-132 / +399 lines)
Lines 9-17 Link Here
9
#include <errno.h>
9
#include <errno.h>
10
#include <glob.h>
10
#include <glob.h>
11
#include <search.h>
11
#include <search.h>
12
#include <stdbool.h>
12
#include <stdio.h>
13
#include <stdio.h>
13
#include <stdlib.h>
14
#include <stdlib.h>
14
#include <string.h>
15
#include <string.h>
16
#include <stringlist.h>
15
#include <sysexits.h>
17
#include <sysexits.h>
16
#include <unistd.h>
18
#include <unistd.h>
17
19
Lines 20-25 Link Here
20
#endif
22
#endif
21
23
22
static glob_t	gl;	/* A cached list of all files in /var/db/pkg */
24
static glob_t	gl;	/* A cached list of all files in /var/db/pkg */
25
static StringList *sl;
26
static size_t	pathc;
27
static char		**pathv;
28
static bool 	uses_pkg;
29
static int		menulen=0;
30
static int		helpfile=-1;
31
static char		*helpfname="/tmp/pkgcleanup.XXXX";
32
23
#ifdef OLD_DIALOG
33
#ifdef OLD_DIALOG
24
typedef dialogMenuItem ListItem;
34
typedef dialogMenuItem ListItem;
25
#else
35
#else
Lines 36-42 Link Here
36
#define ITEM_CHECKED	state
46
#define ITEM_CHECKED	state
37
#endif
47
#endif
38
48
39
int				menulen=0;
49
bool check_pkg(void)
50
{
51
	if(WEXITSTATUS(system("TMPDIR=/dev/null "
52
						"ASSUME_ALWAYS_YES=1 "
53
						"PACKAGESITE=file:///nonexistent "
54
						"pkg info -x 'pkg(-devel)?$' "
55
						">/dev/null 2>&1")
56
				)==0)
57
		return true;
58
	return false;
59
}
40
60
41
void free_menu(void)
61
void free_menu(void)
42
{
62
{
Lines 68-73 Link Here
68
	return(hsearch(item, operation)!=NULL);
88
	return(hsearch(item, operation)!=NULL);
69
}
89
}
70
90
91
char *read_desc(char *path)
92
{
93
	if(uses_pkg) {
94
		char newpath[MAXPATHLEN+1];
95
		char *p=NULL;
96
		char *np=NULL;
97
		FILE *pkg;
98
		char chunk[1024];
99
		size_t	cs, len=0;
100
101
		sprintf(newpath,"/usr/sbin/pkg query %%e \"%s\"", path);
102
		fflush(stdout);
103
		pkg=popen(newpath, "r");
104
		if(!pkg)
105
			return NULL;
106
		while((cs=fread(chunk, 1, sizeof(chunk), pkg))) {
107
			np=(char *)realloc(p, len+cs+1);
108
			if(!np) {
109
				pclose(pkg);
110
				free(p);
111
				return NULL;
112
			}
113
			p=np;
114
			memcpy(p+len, chunk, cs);
115
			len+=cs;
116
			p[len]=0;
117
		}
118
		pclose(pkg);
119
		if(len==0) {
120
			free(p);
121
			return NULL;
122
		}
123
		return p;
124
	}
125
	else {
126
		char *p;
127
		char newpath[MAXPATHLEN+1];
128
		FILE *file;
129
		struct stat	sb;
130
131
		sprintf(newpath,"/var/db/pkg/%s/+DESC",path);
132
		file=fopen(newpath, "r");
133
		if(file) {
134
			if(fstat(fileno(file), &sb)==0) {
135
				p=(char *)malloc(sb.st_size+1);
136
				if(p) {
137
					if(fread(p, sb.st_size, 1, file)==1) {
138
						fclose(file);
139
						p[sb.st_size]=0;
140
						return p;
141
					}
142
					free(p);
143
				}
144
			}
145
			fclose(file);
146
		}
147
	}
148
	return NULL;
149
}
150
71
#ifdef OLD_DIALOG
151
#ifdef OLD_DIALOG
72
int fire(struct _dmenu_item *item)
152
int fire(struct _dmenu_item *item)
73
{
153
{
Lines 89-96 Link Here
89
		wattrset(stdscr, dialog_attr);
169
		wattrset(stdscr, dialog_attr);
90
		mvwaddnstr(stdscr, 4, 4, (char *)item->data, maxx-6);
170
		mvwaddnstr(stdscr, 4, 4, (char *)item->data, maxx-6);
91
		wrefresh(stdscr);
171
		wrefresh(stdscr);
92
		sprintf(path,"/var/db/pkg/%s/+DESC",item->prompt);
172
		if(uses_pkg) {
93
		use_helpfile(path);
173
			char	*desc=read_desc(item->prompt);
174
			lseek(helpfile, 0, SEEK_SET);
175
			if(desc) {
176
				write(helpfile, desc, strlen(desc));
177
				free(desc);
178
			}
179
			ftruncate(helpfile, lseek(helpfile, 0, SEEK_CUR));
180
		}
181
		else {
182
			sprintf(path,"/var/db/pkg/%s/+DESC",item->prompt);
183
			use_helpfile(path);
184
		}
94
	}
185
	}
95
}
186
}
96
187
Lines 102-120 Link Here
102
}
193
}
103
#endif
194
#endif
104
195
196
char *read_comment(char *path)
197
{
198
	if(uses_pkg) {
199
		char newpath[MAXPATHLEN+1];
200
		char *p=NULL;
201
		char *np=NULL;
202
		FILE *pkg;
203
		char chunk[1024];
204
		size_t	cs, len=0;
205
206
		sprintf(newpath,"/usr/sbin/pkg query %%c \"%s\"", path);
207
		fflush(stdout);
208
		pkg=popen(newpath, "r");
209
		if(!pkg)
210
			return strdup("");
211
		while((cs=fread(chunk, 1, sizeof(chunk), pkg))) {
212
			np=(char *)realloc(p, len+cs+1);
213
			if(!np) {
214
				pclose(pkg);
215
				free(p);
216
				return strdup("");
217
			}
218
			p=np;
219
			memcpy(p+len, chunk, cs);
220
			len+=cs;
221
			p[len]=0;
222
		}
223
		pclose(pkg);
224
		if(len==0) {
225
			free(p);
226
			return strdup("");
227
		}
228
		return p;
229
	}
230
	else {
231
		char		comment[80];
232
		FILE		*file;
233
		char		newpath[MAXPATHLEN+1];
234
		char		*p;
235
236
		/* Read +COMMENT */
237
		sprintf(newpath,"%s/+COMMENT",path);
238
		file=fopen(newpath,"r");
239
		if(file) {
240
			fgets(comment, sizeof(comment), file);
241
			fclose(file);
242
			/* Remove trailing whitespace */
243
			for(p=strchr(comment,0)-1; p>=comment; p--) {
244
				if(isspace(*p))
245
					*p=0;
246
				else
247
					break;
248
			}
249
			return strdup(comment);
250
		}
251
	}
252
	return strdup("");
253
}
254
105
/* Read +COMMENT, add to menu and blacklist */
255
/* Read +COMMENT, add to menu and blacklist */
106
int add_item(char *path)
256
int add_item(char *path, char *comment)
107
{
257
{
108
	char		*p;
258
	char		*p;
109
	char		comment[80];
110
	FILE		*file;
111
	char		newpath[MAXPATHLEN+1];
112
	ListItem	*newmenu;
259
	ListItem	*newmenu;
113
260
114
	if(blacklist(path,FIND))
261
	if(blacklist(path,FIND))
115
		return(0);
262
		return(0);
116
	blacklist(path,ENTER);
263
	blacklist(path,ENTER);
117
	comment[0]=0;
118
264
119
	newmenu=(ListItem *)realloc(menu, sizeof(ListItem)*(menulen+1));
265
	newmenu=(ListItem *)realloc(menu, sizeof(ListItem)*(menulen+1));
120
	if(newmenu==NULL)
266
	if(newmenu==NULL)
Lines 122-131 Link Here
122
	menu=newmenu;
268
	menu=newmenu;
123
269
124
	p=strrchr(path,'/');
270
	p=strrchr(path,'/');
125
	if(p==NULL)				/* Not possible */
271
	if(p==NULL)
126
		return(-1);
272
		p=path;
273
	else
274
		p++;
127
275
128
	menu[menulen].ITEM_PROMPT=strdup(p+1);
276
	menu[menulen].ITEM_PROMPT=strdup(p);
129
	menu[menulen].ITEM_CHECKED=0;
277
	menu[menulen].ITEM_CHECKED=0;
130
#ifdef OLD_DIALOG
278
#ifdef OLD_DIALOG
131
	menu[menulen].title="";
279
	menu[menulen].title="";
Lines 139-158 Link Here
139
	menu[menulen].text="";
287
	menu[menulen].text="";
140
#endif
288
#endif
141
289
142
	/* Read +COMMENT */
143
	sprintf(newpath,"%s/+COMMENT",path);
144
	file=fopen(newpath,"r");
145
	if(file) {
146
		fgets(comment, sizeof(comment), file);
147
		fclose(file);
148
		/* Remove trailing whitespace */
149
		for(p=strchr(comment,0)-1; p>=comment; p--) {
150
			if(isspace(*p))
151
				*p=0;
152
			else
153
				break;
154
		}
155
	}
156
	menu[menulen].ITEM_DATA=strdup(comment);
290
	menu[menulen].ITEM_DATA=strdup(comment);
157
	menulen++;
291
	menulen++;
158
292
Lines 187-214 Link Here
187
loop:
321
loop:
188
	switch(ret=dlg_checklist("Welcome to pkg_cleanup.", "These are the leaf packages installed on your system\nChose the packages to deinstall. Help will display the package description.", maxy-1, maxx, maxy-9, menulen, menu, " X", FLAG_CHECK, &curr)) {
322
	switch(ret=dlg_checklist("Welcome to pkg_cleanup.", "These are the leaf packages installed on your system\nChose the packages to deinstall. Help will display the package description.", maxy-1, maxx, maxy-9, menulen, menu, " X", FLAG_CHECK, &curr)) {
189
		case DLG_EXIT_HELP: {
323
		case DLG_EXIT_HELP: {
190
			char *p;
324
			char *p = read_desc(menu[curr].ITEM_PROMPT);
191
			char newpath[MAXPATHLEN+1];
325
			if(p) {
192
			FILE *file;
326
				dialog_vars.help_button=0;
193
			struct stat	sb;
327
				dialog_msgbox(menu[curr].ITEM_DATA, p, maxy-4, maxx-4, TRUE);
194
328
				dialog_vars.help_button=1;
195
			/* READ +DESC */
329
				free(p);
196
			sprintf(newpath,"/var/db/pkg/%s/+DESC",menu[curr].ITEM_PROMPT);
197
			file=fopen(newpath, "r");
198
			if(file) {
199
				if(fstat(fileno(file), &sb)==0) {
200
					p=(char *)malloc(sb.st_size+1);
201
					if(p) {
202
						if(fread(p, sb.st_size, 1, file)==1) {
203
							p[sb.st_size]=0;
204
							dialog_vars.help_button=0;
205
							dialog_msgbox(menu[curr].ITEM_DATA, p, maxy-4, maxx-4, TRUE);
206
							dialog_vars.help_button=1;
207
						}
208
						free(p);
209
					}
210
				}
211
				fclose(file);
212
			}
330
			}
213
			goto loop;
331
			goto loop;
214
		}
332
		}
Lines 226-315 Link Here
226
	return(ret);
344
	return(ret);
227
}
345
}
228
346
229
/* Goes through the glob contents, looking for zero-length +REQUIRED-BY */
347
bool is_leaf_package(char *path)
230
int read_pkglist(int loops)
231
{
348
{
232
	char		path[MAXPATHLEN+1];
349
	char	newpath[MAXPATHLEN+1];
233
	int		p;
234
	struct stat	sb;
350
	struct stat	sb;
235
	int		maxx,maxy;
236
	int		lastgauge=-1;
237
	int		gauge;
238
#ifndef OLD_DIALOG
239
	int		pipepair[2];
240
	FILE	*read_pipe;
241
	FILE	*write_pipe;
242
#endif
243
351
244
	do_init_dialog();
352
	if(uses_pkg) {
245
	getmaxyx(stdscr, maxy, maxx);
353
		FILE	*pkg;
246
	for(p=0;p<gl.gl_pathc;p++) {
354
		char	val[32];
247
		gauge=p*100/gl.gl_pathc;
355
		long	v;
248
		if(gauge != lastgauge) {
356
249
#ifdef OLD_DIALOG
357
		sprintf(newpath,"/usr/sbin/pkg query \"%%#r%%k\" \"%s\"", path);
250
			dialog_gauge(NULL, "Searching for leaves", maxy/2-1, maxx/2-12, 7, 24, gauge);
358
		fflush(stdout);
251
#else
359
		pkg=popen(newpath,"r");
252
			if(pipe(pipepair)!=0) {
360
		if(pkg) {
253
				fputs("Cannot create pipe pair.\n", stderr);
361
			if(fgets(val, sizeof(val), pkg)!=NULL) {
254
				return(-1);
362
				if(WEXITSTATUS(pclose(pkg))==0) {
363
					if(strtol(val, NULL, 10)==0)
364
							return true;
365
					return false;
366
				}
367
				else {
368
					blacklist(path,ENTER);
369
					return false;
370
				}
255
			}
371
			}
256
			if((read_pipe=fdopen(pipepair[0], "r"))==NULL) {
257
				fputs("Cannot open read end of pipe pair.\n", stderr);
258
				return(-1);
259
			}
260
			dialog_state.pipe_input=read_pipe;
261
			if((write_pipe=fdopen(pipepair[1], "r"))==NULL) {
262
				fputs("Cannot open read end of pipe pair.\n", stderr);
263
				return(-1);
264
			}
265
			fprintf(write_pipe, "%d\n%c", gauge, 4);
266
			fclose(write_pipe);
267
			dialog_gauge(NULL, "Searching for leaves", maxy/2-1, maxx/2-12, gauge);
268
			fclose(read_pipe);
269
#endif
270
			lastgauge=gauge;
271
		}
372
		}
272
		sprintf(path,"%s/+REQUIRED_BY",gl.gl_pathv[p]);
373
		blacklist(path,ENTER);
273
		if(stat(path,&sb)) {
374
		pclose(pkg);
375
		return false;
376
	}
377
	else {
378
		sprintf(newpath,"%s/+REQUIRED_BY",path);
379
		if(stat(newpath,&sb)) {
274
			switch(errno) {
380
			switch(errno) {
275
				case ENOENT:
381
				case ENOENT:
276
					/* No +REQUIRED_BY, add to list */
382
					/* No +REQUIRED_BY, add to list */
277
					add_item(gl.gl_pathv[p]);
383
					return true;
278
					break;
384
					break;
279
				default:
385
				default:
280
					/* All other errors, add to blacklist */
386
					/* All other errors, add to blacklist */
281
					blacklist(gl.gl_pathv[p],ENTER);
387
					blacklist(path,ENTER);
282
					break;
388
					break;
283
			}
389
			}
284
		}
390
		}
285
		else {
391
		else {
286
			if(sb.st_size==0)
392
			if(sb.st_size==0)
287
				add_item(gl.gl_pathv[p]);
393
				return true;
288
		}
394
		}
395
		return false;
289
	}
396
	}
397
}
398
399
/* Goes through the glob contents, looking for zero-length +REQUIRED-BY */
400
int read_pkglist(int loops)
401
{
402
	if(uses_pkg) {
403
		FILE	*pkg;
404
		char	line[1024];
405
		char	*p;
406
407
		do_init_dialog();
408
		dialog_msgbox(NULL, "Searching for leaves", 5, 23, FALSE);
409
		fflush(stdout);
410
		pkg=popen("/usr/sbin/pkg query -e \"%#r=0 && %k=0\" \"%n-%v\\t%c\"", "r");
411
		if(!pkg) {
412
			fputs("Error executing pkg.\n", stderr);
413
			return -1;
414
		}
415
		while(fgets(line, sizeof(line), pkg)!=NULL) {
416
			for(p=strchr(line, 0)-1; p>line && isspace(*p); p--)
417
				*p=0;
418
			p=strtok(line, "\t");
419
			p=strtok(NULL, "\0");
420
			add_item(line, p?p:"");
421
		}
422
		if(WEXITSTATUS(pclose(pkg)) && menulen==0) {
423
			fputs("pkg returned an error.\n", stderr);
424
			return -1;
425
		}
290
#ifdef OLD_DIALOG
426
#ifdef OLD_DIALOG
291
	dialog_gauge(NULL, "Searching for leaves", maxy/2-1, maxx/2-12, 7, 24, 100);
427
		dialog_clear_norefresh();
292
	dialog_clear_norefresh();
293
#else
428
#else
294
	if(pipe(pipepair)!=0) {
429
		dlg_clear();
295
		fputs("Cannot create pipe pair.\n", stderr);
430
#endif
296
		return(-1);
297
	}
431
	}
298
	if((read_pipe=fdopen(pipepair[0], "r"))==NULL) {
432
	else {
299
		fputs("Cannot open read end of pipe pair.\n", stderr);
433
		int		p;
300
		return(-1);
434
		int		maxx,maxy;
435
		int		lastgauge=-1;
436
		int		gauge;
437
		char	*comment;
438
#ifndef OLD_DIALOG
439
		int		pipepair[2];
440
		FILE	*read_pipe;
441
		FILE	*write_pipe;
442
#endif
443
444
		do_init_dialog();
445
		getmaxyx(stdscr, maxy, maxx);
446
		for(p=0;p<pathc;p++) {
447
			gauge=p*100/pathc;
448
			if(gauge != lastgauge) {
449
#ifdef OLD_DIALOG
450
				dialog_gauge(NULL, "Searching for leaves", maxy/2-1, maxx/2-12, 7, 24, gauge);
451
#else
452
				if(pipe(pipepair)!=0) {
453
					fputs("Cannot create pipe pair.\n", stderr);
454
					return(-1);
455
				}
456
				if((read_pipe=fdopen(pipepair[0], "r"))==NULL) {
457
					fputs("Cannot open read end of pipe pair.\n", stderr);
458
					return(-1);
459
				}
460
				dialog_state.pipe_input=read_pipe;
461
				if((write_pipe=fdopen(pipepair[1], "r"))==NULL) {
462
					fputs("Cannot open read end of pipe pair.\n", stderr);
463
					return(-1);
464
				}
465
				fprintf(write_pipe, "%d\n%c", gauge, 4);
466
				fclose(write_pipe);
467
				dialog_gauge("", "Searching for leaves", maxy/2-1, maxx/2-12, gauge);
468
				fclose(read_pipe);
469
#endif
470
				lastgauge=gauge;
471
			}
472
			if(is_leaf_package(pathv[p])) {
473
				comment = read_comment(pathv[p]);
474
				add_item(pathv[p], comment);
475
				free(comment);
476
			}
477
		}
478
#ifdef OLD_DIALOG
479
		dialog_gauge(NULL, "Searching for leaves", maxy/2-1, maxx/2-12, 7, 24, 100);
480
		dialog_clear_norefresh();
481
#else
482
		if(pipe(pipepair)!=0) {
483
			fputs("Cannot create pipe pair.\n", stderr);
484
			return(-1);
485
		}
486
		if((read_pipe=fdopen(pipepair[0], "r"))==NULL) {
487
			fputs("Cannot open read end of pipe pair.\n", stderr);
488
			return(-1);
489
		}
490
		dialog_state.pipe_input=read_pipe;
491
		if((write_pipe=fdopen(pipepair[1], "r"))==NULL) {
492
			fputs("Cannot open read end of pipe pair.\n", stderr);
493
			return(-1);
494
		}
495
		fprintf(write_pipe, "%d\n%c", 100, 4);
496
		fclose(write_pipe);
497
		dialog_gauge("", "Searching for leaves", maxy/2-1, maxx/2-12, 100);
498
		fclose(read_pipe);
499
		dlg_clear();
500
#endif
301
	}
501
	}
302
	dialog_state.pipe_input=read_pipe;
303
	if((write_pipe=fdopen(pipepair[1], "r"))==NULL) {
304
		fputs("Cannot open read end of pipe pair.\n", stderr);
305
		return(-1);
306
	}
307
	fprintf(write_pipe, "%d\n%c", 100, 4);
308
	fclose(write_pipe);
309
	dialog_gauge(NULL, "Searching for leaves", maxy/2-1, maxx/2-12, 100);
310
	fclose(read_pipe);
311
	dlg_clear();
312
#endif
313
	if(menulen==0) {
502
	if(menulen==0) {
314
		if(loops)
503
		if(loops)
315
			dialog_msgbox(NULL, "No new leaves found", 5, 23, TRUE);
504
			dialog_msgbox(NULL, "No new leaves found", 5, 23, TRUE);
Lines 324-329 Link Here
324
513
325
int remove_ports(void)
514
int remove_ports(void)
326
{
515
{
516
	char	*cmd;
327
	char	**args;
517
	char	**args;
328
	char	*env[1]={NULL};
518
	char	*env[1]={NULL};
329
	char	**p;
519
	char	**p;
Lines 331-338 Link Here
331
	int		delete_count=0;
521
	int		delete_count=0;
332
	pid_t	child;
522
	pid_t	child;
333
	int		status;
523
	int		status;
524
	size_t	st;
334
525
335
	args=(char **)malloc((menulen+2) * sizeof(char *));
526
	args=(char **)malloc((menulen+4) * sizeof(char *));
336
	if(!args) {
527
	if(!args) {
337
		do_init_dialog();
528
		do_init_dialog();
338
		dialog_msgbox("ERROR", "Can not allocate memory for package list!", 5, 45, TRUE);
529
		dialog_msgbox("ERROR", "Can not allocate memory for package list!", 5, 45, TRUE);
Lines 340-346 Link Here
340
		return(-1);
531
		return(-1);
341
	}
532
	}
342
	p=args;
533
	p=args;
343
	*(p++)="-G";
534
	if(uses_pkg) {
535
		*(p++)="/usr/sbin/pkg";
536
		*(p++)="delete";
537
		*(p++)="-y";
538
	}
539
	else {
540
		*(p++)="/usr/sbin/pkg_delete";
541
		*(p++)="-G";
542
	}
344
	for(i=0;i<menulen;i++) {
543
	for(i=0;i<menulen;i++) {
345
		if(menu[i].ITEM_CHECKED) {
544
		if(menu[i].ITEM_CHECKED) {
346
			*(p++)=menu[i].ITEM_PROMPT;
545
			*(p++)=menu[i].ITEM_PROMPT;
Lines 360-367 Link Here
360
		endwin();
559
		endwin();
361
	child=vfork();
560
	child=vfork();
362
	if(child==0) {
561
	if(child==0) {
363
		execve("/usr/sbin/pkg_delete", args, env);
562
		execve(args[0], args, env);
364
		fprintf(stderr,"ERROR: %d!\n",errno);
563
		fprintf(stderr,"ERROR: %d!\n",errno);
564
#ifdef OLD_DIALOG
565
		if(helpfile != -1) {
566
			close(helpfile);
567
			unlink(helpfname);
568
		}
569
#endif
365
		_exit(EXIT_FAILURE);
570
		_exit(EXIT_FAILURE);
366
	}
571
	}
367
	free(args);
572
	free(args);
Lines 375-381 Link Here
375
	/* On an error return, pause */
580
	/* On an error return, pause */
376
	if(WIFSIGNALED(status) || (WIFEXITED(status) && WEXITSTATUS(status))) {
581
	if(WIFSIGNALED(status) || (WIFEXITED(status) && WEXITSTATUS(status))) {
377
		fputs("\n\nPress ENTER to continue... ",stderr);
582
		fputs("\n\nPress ENTER to continue... ",stderr);
378
		fgetln(stdin, &i);
583
		fgetln(stdin, &st);
379
	}
584
	}
380
585
381
	return(0);
586
	return(0);
Lines 391-396 Link Here
391
	return(ret);
596
	return(ret);
392
}
597
}
393
598
599
int glob_packages(void)
600
{
601
	if(uses_pkg) {
602
		FILE	*pkg;
603
		char	*line;
604
		char	*nline;
605
		size_t	len;
606
		int		ret;
607
608
		sl = sl_init();
609
		fflush(stdout);
610
		pkg = popen("/usr/sbin/pkg query \"%n-%v\"", "r");
611
		if(!pkg) {
612
			fputs("Unable to get list of packages\n",stderr);
613
			return EX_OSERR;
614
		}
615
		while((line = fgetln(pkg, &len))!=NULL) {
616
			if(len > 0 && line[len-1]=='\n')
617
				len--;
618
			nline = strndup(line, len);
619
			if(!nline) {
620
				fprintf(stderr, "Unable allocate memory for \"%.*s\" to list\n", (int)len, line);
621
				return EX_UNAVAILABLE;
622
			}
623
			if(sl_add(sl, nline)) {
624
				fprintf(stderr, "Unable to add package \"%s\" to list\n", nline);
625
				return EX_UNAVAILABLE;
626
			}
627
		}
628
		ret = pclose(pkg);
629
		if(WEXITSTATUS(ret)) {
630
			fprintf(stderr, "pkg exited with error %d\n", WEXITSTATUS(ret));
631
			return WEXITSTATUS(ret);
632
		}
633
634
		pathc = sl->sl_cur;
635
		pathv = sl->sl_str;
636
	}
637
	else {
638
		/* glob() package directories */
639
		if(glob("/var/db/pkg/*", GLOB_ERR, NULL, &gl)) {
640
			fputs("Unable to get list of packages\n",stderr);
641
			switch(errno) {
642
				case GLOB_NOSPACE:
643
					return(EX_UNAVAILABLE);
644
				case GLOB_ABORTED:
645
					return(EX_NOINPUT);
646
				case GLOB_NOMATCH:
647
					return(EX_NOINPUT);
648
			}
649
			return(EXIT_FAILURE);
650
		}
651
		pathc = gl.gl_pathc;
652
		pathv = gl.gl_pathv;
653
	}
654
	return 0;
655
}
656
394
/*
657
/*
395
 * The hash table is to keep track of leaves which  have already been displayed
658
 * The hash table is to keep track of leaves which  have already been displayed
396
 * to the user.
659
 * to the user.
Lines 397-433 Link Here
397
 */
660
 */
398
int main(int argc, char **argv)
661
int main(int argc, char **argv)
399
{
662
{
400
	char		**pathv;
663
	int			i;
401
	struct stat	sb;
402
	int			loops=0;
403
664
404
	/* glob() package directories */
665
	uses_pkg = check_pkg();
405
	if(glob("/var/db/pkg/*", GLOB_ERR, NULL, &gl)) {
406
		fputs("Unable to get list of packages\n",stderr);
407
		switch(errno) {
408
			case GLOB_NOSPACE:
409
				return(EX_UNAVAILABLE);
410
			case GLOB_ABORTED:
411
				return(EX_NOINPUT);
412
			case GLOB_NOMATCH:
413
				return(EX_NOINPUT);
414
		}
415
		return(EXIT_FAILURE);
416
	}
417
666
418
	if(gl.gl_pathc==0) {
667
	i = glob_packages();
668
	if(i)
669
		return i;
670
671
	if(pathc==0) {
419
		fputs("No packages found.\n",stderr);
672
		fputs("No packages found.\n",stderr);
420
		return(EXIT_FAILURE);
673
		return(EXIT_FAILURE);
421
	}
674
	}
422
675
423
	/* Initialize space for blacklist hash table */
676
	/* Initialize space for blacklist hash table */
424
	if(hcreate(1000)==0) {
677
	if(hcreate(10000)==0) {
425
		fputs("Cannot create hash table.\n",stderr);
678
		fputs("Cannot create hash table.\n",stderr);
426
		return(EX_UNAVAILABLE);
679
		return(EX_UNAVAILABLE);
427
	}
680
	}
428
681
682
	/* Create temp help file for the description when using pkg on 8.x */
683
#ifdef OLD_DIALOG
684
	if(uses_pkg)
685
		helpfile=mkstemp(helpfname);
686
#endif
687
688
	i=0;
429
	do {
689
	do {
430
		if(read_pkglist(loops++))
690
		if(read_pkglist(i++))
431
			break;
691
			break;
432
		if(display_menu())
692
		if(display_menu())
433
			break;
693
			break;
Lines 436-441 Link Here
436
		free_menu();
696
		free_menu();
437
	} while(keep_going());
697
	} while(keep_going());
438
698
699
#ifdef OLD_DIALOG
700
	if(helpfile != -1) {
701
		close(helpfile);
702
		unlink(helpfname);
703
	}
704
#endif
705
439
	fputs("\nProgram Terminated Successfully\n",stderr);
706
	fputs("\nProgram Terminated Successfully\n",stderr);
440
	return(0);
707
	return(0);
441
}
708
}

Return to bug 185435