Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 885835
Collapse All | Expand All

(-)a/src/helper/slbt_archive_import.c (-101 / +5 lines)
Lines 21-82 Link Here
21
#include "slibtool_readlink_impl.h"
21
#include "slibtool_readlink_impl.h"
22
#include "slibtool_errinfo_impl.h"
22
#include "slibtool_errinfo_impl.h"
23
23
24
static char * slbt_mri_argument(
25
	int	fdat,
26
	char *	arg,
27
	char *	buf)
28
{
29
	int	i;
30
	char *	lnk;
31
	char *	target;
32
	char 	mricwd[PATH_MAX];
33
	char 	dstbuf[PATH_MAX];
34
35
	if ((!(strchr(arg,'+'))) && (!(strchr(arg,'-'))))
36
		return arg;
37
38
	if (arg[0] == '/')
39
		target = arg;
40
	else {
41
		if (slbt_realpath(fdat,".",O_DIRECTORY,mricwd,sizeof(mricwd)))
42
			return 0;
43
44
		if ((size_t)snprintf(dstbuf,sizeof(dstbuf),"%s/%s",
45
				mricwd,arg) >= sizeof(dstbuf))
46
			return 0;
47
48
		target = dstbuf;
49
	}
50
51
	for (i=0,lnk=0; i<1024 && !lnk; i++) {
52
		if (!(tmpnam(buf)))
53
			return 0;
54
55
		if (!(symlinkat(target,fdat,buf)))
56
			lnk = buf;
57
	}
58
59
	return lnk;
60
}
61
62
static void slbt_archive_import_child(
63
	char *	program,
64
	int	fd[2])
65
{
66
	char *	argv[3];
67
68
	argv[0] = program;
69
	argv[1] = "-M";
70
	argv[2] = 0;
71
72
	close(fd[1]);
73
74
	if (dup2(fd[0],0) == 0)
75
		execvp(program,argv);
76
77
	_exit(EXIT_FAILURE);
78
}
79
80
int slbt_archive_import(
24
int slbt_archive_import(
81
	const struct slbt_driver_ctx *	dctx,
25
	const struct slbt_driver_ctx *	dctx,
82
	struct slbt_exec_ctx *		ectx,
26
	struct slbt_exec_ctx *		ectx,
Lines 86-97 int slbt_archive_import( Link Here
86
	int	fdcwd;
30
	int	fdcwd;
87
	pid_t	pid;
31
	pid_t	pid;
88
	pid_t	rpid;
32
	pid_t	rpid;
89
	int	fd[2];
90
	char *	dst;
91
	char *	src;
92
	char *	fmt;
93
	char	mridst [L_tmpnam];
94
	char	mrisrc [L_tmpnam];
95
	char	program[PATH_MAX];
33
	char	program[PATH_MAX];
96
34
97
	/* fdcwd */
35
	/* fdcwd */
Lines 108-163 int slbt_archive_import( Link Here
108
			>= sizeof(program))
46
			>= sizeof(program))
109
		return SLBT_BUFFER_ERROR(dctx);
47
		return SLBT_BUFFER_ERROR(dctx);
110
48
111
	/* fork */
49
	if ((pid = fork()) < 0)
112
	if (pipe(fd))
113
		return SLBT_SYSTEM_ERROR(dctx,0);
50
		return SLBT_SYSTEM_ERROR(dctx,0);
114
51
115
	if ((pid = fork()) < 0) {
116
		close(fd[0]);
117
		close(fd[1]);
118
		return SLBT_SYSTEM_ERROR(dctx,0);
119
	}
120
121
	/* child */
52
	/* child */
122
	if (pid == 0)
53
	if (pid == 0) {
123
		slbt_archive_import_child(
54
		execlp(program, program, "qL", dstarchive, srcarchive, NULL);
124
			program,
55
		_exit(EXIT_FAILURE);
125
			fd);
56
	}
126
57
127
	/* parent */
58
	/* parent */
128
	close(fd[0]);
129
130
	ectx->pid = pid;
59
	ectx->pid = pid;
131
132
	dst = slbt_mri_argument(fdcwd,dstarchive,mridst);
133
	src = slbt_mri_argument(fdcwd,srcarchive,mrisrc);
134
135
	if (!dst || !src)
136
		return SLBT_SYSTEM_ERROR(dctx,0);
137
138
	fmt = "OPEN %s\n"
139
	      "ADDLIB %s\n"
140
	      "SAVE\n"
141
	      "END\n";
142
143
	if (slbt_dprintf(fd[1],fmt,dst,src) < 0) {
144
		close(fd[1]);
145
		return SLBT_SYSTEM_ERROR(dctx,0);
146
	}
147
148
	close(fd[1]);
149
150
	rpid = waitpid(
60
	rpid = waitpid(
151
		pid,
61
		pid,
152
		&ectx->exitcode,
62
		&ectx->exitcode,
153
		0);
63
		0);
154
64
155
	if (dst == mridst)
156
		unlinkat(fdcwd,dst,0);
157
158
	if (src == mrisrc)
159
		unlinkat(fdcwd,src,0);
160
161
	return (rpid == pid) && (ectx->exitcode == 0)
65
	return (rpid == pid) && (ectx->exitcode == 0)
162
		? 0 : SLBT_CUSTOM_ERROR(dctx,SLBT_ERR_ARCHIVE_IMPORT);
66
		? 0 : SLBT_CUSTOM_ERROR(dctx,SLBT_ERR_ARCHIVE_IMPORT);
163
}
67
}

Return to bug 885835